@vultro/cli 0.0.0-stage → 0.0.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 +142 -2
- package/dist/_virtual/_vite/preload-helper.js +102 -0
- package/dist/args.d.ts +75 -0
- package/dist/args.js +169 -0
- package/dist/check.d.ts +44 -0
- package/dist/check.js +295 -0
- package/dist/codegen-content.d.ts +77 -0
- package/dist/codegen-content.js +594 -0
- package/dist/codegen.d.ts +37 -0
- package/dist/codegen.js +115 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +169 -0
- package/dist/mcp.d.ts +91 -0
- package/dist/mcp.js +440 -0
- package/dist/project.d.ts +172 -0
- package/dist/project.js +597 -0
- package/dist/run.d.ts +37 -0
- package/dist/run.js +103 -0
- package/dist/typecheck.d.ts +36 -0
- package/dist/typecheck.js +85 -0
- package/package.json +29 -4
package/dist/run.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
// src/run.ts
|
|
5
|
+
/**
|
|
6
|
+
* `vultro dev` / `vultro build` 的实现。
|
|
7
|
+
*
|
|
8
|
+
* 运行时差异(Cloudflare / Bun / Node)由 `vultro.config.ts` 和
|
|
9
|
+
* `@vultro/vite-plugin` 决定,所以 CLI 只负责在应用根目录启动 Vite:
|
|
10
|
+
*
|
|
11
|
+
* - `dev` → `vite`
|
|
12
|
+
* - `build` → `vite build`
|
|
13
|
+
*
|
|
14
|
+
* 默认使用项目本地安装的 `node_modules/.bin/vite`,其次 `npx --no-install
|
|
15
|
+
* vite`;只有显式设置 `VULTRO_BUN` 时才退回 `bun x vite`。这样 CLI 不需要
|
|
16
|
+
* 依赖 Bun,也避免 `bun x` 临时下载不同版本的 Vite。
|
|
17
|
+
*/
|
|
18
|
+
/** 构造 Vite 参数;`viaBun` 时保留 `bun x vite` 的写法。 */
|
|
19
|
+
function viteArgs(mode, passthrough = [], viaBun = false) {
|
|
20
|
+
const base = mode === "build" ? ["build"] : [];
|
|
21
|
+
return viaBun ? [
|
|
22
|
+
"--bun",
|
|
23
|
+
"x",
|
|
24
|
+
"vite",
|
|
25
|
+
...base,
|
|
26
|
+
...passthrough
|
|
27
|
+
] : [...base, ...passthrough];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 找到包含 Vite / Vultro 配置的应用根目录。
|
|
31
|
+
*
|
|
32
|
+
* 不能用 `findProjectDir`(它要求当前目录链上有 `convex/`):拆分后的
|
|
33
|
+
* play 应用把 `convex/` 放在共享包里,app 自己只有 `vite.config.ts` /
|
|
34
|
+
* `vultro.config.ts`。这里从当前目录向上找这两个文件;找不到时退回
|
|
35
|
+
* 起始目录,让 Vite 自己报错。
|
|
36
|
+
*/
|
|
37
|
+
function findAppDir(start = process.cwd()) {
|
|
38
|
+
const initial = resolve(start);
|
|
39
|
+
let current = initial;
|
|
40
|
+
while (true) {
|
|
41
|
+
if (existsSync(join(current, "vite.config.ts")) || existsSync(join(current, "vite.config.js")) || existsSync(join(current, "vultro.config.ts"))) return current;
|
|
42
|
+
const parent = dirname(current);
|
|
43
|
+
if (parent === current) return initial;
|
|
44
|
+
current = parent;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** 跨平台的可执行文件名后缀。 */
|
|
48
|
+
function binaryName(name) {
|
|
49
|
+
return process.platform === "win32" ? `${name}.cmd` : name;
|
|
50
|
+
}
|
|
51
|
+
/** 从应用目录向上找本地安装的 Vite 可执行文件。 */
|
|
52
|
+
function findLocalVite(startDir) {
|
|
53
|
+
const executable = binaryName("vite");
|
|
54
|
+
let current = resolve(startDir);
|
|
55
|
+
while (true) {
|
|
56
|
+
const candidate = join(current, "node_modules", ".bin", executable);
|
|
57
|
+
if (existsSync(candidate)) return candidate;
|
|
58
|
+
const parent = dirname(current);
|
|
59
|
+
if (parent === current) return void 0;
|
|
60
|
+
current = parent;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** 选择 Vite 启动方式:本地 bin → npx → 显式 Bun。 */
|
|
64
|
+
function viteCommand(rootDir, mode, passthrough, runtime) {
|
|
65
|
+
const bun = {}.VULTRO_BUN ?? (runtime === "bun" ? "bun" : void 0);
|
|
66
|
+
if (bun) return {
|
|
67
|
+
command: bun,
|
|
68
|
+
args: viteArgs(mode, passthrough, true),
|
|
69
|
+
label: `${bun} x vite`
|
|
70
|
+
};
|
|
71
|
+
const local = findLocalVite(rootDir);
|
|
72
|
+
if (local) return {
|
|
73
|
+
command: local,
|
|
74
|
+
args: viteArgs(mode, passthrough),
|
|
75
|
+
label: "vite (local)"
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
command: "npx",
|
|
79
|
+
args: [
|
|
80
|
+
"--no-install",
|
|
81
|
+
"vite",
|
|
82
|
+
...viteArgs(mode, passthrough)
|
|
83
|
+
],
|
|
84
|
+
label: "npx vite"
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** 在应用根目录启动 Vite,并返回退出码。 */
|
|
88
|
+
function runVite(mode, options) {
|
|
89
|
+
const rootDir = findAppDir(options.dir);
|
|
90
|
+
const { command, args, label } = viteCommand(rootDir, mode, options.passthrough, options.runtime);
|
|
91
|
+
return new Promise((resolvePromise, reject) => {
|
|
92
|
+
const child = spawn(command, args, {
|
|
93
|
+
cwd: rootDir,
|
|
94
|
+
stdio: "inherit",
|
|
95
|
+
env: { ...options.runtime ? { VULTRO_RUNTIME: options.runtime } : {} }
|
|
96
|
+
});
|
|
97
|
+
child.on("error", (error) => {
|
|
98
|
+
reject(/* @__PURE__ */ new Error(`无法启动 Vite(${label}):${error.message}。请确认已安装 vite,或设置 VULTRO_BUN 改用 Bun。`));
|
|
99
|
+
});
|
|
100
|
+
child.on("close", (code) => resolvePromise(code ?? 1));
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
export { findAppDir, findLocalVite, runVite, viteArgs, viteCommand };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 调用项目自己的 TypeScript 编译器做类型检查。
|
|
3
|
+
*
|
|
4
|
+
* 优先找项目侧安装的本地 `tsc`(`node_modules/.bin/tsc`),这样 CLI 不需要
|
|
5
|
+
* Bun 也能工作,并且用的是目标项目的 TypeScript 版本与 tsconfig。只有找
|
|
6
|
+
* 不到本地 tsc 时才退回 `bun check --no-script`,保证旧项目仍可用。
|
|
7
|
+
*
|
|
8
|
+
* 为什么不用全局 `tsc`:全局版本可能和项目依赖的 TypeScript 不一致,报错
|
|
9
|
+
* 会更早出现、也更难解释。
|
|
10
|
+
*/
|
|
11
|
+
export interface TypecheckResult {
|
|
12
|
+
ok: boolean;
|
|
13
|
+
/** 项目没有 tsconfig.json 时为 true。 */
|
|
14
|
+
skipped: boolean;
|
|
15
|
+
detail: string;
|
|
16
|
+
diagnostics: string[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 从起始目录向上寻找本地 bin(不过 Node 的 require.resolve,因为有些包
|
|
20
|
+
* 只把可执行文件放进 `.bin`,并未声明为当前项目的直接依赖)。
|
|
21
|
+
*/
|
|
22
|
+
export declare function findLocalBin(startDir: string, name: string): string | undefined;
|
|
23
|
+
/** 类型检查命令及其可读名称,便于错误提示和测试。 */
|
|
24
|
+
export interface TypecheckCommand {
|
|
25
|
+
command: string;
|
|
26
|
+
args: string[];
|
|
27
|
+
label: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 选择类型检查命令:本地 tsc → bun check(兜底)。
|
|
31
|
+
*
|
|
32
|
+
* 显式设置 `VULTRO_BUN` 时优先尊重用户选择的 Bun,方便 CI 复用已有工具链。
|
|
33
|
+
*/
|
|
34
|
+
export declare function typecheckCommand(projectDir: string): TypecheckCommand;
|
|
35
|
+
/** 运行项目类型检查,返回可供 check / codegen 复用的结构化结果。 */
|
|
36
|
+
export declare function runTypecheck(projectDir: string): TypecheckResult;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
// src/typecheck.ts
|
|
6
|
+
/** 跨平台的可执行文件名后缀。 */
|
|
7
|
+
function binaryName(name) {
|
|
8
|
+
return process.platform === "win32" ? `${name}.cmd` : name;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 从起始目录向上寻找本地 bin(不过 Node 的 require.resolve,因为有些包
|
|
12
|
+
* 只把可执行文件放进 `.bin`,并未声明为当前项目的直接依赖)。
|
|
13
|
+
*/
|
|
14
|
+
function findLocalBin(startDir, name) {
|
|
15
|
+
const executable = binaryName(name);
|
|
16
|
+
let current = resolve(startDir);
|
|
17
|
+
while (true) {
|
|
18
|
+
const candidate = join(current, "node_modules", ".bin", executable);
|
|
19
|
+
if (existsSync(candidate)) return candidate;
|
|
20
|
+
const parent = dirname(current);
|
|
21
|
+
if (parent === current) return void 0;
|
|
22
|
+
current = parent;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 选择类型检查命令:本地 tsc → bun check(兜底)。
|
|
27
|
+
*
|
|
28
|
+
* 显式设置 `VULTRO_BUN` 时优先尊重用户选择的 Bun,方便 CI 复用已有工具链。
|
|
29
|
+
*/
|
|
30
|
+
function typecheckCommand(projectDir) {
|
|
31
|
+
if (!{}.VULTRO_BUN) {
|
|
32
|
+
const tsc = findLocalBin(projectDir, "tsc") ?? findLocalBin(dirname(fileURLToPath(import.meta.url)), "tsc");
|
|
33
|
+
if (tsc) return {
|
|
34
|
+
command: tsc,
|
|
35
|
+
args: [
|
|
36
|
+
"-p",
|
|
37
|
+
join(projectDir, "tsconfig.json"),
|
|
38
|
+
"--noEmit",
|
|
39
|
+
"--pretty",
|
|
40
|
+
"false"
|
|
41
|
+
],
|
|
42
|
+
label: "tsc"
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
command: {}.VULTRO_BUN ?? "bun",
|
|
47
|
+
args: ["check", "--no-script"],
|
|
48
|
+
label: "bun check"
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** 运行项目类型检查,返回可供 check / codegen 复用的结构化结果。 */
|
|
52
|
+
function runTypecheck(projectDir) {
|
|
53
|
+
if (!existsSync(join(projectDir, "tsconfig.json"))) return {
|
|
54
|
+
ok: true,
|
|
55
|
+
skipped: true,
|
|
56
|
+
detail: "项目根目录没有 tsconfig.json,跳过类型检查",
|
|
57
|
+
diagnostics: []
|
|
58
|
+
};
|
|
59
|
+
const { command, args, label } = typecheckCommand(projectDir);
|
|
60
|
+
const result = spawnSync(command, args, {
|
|
61
|
+
cwd: projectDir,
|
|
62
|
+
encoding: "utf8",
|
|
63
|
+
maxBuffer: 16777216
|
|
64
|
+
});
|
|
65
|
+
if (result.error) return {
|
|
66
|
+
ok: false,
|
|
67
|
+
skipped: false,
|
|
68
|
+
detail: `无法启动类型检查(${label}):${result.error.message}`,
|
|
69
|
+
diagnostics: []
|
|
70
|
+
};
|
|
71
|
+
const diagnostics = `${result.stdout ?? ""}${result.stderr ?? ""}`.trim().split(/\r?\n/).map((line) => line.trimEnd()).filter((line) => line.length > 0);
|
|
72
|
+
if (result.status === 0) return {
|
|
73
|
+
ok: true,
|
|
74
|
+
skipped: false,
|
|
75
|
+
detail: diagnostics.find((line) => line.includes("No type errors")) ?? `类型检查通过(${label})`,
|
|
76
|
+
diagnostics: []
|
|
77
|
+
};
|
|
78
|
+
return {
|
|
79
|
+
ok: false,
|
|
80
|
+
skipped: false,
|
|
81
|
+
detail: `类型检查失败(${label},退出码 ${result.status ?? "unknown"})`,
|
|
82
|
+
diagnostics: diagnostics.slice(0, 40)
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export { findLocalBin, runTypecheck, typecheckCommand };
|
package/package.json
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vultro/cli",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Vultro CLI: codegen and project checks for @vultro/core apps",
|
|
6
|
+
"bin": {
|
|
7
|
+
"vultro": "./dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"exports": {
|
|
10
|
+
"./package.json": "./package.json",
|
|
11
|
+
"./args": {
|
|
12
|
+
"types": "./dist/args.d.ts",
|
|
13
|
+
"import": "./dist/args.js",
|
|
14
|
+
"default": "./dist/args.js"
|
|
15
|
+
},
|
|
16
|
+
"./codegen": {
|
|
17
|
+
"types": "./dist/codegen.d.ts",
|
|
18
|
+
"import": "./dist/codegen.js",
|
|
19
|
+
"default": "./dist/codegen.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
24
|
+
"@vultro/core": "0.0.2",
|
|
25
|
+
"convex": "^1.51.0",
|
|
26
|
+
"zod": "^4.6.7"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
}
|
|
31
|
+
}
|