@aiot-toolkit/aiotpack 2.0.4-beta.3 → 2.0.4-beta.5
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/afterCompile/ux/UxAfterCompile.js +2 -2
- package/lib/compiler/javascript/JavascriptCompiler.js +37 -24
- package/lib/compiler/javascript/android/plugin/WrapPlugin.js +1 -1
- package/lib/compiler/javascript/vela/plugin/WrapPlugin.d.ts +1 -0
- package/lib/compiler/javascript/vela/plugin/WrapPlugin.js +32 -16
- package/lib/compiler/javascript/vela/utils/ZipUtil.d.ts +2 -1
- package/lib/compiler/javascript/vela/utils/ZipUtil.js +7 -6
- package/lib/utils/BeforeCompileUtils.js +1 -1
- package/lib/utils/ux/UxFileUtils.d.ts +1 -1
- package/lib/utils/ux/UxFileUtils.js +3 -3
- package/package.json +6 -6
|
@@ -164,7 +164,7 @@ class UxAfterCompile {
|
|
|
164
164
|
outputPath,
|
|
165
165
|
completeFeature
|
|
166
166
|
} = compilerOption;
|
|
167
|
-
const content = _UxFileUtils.default.
|
|
167
|
+
const content = _UxFileUtils.default.getManifestInfo(projectPath, sourceRoot);
|
|
168
168
|
const translateCache = context.translateCache;
|
|
169
169
|
if (!content.minAPILevel) {
|
|
170
170
|
content.minAPILevel = 1;
|
|
@@ -232,7 +232,7 @@ class UxAfterCompile {
|
|
|
232
232
|
const content = Object.keys(comment).map(key => `${key}=${comment[key]}`).join('\n');
|
|
233
233
|
_fsExtra.default.outputFileSync(_path.default.join(outputAbsPath, _ZipUtil.default.BUILD_FILE_PATH), content);
|
|
234
234
|
// cert
|
|
235
|
-
const files = _ZipUtil.default.getSortedFiles(outputAbsPath, compilerOption, _UxFileUtils.default.
|
|
235
|
+
const files = _ZipUtil.default.getSortedFiles(outputAbsPath, compilerOption, _UxFileUtils.default.getManifestInfo(projectPath, sourceRoot));
|
|
236
236
|
const digestDic = Object.fromEntries(files.map(item => [item, _sharedUtils.CommonUtil.calcDataDigest(_fsExtra.default.readFileSync(_path.default.join(outputAbsPath, item))).toString('hex')]));
|
|
237
237
|
const hashJson = [{
|
|
238
238
|
path: _ZipUtil.default.DIGEST_HASH_JSON,
|
|
@@ -16,31 +16,37 @@ class JavascriptCompiler {
|
|
|
16
16
|
QUICKAPP_CONFIG = 'quickapp.config.js';
|
|
17
17
|
async compile(param) {
|
|
18
18
|
return new Promise(async (resolve, reject) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
warnings
|
|
32
|
-
} = statsObj;
|
|
33
|
-
if (errors?.length || warnings?.length) {
|
|
34
|
-
reject({
|
|
19
|
+
try {
|
|
20
|
+
await this.clean(param);
|
|
21
|
+
const config = this.createWebpackConfig(param);
|
|
22
|
+
(0, _core.rspack)(config, (error, stats) => {
|
|
23
|
+
if (error) {
|
|
24
|
+
reject({
|
|
25
|
+
errors: [error]
|
|
26
|
+
});
|
|
27
|
+
} else {
|
|
28
|
+
const statsObj = stats?.toJson({});
|
|
29
|
+
if (statsObj) {
|
|
30
|
+
const {
|
|
35
31
|
errors,
|
|
36
32
|
warnings
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
} = statsObj;
|
|
34
|
+
if (errors?.length || warnings?.length) {
|
|
35
|
+
reject({
|
|
36
|
+
errors,
|
|
37
|
+
warnings
|
|
38
|
+
});
|
|
39
|
+
} else {
|
|
40
|
+
resolve();
|
|
41
|
+
}
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
|
-
}
|
|
43
|
-
})
|
|
44
|
+
});
|
|
45
|
+
} catch (error) {
|
|
46
|
+
reject({
|
|
47
|
+
errors: [error]
|
|
48
|
+
});
|
|
49
|
+
}
|
|
44
50
|
});
|
|
45
51
|
}
|
|
46
52
|
createWebpackConfig(param) {
|
|
@@ -62,7 +68,7 @@ class JavascriptCompiler {
|
|
|
62
68
|
} = param;
|
|
63
69
|
const buildPath = _path.default.resolve(projectPath, outputPath);
|
|
64
70
|
const quickAppConfig = _sharedUtils.CommonUtil.requireModule(_path.default.join(param.projectPath, this.QUICKAPP_CONFIG));
|
|
65
|
-
|
|
71
|
+
let result = {
|
|
66
72
|
context: projectPath,
|
|
67
73
|
mode,
|
|
68
74
|
devtool: devtool,
|
|
@@ -128,12 +134,19 @@ class JavascriptCompiler {
|
|
|
128
134
|
configurator.hook(result);
|
|
129
135
|
}
|
|
130
136
|
|
|
131
|
-
//
|
|
132
|
-
|
|
137
|
+
// 合并用户自定义的webpack配置
|
|
138
|
+
// 数组,则合并数组(默认合并数组中相同序号的项)
|
|
139
|
+
result = _lodash.default.mergeWith({}, result, quickAppConfig?.webpack, (source, target) => {
|
|
133
140
|
if (Array.isArray(target) && Array.isArray(source)) {
|
|
134
141
|
return [...target, ...source];
|
|
135
142
|
}
|
|
136
143
|
});
|
|
144
|
+
|
|
145
|
+
// 触发用户配置的posthook
|
|
146
|
+
if (quickAppConfig?.postHook) {
|
|
147
|
+
quickAppConfig.postHook(result);
|
|
148
|
+
}
|
|
149
|
+
return result;
|
|
137
150
|
}
|
|
138
151
|
getConfigurator(param) {
|
|
139
152
|
const {
|
|
@@ -77,7 +77,7 @@ class WrapPlugin {
|
|
|
77
77
|
return new _webpackSources.ConcatSource(`
|
|
78
78
|
(function () {
|
|
79
79
|
var $app_define_wrap$ = $app_define_wrap$ || function () {};
|
|
80
|
-
var manifestJson =${JSON.stringify(_UxFileUtils.default.
|
|
80
|
+
var manifestJson =${JSON.stringify(_UxFileUtils.default.getManifestInfo(projectPath, sourceRoot))}
|
|
81
81
|
var createAppHandler = function () {
|
|
82
82
|
`, source, `
|
|
83
83
|
}
|
|
@@ -31,6 +31,8 @@ class WrapPlugin {
|
|
|
31
31
|
entrys.forEach(entry => {
|
|
32
32
|
if (compilation.assets[entry]) {
|
|
33
33
|
const source = compilation.assets[entry];
|
|
34
|
+
const isApp = entry === 'app.js';
|
|
35
|
+
const createFuncnName = isApp ? 'createAppHandler' : 'createPageHandler';
|
|
34
36
|
compilation.assets[entry] = new _webpackSources.ConcatSource(`
|
|
35
37
|
export default function(global, globalThis, window, $app_exports$, $app_evaluate$){
|
|
36
38
|
var org_app_require = $app_require$;
|
|
@@ -43,30 +45,44 @@ class WrapPlugin {
|
|
|
43
45
|
var $app_require$ = global.$app_require$ || org_app_require
|
|
44
46
|
|
|
45
47
|
${enableE2e ? `globalThis = undefined; \n global = typeof window === "undefined" ? global.__proto__ : window;` : ''}
|
|
46
|
-
|
|
47
48
|
// 转换动态 style 的函数
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return Object.fromEntries(value.split(';').filter(item => Boolean(item && item.trim())).map(
|
|
51
|
-
item => {
|
|
52
|
-
const matchs = item.match(/([^:]+):(.*)/)
|
|
53
|
-
if (matchs && matchs.length> 2) {
|
|
54
|
-
return [matchs[1].trim().replace(/-([a-z])/g, (_, match) => match.toUpperCase()), matchs[2].trim()]
|
|
55
|
-
}
|
|
56
|
-
return []
|
|
57
|
-
}))}
|
|
58
|
-
return value
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
var createPageHandler = function() {
|
|
49
|
+
${isApp ? this.translateStyleFunc() : ''}
|
|
50
|
+
var ${createFuncnName} = function() {
|
|
62
51
|
return `, source, `
|
|
63
52
|
}
|
|
64
53
|
|
|
65
|
-
return
|
|
54
|
+
return ${createFuncnName}();
|
|
66
55
|
})(global, globalThis, window, $app_exports$, $app_evaluate$)
|
|
67
56
|
}`);
|
|
68
57
|
}
|
|
69
58
|
});
|
|
70
59
|
}
|
|
60
|
+
translateStyleFunc() {
|
|
61
|
+
return `
|
|
62
|
+
var $translateStyle$ = function (value) {
|
|
63
|
+
if (typeof value === 'string') {
|
|
64
|
+
return Object.fromEntries(
|
|
65
|
+
value
|
|
66
|
+
.split(';')
|
|
67
|
+
.filter((item) => Boolean(item && item.trim()))
|
|
68
|
+
.map((item) => {
|
|
69
|
+
const matchs = item.match(/([^:]+):(.*)/);
|
|
70
|
+
if (matchs && matchs.length > 2) {
|
|
71
|
+
return [
|
|
72
|
+
matchs[1]
|
|
73
|
+
.trim()
|
|
74
|
+
.replace(/-([a-z])/g, (_, match) => match.toUpperCase()),
|
|
75
|
+
matchs[2].trim(),
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
return [];
|
|
79
|
+
})
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
return value;
|
|
83
|
+
};
|
|
84
|
+
global.$translateStyle$ = $translateStyle$
|
|
85
|
+
`;
|
|
86
|
+
}
|
|
71
87
|
}
|
|
72
88
|
var _default = exports.default = WrapPlugin;
|
|
@@ -72,9 +72,10 @@ declare class ZipUtil {
|
|
|
72
72
|
*
|
|
73
73
|
* @param dist 打包后的文件目录的绝对路径
|
|
74
74
|
* @param param 打包参数
|
|
75
|
+
* @param manifest manifest.json内容的json对象
|
|
75
76
|
* @returns
|
|
76
77
|
*/
|
|
77
|
-
static getSortedFiles(dist: string, param: IJavascriptCompileOption,
|
|
78
|
+
static getSortedFiles(dist: string, param: IJavascriptCompileOption, manifest: IManifest): string[];
|
|
78
79
|
/**
|
|
79
80
|
* 根据 **固定规则**、**manifest.json入口配置**,获取压缩文件时使用的排序规则
|
|
80
81
|
*
|
|
@@ -58,7 +58,7 @@ class ZipUtil {
|
|
|
58
58
|
* @returns 生成的 rpk 文件名
|
|
59
59
|
*/
|
|
60
60
|
static async createRpk(dist, param) {
|
|
61
|
-
const config = _UxFileUtils.default.
|
|
61
|
+
const config = _UxFileUtils.default.getManifestInfo(param.projectPath, param.sourceRoot);
|
|
62
62
|
|
|
63
63
|
// 1
|
|
64
64
|
const files = this.getSortedFiles(dist, param, config);
|
|
@@ -117,7 +117,7 @@ class ZipUtil {
|
|
|
117
117
|
} = param;
|
|
118
118
|
const filePath = _path.default.join(projectPath, releasePath, fileName);
|
|
119
119
|
_fsExtra.default.outputFileSync(filePath, buffer);
|
|
120
|
-
_sharedUtils.ColorConsole.success(`Project build and generate files:${
|
|
120
|
+
_sharedUtils.ColorConsole.success(`Project build and generate files:${filePath}`);
|
|
121
121
|
return fileName;
|
|
122
122
|
}
|
|
123
123
|
|
|
@@ -196,10 +196,11 @@ class ZipUtil {
|
|
|
196
196
|
*
|
|
197
197
|
* @param dist 打包后的文件目录的绝对路径
|
|
198
198
|
* @param param 打包参数
|
|
199
|
+
* @param manifest manifest.json内容的json对象
|
|
199
200
|
* @returns
|
|
200
201
|
*/
|
|
201
|
-
static getSortedFiles(dist, param,
|
|
202
|
-
const priorities = this.getPriorities(
|
|
202
|
+
static getSortedFiles(dist, param, manifest) {
|
|
203
|
+
const priorities = this.getPriorities(manifest);
|
|
203
204
|
const getFileIndex = file => {
|
|
204
205
|
const result = priorities.findIndex(item => {
|
|
205
206
|
if (typeof item === 'string') {
|
|
@@ -234,11 +235,11 @@ class ZipUtil {
|
|
|
234
235
|
* @param param
|
|
235
236
|
* @returns
|
|
236
237
|
*/
|
|
237
|
-
static getPriorities(
|
|
238
|
+
static getPriorities(manifest) {
|
|
238
239
|
const entrySkFiles = []; // todo
|
|
239
240
|
const {
|
|
240
241
|
entry
|
|
241
|
-
} =
|
|
242
|
+
} = manifest.router;
|
|
242
243
|
const result = ['META-INF/CERT',
|
|
243
244
|
// 多语言配置文件要在 manifest 之前
|
|
244
245
|
/^i18n\/.+\.json$/i,
|
|
@@ -33,7 +33,7 @@ class BeforeCompileUtils {
|
|
|
33
33
|
} = context;
|
|
34
34
|
const srcPath = _path.default.join(projectPath, compilerOption.sourceRoot);
|
|
35
35
|
// 判断路径是否真实存在
|
|
36
|
-
const manifestContent = _UxFileUtils.default.
|
|
36
|
+
const manifestContent = _UxFileUtils.default.getManifestInfo(projectPath);
|
|
37
37
|
// 存储entries
|
|
38
38
|
let entryList = [];
|
|
39
39
|
const {
|
|
@@ -15,7 +15,7 @@ export declare class UxFileUtils {
|
|
|
15
15
|
* @param sourceRoot
|
|
16
16
|
* @returns
|
|
17
17
|
*/
|
|
18
|
-
static
|
|
18
|
+
static getManifestInfo(projectPath: string, sourceRoot?: string): IManifest;
|
|
19
19
|
/**
|
|
20
20
|
* 检查 manifest文件,并显示错误信息
|
|
21
21
|
*
|
|
@@ -30,7 +30,7 @@ class UxFileUtils {
|
|
|
30
30
|
* @param sourceRoot
|
|
31
31
|
* @returns
|
|
32
32
|
*/
|
|
33
|
-
static
|
|
33
|
+
static getManifestInfo(projectPath) {
|
|
34
34
|
let sourceRoot = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'src';
|
|
35
35
|
return _fsExtra.default.readJSONSync(UxFileUtils.getManifestFilePath(projectPath, sourceRoot));
|
|
36
36
|
}
|
|
@@ -55,7 +55,7 @@ class UxFileUtils {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
// 1
|
|
58
|
-
const jsonData = this.
|
|
58
|
+
const jsonData = this.getManifestInfo(projectPath, sourceRoot);
|
|
59
59
|
const schema = _ManifestSchema.default;
|
|
60
60
|
const errors = _CommonUtil.default.validateJson(jsonData, schema) || [];
|
|
61
61
|
|
|
@@ -87,7 +87,7 @@ class UxFileUtils {
|
|
|
87
87
|
const sitemapPath = _path.default.join(projectPath, sourceRoot, 'sitemap.json');
|
|
88
88
|
if (_fsExtra.default.existsSync(sitemapPath)) {
|
|
89
89
|
const rules = _fsExtra.default.readJSONSync(sitemapPath).rules;
|
|
90
|
-
const manifest = this.
|
|
90
|
+
const manifest = this.getManifestInfo(projectPath, sourceRoot);
|
|
91
91
|
const pages = Object.keys(manifest.router.pages || {});
|
|
92
92
|
const errorList = [];
|
|
93
93
|
rules.forEach((item, index) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiot-toolkit/aiotpack",
|
|
3
|
-
"version": "2.0.4-beta.
|
|
3
|
+
"version": "2.0.4-beta.5",
|
|
4
4
|
"description": "The process tool for packaging aiot projects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aiotpack"
|
|
@@ -19,16 +19,16 @@
|
|
|
19
19
|
"test": "node ./__tests__/aiotpack.test.js"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@aiot-toolkit/generator": "2.0.4-beta.
|
|
23
|
-
"@aiot-toolkit/parser": "2.0.4-beta.
|
|
24
|
-
"@aiot-toolkit/shared-utils": "2.0.4-beta.
|
|
22
|
+
"@aiot-toolkit/generator": "2.0.4-beta.5",
|
|
23
|
+
"@aiot-toolkit/parser": "2.0.4-beta.5",
|
|
24
|
+
"@aiot-toolkit/shared-utils": "2.0.4-beta.5",
|
|
25
25
|
"@hap-toolkit/aaptjs": "^2.0.0",
|
|
26
26
|
"@rspack/core": "^1.1.8",
|
|
27
27
|
"aiot-parse5": "^1.0.0",
|
|
28
28
|
"archiver": "^7.0.1",
|
|
29
29
|
"babel-loader": "^9.1.3",
|
|
30
30
|
"fast-glob": "^3.3.2",
|
|
31
|
-
"file-lane": "2.0.4-beta.
|
|
31
|
+
"file-lane": "2.0.4-beta.5",
|
|
32
32
|
"file-loader": "^6.2.0",
|
|
33
33
|
"fs-extra": "^11.2.0",
|
|
34
34
|
"jsrsasign": "^11.1.0",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"@types/jsrsasign": "^10.5.12",
|
|
47
47
|
"@types/webpack-sources": "^3.2.3"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "10c27c5047aa68522c09dc54c79d283b39b1fd8a"
|
|
50
50
|
}
|