create-done-coding 0.5.1 → 0.5.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/es/cli.mjs CHANGED
@@ -1,3 +1,12 @@
1
1
  #!/usr/bin/env node
2
- import { createCli as e } from "./main.mjs";
3
- e();
2
+ import { c as r } from "./index-14b468ab.js";
3
+ import "chalk";
4
+ import "node:child_process";
5
+ import "node:path";
6
+ import "node:fs";
7
+ import "prompts";
8
+ import "@done-coding/cli-template";
9
+ import "@done-coding/node-tools";
10
+ import "yargs";
11
+ import "yargs/helpers";
12
+ r();
@@ -0,0 +1,171 @@
1
+ #!/usr/bin/env node
2
+ import t from "chalk";
3
+ import { execSync as w } from "node:child_process";
4
+ import g, { resolve as E } from "node:path";
5
+ import l, { existsSync as N, rmSync as y } from "node:fs";
6
+ import n from "prompts";
7
+ import { getConfigPath as S, batchHandler as F } from "@done-coding/cli-template";
8
+ import { lookForParentTarget as I } from "@done-coding/node-tools";
9
+ import L from "yargs";
10
+ import { hideBin as O } from "yargs/helpers";
11
+ const P = "git@gitee.com:justsosu/done-coding-cli-config-json.git", C = "自定义模版路径", U = "./.create-done-coding_temp", p = {
12
+ version: "0.5.2",
13
+ name: "create-done-coding",
14
+ description: "项目创建命令行工具",
15
+ cliConfig: {
16
+ namespaceDir: ".done-coding",
17
+ moduleName: "create"
18
+ }
19
+ };
20
+ let h;
21
+ const _ = async () => (h || (h = (await A()).templateList), h), $ = async () => [...await _(), { name: C }], j = {
22
+ type: "text",
23
+ name: "projectName",
24
+ message: "请输入项目名称",
25
+ validate: (e) => e.trim().length > 0 || "项目名称不能为空"
26
+ }, R = async () => ({
27
+ type: "select",
28
+ name: "template",
29
+ message: "请选择模板",
30
+ choices: (await $()).map((o) => ({
31
+ title: o.name,
32
+ value: o.name
33
+ }))
34
+ }), H = {
35
+ type: "confirm",
36
+ name: "saveGitHistory",
37
+ message: "是否保留git历史",
38
+ initial: !1
39
+ }, T = (e = "项目已存在,是否删除") => ({
40
+ type: "confirm",
41
+ name: "isRemove",
42
+ message: e
43
+ }), A = async () => {
44
+ console.log(t.blue("拉取模板列表,请稍等..."));
45
+ const e = g.resolve(
46
+ process.cwd(),
47
+ U
48
+ );
49
+ if (console.log(t.blue(`配置临时目录:${e}`)), l.existsSync(e)) {
50
+ const i = `${e}目录已存在,是否删除?`, { isRemove: r } = await n(T(i));
51
+ r ? l.rmSync(e, { recursive: !0, force: !0 }) : (console.log(t.red(`${e}已存在,请手动删除后再试!`)), process.exit(1));
52
+ }
53
+ w(`git clone ${P} ${e} --depth=1`);
54
+ const o = p.name, c = g.resolve(e, `${o}.json`), f = JSON.parse(l.readFileSync(c, "utf-8"));
55
+ if (!Array.isArray(f.templateList))
56
+ throw new Error("远程配置文件出错,templateList 不是数组");
57
+ return console.log(t.green("模板列表拉取成功!")), l.rmSync(e, { recursive: !0, force: !0 }), f;
58
+ }, G = async (e) => {
59
+ const { projectName: o, template: c } = e, i = ((o ?? (await n(j)).projectName) || "").trim();
60
+ if (!i.trim()) {
61
+ console.log(t.red("项目名称不能为空"));
62
+ return;
63
+ }
64
+ if (i.includes(" ") || i.includes("\\") || i.includes("/")) {
65
+ console.log(t.red("项目名称不能包含空格或者\\或者/"));
66
+ return;
67
+ }
68
+ const r = E(process.cwd(), i);
69
+ if (N(r)) {
70
+ const { isRemove: s } = await n(T());
71
+ if (s === !0)
72
+ y(r, { recursive: !0, force: !0 });
73
+ else
74
+ return console.log(t.red("项目已存在")), process.exit(1);
75
+ }
76
+ const m = c ?? (await n(await R())).template;
77
+ let u = "";
78
+ if (m === C) {
79
+ const { customUrl: s } = await n({
80
+ type: "text",
81
+ name: "customUrl",
82
+ message: "请输入自定义模板路径"
83
+ });
84
+ u = s;
85
+ } else {
86
+ const s = (await $()).find(
87
+ (a) => a.name === m
88
+ );
89
+ if (!s)
90
+ return console.log(t.red(`模板${m}不存在`)), process.exit(1);
91
+ if (!s.url)
92
+ return console.log(t.red(`模板${m}仓库地址不存在`)), process.exit(1);
93
+ u = s.url;
94
+ }
95
+ const d = I(".git");
96
+ console.log(t.green("正在初始化项目,请稍等...")), w(`git clone ${u} ${i} --depth=1`);
97
+ const v = S(r);
98
+ if (v) {
99
+ await F({
100
+ rootDir: r
101
+ });
102
+ const { isRemoveTemplateConfig: s } = await n({
103
+ type: "confirm",
104
+ name: "isRemoveTemplateConfig",
105
+ message: `已成功将模板项目配置注入到当前项目,是否删除模板项目配置文件(${v})`
106
+ });
107
+ s && y(v, { force: !0 });
108
+ }
109
+ if (console.log(t.green("项目初始化完成")), d) {
110
+ const s = g.resolve(r), a = g.resolve(s, ".git");
111
+ if (!N(a))
112
+ throw new Error("git目录不存在");
113
+ const { isRemoveGit: b } = await n({
114
+ type: "confirm",
115
+ name: "isRemoveGit",
116
+ message: `项目创建在父级git仓库${d}中,是否删除${i}目录下的.git(${a})`
117
+ });
118
+ b ? (y(a, { recursive: !0, force: !0 }), console.log(t.green("已删除当前项目git目录"))) : console.log(
119
+ t.yellow(
120
+ `项目创建在父级git仓库${d}中,请手动删除${i}目录下的.git(${a}),否则会影响后续的git操作`
121
+ )
122
+ );
123
+ } else
124
+ (await n(H)).saveGitHistory && (w(
125
+ `cd ${r} && git remote rename origin upstream && git fetch --unshallow`
126
+ ), console.log(
127
+ t.green(
128
+ "已经将origin重命名为upstream,后续可以与模板git仓库有完整的交互"
129
+ )
130
+ ), console.log(
131
+ t.green("已保存git历史记录,后续可以与模板git仓库有完整的交互")
132
+ ));
133
+ console.log(
134
+ t.blue(`
135
+ 使用步骤:
136
+ 1. cd ${i}
137
+ 2. pnpm install
138
+ 3. pnpm run dev
139
+ `)
140
+ );
141
+ }, M = async () => ({
142
+ projectName: {
143
+ type: "string",
144
+ alias: "p",
145
+ describe: j.message
146
+ },
147
+ template: {
148
+ type: "string",
149
+ alias: "t",
150
+ choices: (await $()).map((e) => e.name),
151
+ describe: (await R()).message
152
+ }
153
+ }), x = p.cliConfig.moduleName, k = (e, o) => {
154
+ console.log(e ? t.red(e) : t.red(o.message)), process.exit(1);
155
+ }, Y = p.description, B = `Usage: $0 ${x} [options]`, J = "Usage: $0 [options]", D = async (e, o) => {
156
+ const c = await M();
157
+ return e.strict().usage(o).help("help").version(p.version).alias("v", "version").alias("h", "help").options(c).fail(k).argv;
158
+ }, q = (e) => D(e, B), oe = {
159
+ command: x,
160
+ describe: Y,
161
+ builder: q,
162
+ handler: G
163
+ }, se = async () => {
164
+ const e = L(O(process.argv)), o = await D(e, J);
165
+ return G(o);
166
+ };
167
+ export {
168
+ oe as a,
169
+ se as c,
170
+ G as h
171
+ };
package/es/index.mjs CHANGED
@@ -1,7 +1,15 @@
1
1
  #!/usr/bin/env node
