create-done-coding 0.10.3 → 0.11.1-alpha.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/es/cli.mjs +1 -1
- package/es/index-571ddf9e.js +3837 -0
- package/es/index.mjs +1 -1
- package/package.json +6 -6
- package/types/injectInfo.json.d.ts +1 -1
- package/types/utils/types.d.ts +3 -1
- package/es/index-98d8b088.js +0 -197
package/es/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-done-coding",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1-alpha.0",
|
|
4
4
|
"description": "项目创建命令行工具",
|
|
5
5
|
"module": "es/index.mjs",
|
|
6
6
|
"type": "module",
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
"node": ">=18.0.0"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@done-coding/cli-git": "^0.
|
|
52
|
-
"@done-coding/cli-inject": "^0.5.
|
|
53
|
-
"@done-coding/cli-template": "^0.7.
|
|
54
|
-
"@done-coding/cli-utils": "^0.3.
|
|
51
|
+
"@done-coding/cli-git": "^0.5.1-alpha.0",
|
|
52
|
+
"@done-coding/cli-inject": "^0.5.3-alpha.0",
|
|
53
|
+
"@done-coding/cli-template": "^0.7.4-alpha.0",
|
|
54
|
+
"@done-coding/cli-utils": "^0.3.3-alpha.0"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "9b65389752c25c4b7fff7fa8dfd46e5788ef2390"
|
|
57
57
|
}
|
package/types/utils/types.d.ts
CHANGED
package/es/index-98d8b088.js
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { execSync as l } from "node:child_process";
|
|
3
|
-
import g, { resolve as F } from "node:path";
|
|
4
|
-
import u, { existsSync as v, rmSync as f } from "node:fs";
|
|
5
|
-
import { log as r, xPrompts as c, lookForParentTarget as G, createMainCommand as D, createSubcommand as M } from "@done-coding/cli-utils";
|
|
6
|
-
import { getConfigPath as R, batchCompileHandler as A, MODULE_DEFAULT_CONFIG_RELATIVE_PATH as L } from "@done-coding/cli-template";
|
|
7
|
-
import { getTargetRepoUrl as O } from "@done-coding/cli-git";
|
|
8
|
-
const y = {
|
|
9
|
-
name: "create-done-coding",
|
|
10
|
-
version: "0.10.3",
|
|
11
|
-
description: "项目创建命令行工具",
|
|
12
|
-
cliConfig: {
|
|
13
|
-
namespaceDir: ".done-coding",
|
|
14
|
-
moduleName: "create"
|
|
15
|
-
}
|
|
16
|
-
}, w = "git@gitee.com:justsosu/done-coding-cli-config-json.git", C = "自定义模版路径", j = "某个git平台用户仓库", S = `./.${y.name}_temp`;
|
|
17
|
-
let $;
|
|
18
|
-
const I = async () => ($ || ($ = (await Y()).templateList), $), E = async () => [
|
|
19
|
-
...await I(),
|
|
20
|
-
{ name: C },
|
|
21
|
-
{ name: j }
|
|
22
|
-
], b = {
|
|
23
|
-
type: "text",
|
|
24
|
-
name: "projectName",
|
|
25
|
-
message: "请输入项目名称",
|
|
26
|
-
format: (e) => e.trim(),
|
|
27
|
-
validate: (e) => e.length > 0 || "项目名称不能为空"
|
|
28
|
-
}, U = async () => ({
|
|
29
|
-
type: "select",
|
|
30
|
-
name: "template",
|
|
31
|
-
message: "请选择模板",
|
|
32
|
-
choices: (await E()).map((t) => {
|
|
33
|
-
var n;
|
|
34
|
-
return {
|
|
35
|
-
title: t.branch ? `${t.name}(${t.branch})` : t.name,
|
|
36
|
-
value: t.name,
|
|
37
|
-
description: `${t.description || ""}${(n = t.instances) != null && n.length ? `, 已应用于: ${[""].concat(t.instances).join(`
|
|
38
|
-
- `)}` : ""}` || void 0
|
|
39
|
-
};
|
|
40
|
-
}),
|
|
41
|
-
validate: (t) => t.trim().length > 0 || "模板不能为空"
|
|
42
|
-
}), H = {
|
|
43
|
-
type: "confirm",
|
|
44
|
-
name: "saveGitHistory",
|
|
45
|
-
message: "是否保留git历史",
|
|
46
|
-
initial: !1
|
|
47
|
-
}, x = (e = "项目已存在,是否删除") => ({
|
|
48
|
-
type: "confirm",
|
|
49
|
-
name: "isRemove",
|
|
50
|
-
message: e
|
|
51
|
-
}), k = {
|
|
52
|
-
type: "text",
|
|
53
|
-
name: "customUrl",
|
|
54
|
-
message: "请输入自定义模板路径",
|
|
55
|
-
validate: (e) => e.trim().length > 0 || "路径不能为空"
|
|
56
|
-
}, B = (e) => ({
|
|
57
|
-
type: "text",
|
|
58
|
-
name: "gitCommitMessage",
|
|
59
|
-
message: "请输入git提交信息",
|
|
60
|
-
initial: `feat: 初始化项目${e}`,
|
|
61
|
-
validate: (t) => t.trim().length > 0 || "提交信息不能为空"
|
|
62
|
-
}), Y = async () => {
|
|
63
|
-
r.stage("拉取模板列表,请稍等...");
|
|
64
|
-
const e = g.resolve(
|
|
65
|
-
process.cwd(),
|
|
66
|
-
S
|
|
67
|
-
);
|
|
68
|
-
if (v(e))
|
|
69
|
-
return r.error(`${e} 已存在,请手动删除该目录再试`), process.exit(1);
|
|
70
|
-
if (r.info(`配置临时目录:${e}`), u.existsSync(e)) {
|
|
71
|
-
const n = `${e}目录已存在,是否删除?`, { isRemove: o } = await c(x(n));
|
|
72
|
-
if (o)
|
|
73
|
-
u.rmSync(e, { recursive: !0, force: !0 });
|
|
74
|
-
else
|
|
75
|
-
return r.error(`${e} 已存在,请手动删除该目录再试`), process.exit(1);
|
|
76
|
-
}
|
|
77
|
-
let t;
|
|
78
|
-
try {
|
|
79
|
-
l(`git clone ${w} ${e} --depth=1`);
|
|
80
|
-
const n = y.name, o = g.resolve(e, `${n}.json`);
|
|
81
|
-
if (t = JSON.parse(u.readFileSync(o, "utf-8")), !Array.isArray(t.templateList)) {
|
|
82
|
-
const i = `远程配置文件出错, templateList 不是数组, 请检查 ${w} ${n}.json`;
|
|
83
|
-
throw new Error(i);
|
|
84
|
-
}
|
|
85
|
-
r.success("模板列表拉取成功!");
|
|
86
|
-
} finally {
|
|
87
|
-
u.rmSync(e, { recursive: !0, force: !0 });
|
|
88
|
-
}
|
|
89
|
-
return t;
|
|
90
|
-
}, J = async (e) => {
|
|
91
|
-
const { projectName: t } = e, o = ((t ?? (await c(b)).projectName) || "").trim();
|
|
92
|
-
if (!o)
|
|
93
|
-
return r.error("项目名称不能为空"), process.exit(1);
|
|
94
|
-
if (o.includes(" ") || o.includes("\\") || o.includes("/"))
|
|
95
|
-
return r.error(`项目名称\`${o}\`不能包含空格或者\\或者/`), process.exit(1);
|
|
96
|
-
const i = F(process.cwd(), o);
|
|
97
|
-
if (v(i)) {
|
|
98
|
-
const { isRemove: s } = await c(x());
|
|
99
|
-
if (s === !0)
|
|
100
|
-
f(i, { recursive: !0, force: !0 });
|
|
101
|
-
else
|
|
102
|
-
return r.error(`项目${o}已存在`), process.exit(1);
|
|
103
|
-
}
|
|
104
|
-
const { template: m } = await c(await U());
|
|
105
|
-
let p = "", d = "";
|
|
106
|
-
if (m === C) {
|
|
107
|
-
const { customUrl: s } = await c(k);
|
|
108
|
-
p = s;
|
|
109
|
-
} else if (m === j)
|
|
110
|
-
p = await O();
|
|
111
|
-
else {
|
|
112
|
-
const s = (await E()).find(
|
|
113
|
-
(a) => a.name === m
|
|
114
|
-
);
|
|
115
|
-
if (!s)
|
|
116
|
-
return r.error(`模板${m}不存在`), process.exit(1);
|
|
117
|
-
if (!s.url)
|
|
118
|
-
return r.error(`模板${m}仓库地址不存在`), process.exit(1);
|
|
119
|
-
p = s.url, d = s.branch;
|
|
120
|
-
}
|
|
121
|
-
const N = G(".git");
|
|
122
|
-
r.stage("正在初始化项目,请稍等..."), l(
|
|
123
|
-
`git clone${d ? ` -b ${d}` : ""} ${p} ${o} --depth=1`,
|
|
124
|
-
{ stdio: "inherit" }
|
|
125
|
-
);
|
|
126
|
-
const h = L;
|
|
127
|
-
if (R({
|
|
128
|
-
rootDir: i,
|
|
129
|
-
configPath: h
|
|
130
|
-
}) && (await A({
|
|
131
|
-
rootDir: i,
|
|
132
|
-
configPath: h,
|
|
133
|
-
extraEnvData: {
|
|
134
|
-
$projectName: o
|
|
135
|
-
}
|
|
136
|
-
}), f(h, { force: !0 }), r.stage("模板项目配置注入成功, 模版项目配置文件已删除")), r.stage("项目初始化完成"), N) {
|
|
137
|
-
const s = g.resolve(i), a = g.resolve(s, ".git");
|
|
138
|
-
if (!v(a))
|
|
139
|
-
throw new Error("git目录不存在");
|
|
140
|
-
f(a, { recursive: !0, force: !0 }), r.stage(
|
|
141
|
-
`项目创建在父级git仓库${N}中,已删除${o}目录下的.git(${a})`
|
|
142
|
-
);
|
|
143
|
-
} else if ((await c(H)).saveGitHistory)
|
|
144
|
-
l("git remote rename origin upstream && git fetch --unshallow", {
|
|
145
|
-
cwd: i,
|
|
146
|
-
stdio: "inherit"
|
|
147
|
-
}), r.stage(
|
|
148
|
-
"已经将origin重命名为upstream,后续可以与模板git仓库有完整的交互"
|
|
149
|
-
), r.success("已保存git历史记录");
|
|
150
|
-
else {
|
|
151
|
-
const a = g.resolve(i, ".git");
|
|
152
|
-
f(a, { recursive: !0, force: !0 }), l("git init", {
|
|
153
|
-
cwd: i,
|
|
154
|
-
stdio: "inherit"
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
const { gitCommitMessage: _ } = await c(
|
|
158
|
-
B(o)
|
|
159
|
-
);
|
|
160
|
-
l(`git add . && git commit -m '${_}'`, {
|
|
161
|
-
cwd: i,
|
|
162
|
-
stdio: "inherit"
|
|
163
|
-
}), r.success(`项目${o}初始化完成`), r.info(`
|
|
164
|
-
使用步骤:
|
|
165
|
-
1. cd ${o}
|
|
166
|
-
2. pnpm install
|
|
167
|
-
3. pnpm run dev
|
|
168
|
-
`);
|
|
169
|
-
}, {
|
|
170
|
-
version: V,
|
|
171
|
-
description: q,
|
|
172
|
-
cliConfig: { moduleName: z }
|
|
173
|
-
} = y, T = {
|
|
174
|
-
describe: q,
|
|
175
|
-
version: V,
|
|
176
|
-
positionals: {
|
|
177
|
-
projectName: {
|
|
178
|
-
describe: "项目名称",
|
|
179
|
-
type: "string"
|
|
180
|
-
}
|
|
181
|
-
},
|
|
182
|
-
handler: J
|
|
183
|
-
}, P = (e = !1) => {
|
|
184
|
-
const t = `${e ? `${z} ` : ""}[projectName]`, n = `$0 ${t.trim()}`;
|
|
185
|
-
return { command: t, usage: n };
|
|
186
|
-
}, re = async () => D({
|
|
187
|
-
...T,
|
|
188
|
-
...P()
|
|
189
|
-
}), oe = () => M({
|
|
190
|
-
...T,
|
|
191
|
-
...P(!0)
|
|
192
|
-
});
|
|
193
|
-
export {
|
|
194
|
-
oe as a,
|
|
195
|
-
re as c,
|
|
196
|
-
J as h
|
|
197
|
-
};
|