@gadmin2n/cli 0.0.122 → 0.0.124
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/actions/new.action.js +22 -13
- package/package.json +2 -2
package/actions/new.action.js
CHANGED
|
@@ -36,13 +36,23 @@ class NewAction extends abstract_action_1.AbstractAction {
|
|
|
36
36
|
const isDryRunEnabled = dryRunOption && dryRunOption.value;
|
|
37
37
|
yield askForMissingInformation(inputs, options);
|
|
38
38
|
console.info();
|
|
39
|
+
// 在调用 schematics 之前先解析项目目录
|
|
40
|
+
const projectDirectory = getProjectDirectory(getApplicationNameInput(inputs), directoryOption);
|
|
41
|
+
// 统一解析为绝对路径,确保 --directory /absolute/path 可以正常工作
|
|
42
|
+
const projectAbsDir = (0, path_1.isAbsolute)(projectDirectory)
|
|
43
|
+
? projectDirectory
|
|
44
|
+
: (0, path_1.join)(process.cwd(), projectDirectory);
|
|
45
|
+
// Angular DevKit schematics 引擎始终把 --directory 当作相对于 cwd 的路径处理。
|
|
46
|
+
// 若用户传入绝对路径,需转换为相对路径再传给引擎,否则会被重复拼接 cwd。
|
|
47
|
+
if ((directoryOption === null || directoryOption === void 0 ? void 0 : directoryOption.value) && (0, path_1.isAbsolute)(directoryOption.value)) {
|
|
48
|
+
directoryOption.value = (0, path_1.relative)(process.cwd(), directoryOption.value);
|
|
49
|
+
}
|
|
39
50
|
yield generateApplicationFiles(inputs, options).catch(exports.exit);
|
|
40
51
|
const shouldSkipInstall = options.some((option) => option.name === 'skip-install' && option.value === true);
|
|
41
52
|
const shouldSkipGit = options.some((option) => option.name === 'skip-git' && option.value === true);
|
|
42
|
-
const projectDirectory = getProjectDirectory(getApplicationNameInput(inputs), directoryOption);
|
|
43
53
|
// 落盘用户提供的环境配置(dry-run 模式跳过,因为目录可能未实际生成)
|
|
44
54
|
if (!isDryRunEnabled) {
|
|
45
|
-
yield applyEnvConfig(
|
|
55
|
+
yield applyEnvConfig(projectAbsDir, options).catch((err) => {
|
|
46
56
|
console.error(chalk.yellow(`[warn] Failed to apply env config: ${err && err.message ? err.message : err}`));
|
|
47
57
|
});
|
|
48
58
|
// Pin the 3-way merge base at project init time. Recording the exact
|
|
@@ -51,7 +61,6 @@ class NewAction extends abstract_action_1.AbstractAction {
|
|
|
51
61
|
// bootstrap-then-rerun dance. Failure is non-fatal: if meta can't be
|
|
52
62
|
// written here, `gadmin2 update` still has its bootstrap fallback.
|
|
53
63
|
try {
|
|
54
|
-
const projectAbsDir = (0, path_1.join)(process.cwd(), projectDirectory);
|
|
55
64
|
const schematicsVersion = (0, schematics_root_1.getSchematicsVersion)();
|
|
56
65
|
(0, base_store_1.writeMeta)(projectAbsDir, {
|
|
57
66
|
schematicsVersion,
|
|
@@ -66,7 +75,7 @@ class NewAction extends abstract_action_1.AbstractAction {
|
|
|
66
75
|
// generated files, so executable scripts (compose-ctl.sh, etc.) come
|
|
67
76
|
// out as 0644. Re-apply +x for known entry points.
|
|
68
77
|
try {
|
|
69
|
-
(0, executable_paths_1.ensureExecutableBits)(
|
|
78
|
+
(0, executable_paths_1.ensureExecutableBits)(projectAbsDir);
|
|
70
79
|
}
|
|
71
80
|
catch (_a) {
|
|
72
81
|
// best-effort, never fatal
|
|
@@ -74,15 +83,15 @@ class NewAction extends abstract_action_1.AbstractAction {
|
|
|
74
83
|
}
|
|
75
84
|
if (!shouldSkipInstall) {
|
|
76
85
|
console.info('Begin to install server dependence ...');
|
|
77
|
-
yield installPackages(options, isDryRunEnabled, (0, path_1.join)(
|
|
86
|
+
yield installPackages(options, isDryRunEnabled, (0, path_1.join)(projectAbsDir, 'server'));
|
|
78
87
|
console.info();
|
|
79
88
|
console.info('Begin to install web dependence ...');
|
|
80
|
-
yield installPackages(options, isDryRunEnabled, (0, path_1.join)(
|
|
89
|
+
yield installPackages(options, isDryRunEnabled, (0, path_1.join)(projectAbsDir, 'web'));
|
|
81
90
|
console.info();
|
|
82
91
|
}
|
|
83
92
|
if (!isDryRunEnabled) {
|
|
84
93
|
if (!shouldSkipGit) {
|
|
85
|
-
yield initializeGitRepository(
|
|
94
|
+
yield initializeGitRepository(projectAbsDir);
|
|
86
95
|
}
|
|
87
96
|
const inputPackageManager = (options.find((option) => option.name === 'package-manager')
|
|
88
97
|
.value || 'yarn').toLowerCase();
|
|
@@ -276,17 +285,17 @@ const applyEnvConfig = (projectDirectory, options) => __awaiter(void 0, void 0,
|
|
|
276
285
|
const writeFile = (0, util_1.promisify)(fs.writeFile);
|
|
277
286
|
const readFile = (0, util_1.promisify)(fs.readFile);
|
|
278
287
|
// (1) web/.env.local
|
|
279
|
-
const webEnvLocal = (0, path_1.join)(
|
|
288
|
+
const webEnvLocal = (0, path_1.join)(projectDirectory, 'web', '.env.local');
|
|
280
289
|
const webContent = [
|
|
281
290
|
'# Local overrides for web/.env (do not commit)',
|
|
282
291
|
'# knot Agent ID — see https://knot.woa.com',
|
|
283
292
|
viteAgentId ? `VITE_AGENT_ID=${viteAgentId}` : '# VITE_AGENT_ID=',
|
|
284
293
|
].join('\n') + '\n';
|
|
285
|
-
if (fs.existsSync((0, path_1.join)(
|
|
294
|
+
if (fs.existsSync((0, path_1.join)(projectDirectory, 'web'))) {
|
|
286
295
|
yield writeFile(webEnvLocal, webContent);
|
|
287
296
|
}
|
|
288
297
|
// (2) server/.env.local — DATABASE_URL / TAIHU_APP_TOKEN / TAIHU_ODC_APP_TOKEN
|
|
289
|
-
const serverEnvLocal = (0, path_1.join)(
|
|
298
|
+
const serverEnvLocal = (0, path_1.join)(projectDirectory, 'server', '.env.local');
|
|
290
299
|
const serverContent = [
|
|
291
300
|
'# Local overrides for server/.env (do not commit)',
|
|
292
301
|
'# PostgreSQL: postgresql://user:password@ip:port/db_name?schema=public',
|
|
@@ -300,7 +309,7 @@ const applyEnvConfig = (projectDirectory, options) => __awaiter(void 0, void 0,
|
|
|
300
309
|
? `TAIHU_ODC_APP_TOKEN=${taihuOdcToken}`
|
|
301
310
|
: '# TAIHU_ODC_APP_TOKEN=',
|
|
302
311
|
].join('\n') + '\n';
|
|
303
|
-
if (fs.existsSync((0, path_1.join)(
|
|
312
|
+
if (fs.existsSync((0, path_1.join)(projectDirectory, 'server'))) {
|
|
304
313
|
yield writeFile(serverEnvLocal, serverContent);
|
|
305
314
|
}
|
|
306
315
|
// (3) dev/postgres/init.sql — 同步替换 CREATE DATABASE 行的 db 名
|
|
@@ -309,7 +318,7 @@ const applyEnvConfig = (projectDirectory, options) => __awaiter(void 0, void 0,
|
|
|
309
318
|
if (databaseUrl) {
|
|
310
319
|
const parsedDbName = parseDbNameFromUrl(databaseUrl);
|
|
311
320
|
if (parsedDbName && parsedDbName !== 'gadmin_demo') {
|
|
312
|
-
const initSql = (0, path_1.join)(
|
|
321
|
+
const initSql = (0, path_1.join)(projectDirectory, 'dev', 'postgres', 'init.sql');
|
|
313
322
|
if (fs.existsSync(initSql)) {
|
|
314
323
|
const original = yield readFile(initSql, 'utf8');
|
|
315
324
|
const replaced = original.replace(/^CREATE DATABASE gadmin_demo;$/m, `CREATE DATABASE ${parsedDbName};`);
|
|
@@ -363,7 +372,7 @@ const askForPackageManager = () => __awaiter(void 0, void 0, void 0, function* (
|
|
|
363
372
|
});
|
|
364
373
|
const initializeGitRepository = (dir) => __awaiter(void 0, void 0, void 0, function* () {
|
|
365
374
|
const runner = new git_runner_1.GitRunner();
|
|
366
|
-
yield runner.run('init', true,
|
|
375
|
+
yield runner.run('init', true, dir).catch(() => {
|
|
367
376
|
console.error(chalk.red(ui_1.MESSAGES.GIT_INITIALIZATION_ERROR));
|
|
368
377
|
});
|
|
369
378
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gadmin2n/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.124",
|
|
4
4
|
"description": "Gadmin - modern, fast, powerful node.js web framework (@cli)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@angular-devkit/core": "13.3.2",
|
|
48
48
|
"@angular-devkit/schematics": "13.3.2",
|
|
49
49
|
"@angular-devkit/schematics-cli": "13.3.2",
|
|
50
|
-
"@gadmin2n/schematics": "^0.0.
|
|
50
|
+
"@gadmin2n/schematics": "^0.0.97",
|
|
51
51
|
"abc": "^0.6.1",
|
|
52
52
|
"chalk": "3.0.0",
|
|
53
53
|
"chokidar": "3.5.3",
|