2
- import { handler as e } from "./handler.mjs";
3
- import { command as m } from "./main.mjs";
2
+ import { a as h, h as b } from "./index-14b468ab.js";
3
+ import "chalk";
4
+ import "node:child_process";
5
+ import "node:path";
6
+ import "node:fs";
7
+ import "prompts";
8
+ import "@done-coding/cli-template";
9
+ import "@done-coding/node-tools";
10
+ import "yargs";
11
+ import "yargs/helpers";
4
12
  export {
5
- m as command,
6
- e as handler
13
+ h as command,
14
+ b as handler
7
15
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-done-coding",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "项目创建命令行工具",
5
5
  "module": "es/index.mjs",
6
6
  "type": "module",
@@ -38,7 +38,7 @@
38
38
  "license": "MIT",
39
39
  "sideEffects": false,
40
40
  "devDependencies": {
41
- "@done-coding/cli-inject": "^0.4.2",
41
+ "@done-coding/cli-inject": "^0.4.3",
42
42
  "@types/node": "^18.0.0",
43
43
  "@types/prompts": "^2.4.6",
44
44
  "@types/yargs": "^17.0.28",
@@ -51,11 +51,11 @@
51
51
  "node": ">=18.0.0"
52
52
  },
53
53
  "dependencies": {
54
- "@done-coding/cli-template": "^0.4.1",
55
- "@done-coding/node-tools": "^0.0.1",
54
+ "@done-coding/cli-template": "^0.4.2",
55
+ "@done-coding/node-tools": "^0.0.2",
56
56
  "chalk": "^5.3.0",
57
57
  "prompts": "^2.4.2",
58
58
  "yargs": "^17.7.2"
59
59
  },
60
- "gitHead": "5a8844aa8d54b3f84ab8aa287479bda2da13467a"
60
+ "gitHead": "516ef8bb086ae7be558c68bd7392501ef3ed6052"
61
61
  }
