listpage_cli 0.0.293 → 0.0.294
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/bin/adapters/node-fs-adapter.js +109 -0
- package/bin/app/dispatch.js +15 -0
- package/bin/app/execute.js +33 -0
- package/bin/app/parse-args.js +34 -0
- package/bin/cli.js +55 -74
- package/bin/commands/build-project-command.js +9 -0
- package/bin/commands/init-command.js +9 -0
- package/bin/commands/install-skill-command.js +9 -0
- package/bin/copy.js +14 -126
- package/bin/domain/command-result.js +34 -0
- package/bin/domain/interaction-result.js +14 -0
- package/bin/ports/build-project-command.js +2 -0
- package/bin/ports/filesystem-capability.js +2 -0
- package/bin/ports/fs-port.js +22 -0
- package/bin/ports/init-command.js +2 -0
- package/bin/ports/install-skill-command.js +2 -0
- package/bin/prompts.js +105 -16
- package/bin/services/artifact-validator.js +2 -0
- package/bin/services/build-project-service.js +190 -0
- package/bin/services/command-runner.js +44 -0
- package/bin/services/config-loader.js +113 -0
- package/bin/services/filesystem-capability-service.js +136 -0
- package/bin/services/init-service.js +64 -0
- package/bin/services/install-skill-service.js +34 -0
- package/package.json +6 -4
- package/templates/backend-template/package.json.tmpl +1 -1
- package/templates/frontend-template/package.json.tmpl +2 -2
- package/templates/package-app-template/package.json +1 -1
- package/templates/skills-template/listpage/examples.md +565 -0
- package/skills/listpage/examples.md +0 -243
- package/templates/rush-template/docs/ListPage-AI/347/224/237/346/210/220/350/247/204/350/214/203.md +0 -305
- /package/{skills → templates/skills-template}/listpage/SKILL.md +0 -0
- /package/{skills → templates/skills-template}/listpage/api.md +0 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createNodeFsAdapter = createNodeFsAdapter;
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const os_1 = __importDefault(require("os"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const fs_port_1 = require("../ports/fs-port");
|
|
11
|
+
function createNodeFsAdapter() {
|
|
12
|
+
return {
|
|
13
|
+
cwd: () => process.cwd(),
|
|
14
|
+
homedir: () => os_1.default.homedir(),
|
|
15
|
+
resolve: (...parts) => path_1.default.resolve(...parts),
|
|
16
|
+
join: (...parts) => path_1.default.join(...parts),
|
|
17
|
+
basename: (value) => path_1.default.basename(value),
|
|
18
|
+
dirname: (value) => path_1.default.dirname(value),
|
|
19
|
+
exists: (targetPath) => {
|
|
20
|
+
try {
|
|
21
|
+
return (0, fs_1.existsSync)(targetPath);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
throw toFsPortError("exists", targetPath, error);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
isDirectory: (targetPath) => {
|
|
28
|
+
try {
|
|
29
|
+
return (0, fs_1.statSync)(targetPath).isDirectory();
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
throw toFsPortError("stat", targetPath, error);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
readDir: (targetPath) => {
|
|
36
|
+
try {
|
|
37
|
+
return (0, fs_1.readdirSync)(targetPath);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throw toFsPortError("readDir", targetPath, error);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
ensureDir: (targetPath) => {
|
|
44
|
+
try {
|
|
45
|
+
(0, fs_1.mkdirSync)(targetPath, { recursive: true });
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
throw toFsPortError("ensureDir", targetPath, error);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
copyFile: (sourcePath, targetPath) => {
|
|
52
|
+
try {
|
|
53
|
+
(0, fs_1.copyFileSync)(sourcePath, targetPath);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
throw toFsPortError("copyFile", targetPath, error);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
rename: (sourcePath, targetPath) => {
|
|
60
|
+
try {
|
|
61
|
+
(0, fs_1.renameSync)(sourcePath, targetPath);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
throw toFsPortError("rename", targetPath, error);
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
readText: (targetPath) => {
|
|
68
|
+
try {
|
|
69
|
+
return (0, fs_1.readFileSync)(targetPath, "utf8");
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
throw toFsPortError("readText", targetPath, error);
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
writeText: (targetPath, content) => {
|
|
76
|
+
try {
|
|
77
|
+
(0, fs_1.writeFileSync)(targetPath, content, { encoding: "utf8" });
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
throw toFsPortError("writeText", targetPath, error);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function toFsPortError(operation, targetPath, error) {
|
|
86
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
87
|
+
const nodeCode = getNodeErrnoCode(error);
|
|
88
|
+
const code = mapNodeCodeToFsCode(nodeCode);
|
|
89
|
+
return new fs_port_1.FsPortError(code, operation, targetPath, `[${operation}] ${targetPath}: ${message}`, error);
|
|
90
|
+
}
|
|
91
|
+
function getNodeErrnoCode(error) {
|
|
92
|
+
if (!error || typeof error !== "object") {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
const withCode = error;
|
|
96
|
+
return typeof withCode.code === "string" ? withCode.code : undefined;
|
|
97
|
+
}
|
|
98
|
+
function mapNodeCodeToFsCode(nodeCode) {
|
|
99
|
+
if (nodeCode === "ENOENT" || nodeCode === "ENOTDIR") {
|
|
100
|
+
return fs_port_1.FS_PORT_ERROR_CODES.notFound;
|
|
101
|
+
}
|
|
102
|
+
if (nodeCode === "EACCES" || nodeCode === "EPERM") {
|
|
103
|
+
return fs_port_1.FS_PORT_ERROR_CODES.permissionDenied;
|
|
104
|
+
}
|
|
105
|
+
if (nodeCode === "EINVAL") {
|
|
106
|
+
return fs_port_1.FS_PORT_ERROR_CODES.invalidPath;
|
|
107
|
+
}
|
|
108
|
+
return fs_port_1.FS_PORT_ERROR_CODES.operationFailed;
|
|
109
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dispatchCommand = dispatchCommand;
|
|
4
|
+
const command_result_1 = require("../domain/command-result");
|
|
5
|
+
async function dispatchCommand(input, handlers) {
|
|
6
|
+
const handler = handlers[input.command];
|
|
7
|
+
if (!handler) {
|
|
8
|
+
return (0, command_result_1.commandError)(`命令处理器不存在: ${input.command}`, command_result_1.COMMAND_ERROR_CODES.handlerNotFound, 1);
|
|
9
|
+
}
|
|
10
|
+
const result = await handler(input);
|
|
11
|
+
if (!(0, command_result_1.isCommandResult)(result)) {
|
|
12
|
+
return (0, command_result_1.commandError)(`命令处理器返回非法结果: ${input.command}`, command_result_1.COMMAND_ERROR_CODES.invalidCommandResult, 1);
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeCommand = executeCommand;
|
|
4
|
+
const dispatch_1 = require("./dispatch");
|
|
5
|
+
const parse_args_1 = require("./parse-args");
|
|
6
|
+
const command_result_1 = require("../domain/command-result");
|
|
7
|
+
async function executeCommand(argv, deps) {
|
|
8
|
+
try {
|
|
9
|
+
const parsed = (0, parse_args_1.parseArgs)(argv);
|
|
10
|
+
if (parsed.command === "help") {
|
|
11
|
+
deps.printHelp();
|
|
12
|
+
return (0, command_result_1.commandOk)();
|
|
13
|
+
}
|
|
14
|
+
if (parsed.command === "version") {
|
|
15
|
+
deps.printVersion();
|
|
16
|
+
return (0, command_result_1.commandOk)();
|
|
17
|
+
}
|
|
18
|
+
if (parsed.command === "unknown") {
|
|
19
|
+
return (0, command_result_1.commandError)(`未知命令: ${parsed.unknownCommand ?? ""}`, command_result_1.COMMAND_ERROR_CODES.unknownCommand, 1);
|
|
20
|
+
}
|
|
21
|
+
const dispatchInput = {
|
|
22
|
+
command: parsed.command,
|
|
23
|
+
rawArgs: parsed.rawArgs,
|
|
24
|
+
options: parsed.options,
|
|
25
|
+
positionals: parsed.positionals,
|
|
26
|
+
};
|
|
27
|
+
return await (0, dispatch_1.dispatchCommand)(dispatchInput, deps.handlers);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
31
|
+
return (0, command_result_1.commandError)(message, command_result_1.COMMAND_ERROR_CODES.unexpectedError, 1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseArgs = parseArgs;
|
|
4
|
+
const KNOWN_COMMANDS = new Set(["init", "install-skill", "build-project"]);
|
|
5
|
+
function parseArgs(argv) {
|
|
6
|
+
const rawArgs = [...argv];
|
|
7
|
+
const commandToken = rawArgs[0];
|
|
8
|
+
const options = rawArgs.filter((arg) => arg.startsWith("-"));
|
|
9
|
+
const positionals = rawArgs.slice(1).filter((arg) => !arg.startsWith("-"));
|
|
10
|
+
if (rawArgs.includes("--version") || rawArgs.includes("-V")) {
|
|
11
|
+
return { command: "version", rawArgs, options, positionals };
|
|
12
|
+
}
|
|
13
|
+
if (rawArgs.includes("--help") || rawArgs.includes("-h")) {
|
|
14
|
+
return { command: "help", rawArgs, options, positionals };
|
|
15
|
+
}
|
|
16
|
+
if (!commandToken) {
|
|
17
|
+
return { command: "help", rawArgs, options, positionals };
|
|
18
|
+
}
|
|
19
|
+
if (!KNOWN_COMMANDS.has(commandToken)) {
|
|
20
|
+
return {
|
|
21
|
+
command: "unknown",
|
|
22
|
+
rawArgs,
|
|
23
|
+
options,
|
|
24
|
+
positionals,
|
|
25
|
+
unknownCommand: commandToken,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
command: commandToken,
|
|
30
|
+
rawArgs,
|
|
31
|
+
options,
|
|
32
|
+
positionals,
|
|
33
|
+
};
|
|
34
|
+
}
|
package/bin/cli.js
CHANGED
|
@@ -1,82 +1,63 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
4
|
const prompts_1 = require("./prompts");
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
console.log(`cd ${projectName}`);
|
|
43
|
-
console.log("请手动执行 rush update 安装依赖");
|
|
44
|
-
}
|
|
5
|
+
const execute_1 = require("./app/execute");
|
|
6
|
+
const command_result_1 = require("./domain/command-result");
|
|
7
|
+
const init_command_1 = require("./commands/init-command");
|
|
8
|
+
const install_skill_command_1 = require("./commands/install-skill-command");
|
|
9
|
+
const build_project_command_1 = require("./commands/build-project-command");
|
|
10
|
+
const node_fs_adapter_1 = require("./adapters/node-fs-adapter");
|
|
11
|
+
const filesystem_capability_service_1 = require("./services/filesystem-capability-service");
|
|
12
|
+
const fsAdapter = (0, node_fs_adapter_1.createNodeFsAdapter)();
|
|
13
|
+
const filesystemCapability = (0, filesystem_capability_service_1.createFilesystemCapabilityService)(fsAdapter, {
|
|
14
|
+
templateRootDir: fsAdapter.resolve(__dirname, "..", "templates"),
|
|
15
|
+
});
|
|
16
|
+
const initCommandHandler = (0, init_command_1.createInitCommandHandler)({
|
|
17
|
+
prompts: {
|
|
18
|
+
askProjectPath: prompts_1.askProjectPath,
|
|
19
|
+
askOverwrite: prompts_1.askOverwrite,
|
|
20
|
+
askRushQuestions: prompts_1.askRushQuestions,
|
|
21
|
+
askInstallDeployScript: prompts_1.askInstallDeployScript,
|
|
22
|
+
},
|
|
23
|
+
fs: fsAdapter,
|
|
24
|
+
files: filesystemCapability,
|
|
25
|
+
});
|
|
26
|
+
const installSkillCommandHandler = (0, install_skill_command_1.createInstallSkillCommandHandler)({
|
|
27
|
+
fs: fsAdapter,
|
|
28
|
+
files: filesystemCapability,
|
|
29
|
+
config: {
|
|
30
|
+
getSkillTemplateRoot: () => fsAdapter.join(__dirname, "..", "templates", "skills-template"),
|
|
31
|
+
defaultSkillName: "test",
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
const buildProjectCommandHandler = (0, build_project_command_1.createBuildProjectCommandHandler)({
|
|
35
|
+
fs: fsAdapter,
|
|
36
|
+
});
|
|
45
37
|
async function main() {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (cmd === "install-skill")
|
|
57
|
-
return installSkillCmd();
|
|
58
|
-
(0, prompts_1.printHelp)();
|
|
59
|
-
}
|
|
60
|
-
main();
|
|
61
|
-
async function syncDocsCmd() {
|
|
62
|
-
const execDir = process.cwd();
|
|
63
|
-
const sourceTrae = path_1.default.join(__dirname, "..", "templates", "rush-template", ".trae");
|
|
64
|
-
const sourceDocs = path_1.default.join(__dirname, "..", "templates", "rush-template", "docs");
|
|
65
|
-
const destTrae = path_1.default.join(execDir, ".trae");
|
|
66
|
-
const destDocs = path_1.default.join(execDir, "docs");
|
|
67
|
-
(0, copy_1.syncDirWithRename)(sourceTrae, destTrae);
|
|
68
|
-
(0, copy_1.syncDirWithRename)(sourceDocs, destDocs);
|
|
69
|
-
console.log("已同步 .trae 和 docs 到执行目录的同级目录");
|
|
38
|
+
const result = await (0, execute_1.executeCommand)(process.argv.slice(2), {
|
|
39
|
+
printHelp: prompts_1.printHelp,
|
|
40
|
+
printVersion: prompts_1.printVersion,
|
|
41
|
+
handlers: {
|
|
42
|
+
init: initCommandHandler,
|
|
43
|
+
"install-skill": installSkillCommandHandler,
|
|
44
|
+
"build-project": buildProjectCommandHandler,
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
applyCommandResult(result);
|
|
70
48
|
}
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
49
|
+
main().catch((error) => {
|
|
50
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
51
|
+
applyCommandResult((0, command_result_1.commandError)(message, command_result_1.COMMAND_ERROR_CODES.unexpectedError, 1));
|
|
52
|
+
});
|
|
53
|
+
function applyCommandResult(result) {
|
|
54
|
+
if (result.message) {
|
|
55
|
+
if (result.ok) {
|
|
56
|
+
console.log(result.message);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
console.error(result.message);
|
|
60
|
+
}
|
|
78
61
|
}
|
|
79
|
-
|
|
80
|
-
(0, copy_1.copySkillDir)(sourceDir, targetDir);
|
|
81
|
-
console.log(`已安装 ${skillName} 技能到 ${targetDir}`);
|
|
62
|
+
process.exitCode = result.exitCode;
|
|
82
63
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createBuildProjectCommandHandler = createBuildProjectCommandHandler;
|
|
4
|
+
const build_project_service_1 = require("../services/build-project-service");
|
|
5
|
+
function createBuildProjectCommandHandler(deps) {
|
|
6
|
+
return async (_input) => {
|
|
7
|
+
return (0, build_project_service_1.runBuildProjectFlow)(deps);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createInitCommandHandler = createInitCommandHandler;
|
|
4
|
+
const init_service_1 = require("../services/init-service");
|
|
5
|
+
function createInitCommandHandler(deps) {
|
|
6
|
+
return async (_input) => {
|
|
7
|
+
return (0, init_service_1.runInitFlow)(deps);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createInstallSkillCommandHandler = createInstallSkillCommandHandler;
|
|
4
|
+
const install_skill_service_1 = require("../services/install-skill-service");
|
|
5
|
+
function createInstallSkillCommandHandler(deps) {
|
|
6
|
+
return async (input) => {
|
|
7
|
+
return (0, install_skill_service_1.runInstallSkillFlow)(input, deps);
|
|
8
|
+
};
|
|
9
|
+
}
|
package/bin/copy.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.copyRushTemplate = copyRushTemplate;
|
|
7
4
|
exports.updateRushJsonProjects = updateRushJsonProjects;
|
|
@@ -11,142 +8,33 @@ exports.copyDeployScriptTemplate = copyDeployScriptTemplate;
|
|
|
11
8
|
exports.ensureDir = ensureDir;
|
|
12
9
|
exports.isDirEmpty = isDirEmpty;
|
|
13
10
|
exports.copySkillDir = copySkillDir;
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
11
|
+
const node_fs_adapter_1 = require("./adapters/node-fs-adapter");
|
|
12
|
+
const filesystem_capability_service_1 = require("./services/filesystem-capability-service");
|
|
13
|
+
const fsAdapter = (0, node_fs_adapter_1.createNodeFsAdapter)();
|
|
14
|
+
const filesystemCapability = (0, filesystem_capability_service_1.createFilesystemCapabilityService)(fsAdapter, {
|
|
15
|
+
templateRootDir: fsAdapter.resolve(__dirname, "..", "templates"),
|
|
16
|
+
});
|
|
18
17
|
function copyRushTemplate(targetDir, vars) {
|
|
19
|
-
|
|
20
|
-
copyDir(source, targetDir, vars);
|
|
18
|
+
filesystemCapability.copyRushTemplate(targetDir, vars);
|
|
21
19
|
}
|
|
22
20
|
function updateRushJsonProjects(filepath, feAppName, beAppName) {
|
|
23
|
-
|
|
24
|
-
if (feAppName) {
|
|
25
|
-
projects.push({
|
|
26
|
-
packageName: (0, utils_1.composePkgName)(feAppName),
|
|
27
|
-
projectFolder: `apps/${feAppName}`,
|
|
28
|
-
reviewCategory: "production",
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
if (beAppName) {
|
|
32
|
-
const pkg = (0, utils_1.composePkgName)(beAppName);
|
|
33
|
-
projects.push({
|
|
34
|
-
packageName: pkg,
|
|
35
|
-
projectFolder: `servers/${beAppName}`,
|
|
36
|
-
reviewCategory: "production",
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
const content = (0, fs_1.readFileSync)(filepath, "utf8");
|
|
40
|
-
const json = (0, utils_1.readJsonWithComments)(content);
|
|
41
|
-
json.projects = projects;
|
|
42
|
-
(0, fs_1.writeFileSync)(filepath, JSON.stringify(json, null, 2), { encoding: "utf-8" });
|
|
21
|
+
filesystemCapability.updateRushJsonProjects(filepath, feAppName, beAppName);
|
|
43
22
|
}
|
|
44
23
|
function copyFrontendTemplate(targetDir, vars) {
|
|
45
|
-
|
|
46
|
-
targetDir = path_1.default.join(targetDir, `apps/${appName}`);
|
|
47
|
-
const source = getTemplateDir("frontend");
|
|
48
|
-
copyDir(source, targetDir, vars);
|
|
24
|
+
filesystemCapability.copyFrontendTemplate(targetDir, vars);
|
|
49
25
|
}
|
|
50
26
|
function copyBackendTemplate(targetDir, vars) {
|
|
51
|
-
|
|
52
|
-
targetDir = path_1.default.join(targetDir, `servers/${appName}`);
|
|
53
|
-
const source = getTemplateDir("backend");
|
|
54
|
-
copyDir(source, targetDir, vars);
|
|
27
|
+
filesystemCapability.copyBackendTemplate(targetDir, vars);
|
|
55
28
|
}
|
|
56
29
|
function copyDeployScriptTemplate(targetDir, vars) {
|
|
57
|
-
|
|
58
|
-
const source = getTemplateDir("package-app");
|
|
59
|
-
copyDir(source, targetDir, vars);
|
|
60
|
-
}
|
|
61
|
-
function getTemplateDir(type) {
|
|
62
|
-
return path_1.default.join(__dirname, "..", "templates", `${type}-template`);
|
|
63
|
-
}
|
|
64
|
-
function copyDir(source, destination, vars) {
|
|
65
|
-
ensureDir(destination);
|
|
66
|
-
const files = (0, fs_1.readdirSync)(source);
|
|
67
|
-
files.forEach((file) => {
|
|
68
|
-
const s = path_1.default.join(source, file);
|
|
69
|
-
const d = path_1.default.join(destination, file);
|
|
70
|
-
const stat = (0, fs_1.statSync)(s);
|
|
71
|
-
if (stat.isDirectory()) {
|
|
72
|
-
copyDir(s, d, vars);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
ensureDir(path_1.default.dirname(d));
|
|
76
|
-
const isTmpl = file.endsWith(".tmpl");
|
|
77
|
-
// 正常文件直接复制
|
|
78
|
-
if (!isTmpl) {
|
|
79
|
-
(0, fs_1.copyFileSync)(s, d);
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
// 模板文件替换变量后复制
|
|
83
|
-
const template = (0, fs_1.readFileSync)(s, "utf8");
|
|
84
|
-
const content = compileTemplateContent(template, vars);
|
|
85
|
-
(0, fs_1.writeFileSync)(d.slice(0, -5), content, { encoding: "utf-8" });
|
|
86
|
-
}
|
|
87
|
-
});
|
|
30
|
+
filesystemCapability.copyDeployScriptTemplate(targetDir, vars);
|
|
88
31
|
}
|
|
89
32
|
function ensureDir(dir) {
|
|
90
|
-
|
|
91
|
-
(0, fs_1.mkdirSync)(dir, { recursive: true });
|
|
92
|
-
}
|
|
93
|
-
function compileTemplateContent(str, vars) {
|
|
94
|
-
let out = str;
|
|
95
|
-
for (const [k, v] of Object.entries(vars)) {
|
|
96
|
-
const re = new RegExp(`__${k}__`, "g");
|
|
97
|
-
out = out.replace(re, v);
|
|
98
|
-
}
|
|
99
|
-
return out;
|
|
33
|
+
fsAdapter.ensureDir(dir);
|
|
100
34
|
}
|
|
101
35
|
function isDirEmpty(dir) {
|
|
102
|
-
return
|
|
36
|
+
return filesystemCapability.isDirEmpty(dir);
|
|
103
37
|
}
|
|
104
38
|
function copySkillDir(sourceDir, targetDir) {
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
function syncDirWithRename(source, destination) {
|
|
108
|
-
ensureDir(destination);
|
|
109
|
-
const items = (0, fs_1.readdirSync)(source);
|
|
110
|
-
items.forEach((name) => {
|
|
111
|
-
const s = path_1.default.join(source, name);
|
|
112
|
-
const d = path_1.default.join(destination, name);
|
|
113
|
-
const sStat = (0, fs_1.statSync)(s);
|
|
114
|
-
if (sStat.isDirectory()) {
|
|
115
|
-
if ((0, fs_1.existsSync)(d)) {
|
|
116
|
-
const dStat = (0, fs_1.statSync)(d);
|
|
117
|
-
if (!dStat.isDirectory()) {
|
|
118
|
-
const copyPath = getCopyPath(d);
|
|
119
|
-
(0, fs_1.renameSync)(d, copyPath);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
ensureDir(d);
|
|
123
|
-
syncDirWithRename(s, d);
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
ensureDir(path_1.default.dirname(d));
|
|
127
|
-
if ((0, fs_1.existsSync)(d)) {
|
|
128
|
-
const dStat = (0, fs_1.statSync)(d);
|
|
129
|
-
if (dStat.isFile()) {
|
|
130
|
-
const copyPath = getCopyPath(d);
|
|
131
|
-
(0, fs_1.renameSync)(d, copyPath);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
(0, fs_1.copyFileSync)(s, d);
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
function getCopyPath(filePath) {
|
|
139
|
-
const dir = path_1.default.dirname(filePath);
|
|
140
|
-
const ext = path_1.default.extname(filePath);
|
|
141
|
-
const base = path_1.default.basename(filePath, ext);
|
|
142
|
-
let candidate = path_1.default.join(dir, `${base} copy${ext}`);
|
|
143
|
-
if (!(0, fs_1.existsSync)(candidate))
|
|
144
|
-
return candidate;
|
|
145
|
-
let i = 2;
|
|
146
|
-
while (true) {
|
|
147
|
-
candidate = path_1.default.join(dir, `${base} copy (${i})${ext}`);
|
|
148
|
-
if (!(0, fs_1.existsSync)(candidate))
|
|
149
|
-
return candidate;
|
|
150
|
-
i++;
|
|
151
|
-
}
|
|
39
|
+
filesystemCapability.copySkillDir(sourceDir, targetDir);
|
|
152
40
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.COMMAND_ERROR_CODES = void 0;
|
|
4
|
+
exports.commandOk = commandOk;
|
|
5
|
+
exports.commandError = commandError;
|
|
6
|
+
exports.isCommandResult = isCommandResult;
|
|
7
|
+
exports.COMMAND_ERROR_CODES = {
|
|
8
|
+
unknownCommand: "E_UNKNOWN_COMMAND",
|
|
9
|
+
handlerNotFound: "E_HANDLER_NOT_FOUND",
|
|
10
|
+
invalidCommandResult: "E_INVALID_COMMAND_RESULT",
|
|
11
|
+
userCancelled: "E_USER_CANCELLED",
|
|
12
|
+
invalidInteraction: "E_INVALID_INTERACTION",
|
|
13
|
+
unexpectedError: "E_UNEXPECTED_ERROR",
|
|
14
|
+
skillNotFound: "E_SKILL_NOT_FOUND",
|
|
15
|
+
invalidPath: "E_INVALID_PATH",
|
|
16
|
+
fsOperationFailed: "E_FS_OPERATION_FAILED",
|
|
17
|
+
executionFailed: "E_EXECUTION_FAILED",
|
|
18
|
+
};
|
|
19
|
+
function commandOk(message) {
|
|
20
|
+
return { ok: true, exitCode: 0, message };
|
|
21
|
+
}
|
|
22
|
+
function commandError(message, errorCode, exitCode = 1) {
|
|
23
|
+
return { ok: false, exitCode, message, errorCode };
|
|
24
|
+
}
|
|
25
|
+
function isCommandResult(value) {
|
|
26
|
+
if (!value || typeof value !== "object") {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
const candidate = value;
|
|
30
|
+
return (typeof candidate.ok === "boolean" &&
|
|
31
|
+
typeof candidate.exitCode === "number" &&
|
|
32
|
+
(candidate.message === undefined || typeof candidate.message === "string") &&
|
|
33
|
+
(candidate.errorCode === undefined || typeof candidate.errorCode === "string"));
|
|
34
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.interactionValue = interactionValue;
|
|
4
|
+
exports.interactionCancelled = interactionCancelled;
|
|
5
|
+
exports.interactionInvalid = interactionInvalid;
|
|
6
|
+
function interactionValue(value) {
|
|
7
|
+
return { status: "value", value };
|
|
8
|
+
}
|
|
9
|
+
function interactionCancelled() {
|
|
10
|
+
return { status: "cancelled" };
|
|
11
|
+
}
|
|
12
|
+
function interactionInvalid(reason) {
|
|
13
|
+
return { status: "invalid", reason };
|
|
14
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FsPortError = exports.FS_PORT_ERROR_CODES = void 0;
|
|
4
|
+
exports.FS_PORT_ERROR_CODES = {
|
|
5
|
+
invalidPath: "E_INVALID_PATH",
|
|
6
|
+
permissionDenied: "E_FS_PERMISSION_DENIED",
|
|
7
|
+
notFound: "E_FS_NOT_FOUND",
|
|
8
|
+
operationFailed: "E_FS_OPERATION_FAILED",
|
|
9
|
+
};
|
|
10
|
+
class FsPortError extends Error {
|
|
11
|
+
constructor(code, operation, targetPath, message, cause) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "FsPortError";
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.operation = operation;
|
|
16
|
+
this.targetPath = targetPath;
|
|
17
|
+
if (cause !== undefined) {
|
|
18
|
+
this.cause = cause;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.FsPortError = FsPortError;
|