@done-coding/cli-template 0.6.0 → 0.6.1-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/es/cli.mjs +2 -2
- package/es/{index-07bb6534.js → index-9892305e.js} +36 -36
- package/es/index.mjs +2 -2
- package/package.json +4 -4
- package/types/index.d.ts +1 -1
- package/types/injectInfo.json.d.ts +1 -1
package/es/cli.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { c as r } from "./index-
|
|
2
|
+
import { c as r } from "./index-9892305e.js";
|
|
3
3
|
import "node:path";
|
|
4
4
|
import "node:fs";
|
|
5
5
|
import "chalk";
|
|
6
6
|
import "lodash.template";
|
|
7
7
|
import "lodash.assign";
|
|
8
8
|
import "prompts";
|
|
9
|
-
import "@done-coding/
|
|
9
|
+
import "@done-coding/cli-utils";
|
|
10
10
|
import "yargs";
|
|
11
11
|
import "yargs/helpers";
|
|
12
12
|
r();
|
|
@@ -5,7 +5,7 @@ import o from "chalk";
|
|
|
5
5
|
import E from "lodash.template";
|
|
6
6
|
import A from "lodash.assign";
|
|
7
7
|
import N from "prompts";
|
|
8
|
-
import { onPromptFormStateForSigint as P } from "@done-coding/
|
|
8
|
+
import { onPromptFormStateForSigint as P } from "@done-coding/cli-utils";
|
|
9
9
|
import U from "yargs";
|
|
10
10
|
import { hideBin as W } from "yargs/helpers";
|
|
11
11
|
var g = /* @__PURE__ */ ((e) => (e.OVERWRITE = "overwrite", e.APPEND = "append", e.REPLACE = "replace", e.RETURN = "return", e))(g || {});
|
|
@@ -24,7 +24,7 @@ const $ = {
|
|
|
24
24
|
...i
|
|
25
25
|
};
|
|
26
26
|
}, S = {
|
|
27
|
-
version: "0.6.0",
|
|
27
|
+
version: "0.6.1-alpha.0",
|
|
28
28
|
name: "@done-coding/cli-template",
|
|
29
29
|
description: "预编译命令行工具",
|
|
30
30
|
cliConfig: {
|
|
@@ -50,9 +50,9 @@ const $ = {
|
|
|
50
50
|
return console.log(
|
|
51
51
|
o.red(`${s}必须是json文件,请检查文件后缀名`)
|
|
52
52
|
), process.exit(1);
|
|
53
|
-
const
|
|
54
|
-
let p =
|
|
55
|
-
return i && e.endsWith(".md") && (p =
|
|
53
|
+
const l = c.readFileSync(v.resolve(e), "utf-8");
|
|
54
|
+
let p = l;
|
|
55
|
+
return i && e.endsWith(".md") && (p = l.replace(
|
|
56
56
|
/^\s*```[a-zA-Z0-9]+\s*[\r\n]+([\s\S]+?)```\s*$/,
|
|
57
57
|
"$1"
|
|
58
58
|
)), a ? JSON.parse(p) : p;
|
|
@@ -77,22 +77,22 @@ const $ = {
|
|
|
77
77
|
input: s,
|
|
78
78
|
inputData: u,
|
|
79
79
|
output: i,
|
|
80
|
-
mode:
|
|
80
|
+
mode: l,
|
|
81
81
|
rollback: p,
|
|
82
82
|
dealMarkdown: y,
|
|
83
83
|
envData: h
|
|
84
84
|
} = e;
|
|
85
85
|
if (p)
|
|
86
|
-
switch (
|
|
86
|
+
switch (l) {
|
|
87
87
|
case g.REPLACE:
|
|
88
88
|
case g.RETURN: {
|
|
89
|
-
console.log(o.red(`${
|
|
89
|
+
console.log(o.red(`${l}模式不支持回滚`));
|
|
90
90
|
return;
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
console.log(
|
|
94
94
|
o.blue(`开始处理模板
|
|
95
|
-
mode: ${
|
|
95
|
+
mode: ${l}
|
|
96
96
|
rollback: ${p}
|
|
97
97
|
`)
|
|
98
98
|
);
|
|
@@ -103,30 +103,30 @@ rollback: ${p}
|
|
|
103
103
|
filePathKey: "input",
|
|
104
104
|
dataInitKey: "inputData",
|
|
105
105
|
dealMarkdown: y
|
|
106
|
-
}),
|
|
107
|
-
switch (
|
|
106
|
+
}), r = E(k), m = typeof h == "function" ? h() : h, f = r(m);
|
|
107
|
+
switch (l) {
|
|
108
108
|
case g.OVERWRITE: {
|
|
109
|
-
D(
|
|
109
|
+
D(l, i), R(i, s);
|
|
110
110
|
const t = v.resolve(i);
|
|
111
111
|
if (c.mkdirSync(v.dirname(t), { recursive: !0 }), c.existsSync(t)) {
|
|
112
112
|
if (p)
|
|
113
113
|
if (n || (await N({
|
|
114
114
|
type: "confirm",
|
|
115
115
|
name: "remove",
|
|
116
|
-
message: `${
|
|
116
|
+
message: `${l}模式下回滚将删除${t},是否继续?`,
|
|
117
117
|
onState: P
|
|
118
118
|
})).remove) {
|
|
119
|
-
c.rmSync(t, { force: !0 }), console.log(o.green(`${
|
|
119
|
+
c.rmSync(t, { force: !0 }), console.log(o.green(`${l}模式下${t}已删除`));
|
|
120
120
|
return;
|
|
121
121
|
} else {
|
|
122
|
-
console.log(o.yellow(`${
|
|
122
|
+
console.log(o.yellow(`${l}模式下${t}回滚取消`));
|
|
123
123
|
return;
|
|
124
124
|
}
|
|
125
125
|
console.log(o.blue(`output:${t} 已存在,将覆盖`));
|
|
126
126
|
} else {
|
|
127
127
|
if (p) {
|
|
128
128
|
console.log(
|
|
129
|
-
o.yellow(`${
|
|
129
|
+
o.yellow(`${l}模式下${t}不存在,无需回滚`)
|
|
130
130
|
);
|
|
131
131
|
return;
|
|
132
132
|
}
|
|
@@ -136,7 +136,7 @@ rollback: ${p}
|
|
|
136
136
|
break;
|
|
137
137
|
}
|
|
138
138
|
case g.APPEND: {
|
|
139
|
-
D(
|
|
139
|
+
D(l, i), R(i, s);
|
|
140
140
|
const t = v.resolve(i);
|
|
141
141
|
if (c.mkdirSync(v.dirname(t), { recursive: !0 }), c.existsSync(t)) {
|
|
142
142
|
const d = c.readFileSync(t, "utf-8");
|
|
@@ -145,7 +145,7 @@ rollback: ${p}
|
|
|
145
145
|
t,
|
|
146
146
|
d.replace(f, ""),
|
|
147
147
|
"utf-8"
|
|
148
|
-
), console.log(o.green(`${
|
|
148
|
+
), console.log(o.green(`${l}模式下${t}回滚完成`));
|
|
149
149
|
return;
|
|
150
150
|
}
|
|
151
151
|
const b = d + f;
|
|
@@ -153,7 +153,7 @@ rollback: ${p}
|
|
|
153
153
|
} else {
|
|
154
154
|
if (p) {
|
|
155
155
|
console.log(
|
|
156
|
-
o.yellow(`${
|
|
156
|
+
o.yellow(`${l}模式下${t}不存在,无需回滚`)
|
|
157
157
|
);
|
|
158
158
|
return;
|
|
159
159
|
}
|
|
@@ -162,7 +162,7 @@ rollback: ${p}
|
|
|
162
162
|
break;
|
|
163
163
|
}
|
|
164
164
|
case g.REPLACE: {
|
|
165
|
-
if (i && console.log(o.yellow(`output ${i} 将被忽略`)), M(
|
|
165
|
+
if (i && console.log(o.yellow(`output ${i} 将被忽略`)), M(l, s), a && a === s)
|
|
166
166
|
return console.log(o.red("env 与 input 不能相同")), process.exit(1);
|
|
167
167
|
const t = v.resolve(s);
|
|
168
168
|
let d = t;
|
|
@@ -178,7 +178,7 @@ rollback: ${p}
|
|
|
178
178
|
o.green("模板处理完成,返回结果(函数调用才会拿到返回值)")
|
|
179
179
|
), f;
|
|
180
180
|
default:
|
|
181
|
-
return console.log(o.red(`mode ${
|
|
181
|
+
return console.log(o.red(`mode ${l} 不支持`)), process.exit(1);
|
|
182
182
|
}
|
|
183
183
|
return f;
|
|
184
184
|
}, j = async ({
|
|
@@ -190,20 +190,20 @@ rollback: ${p}
|
|
|
190
190
|
if (s)
|
|
191
191
|
u = s;
|
|
192
192
|
else {
|
|
193
|
-
const
|
|
194
|
-
if (!
|
|
195
|
-
return console.log(o.red(`配置文件${
|
|
196
|
-
const m = c.readFileSync(
|
|
193
|
+
const r = J(e);
|
|
194
|
+
if (!r)
|
|
195
|
+
return console.log(o.red(`配置文件${r}不存在`)), process.exit(1);
|
|
196
|
+
const m = c.readFileSync(r, "utf-8");
|
|
197
197
|
u = JSON.parse(m);
|
|
198
198
|
}
|
|
199
199
|
const {
|
|
200
200
|
list: i,
|
|
201
|
-
globalEnvData:
|
|
201
|
+
globalEnvData: l = {},
|
|
202
202
|
collectEnvDataForm: p = []
|
|
203
203
|
} = u, y = {};
|
|
204
|
-
for (const
|
|
204
|
+
for (const r of p) {
|
|
205
205
|
let m, f, t;
|
|
206
|
-
typeof
|
|
206
|
+
typeof r == "string" ? (m = r, f = r, t = void 0) : (m = r.key, f = r.label, t = r.initial), y[m] = (await N({
|
|
207
207
|
type: "text",
|
|
208
208
|
name: m,
|
|
209
209
|
message: `请输入${f}`,
|
|
@@ -213,14 +213,14 @@ rollback: ${p}
|
|
|
213
213
|
onState: P
|
|
214
214
|
}))[m];
|
|
215
215
|
}
|
|
216
|
-
const h = i.map((
|
|
217
|
-
const { rollback: m = n } =
|
|
216
|
+
const h = i.map((r) => {
|
|
217
|
+
const { rollback: m = n } = r, {
|
|
218
218
|
envData: f,
|
|
219
219
|
env: t,
|
|
220
220
|
input: d,
|
|
221
221
|
output: b,
|
|
222
222
|
...w
|
|
223
|
-
} = C(
|
|
223
|
+
} = C(r);
|
|
224
224
|
return t && console.log(o.yellow(`批量处理中 env:${t} 将被忽略,只读envData`)), {
|
|
225
225
|
...w,
|
|
226
226
|
env: t,
|
|
@@ -229,15 +229,15 @@ rollback: ${p}
|
|
|
229
229
|
envData: A(
|
|
230
230
|
{},
|
|
231
231
|
a,
|
|
232
|
-
|
|
232
|
+
l,
|
|
233
233
|
y,
|
|
234
234
|
f
|
|
235
235
|
),
|
|
236
236
|
rollback: m
|
|
237
237
|
};
|
|
238
238
|
}), k = [];
|
|
239
|
-
for (const
|
|
240
|
-
const m = await x(
|
|
239
|
+
for (const r of h) {
|
|
240
|
+
const m = await x(r, {
|
|
241
241
|
rollbackDelFileAgree: !0
|
|
242
242
|
});
|
|
243
243
|
k.push(m);
|
|
@@ -250,7 +250,7 @@ rollback: ${p}
|
|
|
250
250
|
input: s,
|
|
251
251
|
inputData: u,
|
|
252
252
|
output: i,
|
|
253
|
-
mode:
|
|
253
|
+
mode: l,
|
|
254
254
|
rollback: p,
|
|
255
255
|
dealMarkdown: y,
|
|
256
256
|
batch: h
|
|
@@ -273,7 +273,7 @@ rollback: ${p}
|
|
|
273
273
|
input: s,
|
|
274
274
|
inputData: u,
|
|
275
275
|
output: i,
|
|
276
|
-
mode:
|
|
276
|
+
mode: l,
|
|
277
277
|
rollback: p,
|
|
278
278
|
dealMarkdown: y,
|
|
279
279
|
envData: k
|
package/es/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { O as d, b as h, a as u, g as b, h as f } from "./index-
|
|
3
|
-
export * from "@done-coding/
|
|
2
|
+
import { O as d, b as h, a as u, g as b, h as f } from "./index-9892305e.js";
|
|
3
|
+
export * from "@done-coding/cli-utils";
|
|
4
4
|
import "node:path";
|
|
5
5
|
import "node:fs";
|
|
6
6
|
import "chalk";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@done-coding/cli-template",
|
|
3
|
-
"version": "0.6.0",
|
|
3
|
+
"version": "0.6.1-alpha.0",
|
|
4
4
|
"description": "预编译命令行工具",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"sideEffects": false,
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@done-coding/cli-inject": "^0.4.
|
|
44
|
+
"@done-coding/cli-inject": "^0.4.6-alpha.0",
|
|
45
45
|
"@types/lodash.assign": "^4.2.9",
|
|
46
46
|
"@types/lodash.get": "^4.4.9",
|
|
47
47
|
"@types/lodash.set": "^4.3.9",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"node": ">=18.0.0"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@done-coding/
|
|
61
|
+
"@done-coding/cli-utils": "^0.2.1-alpha.0",
|
|
62
62
|
"chalk": "^5.3.0",
|
|
63
63
|
"lodash.assign": "^4.2.0",
|
|
64
64
|
"lodash.get": "^4.4.2",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"prompts": "^2.4.2",
|
|
68
68
|
"yargs": "^17.7.2"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "21eb698f64179882cfec979bd8f19920b047dacb"
|
|
71
71
|
}
|
package/types/index.d.ts
CHANGED