@@ -1,5 +1,5 @@
1
1
  declare const _default: {
2
- "version": "0.5.1",
2
+ "version": "0.5.2",
3
3
  "name": "create-done-coding",
4
4
  "description": "项目创建命令行工具",
5
5
  "cliConfig": {
package/es/handler.mjs DELETED
@@ -1,97 +0,0 @@
1
- #!/usr/bin/env node
2
- import { CUSTOM_TEMPLATE_NAME as $ } from "./utils/const.mjs";
3
- import { projectNameForm as h, getRemoveDirForm as y, getTemplateForm as N, getTemplateChoices as T, saveGitHistoryForm as G } from "./utils/question.mjs";
4
- import r from "prompts";
5
- import { execSync as g } from "node:child_process";
6
- import { existsSync as p, rmSync as l } from "node:fs";
7
- import f, { resolve as j } from "node:path";
8
- import t from "chalk";
9
- import { getConfigPath as x, batchHandler as R } from "@done-coding/cli-template";
10
- import { lookForParentTarget as C } from "@done-coding/node-tools";
11
- const k = async (u) => {
12
- const { projectName: d, template: v } = u, o = ((d ?? (await r(h)).projectName) || "").trim();
13
- if (!o.trim()) {
14
- console.log(t.red("项目名称不能为空"));
15
- return;
16
- }
17
- if (o.includes(" ") || o.includes("\\") || o.includes("/")) {
18
- console.log(t.red("项目名称不能包含空格或者\\或者/"));
19
- return;
20
- }
21
- const i = j(process.cwd(), o);
22
- if (p(i)) {
23
- const { isRemove: e } = await r(y());
24
- if (e === !0)
25
- l(i, { recursive: !0, force: !0 });
26
- else
27
- return console.log(t.red("项目已存在")), process.exit(1);
28
- }
29
- const n = v ?? (await r(await N())).template;
30
- let c = "";
31
- if (n === $) {
32
- const { customUrl: e } = await r({
33
- type: "text",
34
- name: "customUrl",
35
- message: "请输入自定义模板路径"
36
- });
37
- c = e;
38
- } else {
39
- const e = (await T()).find(
40
- (s) => s.name === n
41
- );
42
- if (!e)
43
- return console.log(t.red(`模板${n}不存在`)), process.exit(1);
44
- if (!e.url)
45
- return console.log(t.red(`模板${n}仓库地址不存在`)), process.exit(1);
46
- c = e.url;
47
- }
48
- const m = C(".git");
49
- console.log(t.green("正在初始化项目,请稍等...")), g(`git clone ${c} ${o} --depth=1`);
50
- const a = x(i);
51
- if (a) {
52
- await R({
53
- rootDir: i
54
- });
55
- const { isRemoveTemplateConfig: e } = await r({
56
- type: "confirm",
57
- name: "isRemoveTemplateConfig",
58
- message: `已成功将模板项目配置注入到当前项目,是否删除模板项目配置文件(${a})`
59
- });
60
- e && l(a, { force: !0 });
61
- }
62
- if (console.log(t.green("项目初始化完成")), m) {
63
- const e = f.resolve(i), s = f.resolve(e, ".git");
64
- if (!p(s))
65
- throw new Error("git目录不存在");
66
- const { isRemoveGit: w } = await r({
67
- type: "confirm",
68
- name: "isRemoveGit",
69
- message: `项目创建在父级git仓库${m}中,是否删除${o}目录下的.git(${s})`
70
- });
71
- w ? (l(s, { recursive: !0, force: !0 }), console.log(t.green("已删除当前项目git目录"))) : console.log(
72
- t.yellow(
73
- `项目创建在父级git仓库${m}中,请手动删除${o}目录下的.git(${s}),否则会影响后续的git操作`
74
- )
75
- );
76
- } else
77
- (await r(G)).saveGitHistory && (g(
78
- `cd ${i} && git remote rename origin upstream && git fetch --unshallow`
79
- ), console.log(
80
- t.green(
81
- "已经将origin重命名为upstream,后续可以与模板git仓库有完整的交互"
82
- )
83
- ), console.log(
84
- t.green("已保存git历史记录,后续可以与模板git仓库有完整的交互")
85
- ));
86
- console.log(
87
- t.blue(`
88
- 使用步骤:
89
- 1. cd ${o}
90
- 2. pnpm install
91
- 3. pnpm run dev
92
- `)
93
- );
94
- };
95
- export {
96
- k as handler
97
- };
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env node
2
- const e = {
3
- version: "0.5.1",
4
- name: "create-done-coding",
5
- description: "项目创建命令行工具",
6
- cliConfig: {
7
- namespaceDir: ".done-coding",
8
- moduleName: "create"
9
- }
10
- };
11
- export {
12
- e as default
13
- };
package/es/main.mjs DELETED
@@ -1,37 +0,0 @@
1
- #!/usr/bin/env node
2
- import c from "yargs";
3
- import { hideBin as m } from "yargs/helpers";
4
- import { handler as a } from "./handler.mjs";
5
- import t from "chalk";
6
- import { projectNameForm as p, getTemplateChoices as l, getTemplateForm as g } from "./utils/question.mjs";
7
- import s from "./injectInfo.json.mjs";
8
- const d = async () => ({
9
- projectName: {
10
- type: "string",
11
- alias: "p",
12
- describe: p.message
13
- },
14
- template: {
15
- type: "string",
16
- alias: "t",
17
- choices: (await l()).map((e) => e.name),
18
- describe: (await g()).message
19
- }
20
- }), n = s.cliConfig.moduleName, f = (e, o) => {
21
- console.log(e ? t.red(e) : t.red(o.message)), process.exit(1);
22
- }, h = s.description, u = `Usage: $0 ${n} [options]`, v = "Usage: $0 [options]", i = async (e, o) => {
23
- const r = await d();
24
- return e.strict().usage(o).help("help").version(s.version).alias("v", "version").alias("h", "help").options(r).fail(f).argv;
25
- }, y = (e) => i(e, u), $ = {
26
- command: n,
27
- describe: h,
28
- builder: y,
29
- handler: a
30
- }, x = async () => {
31
- const e = c(m(process.argv)), o = await i(e, v);
32
- return a(o);
33
- };
34
- export {
35
- $ as command,
36
- x as createCli
37
- };
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env node
2
- const o = "git@gitee.com:justsosu/done-coding-cli-config-json.git", n = "自定义模版路径", e = "./.create-done-coding_temp";
3
- export {
4
- o as CONFIG_GIT_REPO,
5
- n as CUSTOM_TEMPLATE_NAME,
6
- e as READ_CONFIG_TEMPORARY_DIRECTORY
7
- };
@@ -1,35 +0,0 @@
1
- #!/usr/bin/env node
2
- import { CUSTOM_TEMPLATE_NAME as m } from "./const.mjs";
3
- import { readConfig as s } from "./readConfig.mjs";
4
- let t;
5
- const o = async () => (t || (t = (await s()).templateList), t), i = async () => [...await o(), { name: m }], c = {
6
- type: "text",
7
- name: "projectName",
8
- message: "请输入项目名称",
9
- validate: (e) => e.trim().length > 0 || "项目名称不能为空"
10
- }, p = async () => ({
11
- type: "select",
12
- name: "template",
13
- message: "请选择模板",
14
- choices: (await i()).map((a) => ({
15
- title: a.name,
16
- value: a.name
17
- }))
18
- }), l = {
19
- type: "confirm",
20
- name: "saveGitHistory",
21
- message: "是否保留git历史",
22
- initial: !1
23
- }, g = (e = "项目已存在,是否删除") => ({
24
- type: "confirm",
25
- name: "isRemove",
26
- message: e
27
- });
28
- export {
29
- g as getRemoveDirForm,
30
- i as getTemplateChoices,
31
- p as getTemplateForm,
32
- o as getTemplateList,
33
- c as projectNameForm,
34
- l as saveGitHistoryForm
35
- };
@@ -1,28 +0,0 @@
1
- #!/usr/bin/env node
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(
13
- process.cwd(),
14
- p
15
- );
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))
23
- throw new Error("远程配置文件出错,templateList 不是数组");
24
- return console.log(o.green("模板列表拉取成功!")), r.rmSync(e, { recursive: !0, force: !0 }), t;
25
- };
26
- export {
27
- E as readConfig
28
- };