create-done-coding 0.3.1 → 0.4.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 +5 -3
- package/es/handler.mjs +42 -35
- package/es/main.mjs +16 -10
- package/es/utils/question.mjs +13 -8
- package/package.json +9 -24
- package/types/handler.d.ts +2 -3
- package/types/main.d.ts +2 -3
- package/types/utils/index.d.ts +5 -5
- package/types/utils/question.d.ts +6 -2
- package/types/utils/readConfig.d.ts +1 -2
- package/types/utils/types.d.ts +2 -0
package/README.md
CHANGED
package/es/handler.mjs
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { CUSTOM_TEMPLATE_NAME as
|
|
3
|
-
import { projectNameForm as E, templateForm as S, templateChoices as x, saveGitHistoryForm as
|
|
2
|
+
import { CUSTOM_TEMPLATE_NAME as j } from "./utils/const.mjs";
|
|
3
|
+
import { projectNameForm as E, templateForm as S, templateChoices as x, saveGitHistoryForm as k, shallowCloneForm as F } from "./utils/question.mjs";
|
|
4
4
|
import n from "prompts";
|
|
5
5
|
import { execSync as a } from "node:child_process";
|
|
6
|
-
import { existsSync as
|
|
7
|
-
import { resolve as
|
|
8
|
-
import
|
|
9
|
-
const
|
|
6
|
+
import { existsSync as p, rmSync as i, readFileSync as g, writeFileSync as f } from "node:fs";
|
|
7
|
+
import { resolve as M } from "node:path";
|
|
8
|
+
import t from "chalk";
|
|
9
|
+
const b = async (u) => {
|
|
10
10
|
const {
|
|
11
|
-
projectName:
|
|
12
|
-
template:
|
|
13
|
-
saveGitHistory: y
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
projectName: d,
|
|
12
|
+
template: w,
|
|
13
|
+
saveGitHistory: y,
|
|
14
|
+
shallowClone: $
|
|
15
|
+
} = u, r = ((d ?? (await n(E)).projectName) || "").trim();
|
|
16
|
+
if (!r.trim()) {
|
|
17
|
+
console.log(t.red("项目名称不能为空"));
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
19
|
-
if (
|
|
20
|
-
console.log(
|
|
20
|
+
if (r.includes(" ") || r.includes("\\") || r.includes("/")) {
|
|
21
|
+
console.log(t.red("项目名称不能包含空格或者\\或者/"));
|
|
21
22
|
return;
|
|
22
23
|
}
|
|
23
|
-
const e =
|
|
24
|
-
if (
|
|
24
|
+
const e = M(process.cwd(), r);
|
|
25
|
+
if (p(e)) {
|
|
25
26
|
const { isRemove: o } = await n({
|
|
26
27
|
type: "confirm",
|
|
27
28
|
name: "isRemove",
|
|
@@ -30,47 +31,53 @@ const I = async (u) => {
|
|
|
30
31
|
if (o === !0)
|
|
31
32
|
i(e, { recursive: !0, force: !0 });
|
|
32
33
|
else
|
|
33
|
-
return console.log(
|
|
34
|
+
return console.log(t.red("项目已存在")), process.exit(1);
|
|
34
35
|
}
|
|
35
|
-
const s =
|
|
36
|
-
let
|
|
37
|
-
if (s ===
|
|
36
|
+
const s = w ?? (await n(S)).template;
|
|
37
|
+
let l = "";
|
|
38
|
+
if (s === j) {
|
|
38
39
|
const { customUrl: o } = await n({
|
|
39
40
|
type: "text",
|
|
40
41
|
name: "customUrl",
|
|
41
42
|
message: "请输入自定义模板路径"
|
|
42
43
|
});
|
|
43
|
-
|
|
44
|
+
l = o;
|
|
44
45
|
} else {
|
|
45
|
-
const o = x.find((
|
|
46
|
+
const o = x.find((C) => C.name === s);
|
|
46
47
|
if (!o)
|
|
47
|
-
return console.log(
|
|
48
|
+
return console.log(t.red(`模板${s}不存在`)), process.exit(1);
|
|
48
49
|
if (!o.url)
|
|
49
|
-
return console.log(
|
|
50
|
-
|
|
50
|
+
return console.log(t.red(`模板${s}仓库地址不存在`)), process.exit(1);
|
|
51
|
+
l = o.url;
|
|
51
52
|
}
|
|
52
|
-
|
|
53
|
+
console.log(t.green("正在初始化项目,请稍等...")), a(`git clone ${l} ${r} --depth=1`);
|
|
54
|
+
const m = y ?? (await n(k)).saveGitHistory;
|
|
55
|
+
if (m === !1) {
|
|
53
56
|
const o = `${e}/.git`;
|
|
54
|
-
if (!
|
|
57
|
+
if (!p(o))
|
|
55
58
|
throw new Error("git目录不存在");
|
|
56
59
|
i(`${e}/.git`, { recursive: !0, force: !0 });
|
|
57
60
|
} else
|
|
58
61
|
a(`cd ${e} && git remote rename origin upstream`);
|
|
59
|
-
const
|
|
60
|
-
|
|
62
|
+
const h = g(`${e}/package.json`, "utf-8"), c = JSON.parse(h), { name: N } = c;
|
|
63
|
+
c.name = r, i(`${e}/package.json`), f(
|
|
61
64
|
`${e}/package.json`,
|
|
62
|
-
JSON.stringify(
|
|
65
|
+
JSON.stringify(c, null, 2)
|
|
63
66
|
);
|
|
64
|
-
const
|
|
65
|
-
i(`${e}/README.md`),
|
|
66
|
-
|
|
67
|
+
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 && (($ ? (await n(F)).shallowClone : !1) ? console.log(
|
|
69
|
+
t.yellow("当前使用浅克隆,后续不能与模板git仓库有完整的交互")
|
|
70
|
+
) : (a(`cd ${e} && git fetch --unshallow`), console.log(
|
|
71
|
+
t.green("已完整克隆项目,后续可以与模板git仓库有完整的交互")
|
|
72
|
+
))), console.log(
|
|
73
|
+
t.blue(`
|
|
67
74
|
使用步骤:
|
|
68
|
-
1. cd ${
|
|
75
|
+
1. cd ${r}
|
|
69
76
|
2. pnpm install
|
|
70
77
|
3. pnpm run dev
|
|
71
78
|
`)
|
|
72
79
|
);
|
|
73
80
|
};
|
|
74
81
|
export {
|
|
75
|
-
|
|
82
|
+
b as handler
|
|
76
83
|
};
|
package/es/main.mjs
CHANGED
|
@@ -4,31 +4,37 @@ import { hideBin as a } from "yargs/helpers";
|
|
|
4
4
|
import { handler as i } from "./handler.mjs";
|
|
5
5
|
import o from "chalk";
|
|
6
6
|
import { getVersion as n } from "./utils/packageInfo.mjs";
|
|
7
|
-
import { projectNameForm as
|
|
8
|
-
const
|
|
7
|
+
import { projectNameForm as l, templateChoices as m, templateForm as c, saveGitHistoryForm as p, shallowCloneForm as g } from "./utils/question.mjs";
|
|
8
|
+
const d = () => ({
|
|
9
9
|
projectName: {
|
|
10
10
|
type: "string",
|
|
11
11
|
alias: "p",
|
|
12
|
-
describe:
|
|
12
|
+
describe: l.message
|
|
13
13
|
},
|
|
14
14
|
template: {
|
|
15
15
|
type: "string",
|
|
16
16
|
alias: "t",
|
|
17
|
-
choices:
|
|
17
|
+
choices: m.map((e) => e.name),
|
|
18
18
|
describe: c.message
|
|
19
19
|
},
|
|
20
20
|
saveGitHistory: {
|
|
21
21
|
type: "boolean",
|
|
22
22
|
alias: "s",
|
|
23
|
-
describe:
|
|
23
|
+
describe: p.message
|
|
24
|
+
},
|
|
25
|
+
shallowClone: {
|
|
26
|
+
type: "boolean",
|
|
27
|
+
alias: "c",
|
|
28
|
+
describe: g.message,
|
|
29
|
+
default: !0
|
|
24
30
|
}
|
|
25
|
-
}),
|
|
31
|
+
}), h = (e, s) => {
|
|
26
32
|
console.log(e ? o.red(e) : o.red(s.message)), process.exit(1);
|
|
27
|
-
}, f = "Usage: $0 [options]",
|
|
28
|
-
const t =
|
|
29
|
-
return e.strict().usage(s).help("help").version(n()).alias("v", "version").alias("h", "help").options(t).fail(
|
|
33
|
+
}, f = "Usage: $0 [options]", v = (e, s) => {
|
|
34
|
+
const t = d();
|
|
35
|
+
return e.strict().usage(s).help("help").version(n()).alias("v", "version").alias("h", "help").options(t).fail(h).argv;
|
|
30
36
|
}, H = async () => {
|
|
31
|
-
const e = r(a(process.argv)), s = await
|
|
37
|
+
const e = r(a(process.argv)), s = await v(e, f);
|
|
32
38
|
return i(s);
|
|
33
39
|
};
|
|
34
40
|
export {
|
package/es/utils/question.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { CUSTOM_TEMPLATE_NAME as
|
|
3
|
-
import { readConfig as
|
|
2
|
+
import { CUSTOM_TEMPLATE_NAME as o } from "./const.mjs";
|
|
3
|
+
import { readConfig as m } from "./readConfig.mjs";
|
|
4
4
|
let t;
|
|
5
|
-
const a = () => (t || (t =
|
|
5
|
+
const a = () => (t || (t = m().templateList), t), s = [
|
|
6
6
|
...a(),
|
|
7
|
-
{ name:
|
|
7
|
+
{ name: o }
|
|
8
8
|
], r = {
|
|
9
9
|
type: "text",
|
|
10
10
|
name: "projectName",
|
|
11
11
|
message: "请输入项目名称",
|
|
12
12
|
validate: (e) => e.trim().length > 0 || "项目名称不能为空"
|
|
13
|
-
},
|
|
13
|
+
}, l = {
|
|
14
14
|
type: "select",
|
|
15
15
|
name: "template",
|
|
16
16
|
message: "请选择模板",
|
|
@@ -18,15 +18,20 @@ const a = () => (t || (t = o().templateList), t), s = [
|
|
|
18
18
|
title: e.name,
|
|
19
19
|
value: e.name
|
|
20
20
|
}))
|
|
21
|
-
},
|
|
21
|
+
}, c = {
|
|
22
22
|
type: "confirm",
|
|
23
23
|
name: "saveGitHistory",
|
|
24
24
|
message: "是否保留git历史"
|
|
25
|
+
}, p = {
|
|
26
|
+
type: "confirm",
|
|
27
|
+
name: "shallowClone",
|
|
28
|
+
message: "是否使用浅克隆(后续期望与模板git仓库有完整的交互,请选择'N')"
|
|
25
29
|
};
|
|
26
30
|
export {
|
|
27
31
|
a as getTemplateList,
|
|
28
32
|
r as projectNameForm,
|
|
29
|
-
|
|
33
|
+
c as saveGitHistoryForm,
|
|
34
|
+
p as shallowCloneForm,
|
|
30
35
|
s as templateChoices,
|
|
31
|
-
|
|
36
|
+
l as templateForm
|
|
32
37
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-done-coding",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "done-coding项目脚手架",
|
|
4
5
|
"module": "es/cli.mjs",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"types": "types/cli.d.ts",
|
|
@@ -22,42 +23,25 @@
|
|
|
22
23
|
"dev": "vite build --watch",
|
|
23
24
|
"prebuild": "pnpm run clean",
|
|
24
25
|
"build": "vite build",
|
|
25
|
-
"prepack": "pnpm build"
|
|
26
|
-
"push": "dc-publish npm"
|
|
26
|
+
"prepack": "pnpm build"
|
|
27
27
|
},
|
|
28
28
|
"repository": {
|
|
29
29
|
"type": "git",
|
|
30
|
-
"url": "https://gitee.com/justsosu/
|
|
30
|
+
"url": "https://gitee.com/justsosu/done-coding-cli.git",
|
|
31
|
+
"directory": "packages/create"
|
|
31
32
|
},
|
|
32
33
|
"author": "JustSoSu",
|
|
33
|
-
"license": "
|
|
34
|
+
"license": "MIT",
|
|
34
35
|
"sideEffects": false,
|
|
35
36
|
"devDependencies": {
|
|
36
|
-
"@commitlint/cli": "^16.3.0",
|
|
37
|
-
"@commitlint/config-conventional": "^16.2.4",
|
|
38
|
-
"@done-coding/publish": "0.1.0",
|
|
39
37
|
"@types/node": "^16.18.58",
|
|
40
38
|
"@types/prompts": "^2.4.6",
|
|
41
39
|
"@types/yargs": "^17.0.33",
|
|
42
|
-
"
|
|
43
|
-
"@typescript-eslint/parser": "^6.7.0",
|
|
44
|
-
"conventional-changelog-cli": "^4.1.0",
|
|
45
|
-
"eslint": "^8.49.0",
|
|
46
|
-
"eslint-config-alloy": "^5.1.2",
|
|
47
|
-
"husky": "^8.0.3",
|
|
48
|
-
"lint-staged": "^12.5.0",
|
|
49
|
-
"prettier": "^3.0.3",
|
|
50
|
-
"rimraf": "^5.0.1",
|
|
40
|
+
"rimraf": "^6.0.1",
|
|
51
41
|
"typescript": "^5.2.2",
|
|
52
42
|
"vite": "^4.4.11",
|
|
53
43
|
"vite-plugin-dts": "^3.6.0"
|
|
54
44
|
},
|
|
55
|
-
"lint-staged": {
|
|
56
|
-
"*.{ts,js,vue,jsx,tsx}": [
|
|
57
|
-
"eslint --fix",
|
|
58
|
-
"prettier --write"
|
|
59
|
-
]
|
|
60
|
-
},
|
|
61
45
|
"engines": {
|
|
62
46
|
"node": ">=16.0.0"
|
|
63
47
|
},
|
|
@@ -65,5 +49,6 @@
|
|
|
65
49
|
"chalk": "^5.3.0",
|
|
66
50
|
"prompts": "^2.4.2",
|
|
67
51
|
"yargs": "^17.7.2"
|
|
68
|
-
}
|
|
52
|
+
},
|
|
53
|
+
"gitHead": "505e67277f0f24385c0942bbbdbfde17e9076f63"
|
|
69
54
|
}
|
package/types/handler.d.ts
CHANGED
package/types/main.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { CommandModule } from
|
|
2
|
-
import { Options } from './utils';
|
|
3
|
-
|
|
1
|
+
import type { CommandModule } from "yargs";
|
|
2
|
+
import type { Options } from './utils';
|
|
4
3
|
export declare const command: CommandModule<Options, Options>;
|
|
5
4
|
export declare const createCli: () => Promise<undefined>;
|
package/types/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
1
|
+
export * from "./readConfig";
|
|
2
|
+
export * from "./packageInfo";
|
|
3
|
+
export * from "./const";
|
|
4
|
+
export * from "./types";
|
|
5
|
+
export * from "./question";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { PromptObject } from
|
|
2
|
-
|
|
1
|
+
import type { PromptObject } from "prompts";
|
|
3
2
|
/** 模版选项 */
|
|
4
3
|
export interface TemplateChoiceItem {
|
|
5
4
|
name: string;
|
|
@@ -16,3 +15,8 @@ export declare const saveGitHistoryForm: {
|
|
|
16
15
|
name: string;
|
|
17
16
|
message: string;
|
|
18
17
|
};
|
|
18
|
+
export declare const shallowCloneForm: {
|
|
19
|
+
type: "confirm";
|
|
20
|
+
name: string;
|
|
21
|
+
message: string;
|
|
22
|
+
};
|