-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from ember-learn/commander
move from minimist to commander
- Loading branch information
Showing
5 changed files
with
539 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,41 @@ | ||
import minimist from 'minimist'; | ||
#!/usr/bin/env node | ||
|
||
import { apiDocsProcessor } from './main.js'; | ||
import { program, Option, InvalidArgumentError } from 'commander'; | ||
import chalk from 'chalk'; | ||
|
||
function semverVersion(value) { | ||
if (!/^\d+\.\d+\.\d+$/.test(value)) { | ||
throw new InvalidArgumentError('Not a correctly defined semver version i.e. major.minor.patch'); | ||
} | ||
return value; | ||
} | ||
|
||
program | ||
.addOption( | ||
new Option('-p, --projects <project...>', 'the projects that you want to run this for') | ||
.choices(['ember', 'ember-data']) | ||
.makeOptionMandatory(), | ||
) | ||
.addOption( | ||
new Option('-v, --version <version>', 'project version', semverVersion).conflicts('all'), | ||
) | ||
.addOption( | ||
new Option('-a, --all', 'process all versions (this will take a long time)').conflicts( | ||
'version', | ||
), | ||
) | ||
.option('-c, --clean', 'clean (not sure what this does)'); | ||
|
||
program.parse(); | ||
|
||
const argv = minimist(process.argv.slice(2)); | ||
const options = program.opts(); | ||
|
||
let possibleProjects = ['ember', 'ember-data']; | ||
let projects = | ||
argv.project && possibleProjects.includes(argv.project) ? [argv.project] : possibleProjects; | ||
let specificDocsVersion = argv.version ? argv.version : ''; | ||
const { projects, version, clean, all } = options; | ||
|
||
let runClean = !!argv.clean; | ||
let noSync = !argv.sync; | ||
if (!version && !all) { | ||
console.log(chalk.red('You need to specify a --version or pass --all to this program')); | ||
process.exit(1); | ||
} | ||
|
||
apiDocsProcessor(projects, specificDocsVersion, runClean, noSync); | ||
apiDocsProcessor(projects, version, clean); |
Oops, something went wrong.