From f825972b7529212e043db2e111179b3b32812293 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Fri, 15 Dec 2023 22:36:16 +0800 Subject: [PATCH] fix(cli): prepublish command (#1860) --- cli/codegen/commands.ts | 1 + cli/docs/pre-publish.md | 2 +- cli/src/api/pre-publish.ts | 13 ++++++------- cli/src/def/pre-publish.ts | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cli/codegen/commands.ts b/cli/codegen/commands.ts index 33e7bd50..120c8bad 100644 --- a/cli/codegen/commands.ts +++ b/cli/codegen/commands.ts @@ -531,6 +531,7 @@ const PRE_PUBLISH_OPTIONS: CommandSchema = { type: "'npm' | 'lerna'", description: 'git tag style, `npm` or `lerna`', default: "'lerna'", + short: 't', }, { name: 'ghRelease', diff --git a/cli/docs/pre-publish.md b/cli/docs/pre-publish.md index c2a9e059..d47ca9c6 100644 --- a/cli/docs/pre-publish.md +++ b/cli/docs/pre-publish.md @@ -29,7 +29,7 @@ new NapiCli().prePublish({ | 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 | 'npm' \| 'lerna' | false | 'lerna' | git tag style, `npm` or `lerna` | +| 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 | diff --git a/cli/src/api/pre-publish.ts b/cli/src/api/pre-publish.ts index 87d94f5e..1deaccce 100644 --- a/cli/src/api/pre-publish.ts +++ b/cli/src/api/pre-publish.ts @@ -1,6 +1,6 @@ import { execSync } from 'child_process' import { existsSync, statSync } from 'fs' -import { join, relative, resolve } from 'path' +import { join, resolve } from 'path' import { Octokit } from '@octokit/rest' @@ -31,14 +31,13 @@ export async function prePublish(userOptions: PrePublishOptions) { const options = applyDefaultPrePublishOptions(userOptions) - const configPath = relative( - options.cwd, - options.configPath ?? options.packageJsonPath, - ) - const packageJsonPath = relative(options.cwd, options.packageJsonPath) + const packageJsonPath = resolve(options.cwd, options.packageJsonPath) const { packageJson, targets, packageName, binaryName, npmClient } = - await readNapiConfig(configPath, configPath) + await readNapiConfig( + packageJsonPath, + options.configPath ? resolve(options.cwd, options.configPath) : undefined, + ) async function createGhRelease(packageName: string, version: string) { if (!options.ghRelease) { diff --git a/cli/src/def/pre-publish.ts b/cli/src/def/pre-publish.ts index 12098cb8..d2770735 100644 --- a/cli/src/def/pre-publish.ts +++ b/cli/src/def/pre-publish.ts @@ -27,7 +27,7 @@ export abstract class BasePrePublishCommand extends Command { description: 'Path to the folder where the npm packages put', }) - tagStyle = Option.String('--tag-style', 'lerna', { + tagStyle = Option.String('--tag-style,-t', 'lerna', { description: 'git tag style, `npm` or `lerna`', })