@vitarx/release-cli 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/release.js +22 -8
  2. package/package.json +1 -1
package/dist/release.js CHANGED
@@ -3,6 +3,7 @@ import chalk from 'chalk';
3
3
  import fs from 'node:fs';
4
4
  import path from 'node:path';
5
5
  import process from 'node:process';
6
+ import { fileURLToPath, URL } from 'node:url';
6
7
  import { checkGitStatus, detectPackageManager, formatVersionNumber, getWorkspacePackages, isWorkspaceProject, log, prompt, rollbackChanges, runCommand, selectVersion, updateVersion } from './utils.js';
7
8
  /**
8
9
  * 解析命令行参数
@@ -219,13 +220,13 @@ async function publishPackage(pkgDir, packageManager, isDryRun = false, args) {
219
220
  */
220
221
  export async function main() {
221
222
  const args = parseArgs();
223
+ console.log(chalk.cyan('📦 Release CLI - NPM包发布工具'));
222
224
  // 显示版本信息
223
225
  if (args.showVersion) {
224
- const { version } = JSON.parse(fs.readFileSync(path.join(path.dirname(path.dirname(import.meta.url)), 'package.json'), 'utf-8'));
225
- log.info('release-cli v' + version);
226
+ const { version } = JSON.parse(fs.readFileSync(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf-8'));
227
+ console.log(version);
226
228
  process.exit(0);
227
229
  }
228
- console.log(chalk.cyan('📦 Release CLI - NPM包发布工具'));
229
230
  if (args.showHelp) {
230
231
  console.log('');
231
232
  console.log(chalk.yellow('使用方法:'));
@@ -271,16 +272,29 @@ export async function main() {
271
272
  process.exit(0);
272
273
  }
273
274
  const isDryRun = args.isDryRun;
274
- // 如果有未提交的更改,则报错退出
275
- if (!isDryRun && !checkGitStatus()) {
276
- log.error('请先提交或暂存当前更改再发布。');
277
- process.exit(1);
278
- }
279
275
  const packageManager = detectPackageManager();
280
276
  const isWorkspace = isWorkspaceProject();
281
277
  log.info('当前包管理器', packageManager);
282
278
  log.info('当前工作目录', process.cwd());
283
279
  log.info('当前运行模式', isDryRun ? 'dry-run' : 'publish');
280
+ const isSubmit = checkGitStatus();
281
+ log.info('当前工作目录状态', isSubmit ? '已提交' : '未提交');
282
+ // 如果有未提交的更改,则报错退出
283
+ if (!isDryRun && !isSubmit) {
284
+ log.error('请先提交或暂存当前更改再发布。');
285
+ process.exit(1);
286
+ }
287
+ log.info('检查npm登录状态...↙️');
288
+ try {
289
+ runCommand(`npm whoami --registry https://registry.npmjs.org/`);
290
+ }
291
+ catch (err) {
292
+ if (err?.stderr) {
293
+ log.error(err?.stderr.toString()); // 输出 npm 的错误提示
294
+ }
295
+ log.error('您未登录 npm。请先运行:npm login --registry https://registry.npmjs.org/');
296
+ process.exit(1);
297
+ }
284
298
  if (isWorkspace) {
285
299
  log.info('检测到 workspace 项目');
286
300
  const packages = getWorkspacePackages();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitarx/release-cli",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "A CLI tool for automated npm package release with workspace support",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",