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