From 169f8429c83f522ec33b0f4accc850738d2e3e7f Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Fri, 24 Jul 2020 13:51:39 +0800 Subject: [PATCH] chore: build script wip --- .npmrc | 1 + 1-easy/2-return-type/README.md | 1 + 1-easy/2-return-type/info.yml | 11 + .../solutions/README.md} | 0 1-easy/2-return-type/solutions/index.ts | 4 + 1-easy/2-return-type/template.ts | 11 + 9-pending/.gitkeep | 0 package.json | 21 +- pnpm-lock.yaml | 217 ++++++++++++++++++ scripts/list.ts | 37 +++ scripts/toUrl.ts | 10 + scripts/types.ts | 29 +++ tsconfig.json | 5 +- utils/tsconfig.json | 2 +- 14 files changed, 344 insertions(+), 5 deletions(-) create mode 100644 .npmrc create mode 100644 1-easy/2-return-type/README.md create mode 100644 1-easy/2-return-type/info.yml rename 1-easy/{.gitkeep => 2-return-type/solutions/README.md} (100%) create mode 100644 1-easy/2-return-type/solutions/index.ts create mode 100644 1-easy/2-return-type/template.ts create mode 100644 9-pending/.gitkeep create mode 100644 scripts/list.ts create mode 100644 scripts/toUrl.ts create mode 100644 scripts/types.ts diff --git a/.npmrc b/.npmrc new file mode 100644 index 000000000..80c4c4f23 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +ignore-workspace-root-check = true \ No newline at end of file diff --git a/1-easy/2-return-type/README.md b/1-easy/2-return-type/README.md new file mode 100644 index 000000000..e9b77534e --- /dev/null +++ b/1-easy/2-return-type/README.md @@ -0,0 +1 @@ +Implement the built-in `ReturnType` generic without using it. \ No newline at end of file diff --git a/1-easy/2-return-type/info.yml b/1-easy/2-return-type/info.yml new file mode 100644 index 000000000..5071b0bac --- /dev/null +++ b/1-easy/2-return-type/info.yml @@ -0,0 +1,11 @@ +title: Hello World + +author: + name: Anthony Fu + email: hi@antfu.me + github: antfu + +tsconfig: null + +original_issues: null +recommended_solutions: null \ No newline at end of file diff --git a/1-easy/.gitkeep b/1-easy/2-return-type/solutions/README.md similarity index 100% rename from 1-easy/.gitkeep rename to 1-easy/2-return-type/solutions/README.md diff --git a/1-easy/2-return-type/solutions/index.ts b/1-easy/2-return-type/solutions/index.ts new file mode 100644 index 000000000..8f46e52c9 --- /dev/null +++ b/1-easy/2-return-type/solutions/index.ts @@ -0,0 +1,4 @@ +type MyReturnType = + T extends (...args: any) => infer R + ? R + : never diff --git a/1-easy/2-return-type/template.ts b/1-easy/2-return-type/template.ts new file mode 100644 index 000000000..e4d541134 --- /dev/null +++ b/1-easy/2-return-type/template.ts @@ -0,0 +1,11 @@ +// your code here + +// type MyReturnType any> = T + +/* _____________ Test Cases _____________ */ +import { expectType, _ } from '@type-challenges/utils' + +expectType(_ as MyReturnType<() => string>) +expectType<123>(_ as MyReturnType<() => 123>) +expectType<{a: [12, 'foo']; bar: 'hello'}>(_ as MyReturnType<() => {a: [12, 'foo']; bar: 'hello'}>) +expectType>(_ as MyReturnType<() => Promise>) diff --git a/9-pending/.gitkeep b/9-pending/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/package.json b/package.json index 47453ae0b..ac3bea6e6 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "type-challenges", "private": true, "version": "0.0.0", + "type": "module", "repository": "https://github.com/antfu/type-challenges.git", "author": "Anthony Fu ", "license": "MIT", @@ -12,14 +13,28 @@ }, "devDependencies": { "@antfu/eslint-config-ts": "^0.2.14", + "@type-challenges/utils": "workspace:*", + "@types/js-yaml": "^3.12.5", + "@types/lz-string": "^1.3.34", + "@types/node": "^14.0.24", + "@typescript-eslint/eslint-plugin": "^3.7.0", "eslint": "^7.5.0", + "fast-glob": "^3.2.4", + "js-yaml": "^3.14.0", + "lz-string": "^1.4.4", "rollup": "^2.22.2", "rollup-plugin-dts": "^1.4.9", "rollup-plugin-typescript2": "^0.27.1", - "typescript": "^3.9.7", - "@type-challenges/utils": "workspace:*" + "ts-node": "^8.10.2", + "typescript": "^3.9.7" }, "eslintConfig": { - "extends": "@antfu/eslint-config-ts" + "extends": "@antfu/eslint-config-ts", + "rules": { + "import/first": "off" + } + }, + "dependencies": { + "utility-types": "^3.10.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4df148b97..0c8d696f3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,21 +1,40 @@ importers: .: + dependencies: + utility-types: 3.10.0 devDependencies: '@antfu/eslint-config-ts': 0.2.14_eslint@7.5.0+typescript@3.9.7 '@type-challenges/utils': 'link:utils' + '@types/js-yaml': 3.12.5 + '@types/lz-string': 1.3.34 + '@types/node': 14.0.24 + '@typescript-eslint/eslint-plugin': 3.7.0_eslint@7.5.0+typescript@3.9.7 eslint: 7.5.0 + fast-glob: 3.2.4 + js-yaml: 3.14.0 + lz-string: 1.4.4 rollup: 2.22.2 rollup-plugin-dts: 1.4.9_rollup@2.22.2+typescript@3.9.7 rollup-plugin-typescript2: 0.27.1_rollup@2.22.2+typescript@3.9.7 + ts-node: 8.10.2_typescript@3.9.7 typescript: 3.9.7 specifiers: '@antfu/eslint-config-ts': ^0.2.14 '@type-challenges/utils': 'workspace:*' + '@types/js-yaml': ^3.12.5 + '@types/lz-string': ^1.3.34 + '@types/node': ^14.0.24 + '@typescript-eslint/eslint-plugin': ^3.7.0 eslint: ^7.5.0 + fast-glob: ^3.2.4 + js-yaml: ^3.14.0 + lz-string: ^1.4.4 rollup: ^2.22.2 rollup-plugin-dts: ^1.4.9 rollup-plugin-typescript2: ^0.27.1 + ts-node: ^8.10.2 typescript: ^3.9.7 + utility-types: ^3.10.0 utils: devDependencies: rollup: 2.22.2 @@ -139,6 +158,30 @@ packages: dev: true resolution: integrity: sha512-ixV66KWfCI6GKoA/2H9v6bQdbfXEwwpOdQ8cRvb4F+eyvhlaHxWFMQB4+3d9QFJXZsiiiqVrewNV0DFEQpyT4Q== + /@nodelib/fs.scandir/2.1.3: + dependencies: + '@nodelib/fs.stat': 2.0.3 + run-parallel: 1.1.9 + dev: true + engines: + node: '>= 8' + resolution: + integrity: sha512-eGmwYQn3gxo4r7jdQnkrrN6bY478C3P+a/y72IJukF8LjB6ZHeB3c+Ehacj3sYeSmUXGlnA67/PmbM9CVwL7Dw== + /@nodelib/fs.stat/2.0.3: + dev: true + engines: + node: '>= 8' + resolution: + integrity: sha512-bQBFruR2TAwoevBEd/NWMoAAtNGzTRgdrqnYCc7dhzfoNvqPzLyqlEQnzZ3kVnNrSp25iyxE00/3h2fqGAGArA== + /@nodelib/fs.walk/1.2.4: + dependencies: + '@nodelib/fs.scandir': 2.1.3 + fastq: 1.8.0 + dev: true + engines: + node: '>= 8' + resolution: + integrity: sha512-1V9XOY4rDW0rehzbrcqAmHnz8e7SKvX27gh8Gt2WgB0+pdzdiLV83p72kZPU+jvMbS1qU5mauP2iOvO8rhmurQ== /@rollup/pluginutils/3.1.0_rollup@2.22.2: dependencies: '@types/estree': 0.0.39 @@ -164,6 +207,10 @@ packages: dev: true resolution: integrity: sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw== + /@types/js-yaml/3.12.5: + dev: true + resolution: + integrity: sha512-JCcp6J0GV66Y4ZMDAQCXot4xprYB+Zfd3meK9+INSJeVZwJmHAW30BBEEkPzXswMXuiyReUGOP3GxrADc9wPww== /@types/json-schema/7.0.5: dev: true resolution: @@ -172,6 +219,14 @@ packages: dev: true resolution: integrity: sha1-7ihweulOEdK4J7y+UnC86n8+ce4= + /@types/lz-string/1.3.34: + dev: true + resolution: + integrity: sha512-j6G1e8DULJx3ONf6NdR5JiR2ZY3K3PaaqiEuKYkLQO0Czfi1AzrtjfnfCROyWGeDd5IVMKCwsgSmMip9OWijow== + /@types/node/14.0.24: + dev: true + resolution: + integrity: sha512-btt/oNOiDWcSuI721MdL8VQGnjsKjlTMdrKyTcLCKeQp/n4AAMFJ961wMbp+09y8WuGPClDEv07RIItdXKIXAA== /@types/normalize-package-data/2.4.0: dev: true resolution: @@ -199,6 +254,28 @@ packages: optional: true resolution: integrity: sha512-06lfjo76naNeOMDl+mWG9Fh/a0UHKLGhin+mGaIw72FUMbMGBkdi/FEJmgEDzh4eE73KIYzHWvOCYJ0ak7nrJQ== + /@typescript-eslint/eslint-plugin/3.7.0_eslint@7.5.0+typescript@3.9.7: + dependencies: + '@typescript-eslint/experimental-utils': 3.7.0_eslint@7.5.0+typescript@3.9.7 + debug: 4.1.1 + eslint: 7.5.0 + functional-red-black-tree: 1.0.1 + regexpp: 3.1.0 + semver: 7.3.2 + tsutils: 3.17.1_typescript@3.9.7 + typescript: 3.9.7 + dev: true + engines: + node: ^10.12.0 || >=12.0.0 + peerDependencies: + '@typescript-eslint/parser': ^3.0.0 + eslint: ^5.0.0 || ^6.0.0 || ^7.0.0 + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + resolution: + integrity: sha512-4OEcPON3QIx0ntsuiuFP/TkldmBGXf0uKxPQlGtS/W2F3ndYm8Vgdpj/woPJkzUc65gd3iR+qi3K8SDQP/obFg== /@typescript-eslint/experimental-utils/3.6.1_eslint@7.5.0+typescript@3.9.7: dependencies: '@types/json-schema': 7.0.5 @@ -223,6 +300,7 @@ packages: eslint: 7.5.0 eslint-scope: 5.1.0 eslint-utils: 2.1.0 + typescript: 3.9.7 dev: true engines: node: ^10.12.0 || >=12.0.0 @@ -380,6 +458,10 @@ packages: node: '>=8' resolution: integrity: sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA== + /arg/4.1.3: + dev: true + resolution: + integrity: sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA== /argparse/1.0.10: dependencies: sprintf-js: 1.0.3 @@ -438,6 +520,18 @@ packages: dev: true resolution: integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA== + /braces/3.0.2: + dependencies: + fill-range: 7.0.1 + dev: true + engines: + node: '>=8' + resolution: + integrity: sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A== + /buffer-from/1.1.1: + dev: true + resolution: + integrity: sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A== /callsites/3.1.0: dev: true engines: @@ -545,6 +639,12 @@ packages: node: '>= 0.4' resolution: integrity: sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ== + /diff/4.0.2: + dev: true + engines: + node: '>=0.3.1' + resolution: + integrity: sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A== /doctrine/1.5.0: dependencies: esutils: 2.0.3 @@ -881,6 +981,19 @@ packages: dev: true resolution: integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q== + /fast-glob/3.2.4: + dependencies: + '@nodelib/fs.stat': 2.0.3 + '@nodelib/fs.walk': 1.2.4 + glob-parent: 5.1.1 + merge2: 1.4.1 + micromatch: 4.0.2 + picomatch: 2.2.2 + dev: true + engines: + node: '>=8' + resolution: + integrity: sha512-kr/Oo6PX51265qeuCYsyGypiO5uJFgBS0jksyG7FUeCyQzNwYnzrNIMR1NXfkZXsMYXYLRAHgISHBz8gQcxKHQ== /fast-json-stable-stringify/2.1.0: dev: true resolution: @@ -889,6 +1002,12 @@ packages: dev: true resolution: integrity: sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc= + /fastq/1.8.0: + dependencies: + reusify: 1.0.4 + dev: true + resolution: + integrity: sha512-SMIZoZdLh/fgofivvIkmknUXyPnvxRE3DhtZ5Me3Mrsk5gyPL42F0xr51TdRXskBxHfMp+07bcYzfsYEsSQA9Q== /file-entry-cache/5.0.1: dependencies: flat-cache: 2.0.1 @@ -897,6 +1016,14 @@ packages: node: '>=4' resolution: integrity: sha512-bCg29ictuBaKUwwArK4ouCaqDgLZcysCFLmM/Yn/FDoqndh/9vNuQfXRDvTuXKLxfD/JtZQGKFT8MGcJBK644g== + /fill-range/7.0.1: + dependencies: + to-regex-range: 5.0.1 + dev: true + engines: + node: '>=8' + resolution: + integrity: sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ== /find-cache-dir/3.3.1: dependencies: commondir: 1.0.1 @@ -1116,6 +1243,12 @@ packages: node: '>=0.10.0' resolution: integrity: sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg== + /is-number/7.0.0: + dev: true + engines: + node: '>=0.12.0' + resolution: + integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng== /is-regex/1.1.0: dependencies: has-symbols: 1.0.1 @@ -1243,6 +1376,11 @@ packages: dev: true resolution: integrity: sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ== + /lz-string/1.4.4: + dev: true + hasBin: true + resolution: + integrity: sha1-wNjq82BZ9wV5bh40SBHPTEmNOiY= /make-dir/3.1.0: dependencies: semver: 6.3.0 @@ -1251,6 +1389,25 @@ packages: node: '>=8' resolution: integrity: sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw== + /make-error/1.3.6: + dev: true + resolution: + integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw== + /merge2/1.4.1: + dev: true + engines: + node: '>= 8' + resolution: + integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg== + /micromatch/4.0.2: + dependencies: + braces: 3.0.2 + picomatch: 2.2.2 + dev: true + engines: + node: '>=8' + resolution: + integrity: sha512-y7FpHSbMUMoyPbYUSzO6PaZ6FyRnQOpHuKwbo1G+Knck95XVU4QAiKdGEnj5wwoS7PlOgthX/09u5iFJ+aYf5Q== /minimatch/3.0.4: dependencies: brace-expansion: 1.1.11 @@ -1576,6 +1733,13 @@ packages: dev: true resolution: integrity: sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w== + /reusify/1.0.4: + dev: true + engines: + iojs: '>=1.0.0' + node: '>=0.10.0' + resolution: + integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw== /rimraf/2.6.3: dependencies: glob: 7.1.6 @@ -1619,6 +1783,10 @@ packages: fsevents: 2.1.3 resolution: integrity: sha512-2a4Mch4f0W2lEvkPuxtz0GfrtfgLj9bdd/oC9L3LozGOCnmLqO7ivMfKbCJoRgqWIU2UqAcbxRFSwmIKx+uStA== + /run-parallel/1.1.9: + dev: true + resolution: + integrity: sha512-DEqnSRTDw/Tc3FXf49zedI638Z9onwUotBMiUFKmrO2sdFKIbXamXGQ3Axd4qgphxKB4kw/qP1w5kTxnfU1B9Q== /safe-regex/2.1.1: dependencies: regexp-tree: 0.1.21 @@ -1666,12 +1834,25 @@ packages: node: '>=6' resolution: integrity: sha512-Qu+VC3EwYLldKa1fCxuuvULvSJOKEgk9pi8dZeCVK7TqBfUNTH4sFkk4joj8afVSfAYgJoSOetjx9QWOJ5mYoQ== + /source-map-support/0.5.19: + dependencies: + buffer-from: 1.1.1 + source-map: 0.6.1 + dev: true + resolution: + integrity: sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw== /source-map/0.5.7: dev: true engines: node: '>=0.10.0' resolution: integrity: sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w= + /source-map/0.6.1: + dev: true + engines: + node: '>=0.10.0' + resolution: + integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== /spdx-correct/3.1.1: dependencies: spdx-expression-parse: 3.0.1 @@ -1787,6 +1968,30 @@ packages: node: '>=4' resolution: integrity: sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4= + /to-regex-range/5.0.1: + dependencies: + is-number: 7.0.0 + dev: true + engines: + node: '>=8.0' + resolution: + integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ== + /ts-node/8.10.2_typescript@3.9.7: + dependencies: + arg: 4.1.3 + diff: 4.0.2 + make-error: 1.3.6 + source-map-support: 0.5.19 + typescript: 3.9.7 + yn: 3.1.1 + dev: true + engines: + node: '>=6.0.0' + hasBin: true + peerDependencies: + typescript: '>=2.7' + resolution: + integrity: sha512-ISJJGgkIpDdBhWVu3jufsWpK3Rzo7bdiIXJjQc0ynKxVOVcg2oIrf2H2cejminGrptVc6q6/uynAHNCuWGbpVA== /tsconfig-paths/3.9.0: dependencies: '@types/json5': 0.0.29 @@ -1854,6 +2059,12 @@ packages: dev: true resolution: integrity: sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ== + /utility-types/3.10.0: + dev: false + engines: + node: '>= 4' + resolution: + integrity: sha512-O11mqxmi7wMKCo6HKFt5AhO4BwY3VV68YU07tgxfz8zJTIxr4BpsezN49Ffwy9j3ZpwwJp4fkRwjRzq3uWE6Rg== /v8-compile-cache/2.1.1: dev: true resolution: @@ -1892,3 +2103,9 @@ packages: node: '>=4' resolution: integrity: sha512-/lg70HAjtkUgWPVZhZcm+T4hkL8Zbtp1nFNOn3lRrxnlv50SRBv7cR7RqR+GMsd3hUXy9hWBo4CHTbFTcOYwig== + /yn/3.1.1: + dev: true + engines: + node: '>=6' + resolution: + integrity: sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q== diff --git a/scripts/list.ts b/scripts/list.ts new file mode 100644 index 000000000..6a6856697 --- /dev/null +++ b/scripts/list.ts @@ -0,0 +1,37 @@ +import path from 'path' +import { promises as fs } from 'fs' +import fg from 'fast-glob' +import YAML from 'js-yaml' +import { Quiz } from './types' + +export async function loadQuizes(): Promise { + const root = path.resolve(__dirname, '..') + const folders = await fg('{0..9}-*/*', { + onlyDirectories: true, + cwd: root, + }) + + const quizes = await Promise.all( + folders.map(async(dir) => { + const quiz: Quiz = { + no: Number(dir.replace(/^.*[\\/](\d+)-.*/, '$1')), + difficulty: dir.replace(/^\d-(.+)[\\/].*$/, '$1') as any, + path: dir, + info: YAML.safeLoad(await fs.readFile(path.join(root, dir, 'info.yml'), 'utf-8')) as any, + readme: await fs.readFile(path.join(root, dir, 'README.md'), 'utf-8'), + template: await fs.readFile(path.join(root, dir, 'template.ts'), 'utf-8'), + tests: await fs.readFile(path.join(root, dir, 'test-cases.ts'), 'utf-8'), + solutions: { + code: await fs.readFile(path.join(root, dir, 'solutions', 'index.ts'), 'utf-8'), + readme: await fs.readFile(path.join(root, dir, 'solutions', 'index.ts'), 'utf-8'), + }, + } + return quiz + }), + ) + + console.log(quizes) + return quizes +} + +loadQuizes() diff --git a/scripts/toUrl.ts b/scripts/toUrl.ts new file mode 100644 index 000000000..740732da6 --- /dev/null +++ b/scripts/toUrl.ts @@ -0,0 +1,10 @@ +import lzs from 'lz-string' + +// https://github.com/microsoft/TypeScript-Website/tree/v2/packages/playground +export function toPlaygroundUrl( + code: string, + config: Object = {}, + site = 'https://www.staging-typescript.org/play', +) { + return `${site}?${Object.entries(config).map(([k, v]) => `${k}=${v}`).join('&')}#code/${lzs.compressToEncodedURIComponent(code)}` +} diff --git a/scripts/types.ts b/scripts/types.ts new file mode 100644 index 000000000..ba85f0a5f --- /dev/null +++ b/scripts/types.ts @@ -0,0 +1,29 @@ +import { DeepPartial } from 'utility-types' + +export interface QuizMetaInfo { + title: string + author: { + name: string + email: string + github: string + } + tsconfig: any + original_issues: number[] + recommended_solutions: number[] +} + +export type Difficulty = 'warm-up' | 'easy' | 'medium' | 'hard' | 'extreme' | 'pending' + +export interface Quiz { + no: number + difficulty: Difficulty + path: string + readme: string + template: string + info?: DeepPartial + tests?: string + solutions?: { + code?: string + readme?: string + } +} diff --git a/tsconfig.json b/tsconfig.json index b84c26ae2..05f824899 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,3 +1,6 @@ { - "extends": "./tsconfig.base.json" + "extends": "./tsconfig.base.json", + "compilerOptions": { + "module": "commonjs" + } } \ No newline at end of file diff --git a/utils/tsconfig.json b/utils/tsconfig.json index da01ddb00..8e8705b08 100644 --- a/utils/tsconfig.json +++ b/utils/tsconfig.json @@ -1,3 +1,3 @@ { - "extends": "../tsconfig.base.json" + "extends": "../tsconfig.base.json", } \ No newline at end of file