create-done-coding 0.3.1 → 0.4.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
@@ -1,5 +1,7 @@
1
1
  # create-done-coding
2
2
 
3
- ```ts
4
- npx create done-coding@latest
5
- ```
3
+ done-coding项目脚手架
4
+
5
+ ## 使用
6
+
7
+ npm create done-coding
package/es/handler.mjs CHANGED
@@ -1,27 +1,28 @@
1
1
  #!/usr/bin/env node
2
- import { CUSTOM_TEMPLATE_NAME as w } from "./utils/const.mjs";
3
- import { projectNameForm as E, templateForm as S, templateChoices as x, saveGitHistoryForm as h } from "./utils/question.mjs";
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";
4
4
  import n from "prompts";
5
5
  import { execSync as a } from "node:child_process";
6
- import { existsSync as l, rmSync as i, readFileSync as p, writeFileSync as g } from "node:fs";
7
- import { resolve as k } from "node:path";
8
- import r from "chalk";
9
- const I = async (u) => {
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";
8
+ import t from "chalk";
9
+ const b = async (u) => {
10
10
  const {
11
- projectName: f,
12
- template: d,
13
- saveGitHistory: y
14
- } = u, t = ((f ?? (await n(E)).projectName) || "").trim();
15
- if (!t.trim()) {
16
- console.log(r.red("项目名称不能为空"));
11
+ projectName: d,
12
+ template: w,
13
+ saveGitHistory: y,
14
+ shallowClone: $
15
+ } = u, r = ((d ?? (await n(E)).projectName) || "").trim();
16
+ if (!r.trim()) {
17
+ console.log(t.red("项目名称不能为空"));
17
18
  return;
18
19
  }
19
- if (t.includes(" ") || t.includes("\\") || t.includes("/")) {
20
- console.log(r.red("项目名称不能包含空格或者\\或者/"));
20
+ if (r.includes(" ") || r.includes("\\") || r.includes("/")) {
21
+ console.log(t.red("项目名称不能包含空格或者\\或者/"));
21
22
  return;
22
23
  }
23
- const e = k(process.cwd(), t);
24
- if (l(e)) {
24
+ const e = M(process.cwd(), r);
25
+ if (p(e)) {
25
26
  const { isRemove: o } = await n({
26
27
  type: "confirm",
27
28
  name: "isRemove",
@@ -30,47 +31,53 @@ const I = async (u) => {
30
31
  if (o === !0)
31
32
  i(e, { recursive: !0, force: !0 });
32
33
  else
33
- return console.log(r.red("项目已存在")), process.exit(1);
34
+ return console.log(t.red("项目已存在")), process.exit(1);
34
35
  }
35
- const s = d ?? (await n(S)).template;
36
- let c = "";
37
- if (s === w) {
36
+ const s = w ?? (await n(S)).template;
37
+ let l = "";
38
+ if (s === j) {
38
39
  const { customUrl: o } = await n({
39
40
  type: "text",
40
41
  name: "customUrl",
41
42
  message: "请输入自定义模板路径"
42
43
  });
43
- c = o;
44
+ l = o;
44
45
  } else {
45
- const o = x.find((j) => j.name === s);
46
+ const o = x.find((C) => C.name === s);
46
47
  if (!o)
47
- return console.log(r.red(`模板${s}不存在`)), process.exit(1);
48
+ return console.log(t.red(`模板${s}不存在`)), process.exit(1);
48
49
  if (!o.url)
49
- return console.log(r.red(`模板${s}仓库地址不存在`)), process.exit(1);
50
- c = o.url;
50
+ return console.log(t.red(`模板${s}仓库地址不存在`)), process.exit(1);
51
+ l = o.url;
51
52
  }
52
- if (console.log(r.green("正在初始化项目,请稍等...")), a(`git clone ${c} ${t} --depth=1`), (y ?? (await n(h)).saveGitHistory) === !1) {
53
+ console.log(t.green("正在初始化项目,请稍等...")), a(`git clone ${l} ${r} --depth=1`);
54
+ const m = y ?? (await n(k)).saveGitHistory;
55
+ if (m === !1) {
53
56
  const o = `${e}/.git`;
54
- if (!l(o))
57
+ if (!p(o))
55
58
  throw new Error("git目录不存在");
56
59
  i(`${e}/.git`, { recursive: !0, force: !0 });
57
60
  } else
58
61
  a(`cd ${e} && git remote rename origin upstream`);
59
- const $ = p(`${e}/package.json`, "utf-8"), m = JSON.parse($), { name: v } = m;
60
- m.name = t, i(`${e}/package.json`), g(
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(
61
64
  `${e}/package.json`,
62
- JSON.stringify(m, null, 2)
65
+ JSON.stringify(c, null, 2)
63
66
  );
64
- const N = p(`${e}/README.md`, "utf-8").replace(v, t);
65
- i(`${e}/README.md`), g(`${e}/README.md`, N), console.log(r.green("项目初始化完成")), console.log(
66
- r.blue(`
67
+ 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(
69
+ t.yellow("当前使用浅克隆,后续不能与模板git仓库有完整的交互")
70
+ ) : (a(`cd ${e} && git fetch --unshallow`), console.log(
71
+ t.green("已完整克隆项目,后续可以与模板git仓库有完整的交互")
72
+ ))), console.log(
73
+ t.blue(`
67
74
  使用步骤:
68
- 1. cd ${t}
75
+ 1. cd ${r}
69
76
  2. pnpm install
70
77
  3. pnpm run dev
71
78
  `)
72
79
  );
73
80
  };
74
81
  export {
75
- I as handler
82
+ b as handler
76
83
  };
package/es/main.mjs CHANGED
@@ -4,31 +4,37 @@ import { hideBin as a } from "yargs/helpers";
4
4
  import { handler as i } from "./handler.mjs";
5
5
  import o from "chalk";
6
6
  import { getVersion as n } from "./utils/packageInfo.mjs";
7
- import { projectNameForm as m, templateChoices as p, templateForm as c, saveGitHistoryForm as l } from "./utils/question.mjs";
8
- const g = () => ({
7
+ import { projectNameForm as l, templateChoices as m, templateForm as c, saveGitHistoryForm as p, shallowCloneForm as g } from "./utils/question.mjs";
8
+ const d = () => ({
9
9
  projectName: {
10
10
  type: "string",
11
11
  alias: "p",
12
- describe: m.message
12
+ describe: l.message
13
13
  },
14
14
  template: {
15
15
  type: "string",
16
16
  alias: "t",
17
- choices: p.map((e) => e.name),
17
+ choices: m.map((e) => e.name),
18
18
  describe: c.message
19
19
  },
20
20
  saveGitHistory: {
21
21
  type: "boolean",
22
22
  alias: "s",
23
- describe: l.message
23
+ describe: p.message
24
+ },
25
+ shallowClone: {
26
+ type: "boolean",
27
+ alias: "c",
28
+ describe: g.message,
29
+ default: !0
24
30
  }
25
- }), d = (e, s) => {
31
+ }), h = (e, s) => {
26
32
  console.log(e ? o.red(e) : o.red(s.message)), process.exit(1);
27
- }, f = "Usage: $0 [options]", h = (e, s) => {
28
- const t = g();
29
- return e.strict().usage(s).help("help").version(n()).alias("v", "version").alias("h", "help").options(t).fail(d).argv;
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;
30
36
  }, H = async () => {
31
- const e = r(a(process.argv)), s = await h(e, f);
37
+ const e = r(a(process.argv)), s = await v(e, f);
32
38
  return i(s);
33
39
  };
34
40
  export {
@@ -1,16 +1,16 @@
1
1
  #!/usr/bin/env node
2
- import { CUSTOM_TEMPLATE_NAME as m } from "./const.mjs";
3
- import { readConfig as o } from "./readConfig.mjs";
2
+ import { CUSTOM_TEMPLATE_NAME as o } from "./const.mjs";
3
+ import { readConfig as m } from "./readConfig.mjs";
4
4
  let t;
5
- const a = () => (t || (t = o().templateList), t), s = [
5
+ const a = () => (t || (t = m().templateList), t), s = [
6
6
  ...a(),
7
- { name: m }
7
+ { name: o }
8
8
  ], r = {
9
9
  type: "text",
10
10
  name: "projectName",
11
11
  message: "请输入项目名称",
12
12
  validate: (e) => e.trim().length > 0 || "项目名称不能为空"
13
- }, c = {
13
+ }, l = {
14
14
  type: "select",
15
15
  name: "template",
16
16
  message: "请选择模板",
@@ -18,15 +18,20 @@ const a = () => (t || (t = o().templateList), t), s = [
18
18
  title: e.name,
19
19
  value: e.name
20
20
  }))
21
- }, p = {
21
+ }, c = {
22
22
  type: "confirm",
23
23
  name: "saveGitHistory",
24
24
  message: "是否保留git历史"
25
+ }, p = {
26
+ type: "confirm",
27
+ name: "shallowClone",
28
+ message: "是否使用浅克隆(后续期望与模板git仓库有完整的交互,请选择'N')"
25
29
  };
26
30
  export {
27
31
  a as getTemplateList,
28
32
  r as projectNameForm,
29
- p as saveGitHistoryForm,
33
+ c as saveGitHistoryForm,
34
+ p as shallowCloneForm,
30
35
  s as templateChoices,
31
- c as templateForm
36
+ l as templateForm
32
37
  };
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "create-done-coding",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
+ "description": "done-coding项目脚手架",
4
5
  "module": "es/cli.mjs",
5
6
  "type": "module",
6
7
  "types": "types/cli.d.ts",
@@ -22,42 +23,25 @@
22
23
  "dev": "vite build --watch",
23
24
  "prebuild": "pnpm run clean",
24
25
  "build": "vite build",
25
- "prepack": "pnpm build",
26
- "push": "dc-publish npm"
26
+ "prepack": "pnpm build"
27
27
  },
28
28
  "repository": {
29
29
  "type": "git",
30
- "url": "https://gitee.com/justsosu/create-done-coding"
30
+ "url": "https://gitee.com/justsosu/done-coding-cli.git",
31
+ "directory": "packages/create"
31
32
  },
32
33
  "author": "JustSoSu",
33
- "license": "ISC",
34
+ "license": "MIT",
34
35
  "sideEffects": false,
35
36
  "devDependencies": {
36
- "@commitlint/cli": "^16.3.0",
37
- "@commitlint/config-conventional": "^16.2.4",
38
- "@done-coding/publish": "0.1.0",
39
37
  "@types/node": "^16.18.58",
40
38
  "@types/prompts": "^2.4.6",
41
39
  "@types/yargs": "^17.0.33",
42
- "@typescript-eslint/eslint-plugin": "^6.7.0",
43
- "@typescript-eslint/parser": "^6.7.0",
44
- "conventional-changelog-cli": "^4.1.0",
45
- "eslint": "^8.49.0",
46
- "eslint-config-alloy": "^5.1.2",
47
- "husky": "^8.0.3",
48
- "lint-staged": "^12.5.0",
49
- "prettier": "^3.0.3",
50
- "rimraf": "^5.0.1",
40
+ "rimraf": "^6.0.1",
51
41
  "typescript": "^5.2.2",
52
42
  "vite": "^4.4.11",
53
43
  "vite-plugin-dts": "^3.6.0"
54
44
  },
55
- "lint-staged": {
56
- "*.{ts,js,vue,jsx,tsx}": [
57
- "eslint --fix",
58
- "prettier --write"
59
- ]
60
- },
61
45
  "engines": {
62
46
  "node": ">=16.0.0"
63
47
  },
@@ -65,5 +49,6 @@
65
49
  "chalk": "^5.3.0",
66
50
  "prompts": "^2.4.2",
67
51
  "yargs": "^17.7.2"
68
- }
52
+ },
53
+ "gitHead": "505e67277f0f24385c0942bbbdbfde17e9076f63"
69
54
  }
@@ -1,4 +1,3 @@
1
- import { Options } from './utils';
2
- import { ArgumentsCamelCase } from 'yargs';
3
-
1
+ import { type Options } from './utils';
2
+ import type { ArgumentsCamelCase } from "yargs";
4
3
  export declare const handler: (argv: ArgumentsCamelCase<Options>) => Promise<undefined>;
package/types/main.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { CommandModule } from 'yargs';
2
- import { Options } from './utils';
3
-
1
+ import type { CommandModule } from "yargs";
2
+ import type { Options } from './utils';
4
3
  export declare const command: CommandModule<Options, Options>;
5
4
  export declare const createCli: () => Promise<undefined>;
@@ -1,5 +1,5 @@
1
- export * from './readConfig';
2
- export * from './packageInfo';
3
- export * from './const';
4
- export * from './types';
5
- export * from './question';
1
+ export * from "./readConfig";
2
+ export * from "./packageInfo";
3
+ export * from "./const";
4
+ export * from "./types";
5
+ export * from "./question";
@@ -1,5 +1,4 @@
1
- import { PromptObject } from 'prompts';
2
-
1
+ import type { PromptObject } from "prompts";
3
2
  /** 模版选项 */
4
3
  export interface TemplateChoiceItem {
5
4
  name: string;
@@ -16,3 +15,8 @@ export declare const saveGitHistoryForm: {
16
15
  name: string;
17
16
  message: string;
18
17
  };
18
+ export declare const shallowCloneForm: {
19
+ type: "confirm";
20
+ name: string;
21
+ message: string;
22
+ };
@@ -1,5 +1,4 @@
1
- import { TemplateChoiceItem } from './question';
2
-
1
+ import type { TemplateChoiceItem } from "./question";
3
2
  /** 配置文件 */
4
3
  export interface ConfigJson {
5
4
  templateList: TemplateChoiceItem[];
@@ -5,4 +5,6 @@ export interface Options {
5
5
  template: string;
6
6
  /** 保存git历史记录 */
7
7
  saveGitHistory: boolean;
8
+ /** 是否使用shallow clone */
9
+ shallowClone: boolean;
8
10
  }