@ranger1/dx 0.1.0
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/LICENSE +21 -0
- package/README.md +103 -0
- package/bin/dx-with-version-env.js +8 -0
- package/bin/dx.js +86 -0
- package/lib/backend-package.js +664 -0
- package/lib/cli/args.js +19 -0
- package/lib/cli/commands/core.js +233 -0
- package/lib/cli/commands/db.js +239 -0
- package/lib/cli/commands/deploy.js +76 -0
- package/lib/cli/commands/export.js +34 -0
- package/lib/cli/commands/package.js +22 -0
- package/lib/cli/commands/stack.js +451 -0
- package/lib/cli/commands/start.js +83 -0
- package/lib/cli/commands/worktree.js +149 -0
- package/lib/cli/dx-cli.js +864 -0
- package/lib/cli/flags.js +96 -0
- package/lib/cli/help.js +209 -0
- package/lib/cli/index.js +4 -0
- package/lib/confirm.js +213 -0
- package/lib/env.js +296 -0
- package/lib/exec.js +643 -0
- package/lib/logger.js +188 -0
- package/lib/run-with-version-env.js +173 -0
- package/lib/sdk-build.js +424 -0
- package/lib/start-dev.js +401 -0
- package/lib/telegram-webhook.js +134 -0
- package/lib/validate-env.js +284 -0
- package/lib/vercel-deploy.js +237 -0
- package/lib/worktree.js +1032 -0
- package/package.json +34 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ranger
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# dx
|
|
2
|
+
|
|
3
|
+
一个可安装的 Node.js CLI,用于管理 ai-monorepo 类项目的构建/启动/数据库/部署等流程。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
项目内安装(推荐):
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add -D dx
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
使用:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm exec dx --help
|
|
17
|
+
pnpm exec dx status
|
|
18
|
+
pnpm exec dx build sdk --dev
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
也可以全局安装:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pnpm add -g dx
|
|
25
|
+
dx --help
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## 项目配置(必须)
|
|
29
|
+
|
|
30
|
+
dx 会从当前目录向上查找 `dx/config/commands.json` 来定位项目根目录。
|
|
31
|
+
|
|
32
|
+
你需要在项目根目录提供:
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
dx/
|
|
36
|
+
config/
|
|
37
|
+
commands.json
|
|
38
|
+
env-layers.json
|
|
39
|
+
required-env.jsonc
|
|
40
|
+
local-env-allowlist.jsonc
|
|
41
|
+
exempted-keys.jsonc
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
可选覆盖:
|
|
45
|
+
|
|
46
|
+
- 环境变量:`DX_CONFIG_DIR=/abs/path/to/config`
|
|
47
|
+
- 参数:`dx --config-dir /abs/path/to/config ...`
|
|
48
|
+
|
|
49
|
+
## 命令
|
|
50
|
+
|
|
51
|
+
dx 的命令由 `dx/config/commands.json` 驱动,并且内置了一些 internal runner(避免项目侧依赖任何 `scripts/lib/*.js`):
|
|
52
|
+
|
|
53
|
+
- `internal: sdk-build`:SDK 生成/构建
|
|
54
|
+
- `internal: backend-package`:后端打包
|
|
55
|
+
- `internal: start-dev`:开发环境一键启动
|
|
56
|
+
|
|
57
|
+
常用示例:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
dx start backend --dev
|
|
61
|
+
dx start all
|
|
62
|
+
dx build backend --prod
|
|
63
|
+
dx build sdk --dev
|
|
64
|
+
dx db generate
|
|
65
|
+
dx db migrate --dev --name init
|
|
66
|
+
dx db deploy --prod -Y
|
|
67
|
+
dx deploy front --staging
|
|
68
|
+
dx lint
|
|
69
|
+
dx test e2e backend
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 给 Nx target 注入版本信息(可选)
|
|
73
|
+
|
|
74
|
+
本包提供 `dx-with-version-env`,用于在 `nx:run-commands` 中注入版本/sha/构建时间等环境变量:
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"command": "../../node_modules/.bin/dx-with-version-env --app front -- next build"
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
支持的 app:`backend` / `front` / `admin`。
|
|
83
|
+
|
|
84
|
+
## 约束与假设
|
|
85
|
+
|
|
86
|
+
当前版本面向 ai-monorepo 类结构,默认假设:
|
|
87
|
+
|
|
88
|
+
- 使用 pnpm + nx
|
|
89
|
+
- 项目布局包含 `apps/backend`、`apps/front`、`apps/admin-front`、`apps/sdk`
|
|
90
|
+
|
|
91
|
+
## 发布到 npm(准备工作)
|
|
92
|
+
|
|
93
|
+
如果你准备公开发布:
|
|
94
|
+
|
|
95
|
+
1. 注意:npm 上的包名 `dx` 很可能已被占用;更稳妥的是使用 scope(例如 `@ranger1/dx`)。
|
|
96
|
+
2. 发布前需要把 `package.json` 里的 `private: true` 去掉,并补全 `version` / `license` / `repository` 等字段。
|
|
97
|
+
3. 发布命令(公开包):
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
npm publish --access public --registry=https://registry.npmjs.org
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
提示:当前仓库包含一个 `.npmrc`,用于确保 publish 走 npm 官方 registry(避免镜像源导致发布失败)。
|
package/bin/dx.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { existsSync } from 'node:fs'
|
|
4
|
+
import { resolve, dirname, join } from 'node:path'
|
|
5
|
+
|
|
6
|
+
function parseConfigDir(argv) {
|
|
7
|
+
const envValue = process.env.DX_CONFIG_DIR
|
|
8
|
+
if (envValue) return String(envValue)
|
|
9
|
+
|
|
10
|
+
const args = Array.isArray(argv) ? argv : []
|
|
11
|
+
const idx = args.indexOf('--config-dir')
|
|
12
|
+
if (idx !== -1 && idx + 1 < args.length) return String(args[idx + 1])
|
|
13
|
+
for (const token of args) {
|
|
14
|
+
if (token.startsWith('--config-dir=')) return String(token.slice('--config-dir='.length))
|
|
15
|
+
}
|
|
16
|
+
return null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function stripConfigDirArgs(argv) {
|
|
20
|
+
const args = Array.isArray(argv) ? [...argv] : []
|
|
21
|
+
const out = []
|
|
22
|
+
for (let i = 0; i < args.length; i++) {
|
|
23
|
+
const token = args[i]
|
|
24
|
+
if (token === '--config-dir') {
|
|
25
|
+
i++
|
|
26
|
+
continue
|
|
27
|
+
}
|
|
28
|
+
if (token.startsWith('--config-dir=')) continue
|
|
29
|
+
out.push(token)
|
|
30
|
+
}
|
|
31
|
+
return out
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function findProjectRootFrom(startDir) {
|
|
35
|
+
let current = resolve(startDir)
|
|
36
|
+
while (true) {
|
|
37
|
+
const marker = join(current, 'dx', 'config', 'commands.json')
|
|
38
|
+
if (existsSync(marker)) return current
|
|
39
|
+
|
|
40
|
+
const parent = dirname(current)
|
|
41
|
+
if (parent === current) return null
|
|
42
|
+
current = parent
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function main() {
|
|
47
|
+
const rawArgs = process.argv.slice(2)
|
|
48
|
+
const overrideConfigDir = parseConfigDir(rawArgs)
|
|
49
|
+
const filteredArgs = stripConfigDirArgs(rawArgs)
|
|
50
|
+
|
|
51
|
+
const startDir = process.cwd()
|
|
52
|
+
const projectRoot = findProjectRootFrom(startDir)
|
|
53
|
+
if (!projectRoot) {
|
|
54
|
+
console.error('dx: 未找到项目配置目录: dx/config/commands.json')
|
|
55
|
+
console.error('dx: 请在项目目录内执行 dx,或先创建 dx/config 并放置 commands.json')
|
|
56
|
+
console.error('dx: 也可通过 DX_CONFIG_DIR 或 --config-dir 指定配置目录')
|
|
57
|
+
process.exit(1)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
process.env.DX_PROJECT_ROOT = projectRoot
|
|
61
|
+
|
|
62
|
+
const defaultConfigDir = join(projectRoot, 'dx', 'config')
|
|
63
|
+
process.env.DX_CONFIG_DIR = overrideConfigDir ? resolve(projectRoot, overrideConfigDir) : defaultConfigDir
|
|
64
|
+
|
|
65
|
+
process.chdir(projectRoot)
|
|
66
|
+
|
|
67
|
+
process.argv = [process.argv[0], process.argv[1], ...filteredArgs]
|
|
68
|
+
|
|
69
|
+
const [{ logger }, { DxCli }] = await Promise.all([
|
|
70
|
+
import('../lib/logger.js'),
|
|
71
|
+
import('../lib/cli/dx-cli.js'),
|
|
72
|
+
])
|
|
73
|
+
|
|
74
|
+
const cli = new DxCli({ projectRoot, configDir: process.env.DX_CONFIG_DIR, invocation: 'dx' })
|
|
75
|
+
await cli.run().catch(error => {
|
|
76
|
+
logger.error('CLI启动失败')
|
|
77
|
+
logger.error(error?.message || String(error))
|
|
78
|
+
process.exit(1)
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
main().catch(error => {
|
|
83
|
+
console.error('dx: CLI启动失败')
|
|
84
|
+
console.error(error?.message || String(error))
|
|
85
|
+
process.exit(1)
|
|
86
|
+
})
|