yf-system-cli 1.0.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/README.md +82 -0
- package/bin/cli.js +33 -0
- package/package.json +37 -0
- package/src/commands/init.js +699 -0
- package/src/commands/list.js +27 -0
- package/src/commands/push.js +66 -0
- package/src/commands/remove.js +39 -0
- package/src/config.js +76 -0
- package/src/themes/aaa/package-lock.json +2739 -0
- package/templates/theme/README.md +11 -0
- package/templates/theme/build.js +119 -0
- package/templates/theme/localhost.crt +18 -0
- package/templates/theme/localhost.key +28 -0
- package/templates/theme/package-lock.json +2739 -0
- package/templates/theme/package.json +34 -0
- package/templates/theme/server.js +1723 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/commands/list.js
|
|
2
|
+
const { program } = require("commander");
|
|
3
|
+
const chalk = require("chalk");
|
|
4
|
+
const { getConfig } = require("../config");
|
|
5
|
+
|
|
6
|
+
program
|
|
7
|
+
.command("list")
|
|
8
|
+
.description("列出所有可用模板")
|
|
9
|
+
.action(() => {
|
|
10
|
+
const config = getConfig();
|
|
11
|
+
const templates = config.templates;
|
|
12
|
+
|
|
13
|
+
console.log(chalk.blue.bold("\n📦 可用模板列表:\n"));
|
|
14
|
+
|
|
15
|
+
if (Object.keys(templates).length === 0) {
|
|
16
|
+
console.log(chalk.yellow("暂无自定义模板"));
|
|
17
|
+
console.log(chalk.green("\n内置模板:"));
|
|
18
|
+
console.log(" basic-node - 基础Node.js项目");
|
|
19
|
+
} else {
|
|
20
|
+
Object.entries(templates).forEach(([name, template]) => {
|
|
21
|
+
console.log(chalk.green(` ${name}`));
|
|
22
|
+
console.log(` 📝 ${template.description || "无描述"}`);
|
|
23
|
+
console.log(` 🔗 ${template.repo}`);
|
|
24
|
+
console.log(` 📅 ${new Date(template.createdAt).toLocaleDateString()}\n`);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// src/commands/push.js
|
|
2
|
+
const { program } = require("commander");
|
|
3
|
+
const inquirer = require("inquirer");
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const fs = require("fs-extra");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const simpleGit = require("simple-git");
|
|
8
|
+
const { addTemplate } = require("../config");
|
|
9
|
+
|
|
10
|
+
program
|
|
11
|
+
.command("push <template-name>")
|
|
12
|
+
.description("推送新的模板")
|
|
13
|
+
.option("-r, --repo <repository>", "Git仓库地址")
|
|
14
|
+
.option("-d, --description <description>", "模板描述")
|
|
15
|
+
.option("-l, --local <local-path>", "从本地目录创建模板")
|
|
16
|
+
.action(async (templateName, options) => {
|
|
17
|
+
try {
|
|
18
|
+
let repoUrl = options.repo;
|
|
19
|
+
let description = options.description;
|
|
20
|
+
|
|
21
|
+
// 如果没有提供参数,则交互式输入
|
|
22
|
+
if (!repoUrl && !options.local) {
|
|
23
|
+
const answers = await inquirer.prompt([
|
|
24
|
+
{
|
|
25
|
+
type: "list",
|
|
26
|
+
name: "sourceType",
|
|
27
|
+
message: "选择模板来源:",
|
|
28
|
+
choices: [
|
|
29
|
+
{ name: "Git仓库", value: "git" },
|
|
30
|
+
{ name: "本地目录", value: "local" },
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
type: "input",
|
|
35
|
+
name: "repo",
|
|
36
|
+
message: "输入Git仓库地址 (如: owner/repo 或完整URL):",
|
|
37
|
+
when: (answers) => answers.sourceType === "git",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: "input",
|
|
41
|
+
name: "localPath",
|
|
42
|
+
message: "输入本地目录路径:",
|
|
43
|
+
when: (answers) => answers.sourceType === "local",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
type: "input",
|
|
47
|
+
name: "description",
|
|
48
|
+
message: "输入模板描述:",
|
|
49
|
+
default: "",
|
|
50
|
+
},
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
repoUrl = answers.repo;
|
|
54
|
+
description = answers.description;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (repoUrl) {
|
|
58
|
+
// 如果是Git仓库,直接添加到配置
|
|
59
|
+
const template = addTemplate(templateName, repoUrl, "github", description);
|
|
60
|
+
console.log(chalk.green(`✅ 模板 ${templateName} 添加成功!`));
|
|
61
|
+
console.log(chalk.blue(`仓库: ${template.repo}`));
|
|
62
|
+
}
|
|
63
|
+
} catch (error) {
|
|
64
|
+
console.error(chalk.red("推送失败:"), error.message);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/commands/remove.js
|
|
2
|
+
const { program } = require("commander");
|
|
3
|
+
const inquirer = require("inquirer");
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const { removeTemplate, getConfig } = require("../config");
|
|
6
|
+
|
|
7
|
+
program
|
|
8
|
+
.command("remove <template-name>")
|
|
9
|
+
.description("移除模板")
|
|
10
|
+
.action(async (templateName) => {
|
|
11
|
+
try {
|
|
12
|
+
const config = getConfig();
|
|
13
|
+
|
|
14
|
+
if (!config.templates[templateName]) {
|
|
15
|
+
console.log(chalk.yellow(`模板 ${templateName} 不存在`));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const { confirm } = await inquirer.prompt([
|
|
20
|
+
{
|
|
21
|
+
type: "confirm",
|
|
22
|
+
name: "confirm",
|
|
23
|
+
message: `确定要移除模板 ${templateName} 吗?`,
|
|
24
|
+
default: false,
|
|
25
|
+
},
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
if (confirm) {
|
|
29
|
+
const removed = removeTemplate(templateName);
|
|
30
|
+
if (removed) {
|
|
31
|
+
console.log(chalk.green(`✅ 模板 ${templateName} 移除成功`));
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
console.log(chalk.yellow("已取消移除"));
|
|
35
|
+
}
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error(chalk.red("移除失败:"), error.message);
|
|
38
|
+
}
|
|
39
|
+
});
|
package/src/config.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// src/config.js
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const fs = require("fs-extra");
|
|
4
|
+
const os = require("os");
|
|
5
|
+
|
|
6
|
+
const CONFIG_DIR = path.join(os.homedir(), ".demo-cli");
|
|
7
|
+
const CONFIG_FILE = path.join(CONFIG_DIR, "config.json");
|
|
8
|
+
const TEMPLATE_DIR = path.join(CONFIG_DIR, "templates");
|
|
9
|
+
|
|
10
|
+
// 默认配置
|
|
11
|
+
const defaultConfig = {
|
|
12
|
+
templateRegistry: "https://github.com/{owner}/{repo}",
|
|
13
|
+
templates: {},
|
|
14
|
+
currentRegistry: "github",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// 确保配置目录存在
|
|
18
|
+
const ensureConfig = () => {
|
|
19
|
+
if (!fs.existsSync(CONFIG_DIR)) {
|
|
20
|
+
fs.mkdirpSync(CONFIG_DIR);
|
|
21
|
+
fs.mkdirpSync(TEMPLATE_DIR);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!fs.existsSync(CONFIG_FILE)) {
|
|
25
|
+
fs.writeJsonSync(CONFIG_FILE, defaultConfig);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// 读取配置
|
|
30
|
+
const getConfig = () => {
|
|
31
|
+
ensureConfig();
|
|
32
|
+
return fs.readJsonSync(CONFIG_FILE);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// 更新配置
|
|
36
|
+
const updateConfig = (newConfig) => {
|
|
37
|
+
const config = getConfig();
|
|
38
|
+
const merged = { ...config, ...newConfig };
|
|
39
|
+
fs.writeJsonSync(CONFIG_FILE, merged, { spaces: 2 });
|
|
40
|
+
return merged;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// 添加模板
|
|
44
|
+
const addTemplate = (name, repo, type = "github", description = "") => {
|
|
45
|
+
const config = getConfig();
|
|
46
|
+
config.templates[name] = {
|
|
47
|
+
repo,
|
|
48
|
+
type,
|
|
49
|
+
description,
|
|
50
|
+
createdAt: new Date().toISOString(),
|
|
51
|
+
};
|
|
52
|
+
updateConfig(config);
|
|
53
|
+
return config.templates[name];
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// 移除模板
|
|
57
|
+
const removeTemplate = (name) => {
|
|
58
|
+
const config = getConfig();
|
|
59
|
+
if (config.templates[name]) {
|
|
60
|
+
delete config.templates[name];
|
|
61
|
+
updateConfig(config);
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
module.exports = {
|
|
68
|
+
CONFIG_DIR,
|
|
69
|
+
CONFIG_FILE,
|
|
70
|
+
TEMPLATE_DIR,
|
|
71
|
+
ensureConfig,
|
|
72
|
+
getConfig,
|
|
73
|
+
updateConfig,
|
|
74
|
+
addTemplate,
|
|
75
|
+
removeTemplate,
|
|
76
|
+
};
|