create-done-coding 0.2.12 → 0.3.1
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 +1 -1
- package/es/cli.mjs +3 -0
- package/es/handler.mjs +76 -0
- package/es/main.mjs +36 -0
- package/es/utils/const.mjs +7 -0
- package/es/utils/packageInfo.mjs +15 -0
- package/es/utils/question.mjs +32 -0
- package/es/utils/readConfig.mjs +22 -0
- package/package.json +21 -12
- package/types/cli.d.ts +2 -0
- package/types/handler.d.ts +4 -0
- package/types/main.d.ts +5 -0
- package/types/utils/const.d.ts +6 -0
- package/types/utils/index.d.ts +5 -0
- package/types/utils/packageInfo.d.ts +9 -0
- package/types/utils/question.d.ts +18 -0
- package/types/utils/readConfig.d.ts +8 -0
- package/types/utils/types.d.ts +8 -0
- package/dist/index.js +0 -6
- package/types/index.d.ts +0 -1
package/README.md
CHANGED
package/es/cli.mjs
ADDED
package/es/handler.mjs
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
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";
|
|
4
|
+
import n from "prompts";
|
|
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) => {
|
|
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("项目名称不能为空"));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (t.includes(" ") || t.includes("\\") || t.includes("/")) {
|
|
20
|
+
console.log(r.red("项目名称不能包含空格或者\\或者/"));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const e = k(process.cwd(), t);
|
|
24
|
+
if (l(e)) {
|
|
25
|
+
const { isRemove: o } = await n({
|
|
26
|
+
type: "confirm",
|
|
27
|
+
name: "isRemove",
|
|
28
|
+
message: "项目已存在,是否删除"
|
|
29
|
+
});
|
|
30
|
+
if (o === !0)
|
|
31
|
+
i(e, { recursive: !0, force: !0 });
|
|
32
|
+
else
|
|
33
|
+
return console.log(r.red("项目已存在")), process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
const s = d ?? (await n(S)).template;
|
|
36
|
+
let c = "";
|
|
37
|
+
if (s === w) {
|
|
38
|
+
const { customUrl: o } = await n({
|
|
39
|
+
type: "text",
|
|
40
|
+
name: "customUrl",
|
|
41
|
+
message: "请输入自定义模板路径"
|
|
42
|
+
});
|
|
43
|
+
c = o;
|
|
44
|
+
} else {
|
|
45
|
+
const o = x.find((j) => j.name === s);
|
|
46
|
+
if (!o)
|
|
47
|
+
return console.log(r.red(`模板${s}不存在`)), process.exit(1);
|
|
48
|
+
if (!o.url)
|
|
49
|
+
return console.log(r.red(`模板${s}仓库地址不存在`)), process.exit(1);
|
|
50
|
+
c = o.url;
|
|
51
|
+
}
|
|
52
|
+
if (console.log(r.green("正在初始化项目,请稍等...")), a(`git clone ${c} ${t} --depth=1`), (y ?? (await n(h)).saveGitHistory) === !1) {
|
|
53
|
+
const o = `${e}/.git`;
|
|
54
|
+
if (!l(o))
|
|
55
|
+
throw new Error("git目录不存在");
|
|
56
|
+
i(`${e}/.git`, { recursive: !0, force: !0 });
|
|
57
|
+
} else
|
|
58
|
+
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(
|
|
61
|
+
`${e}/package.json`,
|
|
62
|
+
JSON.stringify(m, null, 2)
|
|
63
|
+
);
|
|
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
|
+
使用步骤:
|
|
68
|
+
1. cd ${t}
|
|
69
|
+
2. pnpm install
|
|
70
|
+
3. pnpm run dev
|
|
71
|
+
`)
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
export {
|
|
75
|
+
I as handler
|
|
76
|
+
};
|
package/es/main.mjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
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 m, templateChoices as p, templateForm as c, saveGitHistoryForm as l } from "./utils/question.mjs";
|
|
8
|
+
const g = () => ({
|
|
9
|
+
projectName: {
|
|
10
|
+
type: "string",
|
|
11
|
+
alias: "p",
|
|
12
|
+
describe: m.message
|
|
13
|
+
},
|
|
14
|
+
template: {
|
|
15
|
+
type: "string",
|
|
16
|
+
alias: "t",
|
|
17
|
+
choices: p.map((e) => e.name),
|
|
18
|
+
describe: c.message
|
|
19
|
+
},
|
|
20
|
+
saveGitHistory: {
|
|
21
|
+
type: "boolean",
|
|
22
|
+
alias: "s",
|
|
23
|
+
describe: l.message
|
|
24
|
+
}
|
|
25
|
+
}), d = (e, s) => {
|
|
26
|
+
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;
|
|
30
|
+
}, H = async () => {
|
|
31
|
+
const e = r(a(process.argv)), s = await h(e, f);
|
|
32
|
+
return i(s);
|
|
33
|
+
};
|
|
34
|
+
export {
|
|
35
|
+
H as createCli
|
|
36
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { CUSTOM_TEMPLATE_NAME as m } from "./const.mjs";
|
|
3
|
+
import { readConfig as o } from "./readConfig.mjs";
|
|
4
|
+
let t;
|
|
5
|
+
const a = () => (t || (t = o().templateList), t), s = [
|
|
6
|
+
...a(),
|
|
7
|
+
{ name: m }
|
|
8
|
+
], r = {
|
|
9
|
+
type: "text",
|
|
10
|
+
name: "projectName",
|
|
11
|
+
message: "请输入项目名称",
|
|
12
|
+
validate: (e) => e.trim().length > 0 || "项目名称不能为空"
|
|
13
|
+
}, c = {
|
|
14
|
+
type: "select",
|
|
15
|
+
name: "template",
|
|
16
|
+
message: "请选择模板",
|
|
17
|
+
choices: s.map((e) => ({
|
|
18
|
+
title: e.name,
|
|
19
|
+
value: e.name
|
|
20
|
+
}))
|
|
21
|
+
}, p = {
|
|
22
|
+
type: "confirm",
|
|
23
|
+
name: "saveGitHistory",
|
|
24
|
+
message: "是否保留git历史"
|
|
25
|
+
};
|
|
26
|
+
export {
|
|
27
|
+
a as getTemplateList,
|
|
28
|
+
r as projectNameForm,
|
|
29
|
+
p as saveGitHistoryForm,
|
|
30
|
+
s as templateChoices,
|
|
31
|
+
c as templateForm
|
|
32
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
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(
|
|
11
|
+
process.cwd(),
|
|
12
|
+
m
|
|
13
|
+
);
|
|
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))
|
|
17
|
+
throw new Error("远程配置文件出错,templateList 不是数组");
|
|
18
|
+
return console.log(e.green("模板列表拉取成功!")), n.rmSync(r, { recursive: !0, force: !0 }), o;
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
d as readConfig
|
|
22
|
+
};
|
package/package.json
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-done-coding",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"module": "es/cli.mjs",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"types": "types/cli.d.ts",
|
|
7
|
+
"bin": "es/cli.mjs",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./es/cli.mjs"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
7
13
|
"files": [
|
|
8
|
-
"
|
|
9
|
-
"
|
|
14
|
+
"es",
|
|
15
|
+
"lib",
|
|
16
|
+
"types",
|
|
17
|
+
"gif"
|
|
10
18
|
],
|
|
11
19
|
"scripts": {
|
|
12
|
-
"clean": "rimraf es lib
|
|
13
|
-
"serve": "vite",
|
|
14
|
-
"dev": "vite build -w",
|
|
20
|
+
"clean": "rimraf es lib types",
|
|
15
21
|
"predev": "pnpm run clean",
|
|
16
|
-
"
|
|
22
|
+
"dev": "vite build --watch",
|
|
17
23
|
"prebuild": "pnpm run clean",
|
|
24
|
+
"build": "vite build",
|
|
18
25
|
"prepack": "pnpm build",
|
|
19
26
|
"push": "dc-publish npm"
|
|
20
27
|
},
|
|
@@ -28,9 +35,10 @@
|
|
|
28
35
|
"devDependencies": {
|
|
29
36
|
"@commitlint/cli": "^16.3.0",
|
|
30
37
|
"@commitlint/config-conventional": "^16.2.4",
|
|
31
|
-
"@done-coding/publish": "0.0
|
|
38
|
+
"@done-coding/publish": "0.1.0",
|
|
32
39
|
"@types/node": "^16.18.58",
|
|
33
40
|
"@types/prompts": "^2.4.6",
|
|
41
|
+
"@types/yargs": "^17.0.33",
|
|
34
42
|
"@typescript-eslint/eslint-plugin": "^6.7.0",
|
|
35
43
|
"@typescript-eslint/parser": "^6.7.0",
|
|
36
44
|
"conventional-changelog-cli": "^4.1.0",
|
|
@@ -55,6 +63,7 @@
|
|
|
55
63
|
},
|
|
56
64
|
"dependencies": {
|
|
57
65
|
"chalk": "^5.3.0",
|
|
58
|
-
"prompts": "^2.4.2"
|
|
66
|
+
"prompts": "^2.4.2",
|
|
67
|
+
"yargs": "^17.7.2"
|
|
59
68
|
}
|
|
60
69
|
}
|
package/types/cli.d.ts
ADDED
package/types/main.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PromptObject } from 'prompts';
|
|
2
|
+
|
|
3
|
+
/** 模版选项 */
|
|
4
|
+
export interface TemplateChoiceItem {
|
|
5
|
+
name: string;
|
|
6
|
+
url?: string;
|
|
7
|
+
}
|
|
8
|
+
/** 获取模版选项 */
|
|
9
|
+
export declare const getTemplateList: () => TemplateChoiceItem[];
|
|
10
|
+
/** 模版选项 */
|
|
11
|
+
export declare const templateChoices: TemplateChoiceItem[];
|
|
12
|
+
export declare const projectNameForm: PromptObject<string>;
|
|
13
|
+
export declare const templateForm: PromptObject<string>;
|
|
14
|
+
export declare const saveGitHistoryForm: {
|
|
15
|
+
type: "confirm";
|
|
16
|
+
name: string;
|
|
17
|
+
message: string;
|
|
18
|
+
};
|
package/dist/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";var h=Object.create;var u=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty;var x=(e,n,i,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of b(n))!C.call(e,t)&&t!==i&&u(e,t,{get:()=>n[t],enumerable:!(o=$(n,t))||o.enumerable});return e};var g=(e,n,i)=>(i=e!=null?h(k(e)):{},x(n||!e||!e.__esModule?u(i,"default",{value:e,enumerable:!0}):i,e));const m=require("prompts"),p=require("node:child_process"),s=require("node:fs"),d=require("node:path"),f="template-node-cli",y="CUSTOM",_=[{title:"typescript",value:"template-ts"},{title:"node-cli",value:f},{title:"web-mobile-vue3",value:"template-web-m-vue3"},{title:"web-mobile-react",value:"template-web-m-react"},{title:"uni-vue3",value:"template-uni-m-vue3"},{title:"monorepo",value:"template-monorepo"},{title:"自定义模板路径",value:y}],F=process.cwd();async function O(){const e=d.resolve(__dirname,"../package.json"),n=s.readFileSync(e,"utf-8"),{version:i}=JSON.parse(n),o=(await import("chalk")).default;return console.log(o.green(`v${i}`)),await m([{type:"text",name:"projectName",message:"Project name:"},{type:"select",name:"template",message:"请选择模板",choices:_},{type:"confirm",name:"saveGitHistory",message:"保留git历史"}])}O().then(async({projectName:e,template:n,saveGitHistory:i})=>{const o=(await import("chalk")).default;if(!e.trim()){console.log(o.red("项目名称不能为空"));return}if(e.includes(" ")||e.includes("\\")||e.includes("/")){console.log(o.red("项目名称不能包含空格或者\\或者/"));return}const t=d.resolve(F,e);if(s.existsSync(t)){const{isRemove:c}=await m({type:"confirm",name:"isRemove",message:"项目已存在,是否删除"});if(c===!0)s.rmSync(t,{recursive:!0,force:!0});else throw new Error("项目已存在")}let a="";if(n===y){const{customUrl:c}=await m({type:"text",name:"customUrl",message:"请输入自定义模板路径"});a=c}else a=`https://gitee.com/justsosu/${n}`;if(console.log(o.green("正在初始化项目,请稍等...")),p.execSync(`git clone ${a} ${e}`),i===!1){const c=`${t}/.git`;if(!s.existsSync(c))throw new Error("git目录不存在");s.rmSync(`${t}/.git`,{recursive:!0,force:!0})}else p.execSync(`cd ${t} && git remote rename origin upstream`);const v=s.readFileSync(`${t}/package.json`,"utf-8"),r=JSON.parse(v),{name:S}=r;if(r.name=e,s.rmSync(`${t}/package.json`),n===f){const c=r.bin;r.bin={[e]:Object.values(c)[0]}}s.writeFileSync(`${t}/package.json`,JSON.stringify(r,null,2));const l=`${t}/README.md`;if(s.existsSync(l)){const w=s.readFileSync(l,"utf-8").replace(S,e);s.rmSync(l),s.writeFileSync(l,w)}console.log(o.green("项目初始化完成")),console.log(o.blue(`
|
|
2
|
-
使用步骤:
|
|
3
|
-
1. cd ${e}
|
|
4
|
-
2. pnpm install
|
|
5
|
-
3. pnpm run dev
|
|
6
|
-
`))});
|
package/types/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|