From 017c9dac22e30be3d186353b723784164b635fc2 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Sun, 13 Nov 2022 14:13:41 -0800 Subject: [PATCH] feat: take moduleVersion as a CLI parameter instead of inferring BREAKING CHANGE: The new moduleVersion CLI paramater is required, the module version will no longer be automatically inferred when using the CLI --- src/bin.ts | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/bin.ts b/src/bin.ts index 1648883..f4feedd 100755 --- a/src/bin.ts +++ b/src/bin.ts @@ -15,7 +15,7 @@ const args = minimist(process.argv, { }, }); -const { dir, outDir, useReadme, packageMode, help } = args; +const { dir, outDir, useReadme, packageMode, moduleVersion, help } = args; if (!['single', 'multi'].includes(packageMode)) { console.error(chalk.red('packageMode must be one of "single" and "multi"')); process.exit(1); @@ -35,22 +35,17 @@ if (typeof dir !== 'string') { process.exit(1); } -const resolvedDir = path.isAbsolute(dir) ? dir : path.resolve(process.cwd(), dir); -if (!fs.pathExistsSync(resolvedDir)) { - runner.fail(`${chalk.red('Resolved directory does not exist:')} ${chalk.cyan(resolvedDir)}`); +if (typeof moduleVersion !== 'string') { + runner.fail(chalk.red('Missing required --moduleVersion argument. "--moduleVersion 1.2.3"')); process.exit(1); } -const packageJsonPath = path.resolve(resolvedDir, 'package.json'); -if (!fs.pathExistsSync(packageJsonPath)) { - runner.fail( - `${chalk.red('Expected a package.json file to exist at path:')} ${chalk.cyan(packageJsonPath)}`, - ); +const resolvedDir = path.isAbsolute(dir) ? dir : path.resolve(process.cwd(), dir); +if (!fs.pathExistsSync(resolvedDir)) { + runner.fail(`${chalk.red('Resolved directory does not exist:')} ${chalk.cyan(resolvedDir)}`); process.exit(1); } -const pj = require(packageJsonPath); - const resolvedOutDir = typeof outDir === 'string' ? path.isAbsolute(outDir) @@ -66,7 +61,7 @@ fs.mkdirp(resolvedOutDir).then(() => parseDocs({ useReadme: useReadme ? true : false, baseDirectory: resolvedDir, - moduleVersion: pj.version, + moduleVersion, packageMode, }) .then(data =>