create-done-coding 0.4.0 → 0.4.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 +1 -1
- package/es/handler.mjs +19 -21
- package/es/index.mjs +7 -0
- package/es/injectInfo.json.mjs +9 -0
- package/es/main.mjs +26 -20
- package/es/utils/const.mjs +2 -2
- package/es/utils/question.mjs +19 -17
- package/es/utils/readConfig.mjs +21 -15
- package/package.json +10 -5
- package/types/index.d.ts +2 -0
- package/types/injectInfo.json.d.ts +7 -0
- package/types/utils/const.d.ts +1 -1
- package/types/utils/index.d.ts +0 -1
- package/types/utils/question.d.ts +9 -3
- package/types/utils/readConfig.d.ts +2 -2
- package/es/utils/packageInfo.mjs +0 -15
- package/types/utils/packageInfo.d.ts +0 -9
package/README.md
CHANGED
package/es/handler.mjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { CUSTOM_TEMPLATE_NAME as j } from "./utils/const.mjs";
|
|
3
|
-
import { projectNameForm as E,
|
|
3
|
+
import { projectNameForm as E, getRemoveDirForm as S, getTemplateForm as x, getTemplateChoices as F, saveGitHistoryForm as T, shallowCloneForm as k } from "./utils/question.mjs";
|
|
4
4
|
import n from "prompts";
|
|
5
|
-
import { execSync as
|
|
5
|
+
import { execSync as c } from "node:child_process";
|
|
6
6
|
import { existsSync as p, rmSync as i, readFileSync as g, writeFileSync as f } from "node:fs";
|
|
7
7
|
import { resolve as M } from "node:path";
|
|
8
8
|
import t from "chalk";
|
|
9
|
-
const
|
|
9
|
+
const J = async (u) => {
|
|
10
10
|
const {
|
|
11
11
|
projectName: d,
|
|
12
12
|
template: w,
|
|
13
|
-
saveGitHistory:
|
|
14
|
-
shallowClone:
|
|
13
|
+
saveGitHistory: $,
|
|
14
|
+
shallowClone: h
|
|
15
15
|
} = u, r = ((d ?? (await n(E)).projectName) || "").trim();
|
|
16
16
|
if (!r.trim()) {
|
|
17
17
|
console.log(t.red("项目名称不能为空"));
|
|
@@ -23,17 +23,13 @@ const b = async (u) => {
|
|
|
23
23
|
}
|
|
24
24
|
const e = M(process.cwd(), r);
|
|
25
25
|
if (p(e)) {
|
|
26
|
-
const { isRemove: o } = await n(
|
|
27
|
-
type: "confirm",
|
|
28
|
-
name: "isRemove",
|
|
29
|
-
message: "项目已存在,是否删除"
|
|
30
|
-
});
|
|
26
|
+
const { isRemove: o } = await n(S());
|
|
31
27
|
if (o === !0)
|
|
32
28
|
i(e, { recursive: !0, force: !0 });
|
|
33
29
|
else
|
|
34
30
|
return console.log(t.red("项目已存在")), process.exit(1);
|
|
35
31
|
}
|
|
36
|
-
const s = w ?? (await n(
|
|
32
|
+
const s = w ?? (await n(await x())).template;
|
|
37
33
|
let l = "";
|
|
38
34
|
if (s === j) {
|
|
39
35
|
const { customUrl: o } = await n({
|
|
@@ -43,31 +39,33 @@ const b = async (u) => {
|
|
|
43
39
|
});
|
|
44
40
|
l = o;
|
|
45
41
|
} else {
|
|
46
|
-
const o =
|
|
42
|
+
const o = (await F()).find(
|
|
43
|
+
(C) => C.name === s
|
|
44
|
+
);
|
|
47
45
|
if (!o)
|
|
48
46
|
return console.log(t.red(`模板${s}不存在`)), process.exit(1);
|
|
49
47
|
if (!o.url)
|
|
50
48
|
return console.log(t.red(`模板${s}仓库地址不存在`)), process.exit(1);
|
|
51
49
|
l = o.url;
|
|
52
50
|
}
|
|
53
|
-
console.log(t.green("正在初始化项目,请稍等...")),
|
|
54
|
-
const m =
|
|
51
|
+
console.log(t.green("正在初始化项目,请稍等...")), c(`git clone ${l} ${r} --depth=1`);
|
|
52
|
+
const m = $ ?? (await n(T)).saveGitHistory;
|
|
55
53
|
if (m === !1) {
|
|
56
54
|
const o = `${e}/.git`;
|
|
57
55
|
if (!p(o))
|
|
58
56
|
throw new Error("git目录不存在");
|
|
59
57
|
i(`${e}/.git`, { recursive: !0, force: !0 });
|
|
60
58
|
} else
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
59
|
+
c(`cd ${e} && git remote rename origin upstream`);
|
|
60
|
+
const y = g(`${e}/package.json`, "utf-8"), a = JSON.parse(y), { name: N } = a;
|
|
61
|
+
a.name = r, i(`${e}/package.json`), f(
|
|
64
62
|
`${e}/package.json`,
|
|
65
|
-
JSON.stringify(
|
|
63
|
+
JSON.stringify(a, null, 2)
|
|
66
64
|
);
|
|
67
65
|
const v = g(`${e}/README.md`, "utf-8").replace(N, r);
|
|
68
|
-
i(`${e}/README.md`), f(`${e}/README.md`, v), console.log(t.green("项目初始化完成")), m && ((
|
|
66
|
+
i(`${e}/README.md`), f(`${e}/README.md`, v), console.log(t.green("项目初始化完成")), m && ((h ? (await n(k)).shallowClone : !1) ? console.log(
|
|
69
67
|
t.yellow("当前使用浅克隆,后续不能与模板git仓库有完整的交互")
|
|
70
|
-
) : (
|
|
68
|
+
) : (c(`cd ${e} && git fetch --unshallow`), console.log(
|
|
71
69
|
t.green("已完整克隆项目,后续可以与模板git仓库有完整的交互")
|
|
72
70
|
))), console.log(
|
|
73
71
|
t.blue(`
|
|
@@ -79,5 +77,5 @@ const b = async (u) => {
|
|
|
79
77
|
);
|
|
80
78
|
};
|
|
81
79
|
export {
|
|
82
|
-
|
|
80
|
+
J as handler
|
|
83
81
|
};
|
package/es/index.mjs
ADDED
package/es/main.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import { hideBin as
|
|
4
|
-
import { handler as
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
const
|
|
2
|
+
import c from "yargs";
|
|
3
|
+
import { hideBin as m } from "yargs/helpers";
|
|
4
|
+
import { handler as a } from "./handler.mjs";
|
|
5
|
+
import s from "chalk";
|
|
6
|
+
import { projectNameForm as l, getTemplateChoices as p, getTemplateForm as d, saveGitHistoryForm as g, shallowCloneForm as h } from "./utils/question.mjs";
|
|
7
|
+
import t from "./injectInfo.json.mjs";
|
|
8
|
+
const f = async () => ({
|
|
9
9
|
projectName: {
|
|
10
10
|
type: "string",
|
|
11
11
|
alias: "p",
|
|
@@ -14,29 +14,35 @@ const d = () => ({
|
|
|
14
14
|
template: {
|
|
15
15
|
type: "string",
|
|
16
16
|
alias: "t",
|
|
17
|
-
choices:
|
|
18
|
-
describe:
|
|
17
|
+
choices: (await p()).map((e) => e.name),
|
|
18
|
+
describe: (await d()).message
|
|
19
19
|
},
|
|
20
20
|
saveGitHistory: {
|
|
21
21
|
type: "boolean",
|
|
22
22
|
alias: "s",
|
|
23
|
-
describe:
|
|
23
|
+
describe: g.message
|
|
24
24
|
},
|
|
25
25
|
shallowClone: {
|
|
26
26
|
type: "boolean",
|
|
27
27
|
alias: "c",
|
|
28
|
-
describe:
|
|
28
|
+
describe: h.message,
|
|
29
29
|
default: !0
|
|
30
30
|
}
|
|
31
|
-
}),
|
|
32
|
-
console.log(e ?
|
|
33
|
-
},
|
|
34
|
-
const
|
|
35
|
-
return e.strict().usage(
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
}), r = "create", y = (e, o) => {
|
|
32
|
+
console.log(e ? s.red(e) : s.red(o.message)), process.exit(1);
|
|
33
|
+
}, b = t.description, u = `Usage: $0 ${r} [options]`, v = "Usage: $0 [options]", i = async (e, o) => {
|
|
34
|
+
const n = await f();
|
|
35
|
+
return e.strict().usage(o).help("help").version(t.version).alias("v", "version").alias("h", "help").options(n).fail(y).argv;
|
|
36
|
+
}, C = (e) => i(e, u), $ = {
|
|
37
|
+
command: r,
|
|
38
|
+
describe: b,
|
|
39
|
+
builder: C,
|
|
40
|
+
handler: a
|
|
41
|
+
}, x = async () => {
|
|
42
|
+
const e = c(m(process.argv)), o = await i(e, v);
|
|
43
|
+
return a(o);
|
|
39
44
|
};
|
|
40
45
|
export {
|
|
41
|
-
|
|
46
|
+
$ as command,
|
|
47
|
+
x as createCli
|
|
42
48
|
};
|
package/es/utils/const.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const o = "git@gitee.com:justsosu/done-coding-cli-config-json.git", n = "自定义模版路径",
|
|
2
|
+
const o = "git@gitee.com:justsosu/done-coding-cli-config-json.git", n = "自定义模版路径", e = "./.create-done-coding_temp";
|
|
3
3
|
export {
|
|
4
4
|
o as CONFIG_GIT_REPO,
|
|
5
5
|
n as CUSTOM_TEMPLATE_NAME,
|
|
6
|
-
|
|
6
|
+
e as READ_CONFIG_TEMPORARY_DIRECTORY
|
|
7
7
|
};
|
package/es/utils/question.mjs
CHANGED
|
@@ -2,36 +2,38 @@
|
|
|
2
2
|
import { CUSTOM_TEMPLATE_NAME as o } from "./const.mjs";
|
|
3
3
|
import { readConfig as m } from "./readConfig.mjs";
|
|
4
4
|
let t;
|
|
5
|
-
const
|
|
6
|
-
...a(),
|
|
7
|
-
{ name: o }
|
|
8
|
-
], r = {
|
|
5
|
+
const s = async () => (t || (t = (await m()).templateList), t), n = async () => [...await s(), { name: o }], c = {
|
|
9
6
|
type: "text",
|
|
10
7
|
name: "projectName",
|
|
11
8
|
message: "请输入项目名称",
|
|
12
9
|
validate: (e) => e.trim().length > 0 || "项目名称不能为空"
|
|
13
|
-
}, l = {
|
|
10
|
+
}, l = async () => ({
|
|
14
11
|
type: "select",
|
|
15
12
|
name: "template",
|
|
16
13
|
message: "请选择模板",
|
|
17
|
-
choices:
|
|
18
|
-
title:
|
|
19
|
-
value:
|
|
14
|
+
choices: (await n()).map((a) => ({
|
|
15
|
+
title: a.name,
|
|
16
|
+
value: a.name
|
|
20
17
|
}))
|
|
21
|
-
},
|
|
18
|
+
}), p = {
|
|
22
19
|
type: "confirm",
|
|
23
20
|
name: "saveGitHistory",
|
|
24
21
|
message: "是否保留git历史"
|
|
25
|
-
},
|
|
22
|
+
}, g = {
|
|
26
23
|
type: "confirm",
|
|
27
24
|
name: "shallowClone",
|
|
28
25
|
message: "是否使用浅克隆(后续期望与模板git仓库有完整的交互,请选择'N')"
|
|
29
|
-
}
|
|
26
|
+
}, y = (e = "项目已存在,是否删除") => ({
|
|
27
|
+
type: "confirm",
|
|
28
|
+
name: "isRemove",
|
|
29
|
+
message: e
|
|
30
|
+
});
|
|
30
31
|
export {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
y as getRemoveDirForm,
|
|
33
|
+
n as getTemplateChoices,
|
|
34
|
+
l as getTemplateForm,
|
|
35
|
+
s as getTemplateList,
|
|
36
|
+
c as projectNameForm,
|
|
37
|
+
p as saveGitHistoryForm,
|
|
38
|
+
g as shallowCloneForm
|
|
37
39
|
};
|
package/es/utils/readConfig.mjs
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import { execSync as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { READ_CONFIG_TEMPORARY_DIRECTORY as
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import o from "chalk";
|
|
3
|
+
import { execSync as f } from "node:child_process";
|
|
4
|
+
import s from "node:path";
|
|
5
|
+
import r from "node:fs";
|
|
6
|
+
import { READ_CONFIG_TEMPORARY_DIRECTORY as p, CONFIG_GIT_REPO as l } from "./const.mjs";
|
|
7
|
+
import a from "../injectInfo.json.mjs";
|
|
8
|
+
import { getRemoveDirForm as g } from "./question.mjs";
|
|
9
|
+
import u from "prompts";
|
|
10
|
+
const E = async () => {
|
|
11
|
+
console.log(o.blue("拉取模板列表,请稍等..."));
|
|
12
|
+
const e = s.resolve(
|
|
11
13
|
process.cwd(),
|
|
12
|
-
|
|
14
|
+
p
|
|
13
15
|
);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
if (console.log(o.blue(`配置目录:${e}`)), r.existsSync(e)) {
|
|
17
|
+
const i = `${e}目录已存在,是否删除?`, { isRemove: m } = await u(g(i));
|
|
18
|
+
m ? r.rmSync(e, { recursive: !0, force: !0 }) : (console.log(o.red(`${e}已存在,请手动删除后再试!`)), process.exit(1));
|
|
19
|
+
}
|
|
20
|
+
f(`git clone ${l} ${e} --depth=1`);
|
|
21
|
+
const n = a.name, c = s.resolve(e, `${n}.json`), t = JSON.parse(r.readFileSync(c, "utf-8"));
|
|
22
|
+
if (!Array.isArray(t.templateList))
|
|
17
23
|
throw new Error("远程配置文件出错,templateList 不是数组");
|
|
18
|
-
return console.log(
|
|
24
|
+
return console.log(o.green("模板列表拉取成功!")), r.rmSync(e, { recursive: !0, force: !0 }), t;
|
|
19
25
|
};
|
|
20
26
|
export {
|
|
21
|
-
|
|
27
|
+
E as readConfig
|
|
22
28
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-done-coding",
|
|
3
|
-
"version": "0.4.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.4.2",
|
|
4
|
+
"description": "项目创建命令行工具",
|
|
5
5
|
"module": "es/cli.mjs",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"types": "types/cli.d.ts",
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"import": "./es/cli.mjs"
|
|
12
|
+
},
|
|
13
|
+
"./assets": {
|
|
14
|
+
"import": "./es/index.mjs",
|
|
15
|
+
"types": "./types/index.d.ts"
|
|
12
16
|
}
|
|
13
17
|
},
|
|
14
18
|
"files": [
|
|
@@ -34,9 +38,10 @@
|
|
|
34
38
|
"license": "MIT",
|
|
35
39
|
"sideEffects": false,
|
|
36
40
|
"devDependencies": {
|
|
37
|
-
"@
|
|
41
|
+
"@done-coding/cli-inject": "^0.1.1",
|
|
42
|
+
"@types/node": "^20.0.0",
|
|
38
43
|
"@types/prompts": "^2.4.6",
|
|
39
|
-
"@types/yargs": "^17.0.
|
|
44
|
+
"@types/yargs": "^17.0.28",
|
|
40
45
|
"rimraf": "^6.0.1",
|
|
41
46
|
"typescript": "^5.2.2",
|
|
42
47
|
"vite": "^4.4.11",
|
|
@@ -50,5 +55,5 @@
|
|
|
50
55
|
"prompts": "^2.4.2",
|
|
51
56
|
"yargs": "^17.7.2"
|
|
52
57
|
},
|
|
53
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "454bb76eb20c9b732331c273435e0bf56c8c3f25"
|
|
54
59
|
}
|
package/types/index.d.ts
ADDED
package/types/utils/const.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export declare const CONFIG_GIT_REPO: string;
|
|
|
3
3
|
/** 自定义模板路径 */
|
|
4
4
|
export declare const CUSTOM_TEMPLATE_NAME = "\u81EA\u5B9A\u4E49\u6A21\u7248\u8DEF\u5F84";
|
|
5
5
|
/** 临时目录 */
|
|
6
|
-
export declare const READ_CONFIG_TEMPORARY_DIRECTORY = "
|
|
6
|
+
export declare const READ_CONFIG_TEMPORARY_DIRECTORY = "./.create-done-coding_temp";
|
package/types/utils/index.d.ts
CHANGED
|
@@ -5,11 +5,11 @@ export interface TemplateChoiceItem {
|
|
|
5
5
|
url?: string;
|
|
6
6
|
}
|
|
7
7
|
/** 获取模版选项 */
|
|
8
|
-
export declare const getTemplateList: () => TemplateChoiceItem[]
|
|
8
|
+
export declare const getTemplateList: () => Promise<TemplateChoiceItem[]>;
|
|
9
9
|
/** 模版选项 */
|
|
10
|
-
export declare const
|
|
10
|
+
export declare const getTemplateChoices: () => Promise<TemplateChoiceItem[]>;
|
|
11
11
|
export declare const projectNameForm: PromptObject<string>;
|
|
12
|
-
export declare const
|
|
12
|
+
export declare const getTemplateForm: () => Promise<PromptObject<string>>;
|
|
13
13
|
export declare const saveGitHistoryForm: {
|
|
14
14
|
type: "confirm";
|
|
15
15
|
name: string;
|
|
@@ -20,3 +20,9 @@ export declare const shallowCloneForm: {
|
|
|
20
20
|
name: string;
|
|
21
21
|
message: string;
|
|
22
22
|
};
|
|
23
|
+
/** 获取删除目录的表单 */
|
|
24
|
+
export declare const getRemoveDirForm: (message?: string) => {
|
|
25
|
+
type: "confirm";
|
|
26
|
+
name: string;
|
|
27
|
+
message: string;
|
|
28
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type TemplateChoiceItem } from "./question";
|
|
2
2
|
/** 配置文件 */
|
|
3
3
|
export interface ConfigJson {
|
|
4
4
|
templateList: TemplateChoiceItem[];
|
|
5
5
|
}
|
|
6
6
|
/** 读取配置 */
|
|
7
|
-
export declare const readConfig: () => ConfigJson
|
|
7
|
+
export declare const readConfig: () => Promise<ConfigJson>;
|
package/es/utils/packageInfo.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import n, { dirname as t } from "node:path";
|
|
3
|
-
import o from "node:fs";
|
|
4
|
-
import { fileURLToPath as a } from "node:url";
|
|
5
|
-
const i = a(import.meta.url), m = t(i), r = () => {
|
|
6
|
-
const e = o.readFileSync(
|
|
7
|
-
n.join(m, "../../package.json"),
|
|
8
|
-
"utf-8"
|
|
9
|
-
);
|
|
10
|
-
return JSON.parse(e);
|
|
11
|
-
}, f = () => r().version, g = () => r().name;
|
|
12
|
-
export {
|
|
13
|
-
g as getPkgName,
|
|
14
|
-
f as getVersion
|
|
15
|
-
};
|