create-done-coding 0.4.8 → 0.5.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/handler.mjs CHANGED
@@ -1,81 +1,97 @@
1
1
  #!/usr/bin/env node
2
- import { CUSTOM_TEMPLATE_NAME as j } from "./utils/const.mjs";
3
- import { projectNameForm as E, getRemoveDirForm as S, getTemplateForm as x, getTemplateChoices as F, saveGitHistoryForm as T, shallowCloneForm as k } from "./utils/question.mjs";
4
- import n from "prompts";
5
- import { execSync as c } from "node:child_process";
6
- import { existsSync as p, rmSync as i, readFileSync as g, writeFileSync as f } from "node:fs";
7
- import { resolve as M } from "node:path";
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
8
  import t from "chalk";
9
- const J = async (u) => {
10
- const {
11
- projectName: d,
12
- template: w,
13
- saveGitHistory: $,
14
- shallowClone: h
15
- } = u, r = ((d ?? (await n(E)).projectName) || "").trim();
16
- if (!r.trim()) {
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()) {
17
14
  console.log(t.red("项目名称不能为空"));
18
15
  return;
19
16
  }
20
- if (r.includes(" ") || r.includes("\\") || r.includes("/")) {
17
+ if (o.includes(" ") || o.includes("\\") || o.includes("/")) {
21
18
  console.log(t.red("项目名称不能包含空格或者\\或者/"));
22
19
  return;
23
20
  }
24
- const e = M(process.cwd(), r);
25
- if (p(e)) {
26
- const { isRemove: o } = await n(S());
27
- if (o === !0)
28
- i(e, { recursive: !0, force: !0 });
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 });
29
26
  else
30
27
  return console.log(t.red("项目已存在")), process.exit(1);
31
28
  }
