Skip to content

Commit

Permalink
feat: take moduleVersion as a CLI parameter instead of inferring
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The new moduleVersion CLI paramater is required, the module version will no longer be automatically inferred when using the CLI
  • Loading branch information
MarshallOfSound committed Nov 13, 2022
1 parent 7c78f6c commit 017c9da
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -66,7 +61,7 @@ fs.mkdirp(resolvedOutDir).then(() =>
parseDocs({
useReadme: useReadme ? true : false,
baseDirectory: resolvedDir,
moduleVersion: pj.version,
moduleVersion,
packageMode,
})
.then(data =>
Expand Down

0 comments on commit 017c9da

Please sign in to comment.