diff --git a/package-lock.json b/package-lock.json index 9c4f74f..4e94f48 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,18 @@ { "name": "npmize", - "version": "1.0.8", + "version": "1.0.9", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "npmize", - "version": "1.0.8", + "version": "1.0.9", "license": "ISC", "dependencies": { "@babel/parser": "^7.20.7", "ansi-colors": "^4.1.3", "lskit": "^1.0.0", - "noarg": "^3.0.13", + "noarg": "^3.0.17", "shelljs": "^0.8.5" }, "bin": { @@ -644,9 +644,9 @@ } }, "node_modules/noarg": { - "version": "3.0.13", - "resolved": "https://registry.npmjs.org/noarg/-/noarg-3.0.13.tgz", - "integrity": "sha512-XkgASDCF7LDUEWbmWtVeN9kJ5Zl7Ci0bESNUeFP0Y4cQRri2VfD0k6GkDogwW3YyYeKmlBB3k1ZkR8Cq7FTcgA==", + "version": "3.0.17", + "resolved": "https://registry.npmjs.org/noarg/-/noarg-3.0.17.tgz", + "integrity": "sha512-u5ZHOac6odoaabjHv75Lq1swF8QKUBp5z8lfig33dAMKDngcUy6CxQ1cPcrk1orPHkZO8cOp3FeEvfRSCjPVlA==", "dependencies": { "@inquirer/prompts": "^5.3.8", "ansi-colors": "^4.1.3", diff --git a/package.json b/package.json index b211e1e..6dd8ea3 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "@babel/parser": "^7.20.7", "ansi-colors": "^4.1.3", "lskit": "^1.0.0", - "noarg": "^3.0.13", + "noarg": "^3.0.17", "shelljs": "^0.8.5" }, "devDependencies": { diff --git a/src/__lab.ts b/src/__lab.ts index 5127bcc..04bd110 100644 --- a/src/__lab.ts +++ b/src/__lab.ts @@ -2,7 +2,7 @@ console.clear() import app from './main' -app.start(['dev', '-h']) +app.start(['dev', '-h', '--noEmit']) // app.start(['init', '../npmize-test']) // app.start(['dev', '../npmize-test', '--node']) // app.start(['build', '../npmize-test']) diff --git a/src/main.ts b/src/main.ts index 3de0d48..2365470 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,16 +1,17 @@ import path from 'path' import config from './config' import dev from './program/dev' -import NoArg, { t } from 'noarg' +import NoArg from 'noarg' import init from './program/init' import build from './program/build' import tsconfigJSON from './scripts/tsconfigJSON' import { getVersion } from './utils' +import ansiColors from 'ansi-colors' const app = NoArg.create(config.name, { description: config.description, flags: { - version: t.boolean().aliases('v').description('Show the version'), + version: NoArg.boolean().aliases('v').description('Show the version'), }, }).on((_, flags) => { if (flags.version) { @@ -25,8 +26,7 @@ app arguments: [ { name: 'name', - type: t - .string() + type: NoArg.string() .description('Name of the package') .ask("What's the name of the package?") .default('.'), @@ -34,18 +34,25 @@ app ], flags: { - pkg: t.boolean().default(true).description("Write 'package.json'"), - install: t.boolean().default(true).description('Install TypeScript'), - tsconfig: t.boolean().default(true).description('Write "tsconfig.json"'), - demo: t.boolean().default(true).description('Write a sample file'), - workflow: t.boolean().default(true).description('Write a workflow file'), + pkg: NoArg.boolean().default(true).description("Write 'package.json'"), + install: NoArg.boolean().default(true).description('Install TypeScript'), + tsconfig: NoArg.boolean() + .default(true) + .description('Write "tsconfig.json"'), + demo: NoArg.boolean().default(true).description('Write a sample file'), + workflow: NoArg.boolean() + .default(true) + .description('Write a workflow file'), - ignore: t - .boolean() + ignore: NoArg.boolean() .default(true) .description("Write '.gitignore' and '.npmignore'"), - npmignore: t.boolean().default(true).description("Write '.npmignore'"), - gitignore: t.boolean().default(true).description("Write '.gitignore'"), + npmignore: NoArg.boolean() + .default(true) + .description("Write '.npmignore'"), + gitignore: NoArg.boolean() + .default(true) + .description("Write '.gitignore'"), }, }) .on(([nameArg = '.'], flags) => { @@ -61,24 +68,22 @@ app }) }) -const devAndBuild = { +const devAndBuild = NoArg.createConfig({ optionalArguments: [ { name: 'root', - type: t.string().description('Root directory'), + type: NoArg.string().description('Root directory'), }, ], flags: { - module: t - .string('cjs', 'mjs') + module: NoArg.string('cjs', 'mjs') .aliases('m') .description("Output module's type"), - outDir: t.string().aliases('o').description('Output directory'), + outDir: NoArg.string().aliases('o').description('Output directory'), - node: t - .boolean() + node: NoArg.boolean() .aliases('n') .default(false) .description('Enable __dirname and __filename in ES modules'), @@ -86,8 +91,19 @@ const devAndBuild = { config: { enableTrailingArgs: true, + trailingArgsSeparator: '--tsc', }, -} + + notes: [ + `Arguments after "${ansiColors.yellow( + '--tsc' + )}" will be passed to ${ansiColors.yellow('TypeScript')} compiler.`, + + ['--project', '--module', '--outDir', '--watch'] + .map((flag) => ansiColors.yellow(flag)) + .join(', ') + ' and their aliases are ignored.', + ], +}) app .create('dev', { @@ -100,7 +116,7 @@ app ...options, tsc: railingArgs as string[], outDir: options.outDir - ? path.join(rootPath, options.outDir) + ? path.join(rootPath, options.outDir as string) : path.join( rootPath, tsconfigJSON.read(rootPath)?.compilerOptions?.outDir ?? diff --git a/src/program/build.ts b/src/program/build.ts index 4a27c23..f35deac 100644 --- a/src/program/build.ts +++ b/src/program/build.ts @@ -30,7 +30,7 @@ function runBuild( cleanDir(tempDir) tsc(basePath, [ - ...options.tsc.map((tsc) => `--${tsc}`), + ...options.tsc, `--outDir ${tempDir}`, `--module ${moduleType === 'cjs' ? 'commonjs' : 'esnext'}`, ]) diff --git a/src/program/dev.ts b/src/program/dev.ts index 6513840..ea13941 100644 --- a/src/program/dev.ts +++ b/src/program/dev.ts @@ -30,7 +30,7 @@ export default function (basePath: string, options: DevOptions) { tsc( basePath, [ - ...options.tsc.map((tsc) => `--${tsc}`), + ...options.tsc, `--outDir ${tempDir}`, `--module ${options.module === 'cjs' ? 'commonjs' : 'esnext'}`, '--watch', diff --git a/tsconfig.json b/tsconfig.json index f9a97d9..76f0211 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,7 @@ "resolveJsonModule": true, "skipLibCheck": true, "strict": true, - "removeComments": true, + "removeComments": true }, "compileOnSave": false, "include": ["src"]