@done-coding/cli-template 0.4.1 → 0.5.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,3 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import { createCli as e } from "./main.mjs";
3
- e();
2
+ import { c as r } from "./index-a74172c0.js";
3
+ import "node:path";
4
+ import "node:fs";
5
+ import "chalk";
6
+ import "lodash.template";
7
+ import "lodash.assign";
8
+ import "prompts";
9
+ import "yargs";
10
+ import "yargs/helpers";
11
+ r();
@@ -0,0 +1,355 @@
1
+ #!/usr/bin/env node
2
+ import v from "node:path";
3
+ import i from "node:fs";
4
+ import o from "chalk";
5
+ import D from "lodash.template";
6
+ import T from "lodash.assign";
7
+ import N from "prompts";
8
+ import A from "yargs";
9
+ import { hideBin as U } from "yargs/helpers";
10
+ var g = /* @__PURE__ */ ((e) => (e.OVERWRITE = "overwrite", e.APPEND = "append", e.REPLACE = "replace", e.RETURN = "return", e))(g || {});
11
+ const $ = {
12
+ rollback: !1,
13
+ dealMarkdown: !1,
14
+ mode: g.OVERWRITE,
15
+ batch: !1
16
+ }, P = (e) => {
17
+ const { rollback: n, dealMarkdown: a, mode: s, batch: u, ...c } = e;
18
+ return {
19
+ rollback: n ?? $.rollback,
20
+ dealMarkdown: a ?? $.dealMarkdown,
21
+ mode: s ?? $.mode,
22
+ batch: u ?? $.batch,
23
+ ...c
24
+ };
25
+ }, E = {
26
+ version: "0.5.0-alpha.0",
27
+ name: "@done-coding/cli-template",
28
+ description: "预编译命令行工具",
29
+ cliConfig: {
30
+ namespaceDir: ".done-coding",
31
+ moduleName: "template"
32
+ }
33
+ }, W = (e) => {
34
+ const { namespaceDir: n, moduleName: a } = E.cliConfig, s = [n, `${a}.json`];
35
+ e && s.unshift(e);
36
+ const u = v.resolve(...s);
37
+ if (i.existsSync(u))
38
+ return u;
39
+ }, C = ({
40
+ filePath: e,
41
+ dataInit: n,
42
+ limitJson: a,
43
+ filePathKey: s,
44
+ dataInitKey: u,
45
+ dealMarkdown: c = !1
46
+ }) => {
47
+ if (e) {
48
+ if (a && !e.endsWith(".json"))
49
+ return console.log(
50
+ o.red(`${s}必须是json文件,请检查文件后缀名`)
51
+ ), process.exit(1);
52
+ const r = i.readFileSync(v.resolve(e), "utf-8");
53
+ let p = r;
54
+ return c && e.endsWith(".md") && (p = r.replace(
55
+ /^\s*```[a-zA-Z0-9]+\s*[\r\n]+([\s\S]+?)```\s*$/,
56
+ "$1"
57
+ )), a ? JSON.parse(p) : p;
58
+ } else
59
+ return n ? (console.log(
60
+ o.green(`${s} 为空,将使用${u}作为数据`)
61
+ ), a ? JSON.parse(n) : n) : (console.log(o.red(`${s}与${u}不能同时为空`)), process.exit(1));
62
+ }, R = (e, n) => {
63
+ if (!n)
64
+ return console.log(o.red(`${e}模式下output不能为空`)), process.exit(1);
65
+ }, S = (e, n) => {
66
+ if (n && e === n)
67
+ return console.log(o.red("output与input不能相同")), process.exit(1);
68
+ }, J = (e, n) => {
69
+ if (!n)
70
+ return console.log(o.red(`${e}模式下input不能为空`)), process.exit(1);
71
+ }, I = async (e, {
72
+ rollbackDelFileAgree: n = !1
73
+ } = {}) => {
74
+ const {
75
+ env: a,
76
+ input: s,
77
+ inputData: u,
78
+ output: c,
79
+ mode: r,
80
+ rollback: p,
81
+ dealMarkdown: y,
82
+ envData: h
83
+ } = e;
84
+ if (p)
85
+ switch (r) {
86
+ case g.REPLACE:
87
+ case g.RETURN: {
88
+ console.log(o.red(`${r}模式不支持回滚`));
89
+ return;
90
+ }
91
+ }
92
+ console.log(
93
+ o.blue(`开始处理模板
94
+ mode: ${r}
95
+ rollback: ${p}
96
+ `)
97
+ );
98
+ const k = C({
99
+ filePath: s,
100
+ dataInit: u,
101
+ limitJson: !1,
102
+ filePathKey: "input",
103
+ dataInitKey: "inputData",
104
+ dealMarkdown: y
105
+ }), l = D(k), f = typeof h == "function" ? h() : h, m = l(f);
106
+ switch (r) {
107
+ case g.OVERWRITE: {
108
+ R(r, c), S(c, s);
109
+ const t = v.resolve(c);
110
+ if (i.mkdirSync(v.dirname(t), { recursive: !0 }), i.existsSync(t)) {
111
+ if (p)
112
+ if (n || (await N({
113
+ type: "confirm",
114
+ name: "remove",
115
+ message: `${r}模式下回滚将删除${t},是否继续?`
116
+ })).remove) {
117
+ i.rmSync(t, { force: !0 }), console.log(o.green(`${r}模式下${t}已删除`));
118
+ return;
119
+ } else {
120
+ console.log(o.yellow(`${r}模式下${t}回滚取消`));
121
+ return;
122
+ }
123
+ console.log(o.blue(`output:${t} 已存在,将覆盖`));
124
+ } else {
125
+ if (p) {
126
+ console.log(
127
+ o.yellow(`${r}模式下${t}不存在,无需回滚`)
128
+ );
129
+ return;
130
+ }
131
+ console.log(o.blue(`output:${t} 不存在,将创建`));
132
+ }
133
+ i.writeFileSync(t, m, "utf-8"), console.log(o.green(`模板处理完成,输出到 ${t}`));
134
+ break;
135
+ }
136
+ case g.APPEND: {
137
+ R(r, c), S(c, s);
138
+ const t = v.resolve(c);
139
+ if (i.mkdirSync(v.dirname(t), { recursive: !0 }), i.existsSync(t)) {
140
+ const d = i.readFileSync(t, "utf-8");
141
+ if (p) {
142
+ i.writeFileSync(
143
+ t,
144
+ d.replace(m, ""),
145
+ "utf-8"
146
+ ), console.log(o.green(`${r}模式下${t}回滚完成`));
147
+ return;
148
+ }
149
+ const b = d + m;
150
+ i.writeFileSync(t, b, "utf-8"), console.log(o.green(`模板处理完成,追加到 ${t}`));
151
+ } else {
152
+ if (p) {
153
+ console.log(
154
+ o.yellow(`${r}模式下${t}不存在,无需回滚`)
155
+ );
156
+ return;
157
+ }
158
+ console.log(o.blue(`output:${t} 不存在,将创建`)), i.writeFileSync(t, m, "utf-8"), console.log(o.green(`模板处理完成,输出到 ${t}`));
159
+ }
160
+ break;
161
+ }
162
+ case g.REPLACE: {
163
+ if (c && console.log(o.yellow(`output ${c} 将被忽略`)), J(r, s), a && a === s)
164
+ return console.log(o.red("env 与 input 不能相同")), process.exit(1);
165
+ const t = v.resolve(s);
166
+ let d = t;
167
+ const b = s.replace(`${process.cwd()}/`, ""), w = D(b)(f);
168
+ w !== b && (console.log(
169
+ o.green(`检测输入文件名也需要替换
170
+ ./${b} => ./${w} `)
171
+ ), i.rmSync(t), d = v.resolve(`./${w}`)), i.mkdirSync(v.dirname(d), { recursive: !0 }), i.writeFileSync(d, m, "utf-8"), console.log(o.green(`模板处理完成,输出到 ${d}`));
172
+ break;
173
+ }
174
+ case g.RETURN:
175
+ return console.log(
176
+ o.green("模板处理完成,返回结果(函数调用才会拿到返回值)")
177
+ ), m;
178
+ default:
179
+ return console.log(o.red(`mode ${r} 不支持`)), process.exit(1);
180
+ }
181
+ return m;
182
+ }, M = async ({
183
+ rootDir: e = process.cwd(),
184
+ itemDefaultRollback: n = !1,
185
+ extraEnvData: a = {}
186
+ } = {}, s) => {
187
+ let u;
188
+ if (s)
189
+ u = s;
190
+ else {
191
+ const l = W(e);
192
+ if (!l)
193
+ return console.log(o.red(`配置文件${l}不存在`)), process.exit(1);
194
+ const f = i.readFileSync(l, "utf-8");
195
+ u = JSON.parse(f);
196
+ }
197
+ const {
198
+ list: c,
199
+ globalEnvData: r = {},
200
+ collectEnvDataForm: p = []
201
+ } = u, y = {};
202
+ for (const l of p) {
203
+ let f, m, t;
204
+ typeof l == "string" ? (f = l, m = l, t = void 0) : (f = l.key, m = l.label, t = l.initial), y[f] = (await N({
205
+ type: "text",
206
+ name: f,
207
+ message: `请输入${m}`,
208
+ initial: t,
209
+ format: (d) => (d || "").trim(),
210
+ validate: (d) => d ? !0 : `${m}不能为空`
211
+ }))[f];
212
+ }
213
+ const h = c.map((l) => {
214
+ const { rollback: f = n } = l, {
215
+ envData: m,
216
+ env: t,
217
+ input: d,
218
+ output: b,
219
+ ...w
220
+ } = P(l);
221
+ return t && console.log(o.yellow(`批量处理中 env:${t} 将被忽略,只读envData`)), {
222
+ ...w,
223
+ env: t,
224
+ input: e && d ? v.resolve(e, d) : d,
225
+ output: e && b ? v.resolve(e, b) : b,
226
+ envData: T(
227
+ {},
228
+ a,
229
+ r,
230
+ y,
231
+ m
232
+ ),
233
+ rollback: f
234
+ };
235
+ }), k = [];
236
+ for (const l of h) {
237
+ const f = await I(l, {
238
+ rollbackDelFileAgree: !0
239
+ });
240
+ k.push(f);
241
+ }
242
+ return k;
243
+ }, x = async (e) => {
244
+ const {
245
+ envData: n,
246
+ env: a,
247
+ input: s,
248
+ inputData: u,
249
+ output: c,
250
+ mode: r,
251
+ rollback: p,
252
+ dealMarkdown: y,
253
+ batch: h
254
+ } = P(e);
255
+ if (h)
256
+ return console.log(o.blue("开始批量处理")), M({
257
+ // 回滚默认值 基于全局
258
+ itemDefaultRollback: p
259
+ });
260
+ console.log(o.blue("开始单个处理"));
261
+ const k = C({
262
+ filePath: a,
263
+ dataInit: n,
264
+ limitJson: !0,
265
+ filePathKey: "env",
266
+ dataInitKey: "envData",
267
+ dealMarkdown: y
268
+ });
269
+ return I({
270
+ input: s,
271
+ inputData: u,
272
+ output: c,
273
+ mode: r,
274
+ rollback: p,
275
+ dealMarkdown: y,
276
+ envData: k
277
+ });
278
+ }, j = () => ({
279
+ env: {
280
+ alias: "e",
281
+ describe: "环境数据文件JSON文件相对路径(优先级高于envData)",
282
+ type: "string"
283
+ },
284
+ envData: {
285
+ alias: "E",
286
+ describe: "环境变量数据(JSON字符串)",
287
+ type: "string"
288
+ },
289
+ input: {
290
+ alias: "i",
291
+ describe: "模板文件相对路径(优先级高于inputTemplate)",
292
+ type: "string"
293
+ },
294
+ inputData: {
295
+ alias: "I",
296
+ describe: "模板数据",
297
+ type: "string"
298
+ },
299
+ mode: {
300
+ alias: "m",
301
+ describe: "输出模式",
302
+ type: "string",
303
+ choices: [
304
+ g.OVERWRITE,
305
+ g.APPEND,
306
+ g.REPLACE,
307
+ g.RETURN
308
+ ],
309
+ default: $.mode
310
+ },
311
+ output: {
312
+ alias: "o",
313
+ describe: "输出文件路径",
314
+ type: "string"
315
+ },
316
+ rollback: {
317
+ alias: "r",
318
+ describe: "是否回滚",
319
+ type: "boolean",
320
+ default: $.rollback
321
+ },
322
+ dealMarkdown: {
323
+ alias: "d",
324
+ describe: "(检测是markdown)是否处理(单个)代码块包裹",
325
+ type: "boolean",
326
+ default: $.dealMarkdown
327
+ },
328
+ batch: {
329
+ alias: "b",
330
+ describe: "是否批量处理",
331
+ type: "boolean",
332
+ default: $.batch
333
+ }
334
+ }), F = E.cliConfig.moduleName, L = (e, n) => {
335
+ console.log(e ? o.red(e) : o.red(n.message)), process.exit(1);
336
+ }, V = E.description, H = `Usage: $0 ${F} [options]`, _ = "Usage: $0 [options]", O = (e, n) => {
337
+ const a = j();
338
+ return e.strict().usage(n).help("help").version(E.version).alias("v", "version").alias("h", "help").options(a).fail(L).argv;
339
+ }, q = (e) => O(e, H), ee = {
340
+ command: F,
341
+ describe: V,
342
+ builder: q,
343
+ handler: x
344
+ }, te = async () => {
345
+ const e = A(U(process.argv)), n = await O(e, _);
346
+ return x(n);
347
+ };
348
+ export {
349
+ g as O,
350
+ ee as a,
351
+ M as b,
352
+ te as c,
353
+ W as g,
354
+ x as h
355
+ };
package/es/index.mjs CHANGED
@@ -1,12 +1,17 @@
1
1
  #!/usr/bin/env node
