create-done-coding 0.4.0 → 0.4.2

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
@@ -1,6 +1,6 @@
1
1
  # create-done-coding
2
2
 
3
- done-coding项目脚手架
3
+ 项目创建命令行工具
4
4
 
5
5
  ## 使用
6
6
 
package/es/handler.mjs CHANGED
@@ -1,17 +1,17 @@
1
1
  #!/usr/bin/env node
2
2
  import { CUSTOM_TEMPLATE_NAME as j } from "./utils/const.mjs";
3
- import { projectNameForm as E, templateForm as S, templateChoices as x, saveGitHistoryForm as k, shallowCloneForm as F } from "./utils/question.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
4
  import n from "prompts";
5
- import { execSync as a } from "node:child_process";
5
+ import { execSync as c } from "node:child_process";
6
6
  import { existsSync as p, rmSync as i, readFileSync as g, writeFileSync as f } from "node:fs";
7
7
  import { resolve as M } from "node:path";
8
8
  import t from "chalk";
9
- const b = async (u) => {
9
+ const J = async (u) => {
10
10
  const {
11
11
  projectName: d,
12
12
  template: w,
13
- saveGitHistory: y,
14
- shallowClone: $
13
+ saveGitHistory: $,
14
+ shallowClone: h
15
15
  } = u, r = ((d ?? (await n(E)).projectName) || "").trim();
16
16
  if (!r.trim()) {
17
17
  console.log(t.red("项目名称不能为空"));
@@ -23,17 +23,13 @@ const b = async (u) => {
23
23
  }
24
24
  const e = M(process.cwd(), r);
25
25
  if (p(e)) {
26
- const { isRemove: o } = await n({
27
- type: "confirm",
28
- name: "isRemove",
29
- message: "项目已存在,是否删除"
30
- });
26
+ const { isRemove: o } = await n(S());
31
27
  if (o === !0)
32
28
  i(e, { recursive: !0, force: !0 });
33
29
  else
34
30
  return console.log(t.red("项目已存在")), process.exit(1);
35
31
  }
36
- const s = w ?? (await n(S)).template;
32
+ const s = w ?? (await n(await x())).template;
37
33
  let l = "";
38
34
  if (s === j) {
39
35
  const { customUrl: o } = await n({
@@ -43,31 +39,33 @@ const b = async (u) => {
43
39
  });
44
40
  l = o;
45
41
  } else {
46
- const o = x.find((C) => C.name === s);
42
+ const o = (await F()).find(
43
+ (C) => C.name === s
44
+ );
47
45
  if (!o)
48
46
  return console.log(t.red(`模板${s}不存在`)), process.exit(1);
49
47
  if (!o.url)
50
48
  return console.log(t.red(`模板${s}仓库地址不存在`)), process.exit(1);
51
49
  l = o.url;
52
50
  }
53
- console.log(t.green("正在初始化项目,请稍等...")), a(`git clone ${l} ${r} --depth=1`);
54
- const m = y ?? (await n(k)).saveGitHistory;
51
+ console.log(t.green("正在初始化项目,请稍等...")), c(`git clone ${l} ${r} --depth=1`);
52
+ const m = $ ?? (await n(T)).saveGitHistory;
55
53
  if (m === !1) {
56
54
  const o = `${e}/.git`;
57
55
  if (!p(o))
58
56
  throw new Error("git目录不存在");
59
57
  i(`${e}/.git`, { recursive: !0, force: !0 });
60
58
  } else
61
- a(`cd ${e} && git remote rename origin upstream`);
62
- const h = g(`${e}/package.json`, "utf-8"), c = JSON.parse(h), { name: N } = c;
63
- c.name = r, i(`${e}/package.json`), f(
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(
64
62
  `${e}/package.json`,
65
- JSON.stringify(c, null, 2)
63
+ JSON.stringify(a, null, 2)
66
64
  );
67
65
  const v = g(`${e}/README.md`, "utf-8").replace(N, r);
68
- i(`${e}/README.md`), f(`${e}/README.md`, v), console.log(t.green("项目初始化完成")), m && (($ ? (await n(F)).shallowClone : !1) ? console.log(
66
+ i(`${e}/README.md`), f(`${e}/README.md`, v), console.log(t.green("项目初始化完成")), m && ((h ? (await n(k)).shallowClone : !1) ? console.log(
69
67
  t.yellow("当前使用浅克隆,后续不能与模板git仓库有完整的交互")
70
- ) : (a(`cd ${e} && git fetch --unshallow`), console.log(
68
+ ) : (c(`cd ${e} && git fetch --unshallow`), console.log(
71
69
  t.green("已完整克隆项目,后续可以与模板git仓库有完整的交互")
72
70
  ))), console.log(
73
71
  t.blue(`
@@ -79,5 +77,5 @@ const b = async (u) => {
79
77
  );
80
78
  };
81
79
  export {
82
- b as handler
80
+ J as handler
83
81
  };
package/es/index.mjs ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { handler as e } from "./handler.mjs";
3
+ import { command as m } from "./main.mjs";
4
+ export {
5
+ m as command,
6
+ e as handler
7
+ };
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ const e = {
3
+ name: "create-done-coding",
4
+ version: "0.4.2",
5
+ description: "项目创建命令行工具"
6
+ };
7
+ export {
8
+ e as default
9
+ };
package/es/main.mjs CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import r from "yargs";
3
- import { hideBin as a } from "yargs/helpers";
4
- import { handler as i } from "./handler.mjs";
5
- import o from "chalk";
6
- import { getVersion as n } from "./utils/packageInfo.mjs";
7
- import { projectNameForm as l, templateChoices as m, templateForm as c, saveGitHistoryForm as p, shallowCloneForm as g } from "./utils/question.mjs";
8
- const d = () => ({
2
+ import c from "yargs";
3
+ import { hideBin as m } from "yargs/helpers";
4
+ import { handler as a } from "./handler.mjs";
5
+ import s from "chalk";
6
+ import { projectNameForm as l, getTemplateChoices as p, getTemplateForm as d, saveGitHistoryForm as g, shallowCloneForm as h } from "./utils/question.mjs";
7
+ import t from "./injectInfo.json.mjs";
8
+ const f = async () => ({
9
9
  projectName: {
10
10
  type: "string",
11
11
  alias: "p",
@@ -14,29 +14,35 @@ const d = () => ({
14
14
  template: {
15
15
  type: "string",
16
16
  alias: "t",
17
- choices: m.map((e) => e.name),
18
- describe: c.message
17
+ choices: (await p()).map((e) => e.name),
18
+ describe: (await d()).message
19
19
  },
20
20
  saveGitHistory: {
21
21
  type: "boolean",
22
22
  alias: "s",
23
- describe: p.message
23
+ describe: g.message
24
24
  },
25
25
  shallowClone: {
26
26
  type: "boolean",
27
27
  alias: "c",
28
- describe: g.message,
28
+ describe: h.message,
29
29
  default: !0
30
30
  }
31
- }), h = (e, s) => {
32
- console.log(e ? o.red(e) : o.red(s.message)), process.exit(1);
33
- }, f = "Usage: $0 [options]", v = (e, s) => {
34
- const t = d();
35
- return e.strict().usage(s).help("help").version(n()).alias("v", "version").alias("h", "help").options(t).fail(h).argv;
36
- }, H = async () => {
37
- const e = r(a(process.argv)), s = await v(e, f);
38
- return i(s);
31
+ }), r = "create", y = (e, o) => {
32
+ console.log(e ? s.red(e) : s.red(o.message)), process.exit(1);
33
+ }, b = t.description, u = `Usage: $0 ${r} [options]`, v = "Usage: $0 [options]", i = async (e, o) => {
34
+ const n = await f();
35
+ return e.strict().usage(o).help("help").version(t.version).alias("v", "version").alias("h", "help").options(n).fail(y).argv;
36
+ }, C = (e) => i(e, u), $ = {
37
+ command: r,
38
+ describe: b,
39
+ builder: C,
40
+ handler: a
41
+ }, x = async () => {
42
+ const e = c(m(process.argv)), o = await i(e, v);
43
+ return a(o);
39
44
  };
40
45
  export {
41
- H as createCli
46
+ $ as command,
47
+ x as createCli
42
48
  };
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- const o = "git@gitee.com:justsosu/done-coding-cli-config-json.git", n = "自定义模版路径", t = "./config_temp";
2
+ const o = "git@gitee.com:justsosu/done-coding-cli-config-json.git", n = "自定义模版路径", e = "./.create-done-coding_temp";
3
3
  export {
4
4
  o as CONFIG_GIT_REPO,
5
5
  n as CUSTOM_TEMPLATE_NAME,
6
- t as READ_CONFIG_TEMPORARY_DIRECTORY
6
+ e as READ_CONFIG_TEMPORARY_DIRECTORY
7
7
  };
@@ -2,36 +2,38 @@
2
2
  import { CUSTOM_TEMPLATE_NAME as o } from "./const.mjs";
3
3
  import { readConfig as m } from "./readConfig.mjs";
4
4
  let t;
5
- const a = () => (t || (t = m().templateList), t), s = [
6
- ...a(),
7
- { name: o }
8
- ], r = {
5
+ const s = async () => (t || (t = (await m()).templateList), t), n = async () => [...await s(), { name: o }], c = {
9
6
  type: "text",
10
7
  name: "projectName",
11
8
  message: "请输入项目名称",
12
9
  validate: (e) => e.trim().length > 0 || "项目名称不能为空"
13
- }, l = {
10
+ }, l = async () => ({
14
11
  type: "select",
15
12
  name: "template",
16
13
  message: "请选择模板",
17
- choices: s.map((e) => ({
18
- title: e.name,
19
- value: e.name
14
+ choices: (await n()).map((a) => ({
15
+ title: a.name,
16
+ value: a.name
20
17
  }))
21
- }, c = {
18
+ }), p = {
22
19
  type: "confirm",
23
20
  name: "saveGitHistory",
24
21
  message: "是否保留git历史"
25
- }, p = {
22
+ }, g = {
26
23
  type: "confirm",
27
24
  name: "shallowClone",
28
25
  message: "是否使用浅克隆(后续期望与模板git仓库有完整的交互,请选择'N')"
29
- };
26
+ }, y = (e = "项目已存在,是否删除") => ({
27
+ type: "confirm",
28
+ name: "isRemove",
29
+ message: e
30
+ });
30
31
  export {
31
- a as getTemplateList,
32
- r as projectNameForm,
33
- c as saveGitHistoryForm,
34
- p as shallowCloneForm,
35
- s as templateChoices,
36
- l as templateForm
32
+ y as getRemoveDirForm,
33
+ n as getTemplateChoices,
34
+ l as getTemplateForm,
35
+ s as getTemplateList,
36
+ c as projectNameForm,
37
+ p as saveGitHistoryForm,
38
+ g as shallowCloneForm
37
39
  };
@@ -1,22 +1,28 @@
1
1
  #!/usr/bin/env node
2
- import e from "chalk";
3
- import { execSync as s } from "node:child_process";
4
- import t from "node:path";
5
- import n from "node:fs";
6
- import { READ_CONFIG_TEMPORARY_DIRECTORY as m, CONFIG_GIT_REPO as f } from "./const.mjs";
7
- import { getPkgName as p } from "./packageInfo.mjs";
8
- const d = () => {
9
- console.log(e.blue("拉取模板列表,请稍等..."));
10
- const r = t.resolve(
2
+ import o from "chalk";
3
+ import { execSync as f } from "node:child_process";
4
+ import s from "node:path";
5
+ import r from "node:fs";
6
+ import { READ_CONFIG_TEMPORARY_DIRECTORY as p, CONFIG_GIT_REPO as l } from "./const.mjs";
7
+ import a from "../injectInfo.json.mjs";
8
+ import { getRemoveDirForm as g } from "./question.mjs";
9
+ import u from "prompts";
10
+ const E = async () => {
11
+ console.log(o.blue("拉取模板列表,请稍等..."));
12
+ const e = s.resolve(
11
13
  process.cwd(),
12
- m
14
+ p
13
15
  );
14
- s(`git clone ${f} ${r} --depth=1`);
15
- const c = p(), i = t.resolve(r, `${c}.json`), o = JSON.parse(n.readFileSync(i, "utf-8"));
16
- if (!Array.isArray(o.templateList))
16
+ if (console.log(o.blue(`配置目录:${e}`)), r.existsSync(e)) {
17
+ const i = `${e}目录已存在,是否删除?`, { isRemove: m } = await u(g(i));
18
+ m ? r.rmSync(e, { recursive: !0, force: !0 }) : (console.log(o.red(`${e}已存在,请手动删除后再试!`)), process.exit(1));
19
+ }
20
+ f(`git clone ${l} ${e} --depth=1`);
21
+ const n = a.name, c = s.resolve(e, `${n}.json`), t = JSON.parse(r.readFileSync(c, "utf-8"));
22
+ if (!Array.isArray(t.templateList))
17
23
  throw new Error("远程配置文件出错,templateList 不是数组");
18
- return console.log(e.green("模板列表拉取成功!")), n.rmSync(r, { recursive: !0, force: !0 }), o;
24
+ return console.log(o.green("模板列表拉取成功!")), r.rmSync(e, { recursive: !0, force: !0 }), t;
19
25
  };
20
26
  export {
21
- d as readConfig
27
+ E as readConfig
22
28
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-done-coding",
3
- "version": "0.4.0",
4
- "description": "done-coding项目脚手架",
3
+ "version": "0.4.2",
4
+ "description": "项目创建命令行工具",
5
5
  "module": "es/cli.mjs",
6
6
  "type": "module",
7
7
  "types": "types/cli.d.ts",
@@ -9,6 +9,10 @@
9
9
  "exports": {
10
10
  ".": {
11
11
  "import": "./es/cli.mjs"
12
+ },
13
+ "./assets": {
14
+ "import": "./es/index.mjs",
15
+ "types": "./types/index.d.ts"
12
16
  }
13
17
  },
14
18
  "files": [
@@ -34,9 +38,10 @@
34
38
  "license": "MIT",
35
39
  "sideEffects": false,
36
40
  "devDependencies": {
37
- "@types/node": "^16.18.58",
41
+ "@done-coding/cli-inject": "^0.1.1",
42
+ "@types/node": "^20.0.0",
38
43
  "@types/prompts": "^2.4.6",
39
- "@types/yargs": "^17.0.33",
44
+ "@types/yargs": "^17.0.28",
40
45
  "rimraf": "^6.0.1",
41
46
  "typescript": "^5.2.2",
42
47
  "vite": "^4.4.11",
@@ -50,5 +55,5 @@
50
55
  "prompts": "^2.4.2",
51
56
  "yargs": "^17.7.2"
52
57
  },
53
- "gitHead": "505e67277f0f24385c0942bbbdbfde17e9076f63"
58
+ "gitHead": "454bb76eb20c9b732331c273435e0bf56c8c3f25"
54
59
  }
@@ -0,0 +1,2 @@
1
+ export { handler } from "./handler";
2
+ export { command } from "./main";
@@ -0,0 +1,7 @@
1
+ declare const _default: {
2
+ "name": "create-done-coding",
3
+ "version": "0.4.2",
4
+ "description": "项目创建命令行工具"
5
+ };
6
+
7
+ export default _default;
@@ -3,4 +3,4 @@ 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
5
  /** 临时目录 */
6
- export declare const READ_CONFIG_TEMPORARY_DIRECTORY = "./config_temp";
6
+ export declare const READ_CONFIG_TEMPORARY_DIRECTORY = "./.create-done-coding_temp";
@@ -1,5 +1,4 @@
1
1
  export * from "./readConfig";
2
- export * from "./packageInfo";
3
2
  export * from "./const";
4
3
  export * from "./types";
5
4
  export * from "./question";
@@ -5,11 +5,11 @@ export interface TemplateChoiceItem {
5
5
  url?: string;
6
6
  }
7
7
  /** 获取模版选项 */
8
- export declare const getTemplateList: () => TemplateChoiceItem[];
8
+ export declare const getTemplateList: () => Promise<TemplateChoiceItem[]>;
9
9
  /** 模版选项 */
10
- export declare const templateChoices: TemplateChoiceItem[];
10
+ export declare const getTemplateChoices: () => Promise<TemplateChoiceItem[]>;
11
11
  export declare const projectNameForm: PromptObject<string>;
12
- export declare const templateForm: PromptObject<string>;
12
+ export declare const getTemplateForm: () => Promise<PromptObject<string>>;
13
13
  export declare const saveGitHistoryForm: {
14
14
  type: "confirm";
15
15
  name: string;
@@ -20,3 +20,9 @@ export declare const shallowCloneForm: {
20
20
  name: string;
21
21
  message: string;
22
22
  };
23
+ /** 获取删除目录的表单 */
24
+ export declare const getRemoveDirForm: (message?: string) => {
25
+ type: "confirm";
26
+ name: string;
27
+ message: string;
28
+ };
@@ -1,7 +1,7 @@
1
- import type { TemplateChoiceItem } from "./question";
1
+ import { type TemplateChoiceItem } from "./question";
2
2
  /** 配置文件 */
3
3
  export interface ConfigJson {
4
4
  templateList: TemplateChoiceItem[];
5
5
  }
6
6
  /** 读取配置 */
7
- export declare const readConfig: () => ConfigJson;
7
+ export declare const readConfig: () => Promise<ConfigJson>;
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env node
2
- import n, { dirname as t } from "node:path";
3
- import o from "node:fs";
4
- import { fileURLToPath as a } from "node:url";
5
- const i = a(import.meta.url), m = t(i), r = () => {
6
- const e = o.readFileSync(
7
- n.join(m, "../../package.json"),
8
- "utf-8"
9
- );
10
- return JSON.parse(e);
11
- }, f = () => r().version, g = () => r().name;
12
- export {
13
- g as getPkgName,
14
- f as getVersion
15
- };
@@ -1,9 +0,0 @@
1
- /** 包信息 */
2
- export interface PackageInfo {
3
- name: string;
4
- version: string;
5
- }
6
- /** 获取版本号 */
7
- export declare const getVersion: () => string;
8
- /** 获取包名 */
9
- export declare const getPkgName: () => string;