32
- const s = w ?? (await n(await x())).template;
33
- let l = "";
34
- if (s === j) {
35
- const { customUrl: o } = await n({
29
+ const n = v ?? (await r(await N())).template;
30
+ let c = "";
31
+ if (n === $) {
32
+ const { customUrl: e } = await r({
36
33
  type: "text",
37
34
  name: "customUrl",
38
35
  message: "请输入自定义模板路径"
39
36
  });
40
- l = o;
37
+ c = e;
41
38
  } else {
42
- const o = (await F()).find(
43
- (C) => C.name === s
39
+ const e = (await T()).find(
40
+ (s) => s.name === n
44
41
  );
45
- if (!o)
46
- return console.log(t.red(`模板${s}不存在`)), process.exit(1);
47
- if (!o.url)
48
- return console.log(t.red(`模板${s}仓库地址不存在`)), process.exit(1);
49
- l = o.url;
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;
50
47
  }
51
- console.log(t.green("正在初始化项目,请稍等...")), c(`git clone ${l} ${r} --depth=1`);
52
- const m = $ ?? (await n(T)).saveGitHistory;
53
- if (m === !1) {
54
- const o = `${e}/.git`;
55
- if (!p(o))
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))
56
65
  throw new Error("git目录不存在");
57
- i(`${e}/.git`, { recursive: !0, force: !0 });
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
+ );
58
76
  } else
59
- c(`cd ${e} && git remote rename origin upstream`);
60
- const y = g(`${e}/package.json`, "utf-8"), a = JSON.parse(y), { name: N } = a;
61
- a.name = r, i(`${e}/package.json`), f(
62
- `${e}/package.json`,
63
- JSON.stringify(a, null, 2)
64
- );
65
- const v = g(`${e}/README.md`, "utf-8").replace(N, r);
66
- i(`${e}/README.md`), f(`${e}/README.md`, v), console.log(t.green("项目初始化完成")), m && ((h ? (await n(k)).shallowClone : !1) ? console.log(
67
- t.yellow("当前使用浅克隆,后续不能与模板git仓库有完整的交互")
68
- ) : (c(`cd ${e} && git fetch --unshallow`), console.log(
69
- t.green("已完整克隆项目,后续可以与模板git仓库有完整的交互")
70
- ))), console.log(
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(
71
87
  t.blue(`
72
88
  使用步骤:
73
- 1. cd ${r}
89
+ 1. cd ${o}
74
90
  2. pnpm install
75
91
  3. pnpm run dev
76
92
  `)
77
93
  );
78
94
  };
79
95
  export {
80
- J as handler
96
+ k as handler
81
97
  };
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  const e = {
3
- version: "0.4.8",
3
+ version: "0.5.0",
4
4
  name: "create-done-coding",
5
5
  description: "项目创建命令行工具",
6
6
  cliConfig: {
package/es/main.mjs CHANGED
@@ -1,46 +1,35 @@
1
1
  #!/usr/bin/env node
2
2
  import c from "yargs";
3
3
  import { hideBin as m } from "yargs/helpers";
4
- import { handler as t } from "./handler.mjs";
5
- import a from "chalk";
6
- import { projectNameForm as l, getTemplateChoices as p, getTemplateForm as d, saveGitHistoryForm as g, shallowCloneForm as f } from "./utils/question.mjs";
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
7
  import s from "./injectInfo.json.mjs";
8
- const h = async () => ({
8
+ const d = async () => ({
9
9
  projectName: {
10
10
  type: "string",
11
11
  alias: "p",
12
- describe: l.message
12
+ describe: p.message
13
13
  },
14
14
  template: {
15
15
  type: "string",
16
16
  alias: "t",
17
- choices: (await p()).map((e) => e.name),
18
- describe: (await d()).message
19
- },
20
- saveGitHistory: {
21
- type: "boolean",
22
- alias: "s",
23
- describe: g.message
24
- },
25
- shallowClone: {
26
- type: "boolean",
27
- alias: "c",
28
- describe: f.message,
29
- default: !0
17
+ choices: (await l()).map((e) => e.name),
18
+ describe: (await g()).message
30
19
  }
31
- }), i = s.cliConfig.moduleName, u = (e, o) => {
32
- console.log(e ? a.red(e) : a.red(o.message)), process.exit(1);
33
- }, y = s.description, b = `Usage: $0 ${i} [options]`, v = "Usage: $0 [options]", r = async (e, o) => {
34
- const n = await h();
35
- return e.strict().usage(o).help("help").version(s.version).alias("v", "version").alias("h", "help").options(n).fail(u).argv;
36
- }, C = (e) => r(e, b), $ = {
37
- command: i,
38
- describe: y,
39
- builder: C,
40
- handler: t
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
41
30
  }, x = async () => {
42
- const e = c(m(process.argv)), o = await r(e, v);
43
- return t(o);
31
+ const e = c(m(process.argv)), o = await i(e, v);
32
+ return a(o);
44
33
  };
45
34
  export {
46
35
  $ as command,
@@ -1,39 +1,35 @@
1
1
  #!/usr/bin/env node
2
- import { CUSTOM_TEMPLATE_NAME as o } from "./const.mjs";
3
- import { readConfig as m } from "./readConfig.mjs";
2
+ import { CUSTOM_TEMPLATE_NAME as m } from "./const.mjs";
3
+ import { readConfig as s } from "./readConfig.mjs";
4
4
  let t;
5
- const s = async () => (t || (t = (await m()).templateList), t), n = async () => [...await s(), { name: o }], c = {
5
+ const o = async () => (t || (t = (await s()).templateList), t), i = async () => [...await o(), { name: m }], c = {
6
6
  type: "text",
7
7
  name: "projectName",
8
8
  message: "请输入项目名称",
9
9
  validate: (e) => e.trim().length > 0 || "项目名称不能为空"
10
- }, l = async () => ({
10
+ }, p = async () => ({
11
11
  type: "select",
12
12
  name: "template",
13
13
  message: "请选择模板",
14
- choices: (await n()).map((a) => ({
14
+ choices: (await i()).map((a) => ({
15
15
  title: a.name,
16
16
  value: a.name
17
17
  }))
18
- }), p = {
18
+ }), l = {
19
19
  type: "confirm",
20
20
  name: "saveGitHistory",
21
- message: "是否保留git历史"
22
- }, g = {
23
- type: "confirm",
24
- name: "shallowClone",
25
- message: "是否使用浅克隆(后续期望与模板git仓库有完整的交互,请选择'N')"
26
- }, y = (e = "项目已存在,是否删除") => ({
21
+ message: "是否保留git历史",
22
+ initial: !1
23
+ }, g = (e = "项目已存在,是否删除") => ({
27
24
  type: "confirm",
28
25
  name: "isRemove",
29
26
  message: e
30
27
  });
31
28
  export {
32
- y as getRemoveDirForm,
33
- n as getTemplateChoices,
34
- l as getTemplateForm,
35
- s as getTemplateList,
29
+ g as getRemoveDirForm,
30
+ i as getTemplateChoices,
31
+ p as getTemplateForm,
32
+ o as getTemplateList,
36
33
  c as projectNameForm,
37
- p as saveGitHistoryForm,
38
- g as shallowCloneForm
34
+ l as saveGitHistoryForm
39
35
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-done-coding",
3
- "version": "0.4.8",
3
+ "version": "0.5.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.0",
41
+ "@done-coding/cli-inject": "^0.4.1",
42
42
  "@types/node": "^18.0.0",
43
43
  "@types/prompts": "^2.4.6",
44
44
  "@types/yargs": "^17.0.28",
@@ -51,9 +51,11 @@
51
51
  "node": ">=18.0.0"
52
52
  },
53
53
  "dependencies": {
54
+ "@done-coding/cli-template": "^0.4.0",
55
+ "@done-coding/node-tools": "^0.0.1",
54
56
  "chalk": "^5.3.0",
55
57
  "prompts": "^2.4.2",
56
58
  "yargs": "^17.7.2"
57
59
  },
58
- "gitHead": "b3311b79a55322e4689718d59c072388e2866e17"
60
+ "gitHead": "1778df27cf625b5588b1de38d260cfed75e123f2"
59
61
  }
@@ -1,5 +1,5 @@
1
1
  declare const _default: {
2
- "version": "0.4.8",
2
+ "version": "0.5.0",
3
3
  "name": "create-done-coding",
4
4
  "description": "项目创建命令行工具",
5
5
  "cliConfig": {
@@ -14,6 +14,7 @@ export declare const saveGitHistoryForm: {
14
14
  type: "confirm";
15
15
  name: string;
16
16
  message: string;
17
+ initial: boolean;
17
18
  };
18
19
  export declare const shallowCloneForm: {
19
20
  type: "confirm";
@@ -3,8 +3,4 @@ export interface Options {
3
3
  projectName: string;
4
4
  /** 项目模板 */
5
5
  template: string;
6
- /** 保存git历史记录 */
7
- saveGitHistory: boolean;
8
- /** 是否使用shallow clone */
9
- shallowClone: boolean;
10
6
  }