diff --git a/.gitignore b/.gitignore index fdca830..1f01cff 100644 --- a/.gitignore +++ b/.gitignore @@ -105,3 +105,4 @@ dist # Build build/ +docs/ diff --git a/src/_old/assertions.ts b/_old/assertions.ts similarity index 100% rename from src/_old/assertions.ts rename to _old/assertions.ts diff --git a/src/_old/errors.ts b/_old/errors.ts similarity index 100% rename from src/_old/errors.ts rename to _old/errors.ts diff --git a/src/_old/index.ts b/_old/index.ts similarity index 100% rename from src/_old/index.ts rename to _old/index.ts diff --git a/src/_old/sample.ts b/_old/sample.ts similarity index 100% rename from src/_old/sample.ts rename to _old/sample.ts diff --git a/tests/assertions.test.ts b/_old/tests/assertions.test.ts similarity index 100% rename from tests/assertions.test.ts rename to _old/tests/assertions.test.ts diff --git a/tests/commands.test.ts b/_old/tests/commands.test.ts similarity index 100% rename from tests/commands.test.ts rename to _old/tests/commands.test.ts diff --git a/tests/examples.test.ts b/_old/tests/examples.test.ts similarity index 100% rename from tests/examples.test.ts rename to _old/tests/examples.test.ts diff --git a/tests/extras.test.ts b/_old/tests/extras.test.ts similarity index 100% rename from tests/extras.test.ts rename to _old/tests/extras.test.ts diff --git a/tests/help.test.ts b/_old/tests/help.test.ts similarity index 100% rename from tests/help.test.ts rename to _old/tests/help.test.ts diff --git a/tests/options.test.ts b/_old/tests/options.test.ts similarity index 100% rename from tests/options.test.ts rename to _old/tests/options.test.ts diff --git a/tests/utils.test.ts b/_old/tests/utils.test.ts similarity index 100% rename from tests/utils.test.ts rename to _old/tests/utils.test.ts diff --git a/src/_old/types.ts b/_old/types.ts similarity index 100% rename from src/_old/types.ts rename to _old/types.ts diff --git a/src/_old/utils.ts b/_old/utils.ts similarity index 100% rename from src/_old/utils.ts rename to _old/utils.ts diff --git a/package.json b/package.json index 585c664..d4ffc3f 100644 --- a/package.json +++ b/package.json @@ -15,10 +15,11 @@ "author": "Chen Asraf ", "license": "Apache", "scripts": { - "clean": "rm -rf build", - "build": "echo $(pwd); yarn clean && tsc -p tsconfig.build.json && cp package.json README.md build", - "develop": "tsc --watch", - "test": "jest" + "build": "tsc -p tsconfig.build.json && cp package.json README.md build", + "dev": "tsc --watch", + "example": "ts-node src/example.ts", + "test": "jest", + "docs": "typedoc --out docs src --plugin typedoc-plugin-zod --theme default" }, "devDependencies": { "@types/jest": "^29.5.8", @@ -26,6 +27,8 @@ "jest": "^29.7.0", "ts-jest": "^29.1.1", "ts-node": "^10.9.1", + "typedoc": "^0.25.3", + "typedoc-plugin-zod": "^1.1.0", "typescript": "^5.2.2" }, "dependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0807345..8db2226 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -25,6 +25,12 @@ devDependencies: ts-node: specifier: ^10.9.1 version: 10.9.1(@types/node@20.9.2)(typescript@5.2.2) + typedoc: + specifier: ^0.25.3 + version: 0.25.3(typescript@5.2.2) + typedoc-plugin-zod: + specifier: ^1.1.0 + version: 1.1.0(typedoc@0.25.3) typescript: specifier: ^5.2.2 version: 5.2.2 @@ -779,6 +785,10 @@ packages: engines: {node: '>=8'} dev: true + /ansi-sequence-parser@1.1.1: + resolution: {integrity: sha512-vJXt3yiaUL4UU546s3rPXlsry/RnM730G1+HkpKE012AN0sx1eOrxSu95oKDIonskeLTijMgqWZ3uDEe3NFvyg==} + dev: true + /ansi-styles@3.2.1: resolution: {integrity: sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==} engines: {node: '>=4'} @@ -899,6 +909,12 @@ packages: concat-map: 0.0.1 dev: true + /brace-expansion@2.0.1: + resolution: {integrity: sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==} + dependencies: + balanced-match: 1.0.2 + dev: true + /braces@3.0.2: resolution: {integrity: sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==} engines: {node: '>=8'} @@ -1880,6 +1896,10 @@ packages: hasBin: true dev: true + /jsonc-parser@3.2.0: + resolution: {integrity: sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==} + dev: true + /kleur@3.0.3: resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} engines: {node: '>=6'} @@ -1918,6 +1938,10 @@ packages: yallist: 4.0.0 dev: true + /lunr@2.3.9: + resolution: {integrity: sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow==} + dev: true + /make-dir@4.0.0: resolution: {integrity: sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==} engines: {node: '>=10'} @@ -1935,6 +1959,12 @@ packages: tmpl: 1.0.5 dev: true + /marked@4.3.0: + resolution: {integrity: sha512-PRsaiG84bK+AMvxziE/lCFss8juXjNaWzVbN5tXAm4XjeaS9NAHhop+PjQxz2A9h8Q4M/xGmzP8vqNwy6JeK0A==} + engines: {node: '>= 12'} + hasBin: true + dev: true + /merge-stream@2.0.0: resolution: {integrity: sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==} dev: true @@ -1958,6 +1988,13 @@ packages: brace-expansion: 1.1.11 dev: true + /minimatch@9.0.3: + resolution: {integrity: sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==} + engines: {node: '>=16 || 14 >=14.17'} + dependencies: + brace-expansion: 2.0.1 + dev: true + /ms@2.1.2: resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} dev: true @@ -2156,6 +2193,15 @@ packages: engines: {node: '>=8'} dev: true + /shiki@0.14.5: + resolution: {integrity: sha512-1gCAYOcmCFONmErGTrS1fjzJLA7MGZmKzrBNX7apqSwhyITJg2O102uFzXUeBxNnEkDA9vHIKLyeKq0V083vIw==} + dependencies: + ansi-sequence-parser: 1.1.1 + jsonc-parser: 3.2.0 + vscode-oniguruma: 1.7.0 + vscode-textmate: 8.0.0 + dev: true + /signal-exit@3.0.7: resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==} dev: true @@ -2357,6 +2403,28 @@ packages: engines: {node: '>=10'} dev: true + /typedoc-plugin-zod@1.1.0(typedoc@0.25.3): + resolution: {integrity: sha512-LaQdkYyVVL8CX+4R0GJuOyDa1meiG3M85FiBTPvlikCGaRkTNGSEBZTbx3gQHAsNQ5NWJpLvYJQB6gMhcO8bWw==} + peerDependencies: + typedoc: 0.23.x || 0.24.x || 0.25.x + dependencies: + typedoc: 0.25.3(typescript@5.2.2) + dev: true + + /typedoc@0.25.3(typescript@5.2.2): + resolution: {integrity: sha512-Ow8Bo7uY1Lwy7GTmphRIMEo6IOZ+yYUyrc8n5KXIZg1svpqhZSWgni2ZrDhe+wLosFS8yswowUzljTAV/3jmWw==} + engines: {node: '>= 16'} + hasBin: true + peerDependencies: + typescript: 4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x + dependencies: + lunr: 2.3.9 + marked: 4.3.0 + minimatch: 9.0.3 + shiki: 0.14.5 + typescript: 5.2.2 + dev: true + /typescript@5.2.2: resolution: {integrity: sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==} engines: {node: '>=14.17'} @@ -2391,6 +2459,14 @@ packages: convert-source-map: 2.0.0 dev: true + /vscode-oniguruma@1.7.0: + resolution: {integrity: sha512-L9WMGRfrjOhgHSdOYgCt/yRMsXzLDJSL7BPrOZt73gU0iWO4mpqzqQzOz5srxqTvMBaR0XZTSrVWo4j55Rc6cA==} + dev: true + + /vscode-textmate@8.0.0: + resolution: {integrity: sha512-AFbieoL7a5LMqcnOF04ji+rpXadgOXnZsxQr//r83kLPr7biP7am3g9zbaZIaBGwBRWeSvoMD4mgPdX3e4NWBg==} + dev: true + /walker@1.0.8: resolution: {integrity: sha512-ts/8E8l5b7kY0vlWLewOkDXMmPdLcVV4GmOQLyxuSswIJsweeFZtAsMF7k1Nszz+TYBQrlYRmzOnr398y1JemQ==} dependencies: diff --git a/src/command.ts b/src/command.ts index d177f56..85717b0 100644 --- a/src/command.ts +++ b/src/command.ts @@ -11,14 +11,31 @@ import { setOrPush } from "./utils" export const CommandConfig = (args: RunArgs) => z.object({ + /** Command name */ name: z.string(), + /** Command description, displayed in the help output */ description: z.string(), + /** Command aliases */ aliases: z.string().array().optional(), + /** + * Function used when invoking this command. It receives the parsed options and the primary + * instance of Massarg used to invoke this command (the top-level instance) + */ run: z .function() .args(args, z.any()) .returns(z.union([z.promise(z.void()), z.void()])) as z.ZodType>>, + /** + * Whether to bind the help command to this command + * + * Set this to `true` to automatically add a `help` command to this command's subcommands. + */ bindHelpCommand: z.boolean().optional(), + /** + * Whether to bind the help option to this command + * + * Set this to `true` to automatically add a `--help` option to this command's options. + */ bindHelpOption: z.boolean().optional(), // argsHint: z.string().optional(), }) @@ -138,7 +155,6 @@ export default class MassargCommand { } const defaultOption = this.options.find((o) => o.isDefault) if (defaultOption) { - console.log("Parsing default option") _argv = this.parseOption(`--${defaultOption.name}`, [arg, ..._argv]) continue } @@ -157,7 +173,6 @@ export default class MassargCommand { message: "Unknown option", }) } - console.log("parseOption", [arg, ...argv]) const res = option._parseDetails([arg, ...argv]) this.args[res.key as keyof Args] = setOrPush( res.value, diff --git a/tsconfig.json b/tsconfig.json index f4512f7..219ec5e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -41,7 +41,7 @@ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ /* Module Resolution Options */ - "moduleResolution": "node", // /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + "moduleResolution": "Node16", // /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */