@jayfong/x-server 1.33.8 → 1.33.10
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/build_util.js +36 -19
- package/lib/_cjs/cli/cli.js +9 -2
- package/lib/_cjs/cli/deploy_util.js +1 -0
- package/lib/cli/build_util.d.ts +1 -0
- package/lib/cli/build_util.js +35 -19
- package/lib/cli/cli.js +10 -3
- package/lib/cli/deploy_util.js +1 -0
- package/package.json +1 -1
|
@@ -41,21 +41,30 @@ class BuildUtil {
|
|
|
41
41
|
|
|
42
42
|
const distPm2File = _nodePath.default.join(distDir, 'pm2.config.js');
|
|
43
43
|
|
|
44
|
+
const distNoInstallFile = _nodePath.default.join(distDir, 'no_install.lock');
|
|
45
|
+
|
|
44
46
|
const distBundleFile = _nodePath.default.join(tempDir, `app.${pkgContent.version}.tgz`);
|
|
45
47
|
|
|
46
48
|
await _fsExtra.default.ensureDir(distDir);
|
|
47
49
|
await _fsExtra.default.ensureDir(tempDir); // 处理 external
|
|
48
50
|
|
|
49
51
|
const external = (0, _vtils.uniq)(options.external || []);
|
|
50
|
-
const externalWithVersions = await Promise.all(external.map(async item => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
const externalWithVersions = (await Promise.all(external.map(async item => {
|
|
53
|
+
try {
|
|
54
|
+
const itemPkgFile = require.resolve(`${item}/package.json`);
|
|
55
|
+
|
|
56
|
+
const itemPkgContent = await _fsExtra.default.readJson(itemPkgFile);
|
|
57
|
+
return {
|
|
58
|
+
name: item,
|
|
59
|
+
version: itemPkgContent.version
|
|
60
|
+
};
|
|
61
|
+
} catch {
|
|
62
|
+
return {
|
|
63
|
+
name: item,
|
|
64
|
+
version: ''
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}))).filter(item => !!item.version); // fix: hexoid 构建问题
|
|
59
68
|
|
|
60
69
|
try {
|
|
61
70
|
const hexoidPackageJsonFile = require.resolve('hexoid/package.json');
|
|
@@ -160,17 +169,25 @@ class BuildUtil {
|
|
|
160
169
|
},
|
|
161
170
|
],
|
|
162
171
|
}
|
|
163
|
-
`);
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
//
|
|
170
|
-
|
|
171
|
-
|
|
172
|
+
`);
|
|
173
|
+
|
|
174
|
+
if (externalWithVersions.length) {
|
|
175
|
+
if (options.noInstall) {
|
|
176
|
+
await _fsExtra.default.writeFile(distNoInstallFile, '');
|
|
177
|
+
} else {
|
|
178
|
+
// 安装 external 依赖
|
|
179
|
+
await (0, _execa.default)('tyn', {
|
|
180
|
+
cwd: distDir,
|
|
181
|
+
stdio: 'inherit',
|
|
182
|
+
env: {
|
|
183
|
+
// 禁止 yarn 更新检测,因网络原因容易超时长时间卡住
|
|
184
|
+
// https://classic.yarnpkg.com/lang/en/docs/yarnrc/#toc-disable-self-update-check
|
|
185
|
+
yarn_disable_self_update_check: 'true'
|
|
186
|
+
}
|
|
187
|
+
});
|
|
172
188
|
}
|
|
173
|
-
}
|
|
189
|
+
} // 打包为 tgz
|
|
190
|
+
|
|
174
191
|
|
|
175
192
|
await _compressing.default.tgz.compressDir(distDir, distBundleFile);
|
|
176
193
|
}
|
package/lib/_cjs/cli/cli.js
CHANGED
|
@@ -96,8 +96,14 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
96
96
|
describe: '是否压缩',
|
|
97
97
|
type: 'boolean',
|
|
98
98
|
default: true
|
|
99
|
+
}).positional('no-install', {
|
|
100
|
+
alias: 'n',
|
|
101
|
+
describe: '是否不本地安装外部依赖',
|
|
102
|
+
type: 'boolean',
|
|
103
|
+
default: false
|
|
99
104
|
}), async argv => {
|
|
100
105
|
process.env.NODE_ENV = 'production';
|
|
106
|
+
const externals = (0, _vtils.castArray)(argv.external || []).map(item => item.split(',')).flat().filter(Boolean);
|
|
101
107
|
const envs = await _env_util.EnvUtil.parseFile({
|
|
102
108
|
cwd: process.cwd(),
|
|
103
109
|
file: '.env'
|
|
@@ -118,9 +124,10 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
118
124
|
});
|
|
119
125
|
await _build_util.BuildUtil.build({
|
|
120
126
|
cwd: process.cwd(),
|
|
121
|
-
external:
|
|
127
|
+
external: externals,
|
|
122
128
|
inlineEnvs: envs,
|
|
123
|
-
minify: argv.minify
|
|
129
|
+
minify: argv.minify,
|
|
130
|
+
noInstall: argv['no-install']
|
|
124
131
|
});
|
|
125
132
|
console.log('构建成功');
|
|
126
133
|
}).command('api', '生成 API', async () => {
|
package/lib/cli/build_util.d.ts
CHANGED
package/lib/cli/build_util.js
CHANGED
|
@@ -18,20 +18,28 @@ export class BuildUtil {
|
|
|
18
18
|
const distMainFile = path.join(distDir, 'main.js');
|
|
19
19
|
const distPkgFile = path.join(distDir, 'package.json');
|
|
20
20
|
const distPm2File = path.join(distDir, 'pm2.config.js');
|
|
21
|
+
const distNoInstallFile = path.join(distDir, 'no_install.lock');
|
|
21
22
|
const distBundleFile = path.join(tempDir, `app.${pkgContent.version}.tgz`);
|
|
22
23
|
await fs.ensureDir(distDir);
|
|
23
24
|
await fs.ensureDir(tempDir); // 处理 external
|
|
24
25
|
|
|
25
26
|
const external = uniq(options.external || []);
|
|
26
|
-
const externalWithVersions = await Promise.all(external.map(async item => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
const externalWithVersions = (await Promise.all(external.map(async item => {
|
|
28
|
+
try {
|
|
29
|
+
const itemPkgFile = require.resolve(`${item}/package.json`);
|
|
30
|
+
|
|
31
|
+
const itemPkgContent = await fs.readJson(itemPkgFile);
|
|
32
|
+
return {
|
|
33
|
+
name: item,
|
|
34
|
+
version: itemPkgContent.version
|
|
35
|
+
};
|
|
36
|
+
} catch {
|
|
37
|
+
return {
|
|
38
|
+
name: item,
|
|
39
|
+
version: ''
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}))).filter(item => !!item.version); // fix: hexoid 构建问题
|
|
35
43
|
|
|
36
44
|
try {
|
|
37
45
|
const hexoidPackageJsonFile = require.resolve('hexoid/package.json');
|
|
@@ -134,17 +142,25 @@ export class BuildUtil {
|
|
|
134
142
|
},
|
|
135
143
|
],
|
|
136
144
|
}
|
|
137
|
-
`);
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
|
|
145
|
+
`);
|
|
146
|
+
|
|
147
|
+
if (externalWithVersions.length) {
|
|
148
|
+
if (options.noInstall) {
|
|
149
|
+
await fs.writeFile(distNoInstallFile, '');
|
|
150
|
+
} else {
|
|
151
|
+
// 安装 external 依赖
|
|
152
|
+
await exec('tyn', {
|
|
153
|
+
cwd: distDir,
|
|
154
|
+
stdio: 'inherit',
|
|
155
|
+
env: {
|
|
156
|
+
// 禁止 yarn 更新检测,因网络原因容易超时长时间卡住
|
|
157
|
+
// https://classic.yarnpkg.com/lang/en/docs/yarnrc/#toc-disable-self-update-check
|
|
158
|
+
yarn_disable_self_update_check: 'true'
|
|
159
|
+
}
|
|
160
|
+
});
|
|
146
161
|
}
|
|
147
|
-
}
|
|
162
|
+
} // 打包为 tgz
|
|
163
|
+
|
|
148
164
|
|
|
149
165
|
await compressing.tgz.compressDir(distDir, distBundleFile);
|
|
150
166
|
}
|
package/lib/cli/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ import execa from 'execa';
|
|
|
4
4
|
import yargs from 'yargs';
|
|
5
5
|
import { ApiGenerator } from "./api_generator";
|
|
6
6
|
import { BuildUtil } from "./build_util";
|
|
7
|
-
import { debounce } from 'vtils';
|
|
7
|
+
import { castArray, debounce } from 'vtils';
|
|
8
8
|
import { DeployUtil } from "./deploy_util";
|
|
9
9
|
import { EnvUtil } from "./env_util";
|
|
10
10
|
import { generateManyIndex } from 'vscode-generate-index-standalone';
|
|
@@ -78,8 +78,14 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
78
78
|
describe: '是否压缩',
|
|
79
79
|
type: 'boolean',
|
|
80
80
|
default: true
|
|
81
|
+
}).positional('no-install', {
|
|
82
|
+
alias: 'n',
|
|
83
|
+
describe: '是否不本地安装外部依赖',
|
|
84
|
+
type: 'boolean',
|
|
85
|
+
default: false
|
|
81
86
|
}), async argv => {
|
|
82
87
|
process.env.NODE_ENV = 'production';
|
|
88
|
+
const externals = castArray(argv.external || []).map(item => item.split(',')).flat().filter(Boolean);
|
|
83
89
|
const envs = await EnvUtil.parseFile({
|
|
84
90
|
cwd: process.cwd(),
|
|
85
91
|
file: '.env'
|
|
@@ -100,9 +106,10 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
100
106
|
});
|
|
101
107
|
await BuildUtil.build({
|
|
102
108
|
cwd: process.cwd(),
|
|
103
|
-
external:
|
|
109
|
+
external: externals,
|
|
104
110
|
inlineEnvs: envs,
|
|
105
|
-
minify: argv.minify
|
|
111
|
+
minify: argv.minify,
|
|
112
|
+
noInstall: argv['no-install']
|
|
106
113
|
});
|
|
107
114
|
console.log('构建成功');
|
|
108
115
|
}).command('api', '生成 API', async () => {
|
package/lib/cli/deploy_util.js
CHANGED