@ranger1/dx 0.1.1 → 0.1.2

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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # dx
2
2
 
3
- 一个可安装的 Node.js CLI,用于管理 ai-monorepo 类项目的构建/启动/数据库/部署等流程。
3
+ 一个可安装的 Node.js CLI,用于管理符合约定的 pnpm + nx monorepo 项目的构建/启动/数据库/部署等流程。
4
4
 
5
5
  ## 安装
6
6
 
@@ -76,7 +76,7 @@ dx test e2e backend
76
76
 
77
77
  ```json
78
78
  {
79
- "command": "../../node_modules/.bin/dx-with-version-env --app front -- next build"
79
+ "command": "dx-with-version-env --app front -- next build"
80
80
  }
81
81
  ```
82
82
 
@@ -84,10 +84,11 @@ dx test e2e backend
84
84
 
85
85
  ## 约束与假设
86
86
 
87
- 当前版本面向 ai-monorepo 类结构,默认假设:
87
+ 当前版本面向 pnpm + nx 的 monorepo,默认假设:
88
88
 
89
89
  - 使用 pnpm + nx
90
- - 项目布局包含 `apps/backend`、`apps/front`、`apps/admin-front`、`apps/sdk`
90
+ - 项目布局包含 `apps/backend`、`apps/front`、`apps/admin-front`、`apps/sdk`(如果你的命令配置不依赖这些目录,可自行调整)
91
+ - 版本注入脚本 `dx-with-version-env` 默认支持 app: `backend` / `front` / `admin`
91
92
 
92
93
  ## 发布到 npm(准备工作)
93
94
 
@@ -101,4 +102,3 @@ dx test e2e backend
101
102
  npm publish --access public --registry=https://registry.npmjs.org
102
103
  ```
103
104
 
104
- 提示:当前仓库包含一个 `.npmrc`,用于确保 publish 走 npm 官方 registry(避免镜像源导致发布失败)。
package/lib/cli/dx-cli.js CHANGED
@@ -8,6 +8,7 @@ import { validateEnvironment } from '../validate-env.js'
8
8
  import { FLAG_DEFINITIONS, parseFlags } from './flags.js'
9
9
  import { getCleanArgs } from './args.js'
10
10
  import { showHelp, showCommandHelp } from './help.js'
11
+ import { getPackageVersion } from '../version.js'
11
12
  import {
12
13
  handleHelp,
13
14
  handleDev,
@@ -261,6 +262,11 @@ class DxCli {
261
262
  // 主执行方法
262
263
  async run() {
263
264
  try {
265
+ if (this.flags.version) {
266
+ console.log(getPackageVersion())
267
+ return
268
+ }
269
+
264
270
  // 显示帮助
265
271
  if (this.flags.help || !this.command) {
266
272
  if (this.flags.help && this.command && this.command !== 'help') {
package/lib/cli/flags.js CHANGED
@@ -15,6 +15,8 @@ export const FLAG_DEFINITIONS = {
15
15
  { flag: '--verbose' },
16
16
  { flag: '-h' },
17
17
  { flag: '--help' },
18
+ { flag: '-V' },
19
+ { flag: '--version' },
18
20
  { flag: '--parallel' },
19
21
  { flag: '-P' },
20
22
  ],
@@ -74,6 +76,10 @@ export function parseFlags(args = []) {
74
76
  case '--help':
75
77
  flags.help = true
76
78
  break
79
+ case '-V':
80
+ case '--version':
81
+ flags.version = true
82
+ break
77
83
  case '--no-env-check':
78
84
  flags.noEnvCheck = true
79
85
  break
package/lib/cli/help.js CHANGED
@@ -1,6 +1,9 @@
1
+ import { getPackageVersion } from '../version.js'
2
+
1
3
  export function showHelp() {
4
+ const version = getPackageVersion()
2
5
  console.log(`
3
- DX CLI - 统一开发环境管理工具
6
+ DX CLI v${version} - 统一开发环境管理工具
4
7
 
5
8
  用法:
6
9
  dx <命令> [选项] [参数...]
@@ -67,8 +70,9 @@ DX CLI - 统一开发环境管理工具
67
70
  --test 使用测试环境
68
71
  --e2e 使用E2E测试环境
69
72
  -Y, --yes 跳过所有确认提示
70
- -v, --verbose 详细输出
71
- -h, --help 显示此帮助信息
73
+ -v, --verbose 详细输出
74
+ -h, --help 显示此帮助信息
75
+ -V, --version 显示版本号
72
76
 
73
77
  示例:
74
78
  dx start stack # PM2 交互式服务栈(推荐)- 同时管理三个服务
package/lib/version.js ADDED
@@ -0,0 +1,14 @@
1
+ import { readFileSync } from 'node:fs'
2
+ import { join, dirname } from 'node:path'
3
+ import { fileURLToPath } from 'node:url'
4
+
5
+ export function getPackageVersion() {
6
+ try {
7
+ const here = dirname(fileURLToPath(import.meta.url))
8
+ const pkgPath = join(here, '..', 'package.json')
9
+ const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'))
10
+ return typeof pkg.version === 'string' ? pkg.version : '0.0.0'
11
+ } catch {
12
+ return '0.0.0'
13
+ }
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ranger1/dx",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {