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