create-done-coding 0.5.2 → 0.6.0-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/README.md CHANGED
File without changes
package/es/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { c as r } from "./index-14b468ab.js";
2
+ import { c as r } from "./index-bc94eb69.js";
3
3
  import "chalk";
4
4
  import "node:child_process";
5
5
  import "node:path";
@@ -0,0 +1,185 @@
1
+ #!/usr/bin/env node
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";
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";
9
+ import I from "yargs";
10
+ 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-alpha.0",
13
+ name: "create-done-coding",
14
+ description: "项目创建命令行工具",
15
+ cliConfig: {
16
+ namespaceDir: ".done-coding",
17
+ moduleName: "create"
18
+ }
19
+ };
20
+ let w;
21
+ const _ = async () => (w || (w = (await A()).templateList), w), $ = async () => [...await _(), { name: C }], j = {
22
+ type: "text",
23
+ name: "projectName",
24
+ message: "请输入项目名称",
25
+ validate: (e) => e.trim().length > 0 || "项目名称不能为空"
26
+ }, G = async () => ({
27
+ type: "select",
28
+ name: "template",
29
+ message: "请选择模板",
30
+ choices: (await $()).map((s) => ({
31
+ title: s.name,
32
+ value: s.name
33
+ }))
34
+ }), H = {
35
+ type: "confirm",
36
+ name: "saveGitHistory",
37
+ message: "是否保留git历史",
38
+ initial: !1
39
+ }, R = (e = "项目已存在,是否删除") => ({
40
+ type: "confirm",
41
+ name: "isRemove",
42
+ message: e
43
+ }), A = async () => {
44
+ console.log(t.blue("拉取模板列表,请稍等..."));
45
+ const e = l.resolve(
46
+ process.cwd(),
47
+ U
48
+ );
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));
52
+ }
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))
56
+ 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();
60
+ if (!o.trim()) {
61
+ console.log(t.red("项目名称不能为空"));
62
+ return;
63
+ }
64
+ if (o.includes(" ") || o.includes("\\") || o.includes("/")) {
65
+ console.log(t.red("项目名称不能包含空格或者\\或者/"));
66
+ return;
67
+ }
68
+ const r = b(process.cwd(), o);
69
+ if (N(r)) {
70
+ const { isRemove: i } = await a(R());
71
+ if (i === !0)
72
+ f(r, { recursive: !0, force: !0 });
73
+ else
74
+ return console.log(t.red("项目已存在")), process.exit(1);
75
+ }
76
+ const g = c ?? (await a(await G())).template;
77
+ let v = "";
78
+ if (g === C) {
79
+ const { customUrl: i } = await a({
80
+ type: "text",
81
+ name: "customUrl",
82
+ message: "请输入自定义模板路径"
83
+ });
84
+ v = i;
85
+ } else {
86
+ const i = (await $()).find(
87
+ (n) => n.name === g
88
+ );
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;
94
+ }
95
+ const y = F(".git");
96
+ console.log(t.green("正在初始化项目,请稍等...")), m(`git clone ${v} ${o} --depth=1`);
97
+ const h = P(r);
98
+ if (h) {
99
+ await S({
100
+ rootDir: r,
101
+ extraEnvData: {
102
+ $projectName: o
103
+ }
104
+ });
105
+ const { isRemoveTemplateConfig: i } = await a({
106
+ type: "confirm",
107
+ name: "isRemoveTemplateConfig",
108
+ message: `已成功将模板项目配置注入到当前项目,是否删除模板项目配置文件(${h})`,
109
+ initial: !0
110
+ });
111
+ i && f(h, { force: !0 });
112
+ }
113
+ if (console.log(t.green("项目初始化完成")), y) {
114
+ const i = l.resolve(r), n = l.resolve(i, ".git");
115
+ if (!N(n))
116
+ throw new Error("git目录不存在");
117
+ const { isRemoveGit: E } = await a({
118
+ type: "confirm",
119
+ name: "isRemoveGit",
120
+ message: `项目创建在父级git仓库${y}中,是否删除${o}目录下的.git(${n})`,
121
+ initial: !0
122
+ });
123
+ E ? (f(n, { recursive: !0, force: !0 }), console.log(t.green("已删除当前项目git目录"))) : console.log(
124
+ t.yellow(
125
+ `项目创建在父级git仓库${y}中,请手动删除${o}目录下的.git(${n}),否则会影响后续的git操作`
126
+ )
127
+ );
128
+ } else {
129
+ if ((await a(H)).saveGitHistory)
130
+ m(
131
+ `cd ${r} && git remote rename origin upstream && git fetch --unshallow`
132
+ ), console.log(
133
+ t.green(
134
+ "已经将origin重命名为upstream,后续可以与模板git仓库有完整的交互"
135
+ )
136
+ ), console.log(
137
+ t.green("已保存git历史记录,后续可以与模板git仓库有完整的交互")
138
+ );
139
+ else {
140
+ const n = l.resolve(r, ".git");
141
+ f(n, { recursive: !0, force: !0 }), m(`cd ${r} && git init`);
142
+ }
143
+ m(
144
+ `cd ${r} && git add . && git commit -m '初始化${o}'`
145
+ );
146
+ }
147
+ console.log(
148
+ t.blue(`
149
+ 使用步骤:
150
+ 1. cd ${o}
151
+ 2. pnpm install
152
+ 3. pnpm run dev
153
+ `)
154
+ );
155
+ }, M = async () => ({
156
+ projectName: {
157
+ type: "string",
158
+ alias: "p",
159
+ describe: j.message
160
+ },
161
+ template: {
162
+ type: "string",
163
+ alias: "t",
164
+ choices: (await $()).map((e) => e.name),
165
+ describe: (await G()).message
166
+ }
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 = {
173
+ 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);
180
+ };
181
+ export {
182
+ oe as a,
183
+ se as c,
184
+ T as h
185
+ };
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-14b468ab.js";
2
+ import { a as h, h as b } from "./index-bc94eb69.js";
3
3
  import "chalk";
4
4
  import "node:child_process";
5
5
  import "node:path";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-done-coding",
3
- "version": "0.5.2",
3
+ "version": "0.6.0-alpha.0",
4
4
  "description": "项目创建命令行工具",
5
5
  "module": "es/index.mjs",
6
6
  "type": "module",
@@ -51,11 +51,11 @@
51
51
  "node": ">=18.0.0"
52
52
  },
53
53
  "dependencies": {
54
- "@done-coding/cli-template": "^0.4.2",
54
+ "@done-coding/cli-template": "^0.5.0-alpha.0",
55
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": "516ef8bb086ae7be558c68bd7392501ef3ed6052"
60
+ "gitHead": "c386db9e11a6e5cf017839d657cd4c0bf1fb6a90"
61
61
  }
package/types/cli.d.ts CHANGED
File without changes
File without changes
package/types/index.d.ts CHANGED
File without changes
@@ -1,5 +1,5 @@
1
1
  declare const _default: {
2
- "version": "0.5.2",
2
+ "version": "0.6.0-alpha.0",
3
3
  "name": "create-done-coding",
4
4
  "description": "项目创建命令行工具",
5
5
  "cliConfig": {
package/types/main.d.ts CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,171 +0,0 @@
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
- };