xhs-mp-compiler-cli 2.0.0-beta.4 → 2.0.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/dist/bin/xhs-mp-cli-build.js +48 -34
- package/dist/bin/xhs-mp-cli-dev.js +44 -44
- package/dist/bin/xhs-mp-cli.js +22 -12
- package/dist/compiler.d.ts +21 -28
- package/dist/compiler.js +327 -327
- package/dist/compilerImpl.d.ts +19 -0
- package/dist/compilerImpl.js +173 -0
- package/dist/config/constant.config.d.ts +24 -0
- package/dist/config/constant.config.js +82 -30
- package/dist/config/dir.config.js +23 -13
- package/dist/index.d.ts +9 -9
- package/dist/index.js +454 -408
- package/dist/packs/index.d.ts +4 -4
- package/dist/packs/index.js +38 -30
- package/dist/packs/mp-pack/index.js +38 -30
- package/dist/packs/webpack/dev-server/index.js +61 -50
- package/dist/packs/webpack/dev-server/lib/ensurePort.js +33 -23
- package/dist/packs/webpack/dev-server/lib/openBrowser.js +28 -18
- package/dist/packs/webpack/index.d.ts +1 -1
- package/dist/packs/webpack/index.js +99 -90
- package/dist/packs/webpack/webpack.d.ts +2 -1
- package/dist/packs/webpack/webpack.js +81 -63
- package/dist/presets/babel.d.ts +0 -1
- package/dist/presets/babel.js +64 -58
- package/dist/presets/common.js +42 -45
- package/dist/presets/configs/minigame/assets/assetsEntryPlugin.js +50 -40
- package/dist/presets/configs/minigame/assets/index.js +62 -52
- package/dist/presets/configs/minigame/service/index.js +49 -30
- package/dist/presets/configs/minigame/service/resolveLimitPlugin.js +33 -23
- package/dist/presets/configs/minigame/service/serviceChunkPlugin.d.ts +2 -2
- package/dist/presets/configs/minigame/service/serviceChunkPlugin.js +69 -60
- package/dist/presets/configs/minigame/service/serviceEntryPlugin.d.ts +3 -3
- package/dist/presets/configs/minigame/service/serviceEntryPlugin.js +39 -29
- package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.js +120 -113
- package/dist/presets/configs/miniprogram/assets/index.js +45 -43
- package/dist/presets/configs/miniprogram/render/component.js +51 -41
- package/dist/presets/configs/miniprogram/render/index.d.ts +2 -3
- package/dist/presets/configs/miniprogram/render/index.js +85 -68
- package/dist/presets/configs/miniprogram/render/render.js +53 -43
- package/dist/presets/configs/miniprogram/render/renderChunkPlugin.js +84 -49
- package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.d.ts +15 -0
- package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.js +164 -126
- package/dist/presets/configs/miniprogram/service/index.js +82 -65
- package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.js +60 -50
- package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.js +93 -55
- package/dist/presets/index.js +100 -90
- package/dist/presets/loaders/mg-entry-loader.js +32 -22
- package/dist/presets/loaders/mini-style-loader.js +79 -55
- package/dist/presets/loaders/mp-entry-loader.js +149 -140
- package/dist/presets/loaders/wxss-loader.js +73 -63
- package/dist/presets/plugins/InjectorPlugin.js +23 -13
- package/dist/presets/plugins/SourceMapDevToolPlugin.d.ts +1 -0
- package/dist/presets/plugins/SourceMapDevToolPlugin.js +23 -0
- package/dist/presets/prod.js +88 -78
- package/dist/sharedFs.d.ts +2 -0
- package/dist/sharedFs.js +24 -0
- package/dist/types/index.d.ts +11 -37
- package/dist/types/index.js +23 -13
- package/dist/utils/{apm/index.d.ts → apm.d.ts} +5 -3
- package/dist/utils/apm.js +245 -0
- package/dist/utils/cache.d.ts +28 -0
- package/dist/utils/cache.js +49 -0
- package/dist/utils/common.js +42 -32
- package/dist/utils/css.d.ts +1 -1
- package/dist/utils/css.js +43 -35
- package/dist/utils/depenedHelper.js +95 -85
- package/dist/utils/file.js +39 -29
- package/dist/utils/loader-utils.js +63 -53
- package/dist/utils/postcssRpx2Vw.js +43 -33
- package/dist/utils/project.d.ts +3 -2
- package/dist/utils/project.js +129 -119
- package/dist/utils/projectConfig.js +24 -15
- package/dist/utils/utils.js +51 -42
- package/dist/utils/workerPool.d.ts +29 -0
- package/dist/utils/workerPool.js +125 -0
- package/dist/utils/zip.js +239 -229
- package/package.json +33 -14
- package/dist/compilerCP.d.ts +0 -1
- package/dist/compilerCP.js +0 -175
- package/dist/presets/loaders/sjs-loader/index.d.ts +0 -12
- package/dist/presets/loaders/sjs-loader/index.js +0 -605
- package/dist/presets/loaders/sjs-loader/scope.d.ts +0 -36
- package/dist/presets/loaders/sjs-loader/scope.js +0 -122
- package/dist/presets/loaders/sjs-loader/tranform.d.ts +0 -2
- package/dist/presets/loaders/sjs-loader/tranform.js +0 -31
- package/dist/utils/apm/index.js +0 -198
- package/dist/utils/asyncWebpack.d.ts +0 -3
- package/dist/utils/asyncWebpack.js +0 -38
- package/dist/utils/const.d.ts +0 -27
- package/dist/utils/const.js +0 -47
- package/dist/utils/getSuffixName.d.ts +0 -3
- package/dist/utils/getSuffixName.js +0 -18
- package/dist/utils/tagTransformMap.d.ts +0 -36
- package/dist/utils/tagTransformMap.js +0 -39
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -11,445 +10,492 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
10
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
11
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
12
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const xhs_mp_project_1 = require("xhs-mp-project");
|
|
19
|
-
const events_1 = __importDefault(require("events"));
|
|
20
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
21
|
-
const path_1 = __importDefault(require("path"));
|
|
22
|
-
const utils_1 = require("./utils/utils");
|
|
23
|
-
const zip_1 = require("./utils/zip");
|
|
24
|
-
const project_1 = require("./utils/project");
|
|
25
|
-
const dir_config_1 = require("./config/dir.config");
|
|
26
|
-
const compiler_1 = require("./compiler");
|
|
27
|
-
Object.defineProperty(exports, "getProcessCompilerClass", { enumerable: true, get: function () { return compiler_1.getProcessCompilerClass; } });
|
|
28
|
-
class Compiler extends events_1.default {
|
|
29
|
-
constructor(props) {
|
|
30
|
-
super();
|
|
31
|
-
this.compilerImplMap = {};
|
|
32
|
-
this.initSimulatorCompiler = compiler => {
|
|
33
|
-
compiler.on('buildStart', data => {
|
|
34
|
-
this.emit('buildStart', data);
|
|
35
|
-
});
|
|
36
|
-
compiler.on('buildSuccess', data => {
|
|
37
|
-
this.emit('buildSuccess', data);
|
|
38
|
-
});
|
|
39
|
-
compiler.on('buildError', data => {
|
|
40
|
-
this.emit('buildError', data);
|
|
41
|
-
});
|
|
42
|
-
compiler.on('compileFinishWhenFileChange', data => {
|
|
43
|
-
this.emit('compileFinishWhenFileChange', data);
|
|
44
|
-
});
|
|
45
|
-
compiler.on('emitCompileStats', data => {
|
|
46
|
-
this.emit('emitCompileStats', data);
|
|
47
|
-
});
|
|
48
|
-
compiler.on('unexpectedExit', data => {
|
|
49
|
-
this.emit('unexpectedExit', data);
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
this.initBuildCompiler = compiler => {
|
|
53
|
-
compiler.on('compilePercent', data => {
|
|
54
|
-
this.emit('compilePercent', data);
|
|
55
|
-
});
|
|
56
|
-
compiler.on('emitCompileStats', data => {
|
|
57
|
-
this.emit('emitCompileStats', data);
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
this.getComilerImpl = (entryType = constant_config_1.COMPILE_ENTRY.simulator) => {
|
|
61
|
-
const compilerType = this.getCompilerType(entryType);
|
|
62
|
-
if (!this.compilerImplMap[compilerType]) {
|
|
63
|
-
this.compilerImplMap[compilerType] = this.createCompilerImpl(entryType);
|
|
64
|
-
if (entryType === constant_config_1.COMPILE_ENTRY.simulator) {
|
|
65
|
-
this.initSimulatorCompiler(this.compilerImplMap[compilerType]);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
this.initBuildCompiler(this.compilerImplMap[compilerType]);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return this.compilerImplMap[compilerType];
|
|
72
|
-
};
|
|
73
|
-
const { logger } = props;
|
|
74
|
-
this.logger = logger || console;
|
|
75
|
-
this.compilerProps = props;
|
|
76
|
-
this.project = this.createProject(props);
|
|
77
|
-
this.projectPath = this.project.projectPath;
|
|
13
|
+
(function (factory) {
|
|
14
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
15
|
+
var v = factory(require, exports);
|
|
16
|
+
if (v !== undefined) module.exports = v;
|
|
78
17
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return (project ||
|
|
82
|
-
new xhs_mp_project_1.Project({
|
|
83
|
-
projectPath
|
|
84
|
-
}));
|
|
18
|
+
else if (typeof define === "function" && define.amd) {
|
|
19
|
+
define(["require", "exports", "./config/constant.config", "xhs-mp-project", "events", "fs-extra", "path", "./utils/utils", "./utils/project", "./config/dir.config", "./compiler", "./config/constant.config"], factory);
|
|
85
20
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
21
|
+
})(function (require, exports) {
|
|
22
|
+
"use strict";
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.ProjectCompiler = exports.prepareDevPool = exports.getProjectCompilerClass = exports.COMPILE_ENTRY = void 0;
|
|
25
|
+
const constant_config_1 = require("./config/constant.config");
|
|
26
|
+
Object.defineProperty(exports, "COMPILE_ENTRY", { enumerable: true, get: function () { return constant_config_1.COMPILE_ENTRY; } });
|
|
27
|
+
const xhs_mp_project_1 = require("xhs-mp-project");
|
|
28
|
+
const events_1 = __importDefault(require("events"));
|
|
29
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
30
|
+
const path_1 = __importDefault(require("path"));
|
|
31
|
+
const utils_1 = require("./utils/utils");
|
|
32
|
+
const project_1 = require("./utils/project");
|
|
33
|
+
const dir_config_1 = require("./config/dir.config");
|
|
34
|
+
const compiler_1 = require("./compiler");
|
|
35
|
+
Object.defineProperty(exports, "getProjectCompilerClass", { enumerable: true, get: function () { return compiler_1.getProjectCompilerClass; } });
|
|
36
|
+
Object.defineProperty(exports, "prepareDevPool", { enumerable: true, get: function () { return compiler_1.prepareDevPool; } });
|
|
37
|
+
const constant_config_2 = require("./config/constant.config");
|
|
38
|
+
class ProjectCompiler extends events_1.default {
|
|
39
|
+
constructor(props) {
|
|
40
|
+
super();
|
|
41
|
+
this.compilerImplMap = {};
|
|
42
|
+
this.initSimulatorCompiler = compiler => {
|
|
43
|
+
compiler.on('buildStart', data => {
|
|
44
|
+
this.emit('buildStart', data);
|
|
45
|
+
});
|
|
46
|
+
compiler.on('compileInfo', data => {
|
|
47
|
+
this.emit('compileInfo', data);
|
|
48
|
+
});
|
|
49
|
+
compiler.on('buildSuccess', data => {
|
|
50
|
+
this.emit('buildSuccess', data);
|
|
51
|
+
});
|
|
52
|
+
compiler.on('buildError', data => {
|
|
53
|
+
this.emit('buildError', data);
|
|
54
|
+
});
|
|
55
|
+
compiler.on('compileFinishWhenFileChange', data => {
|
|
56
|
+
this.emit('compileFinishWhenFileChange', data);
|
|
57
|
+
});
|
|
58
|
+
compiler.on('compilePercent', data => {
|
|
59
|
+
this.emit('compilePercent', data);
|
|
60
|
+
});
|
|
61
|
+
compiler.on('emitCompileStats', data => {
|
|
62
|
+
this.emit('emitCompileStats', data);
|
|
63
|
+
});
|
|
64
|
+
compiler.on('unexpectedExit', data => {
|
|
65
|
+
this.emit('unexpectedExit', data);
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
this.initBuildCompiler = compiler => {
|
|
69
|
+
compiler.on('compilePercent', data => {
|
|
70
|
+
this.emit('compilePercent', data);
|
|
71
|
+
});
|
|
72
|
+
compiler.on('compileInfo', data => {
|
|
73
|
+
this.emit('compileInfo', data);
|
|
74
|
+
});
|
|
75
|
+
compiler.on('emitCompileStats', data => {
|
|
76
|
+
this.emit('emitCompileStats', data);
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
this.getComilerImpl = (entryType = constant_config_1.COMPILE_ENTRY.simulator) => {
|
|
80
|
+
const compilerType = this.getCompilerType(entryType);
|
|
81
|
+
if (!this.compilerImplMap[compilerType]) {
|
|
82
|
+
this.compilerImplMap[compilerType] = this.createCompilerImpl(entryType);
|
|
83
|
+
if (entryType === constant_config_1.COMPILE_ENTRY.simulator) {
|
|
84
|
+
this.initSimulatorCompiler(this.compilerImplMap[compilerType]);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
this.initBuildCompiler(this.compilerImplMap[compilerType]);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return this.compilerImplMap[compilerType];
|
|
91
|
+
};
|
|
92
|
+
const { logger } = props;
|
|
93
|
+
this.logger = logger || console;
|
|
94
|
+
this.compilerProps = props;
|
|
95
|
+
this.project = this.createProject(props);
|
|
96
|
+
this.projectPath = this.project.projectPath;
|
|
93
97
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
98
|
+
createProject(props) {
|
|
99
|
+
const { projectPath, project } = props;
|
|
100
|
+
return (project ||
|
|
101
|
+
new xhs_mp_project_1.Project({
|
|
102
|
+
projectPath
|
|
103
|
+
}));
|
|
97
104
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
getUsingPackageType() {
|
|
106
|
-
return __awaiter(this, arguments, void 0, function* (entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
107
|
-
var _a, _b;
|
|
108
|
-
const { libFeatures } = this.compilerProps;
|
|
109
|
-
let enableV1 = false;
|
|
110
|
-
let enableV2 = true;
|
|
111
|
-
let enableVDom = false;
|
|
112
|
-
const settings = this.project.settings || {};
|
|
113
|
-
const isUpload = entryType === constant_config_1.COMPILE_ENTRY.upload;
|
|
114
|
-
if (this.project.appMode === constant_config_1.MiniMode.minigame) {
|
|
115
|
-
enableV1 = true;
|
|
116
|
-
enableV2 = false;
|
|
117
|
-
enableVDom = false;
|
|
118
|
-
}
|
|
119
|
-
else if (entryType === constant_config_1.COMPILE_ENTRY.simulator) {
|
|
120
|
-
const supportV2 = (_a = libFeatures === null || libFeatures === void 0 ? void 0 : libFeatures.supportV2) !== null && _a !== void 0 ? _a : true;
|
|
121
|
-
const supportVDom = (_b = libFeatures === null || libFeatures === void 0 ? void 0 : libFeatures.supportVdom) !== null && _b !== void 0 ? _b : true;
|
|
122
|
-
// 模拟器预览模式下,按照基础库是否支持相关功能 + 用户是否勾选进行判断
|
|
123
|
-
enableV2 = supportV2 && settings.enableV2;
|
|
124
|
-
// 开启v2不编译vdom
|
|
125
|
-
enableVDom = !enableV2 && supportVDom && settings.enableVDom;
|
|
126
|
-
// enableVDom = !enableV2 && settings.enableVDom
|
|
127
|
-
enableV1 = !enableV2;
|
|
105
|
+
getCompilerDir() {
|
|
106
|
+
let compileDirPath;
|
|
107
|
+
let compileCachePath;
|
|
108
|
+
const { compileDir } = this.compilerProps;
|
|
109
|
+
if (compileDir) {
|
|
110
|
+
compileDirPath = path_1.default.join(compileDir, 'xhs-mp-baba');
|
|
111
|
+
compileCachePath = path_1.default.join(compileDir, 'xhs-compile-cache');
|
|
128
112
|
}
|
|
129
113
|
else {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
enableV2 = settings.enableV2;
|
|
133
|
-
enableV1 = true;
|
|
114
|
+
compileDirPath = dir_config_1.mpCompileDirPath;
|
|
115
|
+
compileCachePath = dir_config_1.mpCompileCachePath;
|
|
134
116
|
}
|
|
117
|
+
// this.logger.log('compileDirPath:', compileDirPath)
|
|
135
118
|
return {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
enableVDom
|
|
119
|
+
mpCompileDirPath: compileDirPath,
|
|
120
|
+
mpCompileCachePath: compileCachePath
|
|
139
121
|
};
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
// 根据使用的场景或者配置,采用不同的compiler类型
|
|
143
|
-
getCompilerType(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
144
|
-
const isGame = this.project.appMode === constant_config_1.MiniMode.minigame;
|
|
145
|
-
const settings = this.project.projectJsonContent.setting || {};
|
|
146
|
-
// 使用旧编译
|
|
147
|
-
if (isGame || !settings.useNewCompiler) {
|
|
148
|
-
return entryType === constant_config_1.COMPILE_ENTRY.simulator ? constant_config_1.COMPILER_TYPE.legacy_dev : constant_config_1.COMPILER_TYPE.legacy_build;
|
|
149
122
|
}
|
|
150
|
-
//
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const { mpCompileDirPath } = this.getCompilerDir();
|
|
159
|
-
const compilerType = this.getCompilerType(entryType);
|
|
160
|
-
const basename = path_1.default.basename(this.project.projectPath);
|
|
161
|
-
const hash = (0, utils_1.getMd5)(this.project.projectPath).slice(0, 8);
|
|
162
|
-
const distDir = path_1.default.join(path_1.default.resolve(mpCompileDirPath, `${basename}_${hash}`), compilerType);
|
|
163
|
-
fs_extra_1.default.ensureDirSync(distDir);
|
|
164
|
-
return distDir;
|
|
165
|
-
}
|
|
166
|
-
removeDistDir(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
167
|
-
const distDir = this.getDistDir(entryType);
|
|
168
|
-
if (fs_extra_1.default.existsSync(distDir)) {
|
|
169
|
-
fs_extra_1.default.removeSync(distDir);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
getCacheDir(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
173
|
-
const { mpCompileCachePath } = this.getCompilerDir();
|
|
174
|
-
const compilerType = this.getCompilerType(entryType);
|
|
175
|
-
const basename = path_1.default.basename(this.project.projectPath);
|
|
176
|
-
const hash = (0, utils_1.getMd5)(this.project.projectPath).slice(0, 8);
|
|
177
|
-
const distDir = path_1.default.join(path_1.default.resolve(mpCompileCachePath, `${basename}_${hash}`), compilerType);
|
|
178
|
-
fs_extra_1.default.ensureDirSync(distDir);
|
|
179
|
-
return distDir;
|
|
180
|
-
}
|
|
181
|
-
removeCacheDir(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
182
|
-
const cacheDir = this.getCacheDir(entryType);
|
|
183
|
-
if (fs_extra_1.default.existsSync(cacheDir)) {
|
|
184
|
-
fs_extra_1.default.removeSync(cacheDir);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
createCompilerImpl(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
188
|
-
const { nodeJsPath, mpDevJsonPath } = this.compilerProps;
|
|
189
|
-
const distDir = this.getDistDir(entryType);
|
|
190
|
-
const cacheDir = this.getCacheDir(entryType);
|
|
191
|
-
const compilerType = this.getCompilerType(entryType);
|
|
192
|
-
compilerType === constant_config_1.COMPILER_TYPE.legacy_dev || compilerType === constant_config_1.COMPILER_TYPE.legacy_build
|
|
193
|
-
? 'webpack'
|
|
194
|
-
: 'mp-pack';
|
|
195
|
-
const options = {
|
|
196
|
-
projectPath: this.project.projectPath,
|
|
197
|
-
appMode: this.project.appMode,
|
|
198
|
-
extJsonPath: this.project.extJsonDir,
|
|
199
|
-
platform: 'xhs',
|
|
200
|
-
distDir,
|
|
201
|
-
cacheDirectory: cacheDir
|
|
202
|
-
};
|
|
203
|
-
this.removeDistDir(entryType);
|
|
204
|
-
this.removeCacheDir(entryType);
|
|
205
|
-
const CompilerClass = (0, compiler_1.getProcessCompilerClass)(compilerType);
|
|
206
|
-
const compilerImpl = new CompilerClass(options, {
|
|
207
|
-
logger: this.logger,
|
|
208
|
-
nodeJsPath
|
|
209
|
-
});
|
|
210
|
-
return compilerImpl;
|
|
211
|
-
}
|
|
212
|
-
makePkgsReady(config) {
|
|
213
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
214
|
-
const entryType = constant_config_1.COMPILE_ENTRY.simulator;
|
|
215
|
-
const compilerImpl = this.getComilerImpl(entryType);
|
|
216
|
-
yield compilerImpl.makePkgsReady(config);
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
reCompilePkgs(config) {
|
|
220
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
221
|
-
const entryType = constant_config_1.COMPILE_ENTRY.simulator;
|
|
222
|
-
const compilerImpl = this.getComilerImpl(entryType);
|
|
223
|
-
yield compilerImpl.reCompilePkgs(config);
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
compileProject(config) {
|
|
227
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
228
|
-
var _a, _b, _c;
|
|
229
|
-
try {
|
|
230
|
-
const { entryType, compressJs, enableSourcemap, enableV2, enableV1, enableVDom, mpUploadOptions } = config;
|
|
231
|
-
this.emit('compile-project-start');
|
|
232
|
-
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.log('Compile project...');
|
|
233
|
-
const compilerImpl = this.getComilerImpl(entryType);
|
|
234
|
-
yield compilerImpl.build({
|
|
235
|
-
compressJs,
|
|
236
|
-
enableSourcemap,
|
|
237
|
-
enableV2,
|
|
238
|
-
enableV1,
|
|
239
|
-
enableVDom,
|
|
240
|
-
mpUploadOptions,
|
|
241
|
-
});
|
|
242
|
-
this.emit('compile-project-done');
|
|
243
|
-
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.log('Compile project done');
|
|
244
|
-
}
|
|
245
|
-
catch (stats) {
|
|
246
|
-
let error;
|
|
247
|
-
if (stats instanceof Error) {
|
|
248
|
-
error = stats;
|
|
249
|
-
}
|
|
250
|
-
else {
|
|
251
|
-
const { errors } = stats || {};
|
|
252
|
-
error = new Error(errors.join('\n\n'));
|
|
253
|
-
}
|
|
254
|
-
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.log('Compile project failed', error);
|
|
255
|
-
this.emit('compile-project-fail', error);
|
|
256
|
-
throw error;
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
compileAndZip(opts) {
|
|
261
|
-
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
262
|
-
const { can_upload_ext_json, upload_app_id, entryType } = opts;
|
|
263
|
-
try {
|
|
264
|
-
const appJsonContent = this.project.appJsonContent;
|
|
123
|
+
// 使用的编译目标包类型
|
|
124
|
+
getUsingPackageType() {
|
|
125
|
+
return __awaiter(this, arguments, void 0, function* (entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
126
|
+
var _a, _b;
|
|
127
|
+
const { libFeatures } = this.compilerProps;
|
|
128
|
+
let enableV1 = false;
|
|
129
|
+
let enableV2 = true;
|
|
130
|
+
let enableVDom = false;
|
|
265
131
|
const settings = this.project.settings || {};
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
let compressJs = false;
|
|
272
|
-
let enableSourcemap = true;
|
|
273
|
-
if (entryType === constant_config_1.COMPILE_ENTRY.upload || entryType === constant_config_1.COMPILE_ENTRY.preview) {
|
|
274
|
-
compressJs = true;
|
|
275
|
-
enableSourcemap = false;
|
|
132
|
+
const isUpload = entryType === constant_config_1.COMPILE_ENTRY.upload;
|
|
133
|
+
if (this.project.appMode === constant_config_1.MiniMode.minigame) {
|
|
134
|
+
enableV1 = true;
|
|
135
|
+
enableV2 = false;
|
|
136
|
+
enableVDom = false;
|
|
276
137
|
}
|
|
277
|
-
else if (
|
|
278
|
-
|
|
138
|
+
else if (entryType === constant_config_1.COMPILE_ENTRY.simulator) {
|
|
139
|
+
const supportV2 = (_a = libFeatures === null || libFeatures === void 0 ? void 0 : libFeatures.supportV2) !== null && _a !== void 0 ? _a : true;
|
|
140
|
+
const supportVDom = (_b = libFeatures === null || libFeatures === void 0 ? void 0 : libFeatures.supportVdom) !== null && _b !== void 0 ? _b : true;
|
|
141
|
+
// 模拟器预览模式下,按照基础库是否支持相关功能 + 用户是否勾选进行判断
|
|
142
|
+
enableV2 = supportV2 && settings.enableV2;
|
|
143
|
+
// 开启v2不编译vdom
|
|
144
|
+
enableVDom = !enableV2 && supportVDom && settings.enableVDom;
|
|
145
|
+
enableV1 = !enableV2;
|
|
279
146
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
147
|
+
else {
|
|
148
|
+
// 上传模式下按照勾选开启
|
|
149
|
+
enableVDom = settings.enableVDom;
|
|
150
|
+
enableV2 = settings.enableV2;
|
|
151
|
+
enableV1 = true;
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
285
154
|
enableV1,
|
|
286
|
-
|
|
287
|
-
|
|
155
|
+
enableV2,
|
|
156
|
+
enableVDom
|
|
288
157
|
};
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
// 根据使用的场景或者配置,采用不同的compiler类型
|
|
161
|
+
getCompilerType(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
162
|
+
const isGame = this.project.appMode === constant_config_1.MiniMode.minigame;
|
|
163
|
+
const settings = this.project.projectJsonContent.setting || {};
|
|
164
|
+
// 使用旧编译
|
|
165
|
+
if (isGame || !settings.useNewCompiler) {
|
|
166
|
+
return entryType === constant_config_1.COMPILE_ENTRY.simulator ? constant_config_1.COMPILER_TYPE.legacy_dev : constant_config_1.COMPILER_TYPE.legacy_build;
|
|
167
|
+
}
|
|
168
|
+
// 使用新编译
|
|
169
|
+
return entryType === constant_config_1.COMPILE_ENTRY.simulator
|
|
170
|
+
? constant_config_1.COMPILER_TYPE.dev
|
|
171
|
+
: entryType === constant_config_1.COMPILE_ENTRY.upload
|
|
172
|
+
? constant_config_1.COMPILER_TYPE.legacy_build
|
|
173
|
+
: constant_config_1.COMPILER_TYPE.build;
|
|
174
|
+
}
|
|
175
|
+
getDistDir(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
176
|
+
const { mpCompileDirPath } = this.getCompilerDir();
|
|
177
|
+
const compilerType = this.getCompilerType(entryType);
|
|
178
|
+
const basename = path_1.default.basename(this.project.projectPath);
|
|
179
|
+
const hash = (0, utils_1.getMd5)(this.project.projectPath).slice(0, 8);
|
|
180
|
+
const distDir = path_1.default.join(path_1.default.resolve(mpCompileDirPath, `${basename}_${hash}`), compilerType);
|
|
181
|
+
fs_extra_1.default.ensureDirSync(distDir);
|
|
182
|
+
return distDir;
|
|
183
|
+
}
|
|
184
|
+
removeDistDir(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
185
|
+
const distDir = this.getDistDir(entryType);
|
|
186
|
+
if (fs_extra_1.default.existsSync(distDir)) {
|
|
187
|
+
fs_extra_1.default.removeSync(distDir);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
getCacheDir(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
191
|
+
const { mpCompileCachePath } = this.getCompilerDir();
|
|
192
|
+
const compilerType = this.getCompilerType(entryType);
|
|
193
|
+
const basename = path_1.default.basename(this.project.projectPath);
|
|
194
|
+
const hash = (0, utils_1.getMd5)(this.project.projectPath).slice(0, 8);
|
|
195
|
+
const distDir = path_1.default.join(path_1.default.resolve(mpCompileCachePath, `${basename}_${hash}`), compilerType);
|
|
196
|
+
fs_extra_1.default.ensureDirSync(distDir);
|
|
197
|
+
return distDir;
|
|
198
|
+
}
|
|
199
|
+
removeCacheDir(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
200
|
+
const cacheDir = this.getCacheDir(entryType);
|
|
201
|
+
if (fs_extra_1.default.existsSync(cacheDir)) {
|
|
202
|
+
fs_extra_1.default.removeSync(cacheDir);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
createCompilerImpl(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
206
|
+
const { nodeJsPath, mpDevJsonPath } = this.compilerProps;
|
|
207
|
+
const distDir = this.getDistDir(entryType);
|
|
208
|
+
const cacheDir = this.getCacheDir(entryType);
|
|
209
|
+
const compilerType = this.getCompilerType(entryType);
|
|
210
|
+
compilerType === constant_config_1.COMPILER_TYPE.legacy_dev || compilerType === constant_config_1.COMPILER_TYPE.legacy_build
|
|
211
|
+
? constant_config_2.PACK_MODE.WEBPACK
|
|
212
|
+
: constant_config_2.PACK_MODE.MPPACK;
|
|
213
|
+
const options = {
|
|
214
|
+
projectPath: this.project.projectPath,
|
|
215
|
+
appMode: this.project.appMode,
|
|
216
|
+
extJsonPath: this.project.extJsonDir,
|
|
217
|
+
platform: 'xhs',
|
|
218
|
+
distDir,
|
|
219
|
+
cacheDirectory: cacheDir
|
|
220
|
+
};
|
|
221
|
+
this.removeDistDir(entryType);
|
|
222
|
+
this.removeCacheDir(entryType);
|
|
223
|
+
const CompilerClass = (0, compiler_1.getProjectCompilerClass)(compilerType);
|
|
224
|
+
const compilerImpl = new CompilerClass(options, {
|
|
225
|
+
logger: this.logger,
|
|
226
|
+
nodeJsPath
|
|
227
|
+
});
|
|
228
|
+
return compilerImpl;
|
|
229
|
+
}
|
|
230
|
+
makePkgsReady(config) {
|
|
231
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
+
const entryType = constant_config_1.COMPILE_ENTRY.simulator;
|
|
233
|
+
const compilerImpl = this.getComilerImpl(entryType);
|
|
234
|
+
yield compilerImpl.makePkgsReady(config);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
reCompilePkgs(config) {
|
|
238
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
239
|
+
const entryType = constant_config_1.COMPILE_ENTRY.simulator;
|
|
240
|
+
const compilerImpl = this.getComilerImpl(entryType);
|
|
241
|
+
yield compilerImpl.reCompilePkgs(config);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
compileProject(config) {
|
|
245
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
246
|
+
var _a, _b, _c;
|
|
247
|
+
try {
|
|
248
|
+
const { entryType } = config;
|
|
249
|
+
this.emit('compile-project-start');
|
|
250
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.log('Compile project...');
|
|
251
|
+
const compilerImpl = this.getComilerImpl(entryType);
|
|
252
|
+
yield compilerImpl.build(config);
|
|
253
|
+
this.emit('compile-project-done');
|
|
254
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.log('Compile project done');
|
|
303
255
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
256
|
+
catch (stats) {
|
|
257
|
+
let error;
|
|
258
|
+
if (stats instanceof Error) {
|
|
259
|
+
error = stats;
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
const { errors } = stats || {};
|
|
263
|
+
error = new Error(errors.join('\n\n'));
|
|
264
|
+
}
|
|
265
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.log('Compile project failed', error);
|
|
266
|
+
this.emit('compile-project-fail', error);
|
|
267
|
+
throw error;
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
compileAndZip(opts) {
|
|
272
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
273
|
+
var _a;
|
|
274
|
+
const { can_upload_ext_json, upload_app_id, entryType } = opts;
|
|
275
|
+
try {
|
|
276
|
+
const appJsonContent = this.project.appJsonContent;
|
|
277
|
+
const settings = this.project.settings || {};
|
|
278
|
+
let subPackages = appJsonContent.subPackages || appJsonContent.subpackages || [];
|
|
279
|
+
const formatGameAppJSON = this.project.formatGameAppJSON;
|
|
280
|
+
subPackages =
|
|
281
|
+
this.project.appMode === constant_config_1.MiniMode.miniprogram ? subPackages : formatGameAppJSON(subPackages);
|
|
282
|
+
const { enableV2, enableV1, enableVDom } = yield this.getUsingPackageType(entryType);
|
|
283
|
+
let compressJs = false;
|
|
284
|
+
let compressCss = false;
|
|
285
|
+
let enableSourcemap = true;
|
|
286
|
+
let appendSourcemapComment = true;
|
|
287
|
+
let runInServiceSandbox = false;
|
|
288
|
+
if (entryType === constant_config_1.COMPILE_ENTRY.preview) {
|
|
289
|
+
compressCss = true;
|
|
290
|
+
compressJs = true;
|
|
291
|
+
}
|
|
292
|
+
else if (entryType === constant_config_1.COMPILE_ENTRY.upload) {
|
|
293
|
+
compressCss = true;
|
|
294
|
+
compressJs = true;
|
|
295
|
+
appendSourcemapComment = false;
|
|
296
|
+
}
|
|
297
|
+
else { // 真机调试
|
|
298
|
+
compressCss = false;
|
|
299
|
+
compressJs = (_a = settings.minified) !== null && _a !== void 0 ? _a : false;
|
|
300
|
+
runInServiceSandbox = true;
|
|
301
|
+
}
|
|
302
|
+
const buildConfig = {
|
|
303
|
+
entryType,
|
|
304
|
+
compressCss,
|
|
305
|
+
compressJs,
|
|
306
|
+
enableSourcemap,
|
|
307
|
+
appendSourcemapComment,
|
|
308
|
+
runInServiceSandbox,
|
|
309
|
+
enableV2,
|
|
310
|
+
enableV1,
|
|
311
|
+
enableVDom,
|
|
312
|
+
mpUploadOptions: this.project.appMode === constant_config_1.MiniMode.miniprogram && opts
|
|
313
|
+
};
|
|
314
|
+
// 编译
|
|
315
|
+
this.emit('compile-and-zip-status', { status: 'build-start' });
|
|
316
|
+
yield this.compileProject(buildConfig);
|
|
317
|
+
this.emit('compile-and-zip-status', { status: 'build-done' });
|
|
318
|
+
// 生成zip
|
|
319
|
+
this.emit('compile-and-zip-status', { status: 'zip-start' });
|
|
320
|
+
let entryZips = [];
|
|
321
|
+
if (entryType === constant_config_1.COMPILE_ENTRY.preview) {
|
|
322
|
+
entryZips = [
|
|
323
|
+
this.zipWithFullPackage(opts, subPackages, 'v0'),
|
|
324
|
+
this.zipWithSubPackage(opts, subPackages, 'v1'),
|
|
325
|
+
// 小程序模式有v2包
|
|
326
|
+
enableV2 && this.zipWithSubPackage(opts, subPackages, 'v2')
|
|
327
|
+
];
|
|
328
|
+
}
|
|
329
|
+
else if (entryType === constant_config_1.COMPILE_ENTRY.upload) {
|
|
330
|
+
entryZips = [
|
|
331
|
+
this.zipWithFullPackage(opts, subPackages, 'v0', true),
|
|
332
|
+
this.zipWithSubPackage(opts, subPackages, 'v1', true),
|
|
333
|
+
// 小程序模式有v2包
|
|
334
|
+
enableV2 && this.zipWithSubPackage(opts, subPackages, 'v2', true)
|
|
335
|
+
];
|
|
310
336
|
}
|
|
311
337
|
else {
|
|
312
|
-
//
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
338
|
+
// 真机调试
|
|
339
|
+
entryZips = [this.zipWithSubPackage(opts, subPackages, enableV2 ? 'v2' : 'v1')];
|
|
340
|
+
}
|
|
341
|
+
const zipTask = yield Promise.all(entryZips.filter(Boolean));
|
|
342
|
+
const zipResult = zipTask.flat(2);
|
|
343
|
+
this.emit('compile-and-zip-status', { status: 'zip-done' });
|
|
344
|
+
// change ext
|
|
345
|
+
if (entryType === constant_config_1.COMPILE_ENTRY.preview || entryType === constant_config_1.COMPILE_ENTRY.upload) {
|
|
346
|
+
this.project.changeExtJsonPermission(!!can_upload_ext_json);
|
|
319
347
|
}
|
|
348
|
+
resolve(zipResult);
|
|
320
349
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
this.emit('compile-and-zip-status', { status: 'zip-done' });
|
|
324
|
-
// change ext
|
|
325
|
-
if (entryType === constant_config_1.COMPILE_ENTRY.preview || entryType === constant_config_1.COMPILE_ENTRY.upload) {
|
|
326
|
-
this.project.changeExtJsonPermission(!!can_upload_ext_json);
|
|
350
|
+
catch (error) {
|
|
351
|
+
reject(error);
|
|
327
352
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
/* 使用v0的入口,zip整包 */
|
|
345
|
-
zipWithFullPackage(opts_1) {
|
|
346
|
-
return __awaiter(this, arguments, void 0, function* (opts, subPackages = [], type) {
|
|
347
|
-
const project = this.project;
|
|
348
|
-
const { upload_app_id, can_upload_ext_json, pkgInfo, entryType } = opts;
|
|
349
|
-
const buildDir = this.getDistDir(entryType);
|
|
350
|
-
const appendFile = [];
|
|
351
|
-
const appendBuffer = [];
|
|
352
|
-
appendFile.push(project.projectJsonPath); // zip添加project.config.json
|
|
353
|
-
/* 是否需要上传ext.json */
|
|
354
|
-
if (can_upload_ext_json && fs_extra_1.default.existsSync(project.extJsonPath)) {
|
|
355
|
-
appendFile.push(project.extJsonPath);
|
|
356
|
-
}
|
|
357
|
-
if (pkgInfo) {
|
|
358
|
-
/* 是否需要额外添加pkgInfo.json信息 */
|
|
359
|
-
const content = { version: pkgInfo.version };
|
|
360
|
-
const contentStr = JSON.stringify(content);
|
|
361
|
-
appendBuffer.push({
|
|
362
|
-
name: 'pkgInfo.json',
|
|
363
|
-
buffer: Buffer.from(contentStr, 'utf-8')
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
const zipConfig = {
|
|
367
|
-
outputDir: path_1.default.resolve(buildDir, `${type}-full-pack.zip`), // 输出的路径
|
|
368
|
-
type,
|
|
369
|
-
inputDir: path_1.default.resolve(buildDir, !subPackages.length ? 'v1' : 'v0' // 如果没有开启分包,则把v1包当作v0包
|
|
370
|
-
), // 输入的路径
|
|
371
|
-
ignore: [],
|
|
372
|
-
prefix: upload_app_id,
|
|
373
|
-
appendFile,
|
|
374
|
-
appendBuffer,
|
|
375
|
-
meta: {
|
|
376
|
-
root: ''
|
|
353
|
+
}));
|
|
354
|
+
}
|
|
355
|
+
/* 使用v0的入口,zip整包 */
|
|
356
|
+
zipWithFullPackage(opts_1) {
|
|
357
|
+
return __awaiter(this, arguments, void 0, function* (opts, subPackages = [], type, excludeSourcemap) {
|
|
358
|
+
const project = this.project;
|
|
359
|
+
const { upload_app_id, can_upload_ext_json, pkgInfo, entryType } = opts;
|
|
360
|
+
const buildDir = this.getDistDir(entryType);
|
|
361
|
+
const appendFile = [];
|
|
362
|
+
const appendBuffer = [];
|
|
363
|
+
appendFile.push(project.projectJsonPath); // zip添加project.config.json
|
|
364
|
+
/* 是否需要上传ext.json */
|
|
365
|
+
if (can_upload_ext_json && fs_extra_1.default.existsSync(project.extJsonPath)) {
|
|
366
|
+
appendFile.push(project.extJsonPath);
|
|
377
367
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
if (can_upload_ext_json && fs_extra_1.default.existsSync(project.extJsonPath)) {
|
|
396
|
-
appendFile.push(project.extJsonPath);
|
|
397
|
-
}
|
|
398
|
-
if (pkgInfo) {
|
|
399
|
-
/* 是否需要额外添加pkgInfo.json信息 */
|
|
400
|
-
const content = { version: pkgInfo.version };
|
|
401
|
-
const contentStr = JSON.stringify(content);
|
|
402
|
-
appendBuffer.push({
|
|
403
|
-
name: 'pkgInfo.json',
|
|
404
|
-
buffer: Buffer.from(contentStr, 'utf-8')
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
/* 分包的zip配置 */
|
|
408
|
-
const zipConfig = [
|
|
409
|
-
{
|
|
410
|
-
outputDir: path_1.default.resolve(buildDir, `${type}-main-pack.zip`), // 输出的路径
|
|
368
|
+
if (pkgInfo) {
|
|
369
|
+
/* 是否需要额外添加pkgInfo.json信息 */
|
|
370
|
+
const content = { version: pkgInfo.version };
|
|
371
|
+
const contentStr = JSON.stringify(content);
|
|
372
|
+
appendBuffer.push({
|
|
373
|
+
name: 'pkgInfo.json',
|
|
374
|
+
buffer: Buffer.from(contentStr, 'utf-8')
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
let ignore = [];
|
|
378
|
+
if (excludeSourcemap) {
|
|
379
|
+
ignore = ['**/*.map'];
|
|
380
|
+
}
|
|
381
|
+
const tasks = [];
|
|
382
|
+
const baseZipConfig = {
|
|
383
|
+
inputDir: path_1.default.resolve(buildDir, !subPackages.length ? 'v1' : 'v0' // 如果没有开启分包,则把v1包当作v0包
|
|
384
|
+
), // 输入的路径
|
|
411
385
|
type,
|
|
386
|
+
prefix: upload_app_id,
|
|
387
|
+
meta: {
|
|
388
|
+
root: ''
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
tasks.push((0, project_1.zipFactory)(Object.assign(Object.assign({}, baseZipConfig), { pattern: '**/*', ignore,
|
|
392
|
+
appendFile,
|
|
393
|
+
appendBuffer, outputDir: path_1.default.resolve(buildDir, `${type}-full-pack.zip`) // 输出的路径
|
|
394
|
+
})));
|
|
395
|
+
if (excludeSourcemap) {
|
|
396
|
+
tasks.push((0, project_1.zipFactory)(Object.assign(Object.assign({}, baseZipConfig), { pattern: '**/*.map', ignore: [], appendFile: [], appendBuffer: [], outputDir: path_1.default.resolve(buildDir, `${type}-full-pack-sourcemap.zip`) // 输出的路径
|
|
397
|
+
})));
|
|
398
|
+
}
|
|
399
|
+
return Promise.all(tasks);
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
/* 使用v1的入口。zip主包和分包 */
|
|
403
|
+
zipWithSubPackage(opts, subPackages, type, excludeSourcemap) {
|
|
404
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
405
|
+
const project = this.project;
|
|
406
|
+
const { can_upload_ext_json, pkgInfo, entryType } = opts;
|
|
407
|
+
const isRemoteDebug = entryType === constant_config_1.COMPILE_ENTRY.remotedebug;
|
|
408
|
+
const appendFile = []; // 额外的文件
|
|
409
|
+
const appendBuffer = [];
|
|
410
|
+
appendFile.push(project.projectJsonPath); // zip添加project.config.json
|
|
411
|
+
const buildDir = this.getDistDir(entryType);
|
|
412
|
+
const mainEntry = path_1.default.resolve(buildDir, type);
|
|
413
|
+
// 主包里需要忽略分包的路径
|
|
414
|
+
const mainIgnore = (subPackages || []).map((item) => item.root.endsWith('/') ? `${item.root}**` : `${item.root}/**`);
|
|
415
|
+
const subIgnore = [];
|
|
416
|
+
if (excludeSourcemap) {
|
|
417
|
+
mainIgnore.push('**/*.map');
|
|
418
|
+
subIgnore.push('**/*.map');
|
|
419
|
+
}
|
|
420
|
+
/* 是否需要上传ext.json */
|
|
421
|
+
if (can_upload_ext_json && fs_extra_1.default.existsSync(project.extJsonPath)) {
|
|
422
|
+
appendFile.push(project.extJsonPath);
|
|
423
|
+
}
|
|
424
|
+
if (pkgInfo) {
|
|
425
|
+
/* 是否需要额外添加pkgInfo.json信息 */
|
|
426
|
+
const content = { version: pkgInfo.version };
|
|
427
|
+
const contentStr = JSON.stringify(content);
|
|
428
|
+
appendBuffer.push({
|
|
429
|
+
name: 'pkgInfo.json',
|
|
430
|
+
buffer: Buffer.from(contentStr, 'utf-8')
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
const tasks = [];
|
|
434
|
+
// // 主包
|
|
435
|
+
tasks.push((0, project_1.zipFactory)({
|
|
412
436
|
inputDir: mainEntry, // 输入的路径
|
|
413
|
-
|
|
437
|
+
type,
|
|
414
438
|
prefix: '',
|
|
415
|
-
appendFile,
|
|
416
|
-
appendBuffer,
|
|
417
439
|
meta: {
|
|
418
440
|
root: '/'
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
|
|
441
|
+
},
|
|
442
|
+
pattern: '**/*',
|
|
443
|
+
ignore: mainIgnore,
|
|
444
|
+
appendFile,
|
|
445
|
+
appendBuffer,
|
|
446
|
+
outputDir: path_1.default.resolve(buildDir, `${type}-main-pack.zip`) // 输出的路径
|
|
447
|
+
}));
|
|
448
|
+
(subPackages || []).forEach((item, index) => {
|
|
422
449
|
const pkgRoot = item.root.replace(/\//g, constant_config_1.PKG_ROOT_SEP);
|
|
423
|
-
|
|
424
|
-
outputDir: path_1.default.resolve(buildDir, `${type}-sub-pack-${isRemoteDebug ? pkgRoot : index}.zip`),
|
|
425
|
-
type,
|
|
450
|
+
tasks.push((0, project_1.zipFactory)({
|
|
426
451
|
inputDir: path_1.default.resolve(buildDir, type, item.root),
|
|
427
|
-
ignore: [],
|
|
428
452
|
prefix: `${item.root}`,
|
|
453
|
+
appendFile: [],
|
|
454
|
+
appendBuffer: [],
|
|
455
|
+
pattern: '**/*',
|
|
456
|
+
ignore: subIgnore,
|
|
457
|
+
type,
|
|
429
458
|
meta: {
|
|
430
459
|
root: item.root
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
460
|
+
},
|
|
461
|
+
outputDir: path_1.default.resolve(buildDir, `${type}-sub-pack-${isRemoteDebug ? pkgRoot : index}.zip`)
|
|
462
|
+
}));
|
|
463
|
+
});
|
|
464
|
+
// sourcemap
|
|
465
|
+
if (excludeSourcemap) {
|
|
466
|
+
tasks.push((0, project_1.zipFactory)({
|
|
467
|
+
inputDir: mainEntry, // 输入的路径
|
|
468
|
+
pattern: '**/*.map',
|
|
469
|
+
ignore: [],
|
|
470
|
+
appendFile: [],
|
|
471
|
+
appendBuffer: [],
|
|
472
|
+
type,
|
|
473
|
+
prefix: '',
|
|
474
|
+
meta: {
|
|
475
|
+
root: '/'
|
|
476
|
+
},
|
|
477
|
+
outputDir: path_1.default.resolve(buildDir, `${type}-pack-sourcemap.zip`) // 输出的路径
|
|
478
|
+
}));
|
|
479
|
+
}
|
|
480
|
+
return Promise.all(tasks);
|
|
481
|
+
});
|
|
443
482
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
483
|
+
close(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
484
|
+
const compilerType = this.getCompilerType(entryType);
|
|
485
|
+
const compiler = this.compilerImplMap[compilerType];
|
|
486
|
+
if (compiler) {
|
|
487
|
+
compiler.close();
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
kill(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
491
|
+
const compilerType = this.getCompilerType(entryType);
|
|
492
|
+
const compiler = this.compilerImplMap[compilerType];
|
|
493
|
+
if (!compiler) {
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
compiler.kill();
|
|
497
|
+
delete this.compilerImplMap[entryType];
|
|
450
498
|
}
|
|
451
|
-
compiler.kill();
|
|
452
|
-
delete this.compilerImplMap[entryType];
|
|
453
499
|
}
|
|
454
|
-
|
|
455
|
-
|
|
500
|
+
exports.ProjectCompiler = ProjectCompiler;
|
|
501
|
+
});
|