-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use cac instead of mri in all ui-kit CLIs (#2525)
* chore: use cac instead of mri in all ui-kit CLIs * chore: add changeset * chore: use specific version of cac
- Loading branch information
1 parent
928dd81
commit 6e66d69
Showing
13 changed files
with
252 additions
and
258 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@commercetools-local/generator-package-json': minor | ||
'@commercetools-local/generator-readme': minor | ||
--- | ||
|
||
use cac instead of mri for flags parsing |
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,45 +1,42 @@ | ||
#!/usr/bin/env node | ||
|
||
// Do this as the first thing so that any code reading it knows the right env. | ||
process.env.BABEL_ENV = 'development'; | ||
process.env.NODE_ENV = 'development'; | ||
|
||
import type { CommandFlags } from '../src/types'; | ||
|
||
import mri from 'mri'; | ||
import report from 'vfile-reporter'; | ||
import { cac } from 'cac'; | ||
import { generate } from '../src/index'; | ||
|
||
const flags = mri(process.argv.slice(2), { alias: { help: ['h'] } }); | ||
const [pathToPackage] = flags._; | ||
|
||
const dryRun: boolean = flags['dry-run'] ? true : false; | ||
const allWorkspacePackages: boolean = flags['all-workspace-packages'] | ||
? true | ||
: false; | ||
const hasRequiredArguments = allWorkspacePackages || pathToPackage; | ||
|
||
if (flags.help || !hasRequiredArguments) { | ||
console.log(` | ||
Usage: generate-readme [path-to-package] [options] | ||
Displays help information. | ||
[path-to-package] | ||
The path to the package for which the README.md file should be generated. | ||
This assumes that the path is the package folder containing a "package.json". | ||
Options: | ||
--all-workspace-packages (optional) Run the script to all workspace packages. The "path-to-package" option is ignored. | ||
--dry-run (optional) Simulate a run, the generated content will be printed to stdout. | ||
`); | ||
process.exit(0); | ||
} | ||
|
||
const options: CommandFlags = { | ||
dryRun, | ||
allWorkspacePackages, | ||
}; | ||
|
||
generate(pathToPackage, options).catch((error) => { | ||
console.error(report(error)); | ||
process.exit(1); | ||
}); | ||
const cli = cac('generate-readme'); | ||
|
||
cli | ||
.command( | ||
'[path-to-package]', | ||
'The path to the package for which the README.md file should be generated. \nThis assumes that the path is the package folder containing a "package.json".' | ||
) | ||
.option( | ||
'--all-workspace-packages', | ||
'(optional) Run the script to all workspace packages. The "path-to-package" option is ignored.' | ||
) | ||
.option( | ||
'--dry-run', | ||
'(optional) Simulate a run, the generated content will be printed to stdout.' | ||
) | ||
.action((pathToPackage: string, options: CommandFlags) => { | ||
const hasRequiredArguments = options.allWorkspacePackages || pathToPackage; | ||
|
||
if (!hasRequiredArguments) { | ||
cli.outputHelp(); | ||
process.exit(0); | ||
} | ||
|
||
generate(pathToPackage, options).catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); | ||
}); | ||
|
||
cli.help(); | ||
|
||
cli.parse(); |
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
Oops, something went wrong.
6e66d69
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.
Successfully deployed to the following URLs:
ui-kit – ./
ui-kit-five-rho.vercel.app
ui-kit-git-main-commercetools.vercel.app
ui-kit-commercetools.vercel.app
uikit.commercetools.com