@gadmin2n/cli 0.0.118 → 0.0.120
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
CHANGED
|
@@ -17,7 +17,6 @@ const inquirer = require("inquirer");
|
|
|
17
17
|
const path_1 = require("path");
|
|
18
18
|
const util_1 = require("util");
|
|
19
19
|
const commands_1 = require("../commands");
|
|
20
|
-
const defaults_1 = require("../lib/configuration/defaults");
|
|
21
20
|
const package_managers_1 = require("../lib/package-managers");
|
|
22
21
|
const questions_1 = require("../lib/questions/questions");
|
|
23
22
|
const git_runner_1 = require("../lib/runners/git.runner");
|
|
@@ -84,13 +83,13 @@ class NewAction extends abstract_action_1.AbstractAction {
|
|
|
84
83
|
if (!isDryRunEnabled) {
|
|
85
84
|
if (!shouldSkipGit) {
|
|
86
85
|
yield initializeGitRepository(projectDirectory);
|
|
87
|
-
yield createGitIgnoreFile(projectDirectory);
|
|
88
86
|
}
|
|
89
87
|
const inputPackageManager = (options.find((option) => option.name === 'package-manager')
|
|
90
88
|
.value || 'yarn').toLowerCase();
|
|
91
89
|
// 收集仍未填写、需要在引导中提示用户处理的环境变量
|
|
92
90
|
const viteAgentId = getOptionByName(options, 'vite-agent-id') || '';
|
|
93
91
|
const taihuToken = getOptionByName(options, 'taihu-app-token') || '';
|
|
92
|
+
const taihuOdcToken = getOptionByName(options, 'taihu-odc-app-token') || '';
|
|
94
93
|
const databaseUrl = getOptionByName(options, 'database-url') || '';
|
|
95
94
|
const missingEnv = [];
|
|
96
95
|
if (!viteAgentId) {
|
|
@@ -103,8 +102,15 @@ class NewAction extends abstract_action_1.AbstractAction {
|
|
|
103
102
|
if (!taihuToken) {
|
|
104
103
|
missingEnv.push({
|
|
105
104
|
var: 'TAIHU_APP_TOKEN',
|
|
106
|
-
file: 'server/.env',
|
|
107
|
-
desc: '太湖应用
|
|
105
|
+
file: 'server/.env.local',
|
|
106
|
+
desc: '太湖应用 Token',
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
if (!taihuOdcToken) {
|
|
110
|
+
missingEnv.push({
|
|
111
|
+
var: 'TAIHU_ODC_APP_TOKEN',
|
|
112
|
+
file: 'server/.env.local',
|
|
113
|
+
desc: '太湖合作伙伴版应用 Token',
|
|
108
114
|
});
|
|
109
115
|
}
|
|
110
116
|
if (!databaseUrl) {
|
|
@@ -201,7 +207,8 @@ const askForMissingInformation = (inputs, options) => __awaiter(void 0, void 0,
|
|
|
201
207
|
replaceInputMissingInformation(options, { template: commands_1.Template.GameAngle });
|
|
202
208
|
// 收集环境配置(支持空字符串跳过)
|
|
203
209
|
yield promptIfMissing(options, 'vite-agent-id', 'VITE_AGENT_ID (knot Agent ID, leave blank to skip):');
|
|
204
|
-
yield promptIfMissing(options, 'taihu-app-token', 'TAIHU_APP_TOKEN (太湖应用
|
|
210
|
+
yield promptIfMissing(options, 'taihu-app-token', 'TAIHU_APP_TOKEN (太湖应用 Token, leave blank to skip):');
|
|
211
|
+
yield promptIfMissing(options, 'taihu-odc-app-token', 'TAIHU_ODC_APP_TOKEN (太湖合作伙伴版应用 Token, leave blank to skip):');
|
|
205
212
|
yield promptIfMissing(options, 'database-url', 'DATABASE_URL (postgresql://user:pwd@host:port/db?schema=public, leave blank to skip):');
|
|
206
213
|
});
|
|
207
214
|
/**
|
|
@@ -232,6 +239,7 @@ const mapSchematicOptions = (options) => {
|
|
|
232
239
|
option.value !== 'package-manager' &&
|
|
233
240
|
option.name !== 'vite-agent-id' &&
|
|
234
241
|
option.name !== 'taihu-app-token' &&
|
|
242
|
+
option.name !== 'taihu-odc-app-token' &&
|
|
235
243
|
option.name !== 'database-url') {
|
|
236
244
|
schematicOptions.push(new schematics_1.SchematicOption(option.name, option.value));
|
|
237
245
|
}
|
|
@@ -254,14 +262,16 @@ const parseDbNameFromUrl = (url) => {
|
|
|
254
262
|
};
|
|
255
263
|
/**
|
|
256
264
|
* 在项目生成完毕后,把用户提供的环境配置写入对应文件。
|
|
257
|
-
* - VITE_AGENT_ID
|
|
258
|
-
* - DATABASE_URL
|
|
259
|
-
* - TAIHU_APP_TOKEN→ server/.env
|
|
260
|
-
* -
|
|
265
|
+
* - VITE_AGENT_ID → web/.env.local (始终创建,含注释模板)
|
|
266
|
+
* - DATABASE_URL → server/.env.local (始终创建,含注释模板)
|
|
267
|
+
* - TAIHU_APP_TOKEN → server/.env.local (始终创建,含注释模板)
|
|
268
|
+
* - TAIHU_ODC_APP_TOKEN → server/.env.local (始终创建,含注释模板)
|
|
269
|
+
* - dev/postgres/init.sql (仅当用户提供 database-url 时才替换 CREATE DATABASE 行)
|
|
261
270
|
*/
|
|
262
271
|
const applyEnvConfig = (projectDirectory, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
263
272
|
const viteAgentId = getOptionByName(options, 'vite-agent-id') || '';
|
|
264
273
|
const taihuToken = getOptionByName(options, 'taihu-app-token') || '';
|
|
274
|
+
const taihuOdcToken = getOptionByName(options, 'taihu-odc-app-token') || '';
|
|
265
275
|
const databaseUrl = getOptionByName(options, 'database-url') || '';
|
|
266
276
|
const writeFile = (0, util_1.promisify)(fs.writeFile);
|
|
267
277
|
const readFile = (0, util_1.promisify)(fs.readFile);
|
|
@@ -275,26 +285,25 @@ const applyEnvConfig = (projectDirectory, options) => __awaiter(void 0, void 0,
|
|
|
275
285
|
if (fs.existsSync((0, path_1.join)(process.cwd(), projectDirectory, 'web'))) {
|
|
276
286
|
yield writeFile(webEnvLocal, webContent);
|
|
277
287
|
}
|
|
278
|
-
// (2) server/.env.local
|
|
288
|
+
// (2) server/.env.local — DATABASE_URL / TAIHU_APP_TOKEN / TAIHU_ODC_APP_TOKEN
|
|
279
289
|
const serverEnvLocal = (0, path_1.join)(process.cwd(), projectDirectory, 'server', '.env.local');
|
|
280
290
|
const serverContent = [
|
|
281
291
|
'# Local overrides for server/.env (do not commit)',
|
|
282
292
|
'# PostgreSQL: postgresql://user:password@ip:port/db_name?schema=public',
|
|
283
293
|
databaseUrl ? `DATABASE_URL=${databaseUrl}` : '# DATABASE_URL=',
|
|
294
|
+
'',
|
|
295
|
+
'# 太湖应用 Token',
|
|
296
|
+
taihuToken ? `TAIHU_APP_TOKEN=${taihuToken}` : '# TAIHU_APP_TOKEN=',
|
|
297
|
+
'',
|
|
298
|
+
'# 太湖合作伙伴版应用 Token',
|
|
299
|
+
taihuOdcToken
|
|
300
|
+
? `TAIHU_ODC_APP_TOKEN=${taihuOdcToken}`
|
|
301
|
+
: '# TAIHU_ODC_APP_TOKEN=',
|
|
284
302
|
].join('\n') + '\n';
|
|
285
303
|
if (fs.existsSync((0, path_1.join)(process.cwd(), projectDirectory, 'server'))) {
|
|
286
304
|
yield writeFile(serverEnvLocal, serverContent);
|
|
287
305
|
}
|
|
288
|
-
// (3)
|
|
289
|
-
if (taihuToken) {
|
|
290
|
-
const serverEnv = (0, path_1.join)(process.cwd(), projectDirectory, 'server', '.env');
|
|
291
|
-
if (fs.existsSync(serverEnv)) {
|
|
292
|
-
const original = yield readFile(serverEnv, 'utf8');
|
|
293
|
-
const replaced = original.replace(/^TAIHU_APP_TOKEN=.*$/m, `TAIHU_APP_TOKEN=${taihuToken}`);
|
|
294
|
-
yield writeFile(serverEnv, replaced);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
// (4) dev/postgres/init.sql — 同步替换 CREATE DATABASE 行的 db 名
|
|
306
|
+
// (3) dev/postgres/init.sql — 同步替换 CREATE DATABASE 行的 db 名
|
|
298
307
|
// 仅当用户提供 database-url 且能解析出 db 名时才替换;若跳过则保持模板原样,
|
|
299
308
|
// 由最终引导提示用户自行修改。
|
|
300
309
|
if (databaseUrl) {
|
|
@@ -358,21 +367,6 @@ const initializeGitRepository = (dir) => __awaiter(void 0, void 0, void 0, funct
|
|
|
358
367
|
console.error(chalk.red(ui_1.MESSAGES.GIT_INITIALIZATION_ERROR));
|
|
359
368
|
});
|
|
360
369
|
});
|
|
361
|
-
/**
|
|
362
|
-
* Write a file `.gitignore` in the root of the newly created project.
|
|
363
|
-
* `.gitignore` available in `@gadmin2/schematics` cannot be published to
|
|
364
|
-
* NPM (needs to be investigated).
|
|
365
|
-
*
|
|
366
|
-
* @param dir Relative path to the project.
|
|
367
|
-
* @param content (optional) Content written in the `.gitignore`.
|
|
368
|
-
*
|
|
369
|
-
* @return Resolves when succeeds, or rejects with any error from `fn.writeFile`.
|
|
370
|
-
*/
|
|
371
|
-
const createGitIgnoreFile = (dir, content) => {
|
|
372
|
-
const fileContent = content || defaults_1.defaultGitIgnore;
|
|
373
|
-
const filePath = (0, path_1.join)(process.cwd(), dir, '.gitignore');
|
|
374
|
-
return (0, util_1.promisify)(fs.writeFile)(filePath, fileContent);
|
|
375
|
-
};
|
|
376
370
|
const printCollective = () => {
|
|
377
371
|
const dim = print('dim');
|
|
378
372
|
const yellow = print('yellow');
|
package/commands/new.command.js
CHANGED
|
@@ -26,7 +26,8 @@ class NewCommand extends abstract_command_1.AbstractCommand {
|
|
|
26
26
|
.option('-c, --collection [collectionName]', 'Schematics collection to use', schematics_1.Collection.GADMIN_GENERATOR)
|
|
27
27
|
.option('--strict', 'Enables strict mode in TypeScript.', false)
|
|
28
28
|
.option('--vite-agent-id [id]', 'Set VITE_AGENT_ID (knot Agent ID), written to web/.env.local')
|
|
29
|
-
.option('--taihu-app-token [token]', 'Set TAIHU_APP_TOKEN,
|
|
29
|
+
.option('--taihu-app-token [token]', 'Set TAIHU_APP_TOKEN (太湖应用 Token), written to server/.env.local')
|
|
30
|
+
.option('--taihu-odc-app-token [token]', 'Set TAIHU_ODC_APP_TOKEN (太湖合作伙伴版应用 Token), written to server/.env.local')
|
|
30
31
|
.option('--database-url [url]', 'Set DATABASE_URL (PostgreSQL connection string), written to server/.env.local')
|
|
31
32
|
.action((name, command) => __awaiter(this, void 0, void 0, function* () {
|
|
32
33
|
const options = [];
|
|
@@ -47,6 +48,7 @@ class NewCommand extends abstract_command_1.AbstractCommand {
|
|
|
47
48
|
options.push({ name: 'ui-framework', value: 'antd' });
|
|
48
49
|
options.push({ name: 'vite-agent-id', value: command.viteAgentId });
|
|
49
50
|
options.push({ name: 'taihu-app-token', value: command.taihuAppToken });
|
|
51
|
+
options.push({ name: 'taihu-odc-app-token', value: command.taihuOdcAppToken });
|
|
50
52
|
options.push({ name: 'database-url', value: command.databaseUrl });
|
|
51
53
|
const inputs = [];
|
|
52
54
|
inputs.push({ name: 'name', value: name });
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { Configuration } from './configuration';
|
|
2
2
|
export declare const defaultConfiguration: Required<Configuration>;
|
|
3
3
|
export declare const defaultOutDir = "dist";
|
|
4
|
-
export declare const defaultGitIgnore = "# compiled output\ndist/\nnode_modules/\n\n# Logs\nlogs/\n*.log\nnpm-debug.log*\npnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\nlerna-debug.log*\n\n# OS\n.DS_Store\n\n# Tests\ncoverage\n.nyc_output\n\n# IDEs and editors\n.idea\n.project\n.classpath\n.c9/\n*.launch\n.settings/\n*.sublime-workspace\n\n# IDE - VSCode\n.vscode/*\n!.vscode/settings.json\n!.vscode/tasks.json\n!.vscode/launch.json\n!.vscode/extensions.json";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.defaultOutDir = exports.defaultConfiguration = void 0;
|
|
4
4
|
const schematics_1 = require("../schematics");
|
|
5
5
|
exports.defaultConfiguration = {
|
|
6
6
|
language: 'ts',
|
|
@@ -19,38 +19,3 @@ exports.defaultConfiguration = {
|
|
|
19
19
|
generateOptions: {},
|
|
20
20
|
};
|
|
21
21
|
exports.defaultOutDir = 'dist';
|
|
22
|
-
exports.defaultGitIgnore = `# compiled output
|
|
23
|
-
dist/
|
|
24
|
-
node_modules/
|
|
25
|
-
|
|
26
|
-
# Logs
|
|
27
|
-
logs/
|
|
28
|
-
*.log
|
|
29
|
-
npm-debug.log*
|
|
30
|
-
pnpm-debug.log*
|
|
31
|
-
yarn-debug.log*
|
|
32
|
-
yarn-error.log*
|
|
33
|
-
lerna-debug.log*
|
|
34
|
-
|
|
35
|
-
# OS
|
|
36
|
-
.DS_Store
|
|
37
|
-
|
|
38
|
-
# Tests
|
|
39
|
-
coverage
|
|
40
|
-
.nyc_output
|
|
41
|
-
|
|
42
|
-
# IDEs and editors
|
|
43
|
-
.idea
|
|
44
|
-
.project
|
|
45
|
-
.classpath
|
|
46
|
-
.c9/
|
|
47
|
-
*.launch
|
|
48
|
-
.settings/
|
|
49
|
-
*.sublime-workspace
|
|
50
|
-
|
|
51
|
-
# IDE - VSCode
|
|
52
|
-
.vscode/*
|
|
53
|
-
!.vscode/settings.json
|
|
54
|
-
!.vscode/tasks.json
|
|
55
|
-
!.vscode/launch.json
|
|
56
|
-
!.vscode/extensions.json`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gadmin2n/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.120",
|
|
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.94",
|
|
51
51
|
"abc": "^0.6.1",
|
|
52
52
|
"chalk": "3.0.0",
|
|
53
53
|
"chokidar": "3.5.3",
|