2
- import { batchHandler as e, handler as t } from "./handler.mjs";
3
- import { command as m } from "./main.mjs";
4
- import { OutputModeEnum as d } from "./utils/types.mjs";
5
- import { getConfigPath as p } from "./utils/config.mjs";
2
+ import { O as d, b as h, a as u, g as b, h as g } from "./index-a74172c0.js";
3
+ import "node:path";
4
+ import "node:fs";
5
+ import "chalk";
6
+ import "lodash.template";
7
+ import "lodash.assign";
8
+ import "prompts";
9
+ import "yargs";
10
+ import "yargs/helpers";
6
11
  export {
7
12
  d as OutputModeEnum,
8
- e as batchHandler,
9
- m as command,
10
- p as getConfigPath,
11
- t as handler
13
+ h as batchHandler,
14
+ u as command,
15
+ b as getConfigPath,
16
+ g as handler
12
17
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/cli-template",
3
- "version": "0.4.1",
3
+ "version": "0.5.0-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.2",
44
+ "@done-coding/cli-inject": "^0.4.3",
45
45
  "@types/lodash.assign": "^4.2.9",
46
46
  "@types/lodash.get": "^4.4.9",
47
47
  "@types/lodash.set": "^4.3.9",
@@ -66,5 +66,5 @@
66
66
  "prompts": "^2.4.2",
67
67
  "yargs": "^17.7.2"
68
68
  },
