@yll10243/crud-cli 1.0.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/dist/gitDownload.d.ts +1 -0
- package/dist/gitDownload.js +43 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +136 -0
- package/package.json +32 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function gitClone(repo: any, targetPath: string, opts: any, cb: any): void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { spawn } from "child_process";
|
|
2
|
+
export function gitClone(repo, targetPath, opts, cb) {
|
|
3
|
+
if (typeof opts === "function") {
|
|
4
|
+
cb = opts;
|
|
5
|
+
opts = null;
|
|
6
|
+
}
|
|
7
|
+
opts = opts || {};
|
|
8
|
+
var git = opts.git || "git";
|
|
9
|
+
var args = ["clone"];
|
|
10
|
+
if (opts.shallow) {
|
|
11
|
+
args.push("--depth");
|
|
12
|
+
args.push("1");
|
|
13
|
+
}
|
|
14
|
+
args.push("--");
|
|
15
|
+
args.push(repo);
|
|
16
|
+
args.push(targetPath);
|
|
17
|
+
var process = spawn(git, args);
|
|
18
|
+
function _checkout() {
|
|
19
|
+
var args = ["checkout", opts.checkout];
|
|
20
|
+
var process = spawn(git, args, { cwd: targetPath });
|
|
21
|
+
process.on("close", function (status) {
|
|
22
|
+
if (status == 0) {
|
|
23
|
+
cb && cb();
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
cb && cb(new Error("'git checkout' failed with status " + status));
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
process.on("close", function (status) {
|
|
31
|
+
if (status == 0) {
|
|
32
|
+
if (opts.checkout) {
|
|
33
|
+
_checkout();
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
cb && cb();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
cb && cb(new Error("'git clone' failed with status " + status));
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
package/dist/main.d.ts
ADDED
package/dist/main.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
import { select, input, confirm } from "@inquirer/prompts";
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
import { Command } from "commander";
|
|
14
|
+
import fse from "fs-extra";
|
|
15
|
+
import { exec } from "child_process";
|
|
16
|
+
import { gitClone } from "./gitDownload.js";
|
|
17
|
+
import ora from "ora";
|
|
18
|
+
/**
|
|
19
|
+
* 校验是否有安装git
|
|
20
|
+
*/
|
|
21
|
+
const isInstallGit = () => {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
exec("git --version", (error, _stdout, _stderr) => {
|
|
24
|
+
if (error) {
|
|
25
|
+
reject("no");
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
resolve("ok");
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* 选择vue相关的目标模板的分支
|
|
34
|
+
*/
|
|
35
|
+
const vueSelectBranch = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
const val = yield select({
|
|
37
|
+
message: "请选择vue-crud模版",
|
|
38
|
+
choices: [
|
|
39
|
+
{
|
|
40
|
+
name: "simple【https://www.example.com】",
|
|
41
|
+
value: "jest-init",
|
|
42
|
+
description: "简单的引入使用"
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
});
|
|
46
|
+
return val;
|
|
47
|
+
});
|
|
48
|
+
/**
|
|
49
|
+
* 选择vue相关的目标模板
|
|
50
|
+
*/
|
|
51
|
+
const reactSelectBranch = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
+
const val = yield select({
|
|
53
|
+
message: "请选择react-crud模版",
|
|
54
|
+
choices: [
|
|
55
|
+
{
|
|
56
|
+
name: "simple【https://www.example.com】",
|
|
57
|
+
value: "one",
|
|
58
|
+
description: "简单的引入使用"
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
});
|
|
62
|
+
return val;
|
|
63
|
+
});
|
|
64
|
+
/*
|
|
65
|
+
* 创建项目的核心功能
|
|
66
|
+
*/
|
|
67
|
+
function create() {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
//1,项目名称
|
|
70
|
+
let projectName = "";
|
|
71
|
+
while (!projectName) {
|
|
72
|
+
projectName = yield input({ message: "Project name" });
|
|
73
|
+
}
|
|
74
|
+
const targetPath = path.join(process.cwd(), projectName);
|
|
75
|
+
if (fse.existsSync(targetPath)) {
|
|
76
|
+
const empty = yield confirm({
|
|
77
|
+
message: "该目录不为空,是否清空(请提前做好备份)"
|
|
78
|
+
});
|
|
79
|
+
if (empty) {
|
|
80
|
+
fse.remove(targetPath);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
process.exit(0);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//2,选择是vue还是react分类
|
|
87
|
+
const projectTemplate = yield select({
|
|
88
|
+
message: "请选择是vue还是react?",
|
|
89
|
+
choices: [
|
|
90
|
+
{
|
|
91
|
+
name: "vue-crud项目",
|
|
92
|
+
value: "one"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: "react-crud项目",
|
|
96
|
+
value: "two"
|
|
97
|
+
}
|
|
98
|
+
]
|
|
99
|
+
});
|
|
100
|
+
if (projectTemplate == "one") {
|
|
101
|
+
//3,vue具体模板相关
|
|
102
|
+
let vueSelectBranchVal = yield vueSelectBranch();
|
|
103
|
+
let spinner = ora("clone模版中...").start();
|
|
104
|
+
gitClone("https://gitee.com/1024335892/jest-study.git", targetPath, { checkout: vueSelectBranchVal }, () => {
|
|
105
|
+
let gitDir = targetPath + "/.git";
|
|
106
|
+
if (fse.existsSync(gitDir)) {
|
|
107
|
+
fse.remove(gitDir);
|
|
108
|
+
}
|
|
109
|
+
console.log(targetPath + " clone完成");
|
|
110
|
+
spinner.stop();
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
else if (projectTemplate == "two") {
|
|
114
|
+
//4,vue具体模板相关
|
|
115
|
+
let reactSelectBranchVal = yield reactSelectBranch();
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
const programFun = () => {
|
|
120
|
+
const program = new Command();
|
|
121
|
+
program
|
|
122
|
+
.command("create")
|
|
123
|
+
.description("创建项目")
|
|
124
|
+
.action(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
|
+
create();
|
|
126
|
+
}));
|
|
127
|
+
program.parse();
|
|
128
|
+
};
|
|
129
|
+
isInstallGit()
|
|
130
|
+
.then(() => {
|
|
131
|
+
programFun();
|
|
132
|
+
})
|
|
133
|
+
.catch(() => {
|
|
134
|
+
console.error("请先安装git");
|
|
135
|
+
process.exit(0);
|
|
136
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yll10243/crud-cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "crud创建项目模板的脚手架",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"bin": {
|
|
10
|
+
"viteTemp": "./dist/main.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "npx tsc"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [],
|
|
19
|
+
"author": "",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^25.5.0",
|
|
23
|
+
"typescript": "^5.9.3",
|
|
24
|
+
"@types/fs-extra": "^11.0.4"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@inquirer/prompts": "^8.3.2",
|
|
28
|
+
"commander": "^14.0.3",
|
|
29
|
+
"fs-extra": "^11.3.4",
|
|
30
|
+
"ora": "^9.3.0"
|
|
31
|
+
}
|
|
32
|
+
}
|