@aiot-toolkit/aiotpack 2.0.5-alpha.1 → 2.0.5-beta.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/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/interface/IJavascriptCompileOption.d.ts +13 -0
- package/lib/compiler/javascript/vela/plugin/WrapPlugin.d.ts +1 -0
- package/lib/compiler/javascript/vela/plugin/WrapPlugin.js +31 -17
- package/lib/compiler/javascript/vela/utils/ZipUtil.d.ts +2 -1
- package/lib/compiler/javascript/vela/utils/ZipUtil.js +8 -7
- package/lib/compiler/javascript/vela/utils/signature/SignUtil.d.ts +2 -2
- package/lib/compiler/javascript/vela/utils/signature/SignUtil.js +7 -5
- package/lib/loader/ux/JsLoader.d.ts +1 -1
- package/lib/loader/ux/JsLoader.js +20 -17
- package/lib/loader/ux/android/UxLoader.js +1 -8
- package/lib/loader/ux/vela/AppUxLoader.js +1 -8
- package/lib/loader/ux/vela/UxLoader.js +1 -5
- 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/lib/utils/ux/UxLoaderUtils.js +28 -1
- package/package.json +7 -7
|
@@ -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
|
}
|
|
@@ -56,4 +56,17 @@ export default interface IJavascriptCompileOption extends ICompileParam {
|
|
|
56
56
|
* 是否自动补全 manifest.json 中的 features 配置
|
|
57
57
|
*/
|
|
58
58
|
completeFeature?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* 获取远程证书
|
|
61
|
+
*/
|
|
62
|
+
signRequest?: () => Promise<{
|
|
63
|
+
/**
|
|
64
|
+
* 证书私钥
|
|
65
|
+
*/
|
|
66
|
+
privatekey: Buffer;
|
|
67
|
+
/**
|
|
68
|
+
* 证书
|
|
69
|
+
*/
|
|
70
|
+
certificate: Buffer;
|
|
71
|
+
}>;
|
|
59
72
|
}
|
|
@@ -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,42 @@ 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
|
-
// 转换动态 style 的函数
|
|
48
|
-
var $translateStyle$ = function (value) {
|
|
49
|
-
if (typeof value === 'string') {
|
|
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() {
|
|
48
|
+
var ${createFuncnName} = function() {
|
|
62
49
|
return `, source, `
|
|
63
50
|
}
|
|
64
51
|
|
|
65
|
-
return
|
|
52
|
+
return ${createFuncnName}();
|
|
66
53
|
})(global, globalThis, window, $app_exports$, $app_evaluate$)
|
|
67
54
|
}`);
|
|
68
55
|
}
|
|
69
56
|
});
|
|
70
57
|
}
|
|
58
|
+
translateStyleFunc() {
|
|
59
|
+
return `
|
|
60
|
+
var $translateStyle$ = function (value) {
|
|
61
|
+
if (typeof value === 'string') {
|
|
62
|
+
return Object.fromEntries(
|
|
63
|
+
value
|
|
64
|
+
.split(';')
|
|
65
|
+
.filter((item) => Boolean(item && item.trim()))
|
|
66
|
+
.map((item) => {
|
|
67
|
+
const matchs = item.match(/([^:]+):(.*)/);
|
|
68
|
+
if (matchs && matchs.length > 2) {
|
|
69
|
+
return [
|
|
70
|
+
matchs[1]
|
|
71
|
+
.trim()
|
|
72
|
+
.replace(/-([a-z])/g, (_, match) => match.toUpperCase()),
|
|
73
|
+
matchs[2].trim(),
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
return [];
|
|
77
|
+
})
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
return value;
|
|
81
|
+
};
|
|
82
|
+
global.$translateStyle$ = $translateStyle$
|
|
83
|
+
`;
|
|
84
|
+
}
|
|
71
85
|
}
|
|
72
86
|
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);
|
|
@@ -73,7 +73,7 @@ class ZipUtil {
|
|
|
73
73
|
} = await this.createPackagesDefinition(param, config, files);
|
|
74
74
|
|
|
75
75
|
// 生产出带签名的rpk文件buffer
|
|
76
|
-
const signConfig = _SignUtil.default.getProjectSignConfig(param);
|
|
76
|
+
const signConfig = await _SignUtil.default.getProjectSignConfig(param);
|
|
77
77
|
const rpkBuffer = await ZipUtil.buildProjectAndOutput(fullPackage, signConfig);
|
|
78
78
|
// 3
|
|
79
79
|
return this.generateDistFile(rpkBuffer, param, this.getFileName(param, config, 'rpk'));
|
|
@@ -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,
|
|
@@ -9,10 +9,10 @@ declare class SignUtil {
|
|
|
9
9
|
* @param param IJavascriptCompileOption参数中获取签名目录等内容
|
|
10
10
|
* @returns
|
|
11
11
|
*/
|
|
12
|
-
static getProjectSignConfig(param: IJavascriptCompileOption): {
|
|
12
|
+
static getProjectSignConfig(param: IJavascriptCompileOption): Promise<{
|
|
13
13
|
privatekey: Buffer;
|
|
14
14
|
certificate: Buffer;
|
|
15
|
-
}
|
|
15
|
+
}>;
|
|
16
16
|
/**
|
|
17
17
|
* 对二进制zipBuffer签名
|
|
18
18
|
*
|
|
@@ -25,12 +25,16 @@ class SignUtil {
|
|
|
25
25
|
* @param param IJavascriptCompileOption参数中获取签名目录等内容
|
|
26
26
|
* @returns
|
|
27
27
|
*/
|
|
28
|
-
static getProjectSignConfig(param) {
|
|
28
|
+
static async getProjectSignConfig(param) {
|
|
29
29
|
const {
|
|
30
30
|
mode,
|
|
31
31
|
projectPath,
|
|
32
|
-
signRoot
|
|
32
|
+
signRoot,
|
|
33
|
+
signRequest
|
|
33
34
|
} = param;
|
|
35
|
+
if (signRequest) {
|
|
36
|
+
return signRequest();
|
|
37
|
+
}
|
|
34
38
|
const signPathFolder = _path.default.join(projectPath, signRoot || 'sign');
|
|
35
39
|
const signPathConfig = {
|
|
36
40
|
debug: {
|
|
@@ -55,7 +59,6 @@ class SignUtil {
|
|
|
55
59
|
// release模式 优先sign/release/证书 其次sign/证书
|
|
56
60
|
const releaseSignConfig = [signPathConfig.oldRelease, signPathConfig.sign];
|
|
57
61
|
let modeSignConfig = [];
|
|
58
|
-
let signConfig;
|
|
59
62
|
switch (mode) {
|
|
60
63
|
case _CompileMode.default.DEVELOPMENT:
|
|
61
64
|
modeSignConfig = developmentSignConfig;
|
|
@@ -87,7 +90,7 @@ class SignUtil {
|
|
|
87
90
|
word: certificatePath
|
|
88
91
|
});
|
|
89
92
|
// 读取证书内容
|
|
90
|
-
|
|
93
|
+
return {
|
|
91
94
|
privatekey: _fsExtra.default.readFileSync(privatekeyPath),
|
|
92
95
|
certificate: _fsExtra.default.readFileSync(certificatePath)
|
|
93
96
|
};
|
|
@@ -95,7 +98,6 @@ class SignUtil {
|
|
|
95
98
|
// 抛出错误,在指定模式下未找到证书
|
|
96
99
|
throw new Error(`The current mode is ${mode}, and there is a problem with the certification path`);
|
|
97
100
|
}
|
|
98
|
-
return signConfig;
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
/**
|
|
@@ -6,6 +6,6 @@ import IJavascriptCompileOption from '../../compiler/javascript/interface/IJavas
|
|
|
6
6
|
declare class JsLoader implements ILoader {
|
|
7
7
|
context: IFileLaneContext;
|
|
8
8
|
compilerOption: IJavascriptCompileOption;
|
|
9
|
-
parser(files: IFileParam<any>[]):
|
|
9
|
+
parser(files: IFileParam<any>[]): Promise<IFileParam<any>[]>;
|
|
10
10
|
}
|
|
11
11
|
export default JsLoader;
|
|
@@ -10,29 +10,32 @@ var _sharedUtils = require("@aiot-toolkit/shared-utils");
|
|
|
10
10
|
* JsLoader
|
|
11
11
|
*/
|
|
12
12
|
class JsLoader {
|
|
13
|
-
parser(files) {
|
|
13
|
+
async parser(files) {
|
|
14
14
|
const onLog = () => {};
|
|
15
|
-
|
|
15
|
+
const result = [];
|
|
16
|
+
for (const item of files) {
|
|
16
17
|
if (!item.content) {
|
|
17
|
-
|
|
18
|
+
result.push({
|
|
18
19
|
path: item.path,
|
|
19
20
|
content: item.content
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
const options = {
|
|
24
|
+
filePath: item.path,
|
|
25
|
+
projectPath: this.context.projectPath,
|
|
26
|
+
content: item.content.toString(),
|
|
27
|
+
projectType: _sharedUtils.ProjectType.getProjectType(this.context.projectPath),
|
|
28
|
+
onLog
|
|
20
29
|
};
|
|
30
|
+
result.push({
|
|
31
|
+
path: item.path,
|
|
32
|
+
content: (await new _parser.ScriptToTypescript(options, this.compilerOption, this.context).translate({
|
|
33
|
+
content: new _parser.ScriptParser(options).parser(item.content.toString()).ast.content
|
|
34
|
+
}, [])).targetTree.getFullText()
|
|
35
|
+
});
|
|
21
36
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
projectPath: this.context.projectPath,
|
|
25
|
-
content: item.content.toString(),
|
|
26
|
-
projectType: _sharedUtils.ProjectType.getProjectType(this.context.projectPath),
|
|
27
|
-
onLog
|
|
28
|
-
};
|
|
29
|
-
return {
|
|
30
|
-
path: item.path,
|
|
31
|
-
content: new _parser.ScriptToTypescript(options, this.compilerOption, this.context).translate({
|
|
32
|
-
content: new _parser.ScriptParser(options).parser(item.content.toString()).ast.content
|
|
33
|
-
}, []).targetTree.getFullText()
|
|
34
|
-
};
|
|
35
|
-
});
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
var _default = exports.default = JsLoader;
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _path = _interopRequireDefault(require("path"));
|
|
8
7
|
var _AndroidUx = _interopRequireDefault(require("../../../utils/ux/android/AndroidUx"));
|
|
9
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
9
|
/**
|
|
@@ -13,9 +12,6 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
13
12
|
class UxLoader {
|
|
14
13
|
async parser(files) {
|
|
15
14
|
const result = [];
|
|
16
|
-
const {
|
|
17
|
-
projectPath
|
|
18
|
-
} = this.context;
|
|
19
15
|
for (let item of files) {
|
|
20
16
|
const {
|
|
21
17
|
files,
|
|
@@ -25,10 +21,7 @@ class UxLoader {
|
|
|
25
21
|
file: item,
|
|
26
22
|
compilerOption: this.compilerOption
|
|
27
23
|
});
|
|
28
|
-
this.logs = logs
|
|
29
|
-
...item,
|
|
30
|
-
filePath: item.filePath ? _path.default.relative(projectPath, item.filePath) : ''
|
|
31
|
-
}));
|
|
24
|
+
this.logs = logs;
|
|
32
25
|
result.push(...files);
|
|
33
26
|
}
|
|
34
27
|
return result;
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _path = _interopRequireDefault(require("path"));
|
|
8
7
|
var _UxLoaderUtils = _interopRequireDefault(require("../../../utils/ux/UxLoaderUtils"));
|
|
9
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
9
|
/**
|
|
@@ -13,17 +12,11 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
13
12
|
*/
|
|
14
13
|
class AppUxLoader {
|
|
15
14
|
async parser(files) {
|
|
16
|
-
const {
|
|
17
|
-
projectPath
|
|
18
|
-
} = this.context;
|
|
19
15
|
const {
|
|
20
16
|
files: resultFiles,
|
|
21
17
|
logs
|
|
22
18
|
} = await _UxLoaderUtils.default.compileAppUxToJavascript(files[0], this.context, this.compilerOption);
|
|
23
|
-
this.logs = logs
|
|
24
|
-
...item,
|
|
25
|
-
filePath: item.filePath ? _path.default.relative(projectPath, item.filePath) : ''
|
|
26
|
-
}));
|
|
19
|
+
this.logs = logs;
|
|
27
20
|
return resultFiles;
|
|
28
21
|
}
|
|
29
22
|
}
|
|
@@ -4,15 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _path = _interopRequireDefault(require("path"));
|
|
8
7
|
var _UxLoaderUtils = _interopRequireDefault(require("../../../utils/ux/UxLoaderUtils"));
|
|
9
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
9
|
class UxLoader {
|
|
11
10
|
async parser(files) {
|
|
12
11
|
const resultFiles = [];
|
|
13
|
-
const {
|
|
14
|
-
projectPath
|
|
15
|
-
} = this.context;
|
|
16
12
|
for (const file of files) {
|
|
17
13
|
// 转换每个文件
|
|
18
14
|
const {
|
|
@@ -22,7 +18,7 @@ class UxLoader {
|
|
|
22
18
|
this.logs = logs.map(item => {
|
|
23
19
|
return {
|
|
24
20
|
...item,
|
|
25
|
-
filePath: item.position?.source
|
|
21
|
+
filePath: item.position?.source || item.filePath
|
|
26
22
|
};
|
|
27
23
|
});
|
|
28
24
|
resultFiles.push(...compiledFiles);
|
|
@@ -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) => {
|
|
@@ -115,11 +115,38 @@ class UxLoaderUtils {
|
|
|
115
115
|
// 区分app.ux和一般ux
|
|
116
116
|
// app.ux解析结果中加上manifest.json的内容
|
|
117
117
|
const manifestJson = `require('./manifest.json')`;
|
|
118
|
+
function translateStyleFunc() {
|
|
119
|
+
return `
|
|
120
|
+
var $translateStyle$ = function (value) {
|
|
121
|
+
if (typeof value === 'string') {
|
|
122
|
+
return Object.fromEntries(
|
|
123
|
+
value
|
|
124
|
+
.split(';')
|
|
125
|
+
.filter((item) => Boolean(item && item.trim()))
|
|
126
|
+
.map((item) => {
|
|
127
|
+
const matchs = item.match(/([^:]+):(.*)/);
|
|
128
|
+
if (matchs && matchs.length > 2) {
|
|
129
|
+
return [
|
|
130
|
+
matchs[1]
|
|
131
|
+
.trim()
|
|
132
|
+
.replace(/-([a-z])/g, (_, match) => match.toUpperCase()),
|
|
133
|
+
matchs[2].trim(),
|
|
134
|
+
];
|
|
135
|
+
}
|
|
136
|
+
return [];
|
|
137
|
+
})
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
return value;
|
|
141
|
+
};
|
|
142
|
+
global.$translateStyle$ = $translateStyle$
|
|
143
|
+
`;
|
|
144
|
+
}
|
|
118
145
|
const integrateFunction = (appImport, appStyleTree, appTemplateTree, appScriptTree) => {
|
|
119
146
|
const scriptCode = appScriptTree.getText();
|
|
120
147
|
const hasScript = Boolean(scriptCode) && scriptCode !== '""';
|
|
121
148
|
// script代码放在第三个位置不能变化,影响更新source map
|
|
122
|
-
return isAppUx ? [`${appImport.join('\n')}`, `var $app_style$ = ${UxLoaderUtils.wrapStyle(appStyleTree, file, compilerOption)}`, hasScript ? `var $app_script$ = ${UxLoaderUtils.wrapScript(false, appScriptTree)}` : '', hasScript ? `$app_script$({}, $app_exports$, $app_require$);` : `$app_exports$.default = {}`, `$app_exports$.default.style = $app_style$;`, `$app_exports$.default.manifest = ${manifestJson}
|
|
149
|
+
return isAppUx ? [`${appImport.join('\n')}`, `var $app_style$ = ${UxLoaderUtils.wrapStyle(appStyleTree, file, compilerOption)}`, hasScript ? `var $app_script$ = ${UxLoaderUtils.wrapScript(false, appScriptTree)}` : '', hasScript ? `$app_script$({}, $app_exports$, $app_require$);` : `$app_exports$.default = {}`, `$app_exports$.default.style = $app_style$;`, `$app_exports$.default.manifest = ${manifestJson}`, translateStyleFunc()] : [`${appImport.join('\n')}`, `var $app_style$ = ${UxLoaderUtils.wrapStyle(appStyleTree, file, compilerOption)}`, hasScript ? `var $app_script$ = ${UxLoaderUtils.wrapScript(isPageUx, appScriptTree)}` : '', `var $app_template$ = ${UxLoaderUtils.wrapTempalte(appTemplateTree, file, compilerOption)}`, `${UxLoaderUtils.getReturnType(isPageUx)} function ($app_exports$) {`, hasScript ? `$app_script$({}, $app_exports$, $app_require$);` : `$app_exports$.default = {}`, `$app_exports$.default.template = $app_template$;`, `$app_exports$.default.style = $app_style$;`, `}`];
|
|
123
150
|
};
|
|
124
151
|
const {
|
|
125
152
|
targetTree,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiot-toolkit/aiotpack",
|
|
3
|
-
"version": "2.0.5-
|
|
3
|
+
"version": "2.0.5-beta.10",
|
|
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.5-
|
|
23
|
-
"@aiot-toolkit/parser": "2.0.5-
|
|
24
|
-
"@aiot-toolkit/shared-utils": "2.0.5-
|
|
22
|
+
"@aiot-toolkit/generator": "2.0.5-beta.10",
|
|
23
|
+
"@aiot-toolkit/parser": "2.0.5-beta.10",
|
|
24
|
+
"@aiot-toolkit/shared-utils": "2.0.5-beta.10",
|
|
25
25
|
"@hap-toolkit/aaptjs": "^2.0.0",
|
|
26
26
|
"@rspack/core": "^1.1.8",
|
|
27
|
-
"aiot-parse5": "^1.0.
|
|
27
|
+
"aiot-parse5": "^1.0.2",
|
|
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.5-
|
|
31
|
+
"file-lane": "2.0.5-beta.10",
|
|
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": "b2403dbd071d5a6ae33b27f49c6f47ba95861477"
|
|
50
50
|
}
|