69
- "gitHead": "5a8844aa8d54b3f84ab8aa287479bda2da13467a"
69
+ "gitHead": "c386db9e11a6e5cf017839d657cd4c0bf1fb6a90"
70
70
  }
package/types/cli.d.ts CHANGED
File without changes
@@ -1,10 +1,12 @@
1
1
  import type { CompileTemplateConfig } from './utils';
2
2
  import { type Options } from './utils';
3
3
  import type { ArgumentsCamelCase } from "yargs";
4
- export declare const batchHandler: ({ rootDir, itemDefaultRollback, }?: {
4
+ export declare const batchHandler: ({ rootDir, itemDefaultRollback, extraEnvData, }?: {
5
5
  /** 根目录 */
6
6
  rootDir?: string | undefined;
7
7
  /** item默认回滚? */
8
8
  itemDefaultRollback?: boolean | undefined;
9
+ /** 额外环境变量 */
10
+ extraEnvData?: object | undefined;
9
11
  }, paramsConfig?: CompileTemplateConfig) => Promise<(string | undefined)[]>;
10
12
  export declare const handler: (argv: ArgumentsCamelCase<Options> | Options) => Promise<string | (string | undefined)[] | undefined>;
package/types/index.d.ts CHANGED
File without changes
@@ -1,5 +1,5 @@
1
1
  declare const _default: {
2
- "version": "0.4.1",
2
+ "version": "0.5.0-alpha.0",
3
3
  "name": "@done-coding/cli-template",
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
package/es/handler.mjs DELETED
@@ -1,242 +0,0 @@
1
- #!/usr/bin/env node
2
- import { OutputModeEnum as b } from "./utils/types.mjs";
3
- import { completeDefaultOptions as k } from "./utils/dealOptions.mjs";
4
- import { getConfigPath as N } from "./utils/config.mjs";
5
- import m from "node:path";
6
- import u from "node:fs";
7
- import t from "chalk";
8
- import F from "lodash.template";
9
- import R from "lodash.assign";
10
- import E from "prompts";
11
- const h = ({
12
- filePath: n,
13
- dataInit: l,
14
- limitJson: f,
15
- filePathKey: s,
16
- dataInitKey: g,
17
- dealMarkdown: a = !1
18
- }) => {
19
- if (n) {
20
- if (f && !n.endsWith(".json"))
21
- return console.log(
22
- t.red(`${s}必须是json文件,请检查文件后缀名`)
23
- ), process.exit(1);
24
- const o = u.readFileSync(m.resolve(n), "utf-8");
25
- let c = o;
26
- return a && n.endsWith(".md") && (c = o.replace(
27
- /^\s*```[a-zA-Z0-9]+\s*[\r\n]+([\s\S]+?)```\s*$/,
28
- "$1"
29
- )), f ? JSON.parse(c) : c;
30
- } else
31
- return l ? (console.log(
32
- t.green(`${s} 为空,将使用${g}作为数据`)
33
- ), f ? JSON.parse(l) : l) : (console.log(t.red(`${s}与${g}不能同时为空`)), process.exit(1));
34
- }, S = (n, l) => {
35
- if (!l)
36
- return console.log(t.red(`${n}模式下output不能为空`)), process.exit(1);
37
- }, D = (n, l) => {
38
- if (l && n === l)
39
- return console.log(t.red("output与input不能相同")), process.exit(1);
40
- }, I = (n, l) => {
41
- if (!l)
42
- return console.log(t.red(`${n}模式下input不能为空`)), process.exit(1);
43
- }, x = async (n, {
44
- rollbackDelFileAgree: l = !1
45
- } = {}) => {
46
- const {
47
- env: f,
48
- input: s,
49
- inputData: g,
50
- output: a,
51
- mode: o,
52
- rollback: c,
53
- dealMarkdown: v,
54
- envData: d
55
- } = n;
56
- if (c)
57
- switch (o) {
58
- case b.REPLACE:
59
- case b.RETURN: {
60
- console.log(t.red(`${o}模式不支持回滚`));
61
- return;
62
- }
63
- }
64
- console.log(
65
- t.blue(`开始处理模板
66
- mode: ${o}
67
- rollback: ${c}
68
- `)
69
- );
70
- const r = h({
71
- filePath: s,
72
- dataInit: g,
73
- limitJson: !1,
74
- filePathKey: "input",
75
- dataInitKey: "inputData",
76
- dealMarkdown: v
77
- }), p = F(r), $ = typeof d == "function" ? d() : d, i = p($);
78
- switch (o) {
79
- case b.OVERWRITE: {
80
- S(o, a), D(a, s);
81
- const e = m.resolve(a);
82
- if (u.mkdirSync(m.dirname(e), { recursive: !0 }), u.existsSync(e)) {
83
- if (c)
84
- if (l || (await E({
85
- type: "confirm",
86
- name: "remove",
87
- message: `${o}模式下回滚将删除${e},是否继续?`
88
- })).remove) {
89
- u.rmSync(e, { force: !0 }), console.log(t.green(`${o}模式下${e}已删除`));
90
- return;
91
- } else {
92
- console.log(t.yellow(`${o}模式下${e}回滚取消`));
93
- return;
94
- }
95
- console.log(t.blue(`output:${e} 已存在,将覆盖`));
96
- } else {
97
- if (c) {
98
- console.log(
99
- t.yellow(`${o}模式下${e}不存在,无需回滚`)
100
- );
101
- return;
102
- }
103
- console.log(t.blue(`output:${e} 不存在,将创建`));
104
- }
105
- u.writeFileSync(e, i, "utf-8"), console.log(t.green(`模板处理完成,输出到 ${e}`));
106
- break;
107
- }
108
- case b.APPEND: {
109
- S(o, a), D(a, s);
110
- const e = m.resolve(a);
111
- if (u.mkdirSync(m.dirname(e), { recursive: !0 }), u.existsSync(e)) {
112
- const y = u.readFileSync(e, "utf-8");
113
- if (c) {
114
- u.writeFileSync(
115
- e,
116
- y.replace(i, ""),
117
- "utf-8"
118
- ), console.log(t.green(`${o}模式下${e}回滚完成`));
119
- return;
120
- }
121
- const w = y + i;
122
- u.writeFileSync(e, w, "utf-8"), console.log(t.green(`模板处理完成,追加到 ${e}`));
123
- } else {
124
- if (c) {
125
- console.log(
126
- t.yellow(`${o}模式下${e}不存在,无需回滚`)
127
- );
128
- return;
129
- }
130
- console.log(t.blue(`output:${e} 不存在,将创建`)), u.writeFileSync(e, i, "utf-8"), console.log(t.green(`模板处理完成,输出到 ${e}`));
131
- }
132
- break;
133
- }
134
- case b.REPLACE: {
135
- if (a && console.log(t.yellow(`output ${a} 将被忽略`)), I(o, s), f && f === s)
136
- return console.log(t.red("env 与 input 不能相同")), process.exit(1);
137
- const e = m.resolve(s);
138
- u.mkdirSync(m.dirname(e), { recursive: !0 }), u.writeFileSync(e, i, "utf-8"), console.log(t.green(`模板处理完成,输出到 ${e}`));
139
- break;
140
- }
141
- case b.RETURN:
142
- return console.log(
143
- t.green("模板处理完成,返回结果(函数调用才会拿到返回值)")
144
- ), i;
145
- default:
146
- return console.log(t.red(`mode ${o} 不支持`)), process.exit(1);
147
- }
148
- return i;
149
- }, C = async ({
150
- rootDir: n = process.cwd(),
151
- itemDefaultRollback: l = !1
152
- } = {}, f) => {
153
- let s;
154
- if (f)
155
- s = f;
156
- else {
157
- const r = N(n);
158
- if (!r)
159
- return console.log(t.red(`配置文件${r}不存在`)), process.exit(1);
160
- const p = u.readFileSync(r, "utf-8");
161
- s = JSON.parse(p);
162
- }
163
- const {
164
- list: g,
165
- globalEnvData: a = {},
166
- collectEnvDataForm: o = []
167
- } = s, c = {};
168
- for (const r of o) {
169
- let p, $, i;
170
- typeof r == "string" ? (p = r, $ = r, i = void 0) : (p = r.key, $ = r.label, i = r.initial), c[p] = (await E({
171
- type: "text",
172
- name: p,
173
- message: `请输入${$}`,
174
- initial: i,
175
- format: (e) => (e || "").trim(),
176
- validate: (e) => e ? !0 : `${$}不能为空`
177
- }))[p];
178
- }
179
- const v = g.map((r) => {
180
- const { rollback: p = l } = r, {
181
- envData: $,
182
- env: i,
183
- input: e,
184
- output: y,
185
- ...w
186
- } = k(r);
187
- return i && console.log(t.yellow(`批量处理中 env:${i} 将被忽略,只读envData`)), {
188
- ...w,
189
- env: i,
190
- input: n && e ? m.resolve(n, e) : e,
191
- output: n && y ? m.resolve(n, y) : y,
192
- envData: R({}, a, c, $),
193
- rollback: p
194
- };
195
- }), d = [];
196
- for (const r of v) {
197
- const p = await x(r, {
198
- rollbackDelFileAgree: !0
199
- });
200
- d.push(p);
201
- }
202
- return d;
203
- }, U = async (n) => {
204
- const {
205
- envData: l,
206
- env: f,
207
- input: s,
208
- inputData: g,
209
- output: a,
210
- mode: o,
211
- rollback: c,
212
- dealMarkdown: v,
213
- batch: d
214
- } = k(n);
215
- if (d)
216
- return console.log(t.blue("开始批量处理")), C({
217
- // 回滚默认值 基于全局
218
- itemDefaultRollback: c
219
- });
220
- console.log(t.blue("开始单个处理"));
221
- const r = h({
222
- filePath: f,
223
- dataInit: l,
224
- limitJson: !0,
225
- filePathKey: "env",
226
- dataInitKey: "envData",
227
- dealMarkdown: v
228
- });
229
- return x({
230
- input: s,
231
- inputData: g,
232
- output: a,
233
- mode: o,
234
- rollback: c,
235
- dealMarkdown: v,
236
- envData: r
237
- });
238
- };
239
- export {
240
- C as batchHandler,
241
- U as handler
242
- };
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env node
2
- const e = {
3
- version: "0.4.1",
4
- name: "@done-coding/cli-template",
5
- description: "预编译命令行工具",
6
- cliConfig: {
7
- namespaceDir: ".done-coding",
8
- moduleName: "template"
9
- }
10
- };
11
- export {
12
- e as default
13
- };
package/es/main.mjs DELETED
@@ -1,84 +0,0 @@
1
- #!/usr/bin/env node
2
- import d from "yargs";
3
- import { hideBin as m } from "yargs/helpers";
4
- import { OutputModeEnum as t } from "./utils/types.mjs";
5
- import { defaultOptions as a } from "./utils/dealOptions.mjs";
6
- import i from "./injectInfo.json.mjs";
7
- import "node:path";
8
- import "node:fs";
9
- import { handler as n } from "./handler.mjs";
10
- import s from "chalk";
11
- const p = () => ({
12
- env: {
13
- alias: "e",
14
- describe: "环境数据文件JSON文件相对路径(优先级高于envData)",
15
- type: "string"
16
- },
17
- envData: {
18
- alias: "E",
19
- describe: "环境变量数据(JSON字符串)",
20
- type: "string"
21
- },
22
- input: {
23
- alias: "i",
24
- describe: "模板文件相对路径(优先级高于inputTemplate)",
25
- type: "string"
26
- },
27
- inputData: {
28
- alias: "I",
29
- describe: "模板数据",
30
- type: "string"
31
- },
32
- mode: {
33
- alias: "m",
34
- describe: "输出模式",
35
- type: "string",
36
- choices: [
37
- t.OVERWRITE,
38
- t.APPEND,
39
- t.REPLACE,
40
- t.RETURN
41
- ],
42
- default: a.mode
43
- },
44
- output: {
45
- alias: "o",
46
- describe: "输出文件路径",
47
- type: "string"
48
- },
49
- rollback: {
50
- alias: "r",
51
- describe: "是否回滚",
52
- type: "boolean",
53
- default: a.rollback
54
- },
55
- dealMarkdown: {
56
- alias: "d",
57
- describe: "(检测是markdown)是否处理(单个)代码块包裹",
58
- type: "boolean",
59
- default: a.dealMarkdown
60
- },
61
- batch: {
62
- alias: "b",
63
- describe: "是否批量处理",
64
- type: "boolean",
65
- default: a.batch
66
- }
67
- }), r = i.cliConfig.moduleName, u = (e, o) => {
68
- console.log(e ? s.red(e) : s.red(o.message)), process.exit(1);
69
- }, b = i.description, g = `Usage: $0 ${r} [options]`, f = "Usage: $0 [options]", c = (e, o) => {
70
- const l = p();
71
- return e.strict().usage(o).help("help").version(i.version).alias("v", "version").alias("h", "help").options(l).fail(u).argv;
72
- }, h = (e) => c(e, g), U = {
73
- command: r,
74
- describe: b,
75
- builder: h,
76
- handler: n
77
- }, w = async () => {
78
- const e = d(m(process.argv)), o = await c(e, f);
79
- return n(o);
80
- };
81
- export {
82
- U as command,
83
- w as createCli
84
- };
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env node
2
- import i from "../injectInfo.json.mjs";
3
- import r from "node:path";
4
- import f from "node:fs";
5
- const p = (o) => {
6
- const { namespaceDir: t, moduleName: s } = i.cliConfig, e = [t, `${s}.json`];
7
- o && e.unshift(o);
8
- const n = r.resolve(...e);
9
- if (f.existsSync(n))
10
- return n;
11
- };
12
- export {
13
- p as getConfigPath
14
- };
@@ -1,21 +0,0 @@
1
- #!/usr/bin/env node
2
- import { OutputModeEnum as n } from "./types.mjs";
3
- const o = {
4
- rollback: !1,
5
- dealMarkdown: !1,
6
- mode: n.OVERWRITE,
7
- batch: !1
8
- }, s = (a) => {
9
- const { rollback: e, dealMarkdown: l, mode: t, batch: d, ...r } = a;
10
- return {
11
- rollback: e ?? o.rollback,
12
- dealMarkdown: l ?? o.dealMarkdown,
13
- mode: t ?? o.mode,
14
- batch: d ?? o.batch,
15
- ...r
16
- };
17
- };
18
- export {
19
- s as completeDefaultOptions,
20
- o as defaultOptions
21
- };
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
- var e = /* @__PURE__ */ ((r) => (r.OVERWRITE = "overwrite", r.APPEND = "append", r.REPLACE = "replace", r.RETURN = "return", r))(e || {});
3
- export {
4
- e as OutputModeEnum
5
- };