@gadmin2n/cli 0.0.121 → 0.0.123
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 +15 -12
- package/package.json +2 -2
package/actions/new.action.js
CHANGED
|
@@ -40,9 +40,13 @@ class NewAction extends abstract_action_1.AbstractAction {
|
|
|
40
40
|
const shouldSkipInstall = options.some((option) => option.name === 'skip-install' && option.value === true);
|
|
41
41
|
const shouldSkipGit = options.some((option) => option.name === 'skip-git' && option.value === true);
|
|
42
42
|
const projectDirectory = getProjectDirectory(getApplicationNameInput(inputs), directoryOption);
|
|
43
|
+
// 统一解析为绝对路径,确保 --directory /absolute/path 可以正常工作
|
|
44
|
+
const projectAbsDir = (0, path_1.isAbsolute)(projectDirectory)
|
|
45
|
+
? projectDirectory
|
|
46
|
+
: (0, path_1.join)(process.cwd(), projectDirectory);
|
|
43
47
|
// 落盘用户提供的环境配置(dry-run 模式跳过,因为目录可能未实际生成)
|
|
44
48
|
if (!isDryRunEnabled) {
|
|
45
|
-
yield applyEnvConfig(
|
|
49
|
+
yield applyEnvConfig(projectAbsDir, options).catch((err) => {
|
|
46
50
|
console.error(chalk.yellow(`[warn] Failed to apply env config: ${err && err.message ? err.message : err}`));
|
|
47
51
|
});
|
|
48
52
|
// Pin the 3-way merge base at project init time. Recording the exact
|
|
@@ -51,7 +55,6 @@ class NewAction extends abstract_action_1.AbstractAction {
|
|
|
51
55
|
// bootstrap-then-rerun dance. Failure is non-fatal: if meta can't be
|
|
52
56
|
// written here, `gadmin2 update` still has its bootstrap fallback.
|
|
53
57
|
try {
|
|
54
|
-
const projectAbsDir = (0, path_1.join)(process.cwd(), projectDirectory);
|
|
55
58
|
const schematicsVersion = (0, schematics_root_1.getSchematicsVersion)();
|
|
56
59
|
(0, base_store_1.writeMeta)(projectAbsDir, {
|
|
57
60
|
schematicsVersion,
|
|
@@ -66,7 +69,7 @@ class NewAction extends abstract_action_1.AbstractAction {
|
|
|
66
69
|
// generated files, so executable scripts (compose-ctl.sh, etc.) come
|
|
67
70
|
// out as 0644. Re-apply +x for known entry points.
|
|
68
71
|
try {
|
|
69
|
-
(0, executable_paths_1.ensureExecutableBits)(
|
|
72
|
+
(0, executable_paths_1.ensureExecutableBits)(projectAbsDir);
|
|
70
73
|
}
|
|
71
74
|
catch (_a) {
|
|
72
75
|
// best-effort, never fatal
|
|
@@ -74,15 +77,15 @@ class NewAction extends abstract_action_1.AbstractAction {
|
|
|
74
77
|
}
|
|
75
78
|
if (!shouldSkipInstall) {
|
|
76
79
|
console.info('Begin to install server dependence ...');
|
|
77
|
-
yield installPackages(options, isDryRunEnabled, (0, path_1.join)(
|
|
80
|
+
yield installPackages(options, isDryRunEnabled, (0, path_1.join)(projectAbsDir, 'server'));
|
|
78
81
|
console.info();
|
|
79
82
|
console.info('Begin to install web dependence ...');
|
|
80
|
-
yield installPackages(options, isDryRunEnabled, (0, path_1.join)(
|
|
83
|
+
yield installPackages(options, isDryRunEnabled, (0, path_1.join)(projectAbsDir, 'web'));
|
|
81
84
|
console.info();
|
|
82
85
|
}
|
|
83
86
|
if (!isDryRunEnabled) {
|
|
84
87
|
if (!shouldSkipGit) {
|
|
85
|
-
yield initializeGitRepository(
|
|
88
|
+
yield initializeGitRepository(projectAbsDir);
|
|
86
89
|
}
|
|
87
90
|
const inputPackageManager = (options.find((option) => option.name === 'package-manager')
|
|
88
91
|
.value || 'yarn').toLowerCase();
|
|
@@ -276,17 +279,17 @@ const applyEnvConfig = (projectDirectory, options) => __awaiter(void 0, void 0,
|
|
|
276
279
|
const writeFile = (0, util_1.promisify)(fs.writeFile);
|
|
277
280
|
const readFile = (0, util_1.promisify)(fs.readFile);
|
|
278
281
|
// (1) web/.env.local
|
|
279
|
-
const webEnvLocal = (0, path_1.join)(
|
|
282
|
+
const webEnvLocal = (0, path_1.join)(projectDirectory, 'web', '.env.local');
|
|
280
283
|
const webContent = [
|
|
281
284
|
'# Local overrides for web/.env (do not commit)',
|
|
282
285
|
'# knot Agent ID — see https://knot.woa.com',
|
|
283
286
|
viteAgentId ? `VITE_AGENT_ID=${viteAgentId}` : '# VITE_AGENT_ID=',
|
|
284
287
|
].join('\n') + '\n';
|
|
285
|
-
if (fs.existsSync((0, path_1.join)(
|
|
288
|
+
if (fs.existsSync((0, path_1.join)(projectDirectory, 'web'))) {
|
|
286
289
|
yield writeFile(webEnvLocal, webContent);
|
|
287
290
|
}
|
|
288
291
|
// (2) server/.env.local — DATABASE_URL / TAIHU_APP_TOKEN / TAIHU_ODC_APP_TOKEN
|
|
289
|
-
const serverEnvLocal = (0, path_1.join)(
|
|
292
|
+
const serverEnvLocal = (0, path_1.join)(projectDirectory, 'server', '.env.local');
|
|
290
293
|
const serverContent = [
|
|
291
294
|
'# Local overrides for server/.env (do not commit)',
|
|
292
295
|
'# PostgreSQL: postgresql://user:password@ip:port/db_name?schema=public',
|
|
@@ -300,7 +303,7 @@ const applyEnvConfig = (projectDirectory, options) => __awaiter(void 0, void 0,
|
|
|
300
303
|
? `TAIHU_ODC_APP_TOKEN=${taihuOdcToken}`
|
|
301
304
|
: '# TAIHU_ODC_APP_TOKEN=',
|
|
302
305
|
].join('\n') + '\n';
|
|
303
|
-
if (fs.existsSync((0, path_1.join)(
|
|
306
|
+
if (fs.existsSync((0, path_1.join)(projectDirectory, 'server'))) {
|
|
304
307
|
yield writeFile(serverEnvLocal, serverContent);
|
|
305
308
|
}
|
|
306
309
|
// (3) dev/postgres/init.sql — 同步替换 CREATE DATABASE 行的 db 名
|
|
@@ -309,7 +312,7 @@ const applyEnvConfig = (projectDirectory, options) => __awaiter(void 0, void 0,
|
|
|
309
312
|
if (databaseUrl) {
|
|
310
313
|
const parsedDbName = parseDbNameFromUrl(databaseUrl);
|
|
311
314
|
if (parsedDbName && parsedDbName !== 'gadmin_demo') {
|
|
312
|
-
const initSql = (0, path_1.join)(
|
|
315
|
+
const initSql = (0, path_1.join)(projectDirectory, 'dev', 'postgres', 'init.sql');
|
|
313
316
|
if (fs.existsSync(initSql)) {
|
|
314
317
|
const original = yield readFile(initSql, 'utf8');
|
|
315
318
|
const replaced = original.replace(/^CREATE DATABASE gadmin_demo;$/m, `CREATE DATABASE ${parsedDbName};`);
|
|
@@ -363,7 +366,7 @@ const askForPackageManager = () => __awaiter(void 0, void 0, void 0, function* (
|
|
|
363
366
|
});
|
|
364
367
|
const initializeGitRepository = (dir) => __awaiter(void 0, void 0, void 0, function* () {
|
|
365
368
|
const runner = new git_runner_1.GitRunner();
|
|
366
|
-
yield runner.run('init', true,
|
|
369
|
+
yield runner.run('init', true, dir).catch(() => {
|
|
367
370
|
console.error(chalk.red(ui_1.MESSAGES.GIT_INITIALIZATION_ERROR));
|
|
368
371
|
});
|
|
369
372
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gadmin2n/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.123",
|
|
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",
|