-
Notifications
You must be signed in to change notification settings - Fork 0
config file support in ecp, local & validate modes #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,24 +13,20 @@ function docworks() { | |
| process.exit(1) | ||
| } | ||
|
|
||
| let command = process.argv[2] | ||
| const command = process.argv[2] | ||
| const cliArgs = process.argv.slice(3) | ||
|
|
||
| if (command === 'ecp') { | ||
| ecp() | ||
| } | ||
| else if (command === 'validate' || command === 'val') { | ||
| validateCommand() | ||
| } | ||
| else if (command === 'tern') { | ||
| tern() | ||
| } | ||
| else if (command === 'dts') { | ||
| dts() | ||
| } | ||
| else if (command === 'local') { | ||
| ldw() | ||
| } | ||
| else { | ||
| return ecp() | ||
| } else if (command === 'validate' || command === 'val') { | ||
| return validateCommand() | ||
| } else if (command === 'tern') { | ||
| return tern() | ||
| } else if (command === 'dts') { | ||
| return dts() | ||
| } else if (command === 'local') { | ||
| return ldw() | ||
| } else { | ||
| printUsage(1) | ||
| process.exit(1) | ||
| } | ||
|
|
@@ -50,49 +46,52 @@ function docworks() { | |
| /* eslint-enable no-console */ | ||
|
|
||
| function ecp() { | ||
| let argv = optimist | ||
| .usage('Usage: $0 ecp -r [remote repo] [-b [remote branch]] -s [local sources] -p [file pattern] [-ed [enrichment docs directory]] [--plug [plugin]] [--dryrun]') | ||
| .demand('r') | ||
| const commandConfig = optimist | ||
| .usage('Usage: $0 ecp -r [remote repo] [-b [remote branch]] -fs [local sources] -fp [file pattern] [-ed [enrichment docs directory]] [--plug [plugin]] [--dryrun]') | ||
| .alias('r', 'remote') | ||
| .describe('r', 'remote repository to merge docs into') | ||
| .alias('b', 'branch') | ||
| .describe('b', 'branch on the remote repository to work with') | ||
| .demand('fs') | ||
| .alias('fs', 'sources') | ||
| .describe('fs', 'one or more folders containing the source files to extract docs from') | ||
| .alias('fx', 'excludes') | ||
| .describe('fx', 'one or more folders to exclude (including their children) from extracting docs') | ||
| .default('fp', '.+\\.js?$') | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did you remove this default on purpose? |
||
| .alias('fp', 'pattern') | ||
| .describe('fp', 'file pattern, defaults to ".+\\.js$"') | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you did remove it on purpose (see previous comment) then you also need to modify the text here |
||
| .demand('p') | ||
| .alias('p', 'project') | ||
| .describe('p', 'project folder name in the docs repo') | ||
| .describe('ed', 'project enrichment docs relative directory') | ||
| .describe('plug', 'a module name that is a jsdoc or docworks plugin') | ||
| .describe('dryrun', 'dry run - do not push to remote repo') | ||
| .parse(process.argv.slice(3)) | ||
| .describe('config', 'js/json file to load configurations from') | ||
|
|
||
| let remote = argv.remote | ||
| let branch = argv.branch | ||
| let sources = argv.sources | ||
| let excludes = argv.excludes ? (Array.isArray(argv.excludes) ? argv.excludes : [argv.excludes]) : [] | ||
| let pattern = argv.pattern | ||
| let project = argv.project | ||
| let dryrun = !!argv.dryrun | ||
| let enrichmentDocsDir = argv.ed | ||
| let plugins = resolveAndInitPlugins(argv.plug) | ||
| const argv = commandConfig.parse(cliArgs) | ||
|
|
||
| const config = argv.config | ||
| ? Object.assign(require(argv.config), argv) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. config file is assumed to be what? a path to a JS that exports an object? |
||
| : argv | ||
|
|
||
| if (!config.remote || !config.sources || !config.project) { | ||
| commandConfig.showHelp() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To my understanding, this will make the command description pop up, which is why it should be more descriptive |
||
| process.exit(1) | ||
| } | ||
|
|
||
| tmp.dir().then(o => { | ||
| return tmp | ||
| .dir() | ||
| .then(({ path: tmpWorkingDir }) => { | ||
| return extractComparePush({ | ||
| remoteRepo: remote, | ||
| remoteBranch: branch, | ||
| workingDir: o.path, | ||
| projectSubdir: project, | ||
| jsDocSources: {'include': sources, 'includePattern': pattern, 'exclude': excludes}, | ||
| plugins, | ||
| enrichmentDocsDir, | ||
| dryrun | ||
| remoteRepo: config.remote, | ||
| remoteBranch: config.branch, | ||
| workingDir: tmpWorkingDir, | ||
| projectSubdir: config.project, | ||
| jsDocSources: { | ||
| include: config.sources, | ||
| includePattern: config.pattern || '.+\\.js?$', | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I now understand why you removed the default from the |
||
| exclude: [].concat(config.excludes), | ||
| }, | ||
| plugins: resolveAndInitPlugins(config.plug), | ||
| enrichmentDocsDir: config.ed, | ||
| dryrun: !!config.dryrun, | ||
| }) | ||
| }) | ||
| .catch(() => { | ||
|
|
@@ -101,26 +100,38 @@ function docworks() { | |
| } | ||
|
|
||
| function validateCommand() { | ||
| let argv = optimist | ||
| let commandConfig = optimist | ||
| .usage('Usage: $0 validate -fs [local sources] -p [file pattern] -fp [file pattern]') | ||
| .demand('fs') | ||
| .alias('fs', 'sources') | ||
| .describe('fs', 'folder containing the source files to extract docs from') | ||
| .default('fp', '.+\\.js?$') | ||
| .alias('fx', 'excludes') | ||
| .describe('fx', 'one or more folders to exclude (including their children) from extracting docs') | ||
| .alias('fp', 'pattern') | ||
| .describe('fp', 'file pattern, defaults to ".+\\.js$"') | ||
| .alias('plug', 'jsdocplugin') | ||
| .describe('plug', 'a module name that is a jsdoc plugin') | ||
| .parse(process.argv.slice(3)) | ||
| .describe('config', 'js/json file to load configurations from') | ||
|
|
||
| const argv = commandConfig.parse(cliArgs) | ||
|
|
||
| let sources = argv.sources | ||
| let pattern = argv.pattern | ||
| let plugins = resolveAndInitPlugins(argv.jsdocplugin) | ||
| const config = argv.config | ||
| ? Object.assign(require(argv.config), argv) | ||
| : argv | ||
|
|
||
| if (!validate({'include': sources, 'includePattern': pattern}, plugins)) | ||
| if (!config.sources) { | ||
| commandConfig.showHelp() | ||
| process.exit(1) | ||
| } | ||
|
|
||
| const jsDocSources = { | ||
| include: config.sources, | ||
| includePattern: config.pattern || '.+\\.js?$', | ||
| exclude: [].concat(config.excludes), | ||
| } | ||
| const plugins = resolveAndInitPlugins(config.plug) | ||
|
|
||
| if (!validate(jsDocSources, plugins)) process.exit(1) | ||
| } | ||
|
|
||
| function tern() { | ||
| const cmdDefinition = optimist | ||
| .usage('Usage: $0 tern (-r [remote repo] [-b [remote branch]] | -l [local services folder] ) -u [base url] -n [api name] -o [output file]') | ||
|
|
@@ -199,54 +210,54 @@ function docworks() { | |
| } | ||
|
|
||
| function ldw() { | ||
| let argv = optimist | ||
| let commandConfig = optimist | ||
| .usage('Usage: $0 local -r [remote repo] -d [local directory] -fs [local sources] -fp [file pattern] -p [project name] [-ed [enrichment docs directory]] [--plug [plugin]]') | ||
| .demand('r') | ||
| .alias('r', 'remote') | ||
| .describe('r', 'remote repository to merge docs into') | ||
| .alias('b', 'branch') | ||
| .describe('b', 'branch on the remote repository to work with') | ||
| .demand('d') | ||
| .alias('d', 'dist') | ||
| .describe('d', 'local directory to output docs into') | ||
| .demand('fs') | ||
| .alias('fs', 'sources') | ||
| .describe('fs', 'one or more folders containing the source files to extract docs from') | ||
| .alias('fx', 'excludes') | ||
| .describe('fx', 'one or more folders to exclude (including their children) from extracting docs') | ||
| .default('fp', '.+\\.js?$') | ||
| .alias('fp', 'pattern') | ||
| .describe('fp', 'file pattern, defaults to ".+\\.js$"') | ||
| .demand('p') | ||
| .alias('p', 'project') | ||
| .describe('p', 'project folder name in the docs repo') | ||
| .describe('ed', 'project enrichment docs relative directory') | ||
| .describe('plug', 'a module name that is a jsdoc or docworks plugin') | ||
| .parse(process.argv.slice(3)) | ||
| .describe('config', 'js/json file to load configurations from') | ||
|
|
||
| const remote = argv.remote | ||
| const branch = argv.branch | ||
| const dist = argv.dist | ||
| const sources = argv.sources | ||
| const excludes = argv.excludes ? (Array.isArray(argv.excludes) ? argv.excludes : [argv.excludes]) : [] | ||
| const pattern = argv.pattern | ||
| const project = argv.project | ||
| const dryrun = !!argv.dryrun | ||
| const enrichmentDocsDir = argv.ed | ||
| const plugins = resolveAndInitPlugins(argv.plug) | ||
| const argv = commandConfig.parse(cliArgs) | ||
|
|
||
| const config = argv.config | ||
| ? Object.assign(require(argv.config), argv) | ||
| : argv | ||
|
|
||
| if (!config.remote || !config.dist || !config.sources || !config.project) { | ||
| commandConfig.showHelp() | ||
| process.exit(1) | ||
| } | ||
|
|
||
| tmp.dir() | ||
| .then(wd => { | ||
| return tmp | ||
| .dir() | ||
| .then(({ path: tmpWorkingDir }) => { | ||
| return localDocworks({ | ||
| remoteRepo: remote, | ||
| branch, | ||
| outputDirectory: dist, | ||
| tmpDir: wd.path, | ||
| projectDir: project, | ||
| jsDocSources: {'include': sources, 'includePattern': pattern, 'exclude': excludes}, | ||
| plugins, | ||
| enrichmentDocsDir, | ||
| dryrun | ||
| remoteRepo: config.remote, | ||
| branch: config.branch, | ||
| outputDirectory: config.dist, | ||
| tmpDir: tmpWorkingDir, | ||
| projectDir: config.project, | ||
| jsDocSources: { | ||
| include: config.sources, | ||
| includePattern: config.pattern || '.+\\.js?$', | ||
| exclude: [].concat(config.excludes), | ||
| }, | ||
| plugins: resolveAndInitPlugins(config.plug), | ||
| enrichmentDocsDir: config.ed, | ||
| dryrun: !!config.dryrun, | ||
| }) | ||
| }) | ||
| .catch(() => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
according to
https://github.com/substack/node-optimistoptimist is deprecated, it might be worth replacing it already (it won't be a lot of work). Acceptable to do separately IMO.