listpage_cli 0.0.191 → 0.0.193
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/bin/cli.js +14 -202
- package/bin/copy.js +99 -0
- package/bin/prompts.js +67 -0
- package/bin/utils.js +20 -0
- package/package.json +1 -1
- package/templates/backend-template/AGENTS.md +14 -0
- package/templates/{app-templates/backend-tempalte → backend-template}/package.json.tmpl +1 -1
- package/templates/backend-template/src/main.ts +22 -0
- package/templates/backend-template/src/modules/app.module.ts +7 -0
- package/templates/backend-template/src/modules/prisma/prisma.module.ts +8 -0
- package/templates/backend-template/src/modules/prisma/prisma.service.ts +12 -0
- package/templates/{app-templates/frontend-template → frontend-template}/package.json.tmpl +1 -1
- package/templates/app-templates/backend-tempalte/src/app.controller.ts +0 -12
- package/templates/app-templates/backend-tempalte/src/app.module.ts +0 -10
- package/templates/app-templates/backend-tempalte/src/app.service.ts +0 -8
- package/templates/app-templates/backend-tempalte/src/main.ts +0 -8
- /package/templates/{app-templates/backend-tempalte → backend-template}/.gitignore.tmpl +0 -0
- /package/templates/{app-templates/backend-tempalte → backend-template}/.prettierrc +0 -0
- /package/templates/{app-templates/backend-tempalte → backend-template}/README.md +0 -0
- /package/templates/{app-templates/backend-tempalte → backend-template}/nest-cli.json +0 -0
- /package/templates/{app-templates/backend-tempalte → backend-template}/prisma/schema.prisma +0 -0
- /package/templates/{app-templates/backend-tempalte → backend-template}/tsconfig.build.json +0 -0
- /package/templates/{app-templates/backend-tempalte → backend-template}/tsconfig.json +0 -0
- /package/templates/{app-templates/frontend-template → frontend-template}/.gitignore.tmpl +0 -0
- /package/templates/{app-templates/frontend-template → frontend-template}/.prettierignore +0 -0
- /package/templates/{app-templates/frontend-template → frontend-template}/.prettierrc +0 -0
- /package/templates/{app-templates/frontend-template → frontend-template}/AGENTS.md +0 -0
- /package/templates/{app-templates/frontend-template → frontend-template}/README.md +0 -0
- /package/templates/{app-templates/frontend-template → frontend-template}/public/favicon.png +0 -0
- /package/templates/{app-templates/frontend-template → frontend-template}/rsbuild.config.ts +0 -0
- /package/templates/{app-templates/frontend-template → frontend-template}/src/App.css +0 -0
- /package/templates/{app-templates/frontend-template → frontend-template}/src/App.tsx +0 -0
- /package/templates/{app-templates/frontend-template → frontend-template}/src/Layout.tsx +0 -0
- /package/templates/{app-templates/frontend-template → frontend-template}/src/api/config.tsx +0 -0
- /package/templates/{app-templates/frontend-template → frontend-template}/src/api/index.ts +0 -0
- /package/templates/{app-templates/frontend-template → frontend-template}/src/env.d.ts +0 -0
- /package/templates/{app-templates/frontend-template → frontend-template}/src/index.tsx +0 -0
- /package/templates/{app-templates/frontend-template → frontend-template}/src/router/index.tsx +0 -0
- /package/templates/{app-templates/frontend-template → frontend-template}/tsconfig.json +0 -0
- /package/templates/{.gitattributes → rush-template/.gitattributes} +0 -0
- /package/templates/{.github → rush-template/.github}/workflows/ci.yml +0 -0
- /package/templates/{.gitignore.tmpl → rush-template/.gitignore.tmpl} +0 -0
- /package/templates/{common → rush-template/common}/config/rush/.npmrc-publish +0 -0
- /package/templates/{common → rush-template/common}/config/rush/.pnpmfile.cjs +0 -0
- /package/templates/{common → rush-template/common}/config/rush/artifactory.json +0 -0
- /package/templates/{common → rush-template/common}/config/rush/build-cache.json +0 -0
- /package/templates/{common → rush-template/common}/config/rush/cobuild.json +0 -0
- /package/templates/{common → rush-template/common}/config/rush/command-line.json +0 -0
- /package/templates/{common → rush-template/common}/config/rush/common-versions.json +0 -0
- /package/templates/{common → rush-template/common}/config/rush/custom-tips.json +0 -0
- /package/templates/{common → rush-template/common}/config/rush/experiments.json +0 -0
- /package/templates/{common → rush-template/common}/config/rush/pnpm-config.json +0 -0
- /package/templates/{common → rush-template/common}/config/rush/rush-plugins.json +0 -0
- /package/templates/{common → rush-template/common}/config/rush/subspaces.json +0 -0
- /package/templates/{common → rush-template/common}/config/rush/version-policies.json +0 -0
- /package/templates/{common → rush-template/common}/git-hooks/commit-msg.sample +0 -0
- /package/templates/{rush.json → rush-template/rush.json} +0 -0
package/bin/cli.js
CHANGED
|
@@ -4,229 +4,41 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
7
|
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const h = [
|
|
12
|
-
"用法: listpage_cli init",
|
|
13
|
-
"说明: 进入中文引导式交互,按提示填写即可",
|
|
14
|
-
].join("\n");
|
|
15
|
-
console.log(h);
|
|
16
|
-
}
|
|
17
|
-
function printVersion() {
|
|
18
|
-
try {
|
|
19
|
-
const p = path_1.default.join(__dirname, "..", "package.json");
|
|
20
|
-
const pkg = JSON.parse(fs_1.default.readFileSync(p, "utf8"));
|
|
21
|
-
console.log(pkg.version || "");
|
|
22
|
-
}
|
|
23
|
-
catch {
|
|
24
|
-
console.log("");
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function safePkgName(name) {
|
|
28
|
-
return name
|
|
29
|
-
.toLowerCase()
|
|
30
|
-
.replace(/\s+/g, "-")
|
|
31
|
-
.replace(/[^a-z0-9-_.]/g, "-");
|
|
32
|
-
}
|
|
33
|
-
function listFilesRecursive(root) {
|
|
34
|
-
const out = [];
|
|
35
|
-
const stack = [root];
|
|
36
|
-
while (stack.length) {
|
|
37
|
-
const d = stack.pop();
|
|
38
|
-
const items = fs_1.default.readdirSync(d);
|
|
39
|
-
items.forEach((name) => {
|
|
40
|
-
const p = path_1.default.join(d, name);
|
|
41
|
-
const stat = fs_1.default.statSync(p);
|
|
42
|
-
if (stat.isDirectory())
|
|
43
|
-
stack.push(p);
|
|
44
|
-
else
|
|
45
|
-
out.push(p);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
return out;
|
|
49
|
-
}
|
|
50
|
-
function ensureDir(dir) {
|
|
51
|
-
if (!fs_1.default.existsSync(dir))
|
|
52
|
-
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
53
|
-
}
|
|
54
|
-
function isDirEmpty(dir) {
|
|
55
|
-
return !fs_1.default.existsSync(dir) || fs_1.default.readdirSync(dir).length === 0;
|
|
56
|
-
}
|
|
8
|
+
const prompts_1 = require("./prompts");
|
|
9
|
+
const copy_1 = require("./copy");
|
|
57
10
|
async function initCmd() {
|
|
58
|
-
const projectName = await askProjectPath();
|
|
11
|
+
const projectName = await (0, prompts_1.askProjectPath)();
|
|
59
12
|
const targetDir = path_1.default.resolve(process.cwd(), projectName);
|
|
60
|
-
if (!isDirEmpty(targetDir)) {
|
|
61
|
-
|
|
62
|
-
type: "confirm",
|
|
63
|
-
name: "ok",
|
|
64
|
-
message: "目标目录非空,是否覆盖?",
|
|
65
|
-
initial: false,
|
|
66
|
-
});
|
|
67
|
-
if (!ok) {
|
|
68
|
-
console.error("已取消");
|
|
69
|
-
process.exit(1);
|
|
70
|
-
}
|
|
13
|
+
if (!(0, copy_1.isDirEmpty)(targetDir)) {
|
|
14
|
+
await (0, prompts_1.askOverwrite)();
|
|
71
15
|
}
|
|
72
|
-
ensureDir(targetDir);
|
|
16
|
+
(0, copy_1.ensureDir)(targetDir);
|
|
73
17
|
return initRush(targetDir, projectName);
|
|
74
18
|
}
|
|
75
|
-
async function askRushQuestions() {
|
|
76
|
-
const { name: frontendName } = await (0, enquirer_1.prompt)({
|
|
77
|
-
type: "input",
|
|
78
|
-
name: "name",
|
|
79
|
-
message: "请输入前端项目名称,为空表示不创建前端项目",
|
|
80
|
-
initial: "",
|
|
81
|
-
});
|
|
82
|
-
const { name: backendName } = await (0, enquirer_1.prompt)({
|
|
83
|
-
type: "input",
|
|
84
|
-
name: "name",
|
|
85
|
-
message: "请输入后端项目名称,为空表示不创建后端项目",
|
|
86
|
-
initial: "",
|
|
87
|
-
});
|
|
88
|
-
return { frontendName, backendName };
|
|
89
|
-
}
|
|
90
|
-
function copyRushSkeleton(targetDir) {
|
|
91
|
-
const srcRoot = path_1.default.join(__dirname, "..", "templates");
|
|
92
|
-
const exclude = new Set(["vanilla-js", "app-templates"]);
|
|
93
|
-
const entries = fs_1.default.readdirSync(srcRoot);
|
|
94
|
-
entries.forEach((name) => {
|
|
95
|
-
if (exclude.has(name))
|
|
96
|
-
return;
|
|
97
|
-
const srcPath = path_1.default.join(srcRoot, name);
|
|
98
|
-
const destPath = path_1.default.join(targetDir, name);
|
|
99
|
-
const stat = fs_1.default.statSync(srcPath);
|
|
100
|
-
if (stat.isDirectory()) {
|
|
101
|
-
copyDir(srcPath, destPath);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
ensureDir(path_1.default.dirname(destPath));
|
|
105
|
-
fs_1.default.copyFileSync(srcPath, destPath);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
function copyDir(src, dest) {
|
|
110
|
-
ensureDir(dest);
|
|
111
|
-
for (const entry of fs_1.default.readdirSync(src)) {
|
|
112
|
-
const s = path_1.default.join(src, entry);
|
|
113
|
-
let outEntry = entry;
|
|
114
|
-
if (entry === "gitignore")
|
|
115
|
-
outEntry = ".gitignore";
|
|
116
|
-
else if (entry === ".gitignore.tmpl")
|
|
117
|
-
outEntry = ".gitignore";
|
|
118
|
-
else if (entry.endsWith(".tmpl"))
|
|
119
|
-
outEntry = entry.slice(0, -5);
|
|
120
|
-
const d = path_1.default.join(dest, outEntry);
|
|
121
|
-
const stat = fs_1.default.statSync(s);
|
|
122
|
-
if (stat.isDirectory())
|
|
123
|
-
copyDir(s, d);
|
|
124
|
-
else {
|
|
125
|
-
ensureDir(path_1.default.dirname(d));
|
|
126
|
-
fs_1.default.copyFileSync(s, d);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
function readJsonWithComments(str) {
|
|
131
|
-
const noBlock = str.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
132
|
-
const noLine = noBlock.replace(/(^|\s)\/\/.*$/gm, "");
|
|
133
|
-
const noTrailingComma = noLine.replace(/,\s*([}\]])/g, "$1");
|
|
134
|
-
return JSON.parse(noTrailingComma);
|
|
135
|
-
}
|
|
136
19
|
async function initRush(targetDir, projectName) {
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
const { frontendName, backendName } = await askRushQuestions();
|
|
141
|
-
const projects = rushCfg.projects || [];
|
|
20
|
+
(0, copy_1.copyRushTemplate)(targetDir);
|
|
21
|
+
const { frontendName, backendName } = await (0, prompts_1.askRushQuestions)();
|
|
22
|
+
(0, copy_1.updateRushJsonProjects)(path_1.default.join(targetDir, "rush.json"), frontendName, backendName);
|
|
142
23
|
if (frontendName) {
|
|
143
|
-
|
|
144
|
-
scaffoldApp(targetDir, "frontend", frontendName, pkg);
|
|
145
|
-
projects.push({
|
|
146
|
-
packageName: pkg,
|
|
147
|
-
projectFolder: `apps/${frontendName}`,
|
|
148
|
-
reviewCategory: "production",
|
|
149
|
-
});
|
|
24
|
+
(0, copy_1.copyFrontendTemplate)(targetDir, frontendName);
|
|
150
25
|
}
|
|
151
26
|
if (backendName) {
|
|
152
|
-
|
|
153
|
-
scaffoldApp(targetDir, "backend", backendName, pkg);
|
|
154
|
-
projects.push({
|
|
155
|
-
packageName: pkg,
|
|
156
|
-
projectFolder: `servers/${backendName}`,
|
|
157
|
-
reviewCategory: "production",
|
|
158
|
-
});
|
|
27
|
+
(0, copy_1.copyBackendTemplate)(targetDir, backendName);
|
|
159
28
|
}
|
|
160
|
-
rushCfg.projects = projects;
|
|
161
|
-
fs_1.default.writeFileSync(cfgPath, JSON.stringify(rushCfg, null, 2));
|
|
162
|
-
if (fs_1.default.existsSync(path_1.default.join(targetDir, "common"))) {
|
|
163
|
-
console.log("Skipping rush update in CLI; install manually if needed.");
|
|
164
|
-
}
|
|
165
|
-
console.log(`Rush repo created at ${targetDir}`);
|
|
166
|
-
console.log("Next:");
|
|
167
29
|
if (projectName !== ".")
|
|
168
30
|
console.log(` cd ${projectName}`);
|
|
169
|
-
console.log("
|
|
170
|
-
}
|
|
171
|
-
async function askProjectPath() {
|
|
172
|
-
const ans = await (0, enquirer_1.prompt)({
|
|
173
|
-
type: "input",
|
|
174
|
-
name: "path",
|
|
175
|
-
message: "请填写项目名称或路径,如果填.表示直接把项目放到当前目录下",
|
|
176
|
-
initial: ".",
|
|
177
|
-
});
|
|
178
|
-
const p = (ans.path || ".").trim();
|
|
179
|
-
return p || ".";
|
|
180
|
-
}
|
|
181
|
-
function composePkgName(name) {
|
|
182
|
-
const n = safePkgName(name);
|
|
183
|
-
return `${n}`;
|
|
184
|
-
}
|
|
185
|
-
function scaffoldApp(repoDir, kind, appName, pkgName) {
|
|
186
|
-
const tplBase = path_1.default.join(__dirname, "..", "templates", "app-templates");
|
|
187
|
-
const dir = kind === "frontend"
|
|
188
|
-
? "frontend-template"
|
|
189
|
-
: kind === "backend"
|
|
190
|
-
? "backend-tempalte"
|
|
191
|
-
: undefined;
|
|
192
|
-
if (!dir)
|
|
193
|
-
throw new Error(`Unknown kind: ${kind}`);
|
|
194
|
-
const srcDir = path_1.default.join(tplBase, dir);
|
|
195
|
-
const destBase = kind === "frontend" ? "apps" : "servers";
|
|
196
|
-
const destDir = path_1.default.join(repoDir, destBase, appName);
|
|
197
|
-
copyTemplateDir(srcDir, destDir, { APP_NAME: appName, PKG_NAME: pkgName });
|
|
198
|
-
}
|
|
199
|
-
function copyTemplateDir(srcDir, destDir, vars) {
|
|
200
|
-
const files = listFilesRecursive(srcDir);
|
|
201
|
-
files.forEach((src) => {
|
|
202
|
-
const rel = path_1.default.relative(srcDir, src);
|
|
203
|
-
const isTmpl = rel.endsWith(".tmpl");
|
|
204
|
-
let outRel = isTmpl ? rel.slice(0, -5) : rel;
|
|
205
|
-
console.log(rel);
|
|
206
|
-
const dest = path_1.default.join(destDir, outRel);
|
|
207
|
-
ensureDir(path_1.default.dirname(dest));
|
|
208
|
-
const buf = fs_1.default.readFileSync(src, "utf8");
|
|
209
|
-
const content = isTmpl ? renderVars(buf, vars) : buf;
|
|
210
|
-
fs_1.default.writeFileSync(dest, content);
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
function renderVars(str, vars) {
|
|
214
|
-
let out = str;
|
|
215
|
-
for (const [k, v] of Object.entries(vars)) {
|
|
216
|
-
const re = new RegExp(`__${k}__`, "g");
|
|
217
|
-
out = out.replace(re, v);
|
|
218
|
-
}
|
|
219
|
-
return out;
|
|
31
|
+
console.log("请手动执行 rush update 安装依赖");
|
|
220
32
|
}
|
|
221
33
|
async function main() {
|
|
222
34
|
const args = process.argv.slice(2);
|
|
223
35
|
if (args.includes("--version") || args.includes("-V")) {
|
|
224
|
-
printVersion();
|
|
36
|
+
(0, prompts_1.printVersion)();
|
|
225
37
|
return;
|
|
226
38
|
}
|
|
227
39
|
const cmd = args[0];
|
|
228
40
|
if (cmd === "init")
|
|
229
41
|
return initCmd();
|
|
230
|
-
printHelp();
|
|
42
|
+
(0, prompts_1.printHelp)();
|
|
231
43
|
}
|
|
232
44
|
main();
|
package/bin/copy.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.copyRushTemplate = copyRushTemplate;
|
|
7
|
+
exports.updateRushJsonProjects = updateRushJsonProjects;
|
|
8
|
+
exports.copyFrontendTemplate = copyFrontendTemplate;
|
|
9
|
+
exports.copyBackendTemplate = copyBackendTemplate;
|
|
10
|
+
exports.ensureDir = ensureDir;
|
|
11
|
+
exports.isDirEmpty = isDirEmpty;
|
|
12
|
+
const fs_1 = require("fs");
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const utils_1 = require("./utils");
|
|
15
|
+
function copyRushTemplate(targetDir) {
|
|
16
|
+
const source = getTemplateDir("rush");
|
|
17
|
+
copyDir(source, targetDir, {});
|
|
18
|
+
}
|
|
19
|
+
function updateRushJsonProjects(filepath, feAppName, beAppName) {
|
|
20
|
+
const projects = [];
|
|
21
|
+
if (feAppName) {
|
|
22
|
+
projects.push({
|
|
23
|
+
packageName: (0, utils_1.composePkgName)(feAppName),
|
|
24
|
+
projectFolder: `apps/${feAppName}`,
|
|
25
|
+
reviewCategory: "production",
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (beAppName) {
|
|
29
|
+
const pkg = (0, utils_1.composePkgName)(beAppName);
|
|
30
|
+
projects.push({
|
|
31
|
+
packageName: pkg,
|
|
32
|
+
projectFolder: `servers/${beAppName}`,
|
|
33
|
+
reviewCategory: "production",
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const content = (0, fs_1.readFileSync)(filepath, "utf8");
|
|
37
|
+
const json = (0, utils_1.readJsonWithComments)(content);
|
|
38
|
+
json.projects = projects;
|
|
39
|
+
(0, fs_1.writeFileSync)(filepath, JSON.stringify(json, null, 2), { encoding: "utf-8" });
|
|
40
|
+
}
|
|
41
|
+
function copyFrontendTemplate(targetDir, appName) {
|
|
42
|
+
appName = (0, utils_1.composePkgName)(appName);
|
|
43
|
+
targetDir = path_1.default.join(targetDir, `apps/${appName}`);
|
|
44
|
+
const source = getTemplateDir("frontend");
|
|
45
|
+
copyDir(source, targetDir, {
|
|
46
|
+
PKG_NAME: appName,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function copyBackendTemplate(targetDir, appName) {
|
|
50
|
+
appName = (0, utils_1.composePkgName)(appName);
|
|
51
|
+
targetDir = path_1.default.join(targetDir, `servers/${appName}`);
|
|
52
|
+
const source = getTemplateDir("backend");
|
|
53
|
+
copyDir(source, targetDir, {
|
|
54
|
+
PKG_NAME: appName,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function getTemplateDir(type) {
|
|
58
|
+
return path_1.default.join(__dirname, "..", "templates", `${type}-template`);
|
|
59
|
+
}
|
|
60
|
+
function copyDir(source, destination, vars) {
|
|
61
|
+
ensureDir(destination);
|
|
62
|
+
const files = (0, fs_1.readdirSync)(source);
|
|
63
|
+
files.forEach((file) => {
|
|
64
|
+
const s = path_1.default.join(source, file);
|
|
65
|
+
const d = path_1.default.join(destination, file);
|
|
66
|
+
const stat = (0, fs_1.statSync)(s);
|
|
67
|
+
if (stat.isDirectory()) {
|
|
68
|
+
copyDir(s, d, vars);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
ensureDir(path_1.default.dirname(d));
|
|
72
|
+
const isTmpl = file.endsWith(".tmpl");
|
|
73
|
+
// 正常文件直接复制
|
|
74
|
+
if (!isTmpl) {
|
|
75
|
+
(0, fs_1.copyFileSync)(s, d);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// 模板文件替换变量后复制
|
|
79
|
+
const template = (0, fs_1.readFileSync)(s, "utf8");
|
|
80
|
+
const content = compileTemplateContent(template, vars);
|
|
81
|
+
(0, fs_1.writeFileSync)(d.slice(0, -5), content, { encoding: "utf-8" });
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function ensureDir(dir) {
|
|
86
|
+
if (!(0, fs_1.existsSync)(dir))
|
|
87
|
+
(0, fs_1.mkdirSync)(dir, { recursive: true });
|
|
88
|
+
}
|
|
89
|
+
function compileTemplateContent(str, vars) {
|
|
90
|
+
let out = str;
|
|
91
|
+
for (const [k, v] of Object.entries(vars)) {
|
|
92
|
+
const re = new RegExp(`__${k}__`, "g");
|
|
93
|
+
out = out.replace(re, v);
|
|
94
|
+
}
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
function isDirEmpty(dir) {
|
|
98
|
+
return !(0, fs_1.existsSync)(dir) || (0, fs_1.readdirSync)(dir).length === 0;
|
|
99
|
+
}
|
package/bin/prompts.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.askRushQuestions = askRushQuestions;
|
|
7
|
+
exports.askProjectPath = askProjectPath;
|
|
8
|
+
exports.askOverwrite = askOverwrite;
|
|
9
|
+
exports.printHelp = printHelp;
|
|
10
|
+
exports.printVersion = printVersion;
|
|
11
|
+
const enquirer_1 = require("enquirer");
|
|
12
|
+
const fs_1 = require("fs");
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
async function askRushQuestions() {
|
|
15
|
+
const { name: frontendName } = await (0, enquirer_1.prompt)({
|
|
16
|
+
type: "input",
|
|
17
|
+
name: "name",
|
|
18
|
+
message: "请输入前端项目名称,为空表示不创建前端项目",
|
|
19
|
+
initial: "",
|
|
20
|
+
});
|
|
21
|
+
const { name: backendName } = await (0, enquirer_1.prompt)({
|
|
22
|
+
type: "input",
|
|
23
|
+
name: "name",
|
|
24
|
+
message: "请输入后端项目名称,为空表示不创建后端项目",
|
|
25
|
+
initial: "",
|
|
26
|
+
});
|
|
27
|
+
return { frontendName, backendName };
|
|
28
|
+
}
|
|
29
|
+
async function askProjectPath() {
|
|
30
|
+
const ans = await (0, enquirer_1.prompt)({
|
|
31
|
+
type: "input",
|
|
32
|
+
name: "path",
|
|
33
|
+
message: "请填写项目名称或路径,如果填.表示直接把项目放到当前目录下",
|
|
34
|
+
initial: ".",
|
|
35
|
+
});
|
|
36
|
+
const p = (ans.path || ".").trim();
|
|
37
|
+
return p || ".";
|
|
38
|
+
}
|
|
39
|
+
async function askOverwrite() {
|
|
40
|
+
const { ok } = await (0, enquirer_1.prompt)({
|
|
41
|
+
type: "confirm",
|
|
42
|
+
name: "ok",
|
|
43
|
+
message: "目标目录非空,是否覆盖?",
|
|
44
|
+
initial: false,
|
|
45
|
+
});
|
|
46
|
+
if (!ok) {
|
|
47
|
+
console.error("已取消");
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function printHelp() {
|
|
52
|
+
const h = [
|
|
53
|
+
"用法: listpage_cli init",
|
|
54
|
+
"说明: 进入中文引导式交互,按提示填写即可",
|
|
55
|
+
].join("\n");
|
|
56
|
+
console.log(h);
|
|
57
|
+
}
|
|
58
|
+
function printVersion() {
|
|
59
|
+
try {
|
|
60
|
+
const p = path_1.default.join(__dirname, "..", "package.json");
|
|
61
|
+
const pkg = JSON.parse((0, fs_1.readFileSync)(p, "utf8"));
|
|
62
|
+
console.log(pkg.version || "");
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
console.log("");
|
|
66
|
+
}
|
|
67
|
+
}
|
package/bin/utils.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readJsonWithComments = readJsonWithComments;
|
|
4
|
+
exports.composePkgName = composePkgName;
|
|
5
|
+
function readJsonWithComments(str) {
|
|
6
|
+
const noBlock = str.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
7
|
+
const noLine = noBlock.replace(/(^|\s)\/\/.*$/gm, "");
|
|
8
|
+
const noTrailingComma = noLine.replace(/,\s*([}\]])/g, "$1");
|
|
9
|
+
return JSON.parse(noTrailingComma);
|
|
10
|
+
}
|
|
11
|
+
function composePkgName(name) {
|
|
12
|
+
const n = safePkgName(name);
|
|
13
|
+
return n;
|
|
14
|
+
}
|
|
15
|
+
function safePkgName(name) {
|
|
16
|
+
return name
|
|
17
|
+
.toLowerCase()
|
|
18
|
+
.replace(/\s+/g, "-")
|
|
19
|
+
.replace(/[^a-z0-9-_.]/g, "-");
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { NestFactory } from '@nestjs/core';
|
|
2
|
+
import { ValidationPipe } from '@nestjs/common';
|
|
3
|
+
import { ResponseInterceptor } from 'listpage-next-nest';
|
|
4
|
+
|
|
5
|
+
import { AppModule } from './modules/app.module';
|
|
6
|
+
|
|
7
|
+
async function bootstrap() {
|
|
8
|
+
const app = await NestFactory.create(AppModule);
|
|
9
|
+
app.useGlobalInterceptors(new ResponseInterceptor());
|
|
10
|
+
app.setGlobalPrefix('api/v1');
|
|
11
|
+
// 启用全局验证管道
|
|
12
|
+
app.useGlobalPipes(
|
|
13
|
+
new ValidationPipe({
|
|
14
|
+
whitelist: true,
|
|
15
|
+
transform: true,
|
|
16
|
+
}),
|
|
17
|
+
);
|
|
18
|
+
// 启用CORS
|
|
19
|
+
app.enableCors();
|
|
20
|
+
await app.listen(3000);
|
|
21
|
+
}
|
|
22
|
+
bootstrap();
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Controller, Get } from '@nestjs/common';
|
|
2
|
-
import { AppService } from './app.service';
|
|
3
|
-
|
|
4
|
-
@Controller()
|
|
5
|
-
export class AppController {
|
|
6
|
-
constructor(private readonly appService: AppService) {}
|
|
7
|
-
|
|
8
|
-
@Get()
|
|
9
|
-
getHello(): string {
|
|
10
|
-
return this.appService.getHello();
|
|
11
|
-
}
|
|
12
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/templates/{app-templates/frontend-template → frontend-template}/src/router/index.tsx
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|