@jayfong/x-server 2.22.5 → 2.23.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/lib/_cjs/cli/cli.js +8 -3
- package/lib/_cjs/cli/env_util.js +9 -4
- package/lib/cli/cli.js +8 -3
- package/lib/cli/env_util.d.ts +1 -1
- package/lib/cli/env_util.js +10 -5
- package/package.json +1 -1
package/lib/_cjs/cli/cli.js
CHANGED
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
5
|
var _chokidar = _interopRequireDefault(require("chokidar"));
|
|
6
6
|
var _execa = _interopRequireDefault(require("execa"));
|
|
7
|
+
var _vscodeGenerateIndexStandalone = require("vscode-generate-index-standalone");
|
|
8
|
+
var _vtils = require("vtils");
|
|
7
9
|
var _yargs = _interopRequireDefault(require("yargs"));
|
|
8
10
|
var _api_generator = require("./api_generator");
|
|
9
11
|
var _build_util = require("./build_util");
|
|
10
|
-
var _vtils = require("vtils");
|
|
11
12
|
var _deploy_util = require("./deploy_util");
|
|
12
13
|
var _dev_util = require("./dev_util");
|
|
13
14
|
var _env_util = require("./env_util");
|
|
14
|
-
var _vscodeGenerateIndexStandalone = require("vscode-generate-index-standalone");
|
|
15
15
|
var _template_util = require("./template_util");
|
|
16
16
|
_yargs.default.command('dev', '开始开发', _ => _.positional('index', {
|
|
17
17
|
alias: 'i',
|
|
@@ -24,6 +24,11 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
24
24
|
}).positional('tsx', {
|
|
25
25
|
describe: '使用 tsx 运行',
|
|
26
26
|
type: 'boolean'
|
|
27
|
+
}).positional('env', {
|
|
28
|
+
alias: 'e',
|
|
29
|
+
describe: '环境变量文件',
|
|
30
|
+
type: 'string',
|
|
31
|
+
default: 'development'
|
|
27
32
|
}), async argv => {
|
|
28
33
|
process.env.NODE_ENV = 'development';
|
|
29
34
|
let lastRun;
|
|
@@ -49,7 +54,7 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
49
54
|
watcher.on('all', (0, _vtils.debounce)(async () => {
|
|
50
55
|
await _env_util.EnvUtil.importFile({
|
|
51
56
|
cwd: process.cwd(),
|
|
52
|
-
file: '.env'
|
|
57
|
+
file: ['.env', `.env.${argv.env}`]
|
|
53
58
|
});
|
|
54
59
|
_env_util.EnvUtil.outputTypes({
|
|
55
60
|
cwd: process.cwd(),
|
package/lib/_cjs/cli/env_util.js
CHANGED
|
@@ -122,11 +122,16 @@ class EnvUtil {
|
|
|
122
122
|
return envsObj;
|
|
123
123
|
}
|
|
124
124
|
static async importFile(options) {
|
|
125
|
-
const envs = await EnvUtil.parseFile(options);
|
|
126
125
|
const envsObj = {};
|
|
127
|
-
for (const
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
for (const file of (0, _vtils.castArray)(options.file)) {
|
|
127
|
+
const envs = await EnvUtil.parseFile({
|
|
128
|
+
...options,
|
|
129
|
+
file: file
|
|
130
|
+
});
|
|
131
|
+
for (const env of envs) {
|
|
132
|
+
envsObj[env.key] = env.value;
|
|
133
|
+
process.env[env.key] = env.value;
|
|
134
|
+
}
|
|
130
135
|
}
|
|
131
136
|
process.env.X_SERVER_ENVS = JSON.stringify({
|
|
132
137
|
// @ts-ignore
|
package/lib/cli/cli.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import chokidar from 'chokidar';
|
|
3
3
|
import execa from 'execa';
|
|
4
|
+
import { generateManyIndex } from 'vscode-generate-index-standalone';
|
|
5
|
+
import { castArray, debounce } from 'vtils';
|
|
4
6
|
import yargs from 'yargs';
|
|
5
7
|
import { ApiGenerator } from "./api_generator";
|
|
6
8
|
import { BuildUtil } from "./build_util";
|
|
7
|
-
import { castArray, debounce } from 'vtils';
|
|
8
9
|
import { DeployUtil } from "./deploy_util";
|
|
9
10
|
import { DevUtil } from "./dev_util";
|
|
10
11
|
import { EnvUtil } from "./env_util";
|
|
11
|
-
import { generateManyIndex } from 'vscode-generate-index-standalone';
|
|
12
12
|
import { TemplateUtil } from "./template_util";
|
|
13
13
|
yargs.command('dev', '开始开发', _ => _.positional('index', {
|
|
14
14
|
alias: 'i',
|
|
@@ -21,6 +21,11 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
21
21
|
}).positional('tsx', {
|
|
22
22
|
describe: '使用 tsx 运行',
|
|
23
23
|
type: 'boolean'
|
|
24
|
+
}).positional('env', {
|
|
25
|
+
alias: 'e',
|
|
26
|
+
describe: '环境变量文件',
|
|
27
|
+
type: 'string',
|
|
28
|
+
default: 'development'
|
|
24
29
|
}), async argv => {
|
|
25
30
|
process.env.NODE_ENV = 'development';
|
|
26
31
|
let lastRun;
|
|
@@ -46,7 +51,7 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
46
51
|
watcher.on('all', debounce(async () => {
|
|
47
52
|
await EnvUtil.importFile({
|
|
48
53
|
cwd: process.cwd(),
|
|
49
|
-
file: '.env'
|
|
54
|
+
file: ['.env', `.env.${argv.env}`]
|
|
50
55
|
});
|
|
51
56
|
EnvUtil.outputTypes({
|
|
52
57
|
cwd: process.cwd(),
|
package/lib/cli/env_util.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export declare class EnvUtil {
|
|
|
21
21
|
}): Promise<Record<string, any>>;
|
|
22
22
|
static importFile(options: {
|
|
23
23
|
cwd: string;
|
|
24
|
-
file: string;
|
|
24
|
+
file: string | string[];
|
|
25
25
|
}): Promise<void>;
|
|
26
26
|
static makeTypes(envs: ParsedEnv[]): string;
|
|
27
27
|
static outputTypes(options: {
|
package/lib/cli/env_util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { dedent, devOrProd, escapeRegExp, isNumeric, isPlainObject } from 'vtils';
|
|
3
|
+
import { castArray, dedent, devOrProd, escapeRegExp, isNumeric, isPlainObject } from 'vtils';
|
|
4
4
|
import { parse as yamlParse } from 'yaml';
|
|
5
5
|
export class EnvUtil {
|
|
6
6
|
static normalizeValue(value) {
|
|
@@ -117,11 +117,16 @@ export class EnvUtil {
|
|
|
117
117
|
return envsObj;
|
|
118
118
|
}
|
|
119
119
|
static async importFile(options) {
|
|
120
|
-
const envs = await EnvUtil.parseFile(options);
|
|
121
120
|
const envsObj = {};
|
|
122
|
-
for (const
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
for (const file of castArray(options.file)) {
|
|
122
|
+
const envs = await EnvUtil.parseFile({
|
|
123
|
+
...options,
|
|
124
|
+
file: file
|
|
125
|
+
});
|
|
126
|
+
for (const env of envs) {
|
|
127
|
+
envsObj[env.key] = env.value;
|
|
128
|
+
process.env[env.key] = env.value;
|
|
129
|
+
}
|
|
125
130
|
}
|
|
126
131
|
process.env.X_SERVER_ENVS = JSON.stringify({
|
|
127
132
|
// @ts-ignore
|