Skip to content

Commit

Permalink
fix(cli): prepublish tagstyle flag (#1863)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Dec 16, 2023
1 parent 9211660 commit 0faf752
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 41 deletions.
55 changes: 29 additions & 26 deletions cli/codegen/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export interface OptionSchema {
description: string
required?: boolean
default?: any
short?: string
short?: string[]
alias?: string[]
long?: string
}

Expand Down Expand Up @@ -42,14 +43,14 @@ const NEW_OPTIONS: CommandSchema = {
type: 'string',
description:
'The name of the project, default to the name of the directory if not provided',
short: 'n',
short: ['n'],
},
{
name: 'minNodeApiVersion',
type: 'number',
description: 'The minimum Node-API version to support',
default: 4,
short: 'v',
short: ['v'],
long: 'min-node-api',
},
// will support it later
Expand All @@ -63,14 +64,14 @@ const NEW_OPTIONS: CommandSchema = {
name: 'license',
type: 'string',
description: 'License for open-sourced project',
short: 'l',
short: ['l'],
default: "'MIT'",
},
{
name: 'targets',
type: 'string[]',
description: 'All targets the crate will be compiled for.',
short: 't',
short: ['t'],
default: '[]',
},
{
Expand Down Expand Up @@ -117,7 +118,7 @@ const BUILD_OPTIONS: CommandSchema = {
type: 'string',
description:
'Build for the target triple, bypassed to `cargo build --target`',
short: 't',
short: ['t'],
},
{
name: 'cwd',
Expand All @@ -134,7 +135,7 @@ const BUILD_OPTIONS: CommandSchema = {
name: 'configPath',
type: 'string',
description: 'Path to `napi` config json file',
short: 'c',
short: ['c'],
},
{
name: 'packageJsonPath',
Expand All @@ -152,7 +153,7 @@ const BUILD_OPTIONS: CommandSchema = {
type: 'string',
description:
'Path to where all the built files would be put. Default to the crate folder',
short: 'o',
short: ['o'],
},
{
name: 'platform',
Expand Down Expand Up @@ -207,19 +208,19 @@ const BUILD_OPTIONS: CommandSchema = {
name: 'strip',
type: 'boolean',
description: 'Whether strip the library to achieve the minimum file size',
short: 's',
short: ['s'],
},
{
name: 'release',
type: 'boolean',
description: 'Build in release mode',
short: 'r',
short: ['r'],
},
{
name: 'verbose',
type: 'boolean',
description: 'Verbosely log build command trace',
short: 'v',
short: ['v'],
},
{
name: 'bin',
Expand All @@ -230,7 +231,7 @@ const BUILD_OPTIONS: CommandSchema = {
name: 'package',
type: 'string',
description: 'Build the specified library or the one at cwd',
short: 'p',
short: ['p'],
},
{
name: 'profile',
Expand All @@ -242,7 +243,7 @@ const BUILD_OPTIONS: CommandSchema = {
type: 'boolean',
description:
'[experimental] cross-compile for the specified target with `cargo-xwin` on windows and `cargo-zigbuild` on other platform',
short: 'x',
short: ['x'],
},
{
name: 'useCross',
Expand All @@ -261,13 +262,13 @@ const BUILD_OPTIONS: CommandSchema = {
type: 'boolean',
description:
'watch the crate changes and build continuously with `cargo-watch` crates',
short: 'w',
short: ['w'],
},
{
name: 'features',
type: 'string[]',
description: 'Space-separated list of features to activate',
short: 'F',
short: ['F'],
},
{
name: 'allFeatures',
Expand Down Expand Up @@ -299,7 +300,7 @@ const ARTIFACTS_OPTIONS: CommandSchema = {
name: 'configPath',
type: 'string',
description: 'Path to `napi` config json file',
short: 'c',
short: ['c'],
},
{
name: 'packageJsonPath',
Expand All @@ -312,7 +313,7 @@ const ARTIFACTS_OPTIONS: CommandSchema = {
type: 'string',
description:
'Path to the folder where all built `.node` files put, same as `--output-dir` of build command',
short: 'o',
short: ['o'],
default: "'./artifacts'",
},
{
Expand Down Expand Up @@ -340,7 +341,7 @@ const CREATE_NPM_DIRS_OPTIONS: CommandSchema = {
name: 'configPath',
type: 'string',
description: 'Path to `napi` config json file',
short: 'c',
short: ['c'],
},
{
name: 'packageJsonPath',
Expand Down Expand Up @@ -379,7 +380,7 @@ const RENAME_OPTIONS: CommandSchema = {
name: 'configPath',
type: 'string',
description: 'Path to `napi` config json file',
short: 'c',
short: ['c'],
},
{
name: 'packageJsonPath',
Expand All @@ -397,13 +398,13 @@ const RENAME_OPTIONS: CommandSchema = {
name: 'name',
type: 'string',
description: 'The new name of the project',
short: 'n',
short: ['n'],
},
{
name: 'binaryName',
type: 'string',
description: 'The new binary name *.node files',
short: 'b',
short: ['b'],
},
{
name: 'packageName',
Expand Down Expand Up @@ -445,7 +446,7 @@ const UNIVERSALIZE_OPTIONS: CommandSchema = {
name: 'configPath',
type: 'string',
description: 'Path to `napi` config json file',
short: 'c',
short: ['c'],
},
{
name: 'packageJsonPath',
Expand All @@ -458,7 +459,7 @@ const UNIVERSALIZE_OPTIONS: CommandSchema = {
type: 'string',
description:
'Path to the folder where all built `.node` files put, same as `--output-dir` of build command',
short: 'o',
short: ['o'],
default: "'./'",
},
],
Expand All @@ -480,7 +481,7 @@ const VERSION_OPTIONS: CommandSchema = {
name: 'configPath',
type: 'string',
description: 'Path to `napi` config json file',
short: 'c',
short: ['c'],
},
{
name: 'packageJsonPath',
Expand Down Expand Up @@ -515,7 +516,7 @@ const PRE_PUBLISH_OPTIONS: CommandSchema = {
name: 'configPath',
type: 'string',
description: 'Path to `napi` config json file',
short: 'c',
short: ['c'],
},
{
name: 'packageJsonPath',
Expand All @@ -528,13 +529,15 @@ const PRE_PUBLISH_OPTIONS: CommandSchema = {
type: 'string',
description: 'Path to the folder where the npm packages put',
default: "'npm'",
short: ['p'],
},
{
name: 'tagStyle',
type: "'npm' | 'lerna'",
description: 'git tag style, `npm` or `lerna`',
default: "'lerna'",
short: 't',
alias: ['tagstyle'],
short: ['t'],
},
{
name: 'ghRelease',
Expand Down
5 changes: 4 additions & 1 deletion cli/codegen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ function generateOptionsDef(command: CommandSchema) {

function getOptionDescriptor(opt: OptionSchema) {
let desc = `--${opt.long ?? kebabCase(opt.name)}`
if (opt.alias) {
desc += `,${opt.alias.map((alias) => `--${alias}`).join(',')}`
}
if (opt.short) {
desc += `,-${opt.short}`
desc += `,${opt.short.map((short) => `-${short}`).join(',')}`
}

return desc
Expand Down
24 changes: 12 additions & 12 deletions cli/docs/pre-publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ new NapiCli().prePublish({

## Options

| Options | CLI Options | type | required | default | description |
| --------------- | ------------------- | ---------------- | -------- | -------------- | ------------------------------------------------------------------------------------------------------------------ |
| | --help,-h | | | | get help |
| cwd | --cwd | string | false | process.cwd() | The working directory of where napi command will be executed in, all other paths options are relative to this path |
| configPath | --config-path,-c | string | false | | Path to `napi` config json file |
| packageJsonPath | --package-json-path | string | false | 'package.json' | Path to `package.json` |
| npmDir | --npm-dir | string | false | 'npm' | Path to the folder where the npm packages put |
| tagStyle | --tag-style,-t | 'npm' \| 'lerna' | false | 'lerna' | git tag style, `npm` or `lerna` |
| ghRelease | --gh-release | boolean | false | true | Whether create GitHub release |
| ghReleaseName | --gh-release-name | string | false | | GitHub release name |
| ghReleaseId | --gh-release-id | string | false | | Existing GitHub release id |
| dryRun | --dry-run | boolean | false | false | Dry run without touching file system |
| Options | CLI Options | type | required | default | description |
| --------------- | ------------------------- | ---------------- | -------- | -------------- | ------------------------------------------------------------------------------------------------------------------ |
| | --help,-h | | | | get help |
| cwd | --cwd | string | false | process.cwd() | The working directory of where napi command will be executed in, all other paths options are relative to this path |
| configPath | --config-path,-c | string | false | | Path to `napi` config json file |
| packageJsonPath | --package-json-path | string | false | 'package.json' | Path to `package.json` |
| npmDir | --npm-dir,-p | string | false | 'npm' | Path to the folder where the npm packages put |
| tagStyle | --tag-style,--tagstyle,-t | 'npm' \| 'lerna' | false | 'lerna' | git tag style, `npm` or `lerna` |
| ghRelease | --gh-release | boolean | false | true | Whether create GitHub release |
| ghReleaseName | --gh-release-name | string | false | | GitHub release name |
| ghReleaseId | --gh-release-id | string | false | | Existing GitHub release id |
| dryRun | --dry-run | boolean | false | false | Dry run without touching file system |
4 changes: 2 additions & 2 deletions cli/src/def/pre-publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export abstract class BasePrePublishCommand extends Command {
description: 'Path to `package.json`',
})

npmDir = Option.String('--npm-dir', 'npm', {
npmDir = Option.String('--npm-dir,-p', 'npm', {
description: 'Path to the folder where the npm packages put',
})

tagStyle = Option.String('--tag-style,-t', 'lerna', {
tagStyle = Option.String('--tag-style,--tagstyle,-t', 'lerna', {
description: 'git tag style, `npm` or `lerna`',
})

Expand Down

0 comments on commit 0faf752

Please sign in to comment.