@aiot-toolkit/aiotpack 2.0.6-beta.2 → 2.0.6-beta.20
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 +51 -16
- package/lib/compiler/javascript/interface/IJavascriptCompileOption.d.ts +5 -0
- package/lib/compiler/javascript/vela/VelaWebpackConfigurator.d.ts +3 -1
- package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js +16 -1
- package/lib/compiler/javascript/vela/interface/IManifest.d.ts +13 -0
- package/lib/compiler/javascript/vela/utils/UxCompileUtil.d.ts +3 -2
- package/lib/compiler/javascript/vela/utils/UxCompileUtil.js +3 -4
- package/lib/compiler/javascript/vela/utils/webpackLoader/IWebpackLoaderOption.d.ts +2 -0
- package/lib/compiler/javascript/vela/utils/webpackLoader/WebpackJsLoader.js +1 -1
- package/lib/compiler/javascript/vela/utils/webpackLoader/WebpackUxLoader.js +3 -2
- package/lib/config/UxConfig.d.ts +10 -5
- package/lib/config/UxConfig.js +2 -5
- package/lib/loader/ux/JsLoader.d.ts +4 -0
- package/lib/loader/ux/JsLoader.js +16 -5
- package/lib/loader/ux/android/UxLoader.d.ts +2 -0
- package/lib/loader/ux/android/UxLoader.js +2 -1
- package/lib/loader/ux/vela/AppUxLoader.d.ts +2 -0
- package/lib/loader/ux/vela/AppUxLoader.js +1 -1
- package/lib/loader/ux/vela/HmlLoader.d.ts +6 -6
- package/lib/loader/ux/vela/HmlLoader.js +30 -13
- package/lib/loader/ux/vela/UxLoader.d.ts +2 -0
- package/lib/loader/ux/vela/UxLoader.js +2 -2
- package/lib/utils/BeforeCompileUtils.d.ts +1 -3
- package/lib/utils/BeforeCompileUtils.js +28 -9
- package/lib/utils/ux/UxLoaderUtils.d.ts +10 -3
- package/lib/utils/ux/UxLoaderUtils.js +47 -8
- package/lib/utils/ux/android/AndroidUx.d.ts +2 -0
- package/lib/utils/ux/android/AndroidUx.js +5 -4
- package/package.json +6 -6
|
@@ -18,6 +18,7 @@ var _FileLaneTriggerType = _interopRequireDefault(require("file-lane/lib/enum/Fi
|
|
|
18
18
|
var _ZipFileUtil = _interopRequireDefault(require("@aiot-toolkit/shared-utils/lib/utils/ZipFileUtil"));
|
|
19
19
|
var _ImageIcu = _interopRequireDefault(require("../../compiler/tools/icu/ImageIcu"));
|
|
20
20
|
var _LiteCard = _interopRequireDefault(require("../../compiler/javascript/vela/utils/LiteCard"));
|
|
21
|
+
var _UxUtil = _interopRequireDefault(require("@aiot-toolkit/parser/lib/ux/utils/UxUtil"));
|
|
21
22
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
22
23
|
const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
|
|
23
24
|
|
|
@@ -39,7 +40,10 @@ class UxAfterCompile {
|
|
|
39
40
|
..._JavascriptDefaultCompileOption.default,
|
|
40
41
|
...compilerOption
|
|
41
42
|
}).then(() => {
|
|
42
|
-
|
|
43
|
+
onLog?.([{
|
|
44
|
+
level: _sharedUtils.Loglevel.SUCCESS,
|
|
45
|
+
message: ['javascript compile success']
|
|
46
|
+
}]);
|
|
43
47
|
}).catch(_ref => {
|
|
44
48
|
let {
|
|
45
49
|
errors,
|
|
@@ -64,10 +68,16 @@ class UxAfterCompile {
|
|
|
64
68
|
});
|
|
65
69
|
}
|
|
66
70
|
if (errors?.length) {
|
|
67
|
-
|
|
71
|
+
onLog?.([{
|
|
72
|
+
level: _sharedUtils.Loglevel.THROW,
|
|
73
|
+
message: messages
|
|
74
|
+
}]);
|
|
68
75
|
throw new Error();
|
|
69
76
|
} else {
|
|
70
|
-
|
|
77
|
+
onLog?.([{
|
|
78
|
+
level: _sharedUtils.Loglevel.WARN,
|
|
79
|
+
message: messages
|
|
80
|
+
}]);
|
|
71
81
|
}
|
|
72
82
|
});
|
|
73
83
|
};
|
|
@@ -91,13 +101,13 @@ class UxAfterCompile {
|
|
|
91
101
|
static toRpk = async params => {
|
|
92
102
|
const {
|
|
93
103
|
compilerOption,
|
|
94
|
-
|
|
104
|
+
compilation,
|
|
95
105
|
context
|
|
96
106
|
} = params;
|
|
97
107
|
if (compilerOption) {
|
|
98
108
|
const fileName = await _ZipUtil.default.createRpk(_path.default.join(compilerOption.projectPath, compilerOption.outputPath), compilerOption);
|
|
99
|
-
if (
|
|
100
|
-
|
|
109
|
+
if (compilation && fileName) {
|
|
110
|
+
compilation.info.rpk = _path.default.join(context.projectPath, compilerOption.releasePath, fileName);
|
|
101
111
|
}
|
|
102
112
|
return fileName;
|
|
103
113
|
}
|
|
@@ -187,13 +197,15 @@ class UxAfterCompile {
|
|
|
187
197
|
}
|
|
188
198
|
|
|
189
199
|
// feature
|
|
200
|
+
// 无需检查的feature
|
|
201
|
+
const ignoreFeatureList = ['system.router', 'system.configuration', 'system.app'];
|
|
190
202
|
if (translateCache?.featureCache.size) {
|
|
191
203
|
// 消息提示
|
|
192
204
|
// 1. 获取未手动配置的 feature
|
|
193
205
|
// 2. 如果开启自动填充,则 info;否则 warn
|
|
194
206
|
const featureSet = new Set([...Array.from(translateCache.featureCache), ...(content.features || []).map(item => item.name)]);
|
|
195
207
|
const usedList = Array.from(featureSet).filter(Boolean);
|
|
196
|
-
const unSetList = usedList.filter(featureItem => !content.features?.find(item => item.name === featureItem));
|
|
208
|
+
const unSetList = usedList.filter(featureItem => !ignoreFeatureList.includes(featureItem) && !content.features?.find(item => item.name === featureItem));
|
|
197
209
|
if (unSetList?.length) {
|
|
198
210
|
const featureMessage = {
|
|
199
211
|
word: `\n${JSON.stringify(unSetList.map(item => ({
|
|
@@ -228,6 +240,28 @@ class UxAfterCompile {
|
|
|
228
240
|
});
|
|
229
241
|
}
|
|
230
242
|
}
|
|
243
|
+
|
|
244
|
+
// e2e
|
|
245
|
+
if (compilerOption.e2eConfigPath && compilerOption.enableE2e) {
|
|
246
|
+
const testConfig = _UxUtil.default.getE2eConfig({
|
|
247
|
+
projectPath: compilerOption.projectPath,
|
|
248
|
+
e2eConfigPath: compilerOption.e2eConfigPath
|
|
249
|
+
});
|
|
250
|
+
const testPagePath = _path.default.parse(_path.default.relative(_path.default.join(compilerOption.projectPath, sourceRoot), _path.default.join(testConfig.dir, testConfig.entry.path)).replaceAll(_path.default.sep, _path.default.posix.sep));
|
|
251
|
+
// 1. 修改entry
|
|
252
|
+
const entryName = testPagePath.dir;
|
|
253
|
+
const launchMode = testConfig.entry?.launchMode;
|
|
254
|
+
if (entryName) {
|
|
255
|
+
content.router.entry = entryName;
|
|
256
|
+
}
|
|
257
|
+
// 2. 添加测试页到router.pages
|
|
258
|
+
if (content.router.pages) {
|
|
259
|
+
content.router.pages[entryName] = {
|
|
260
|
+
component: testPagePath.name,
|
|
261
|
+
launchMode
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
}
|
|
231
265
|
_fsExtra.default.writeJSONSync(_path.default.join(projectPath, outputPath, _UxFileUtils.default.CONFIG_FILE_NAME), content, {
|
|
232
266
|
spaces: 2
|
|
233
267
|
});
|
|
@@ -304,13 +338,13 @@ class UxAfterCompile {
|
|
|
304
338
|
static generateDiff = async params => {
|
|
305
339
|
const {
|
|
306
340
|
compilerOption,
|
|
307
|
-
|
|
341
|
+
compilation,
|
|
308
342
|
context
|
|
309
343
|
} = params;
|
|
310
|
-
if (!compilerOption || !
|
|
344
|
+
if (!compilerOption || !compilation) {
|
|
311
345
|
return;
|
|
312
346
|
}
|
|
313
|
-
if (
|
|
347
|
+
if (compilation.trigger === _FileLaneTriggerType.default.START) {
|
|
314
348
|
return;
|
|
315
349
|
}
|
|
316
350
|
// 读取临时项目build文件夹中所有文件路径
|
|
@@ -318,7 +352,7 @@ class UxAfterCompile {
|
|
|
318
352
|
// 待优化,map文件跟随源文件变化,与时间戳有关文件无需对比
|
|
319
353
|
const tempFileList = _sharedUtils.FileUtil.readAlldirSync(tempBuildDir);
|
|
320
354
|
const buildDir = _path.default.join(context.projectPath, compilerOption.outputPath);
|
|
321
|
-
const diffList = _UxFileUtils.default.getDiffJSON(
|
|
355
|
+
const diffList = _UxFileUtils.default.getDiffJSON(compilation.buildFileList, tempFileList, buildDir, tempBuildDir);
|
|
322
356
|
|
|
323
357
|
// 所有差异文件,压缩到 .diff.rpk 中
|
|
324
358
|
if (diffList?.length) {
|
|
@@ -330,8 +364,8 @@ class UxAfterCompile {
|
|
|
330
364
|
filePath: _path.default.join(buildFold, item),
|
|
331
365
|
zipFilePath: item
|
|
332
366
|
})));
|
|
333
|
-
|
|
334
|
-
|
|
367
|
+
compilation.info.diffList = diffList;
|
|
368
|
+
compilation.info.diffFile = _path.default.join(context.projectPath, compilerOption.releasePath, diffFileName);
|
|
335
369
|
}
|
|
336
370
|
};
|
|
337
371
|
|
|
@@ -411,10 +445,11 @@ class UxAfterCompile {
|
|
|
411
445
|
static compileLiteCard = async params => {
|
|
412
446
|
const {
|
|
413
447
|
compilerOption,
|
|
414
|
-
context
|
|
448
|
+
context,
|
|
449
|
+
compilation
|
|
415
450
|
} = params;
|
|
416
451
|
try {
|
|
417
|
-
if (
|
|
452
|
+
if (compilation && compilation?.liteCards?.length > 0 && compilerOption) {
|
|
418
453
|
const {
|
|
419
454
|
projectPath: tempProjectPath,
|
|
420
455
|
outputPath: LITE_OUTPUT_PATH
|
|
@@ -425,7 +460,7 @@ class UxAfterCompile {
|
|
|
425
460
|
// 1.
|
|
426
461
|
await new _LiteCard.default(projectPath).compileLiteCard();
|
|
427
462
|
// 2.
|
|
428
|
-
|
|
463
|
+
compilation.liteCards.forEach(card => {
|
|
429
464
|
// hap-toolkit的产物在项目的build文件夹下
|
|
430
465
|
const fromPath = _path.default.join(projectPath, LITE_OUTPUT_PATH, card);
|
|
431
466
|
// aiot-toolkit的产物在临时项目的build文件夹下
|
|
@@ -8,7 +8,9 @@ declare class VelaWebpackConfigurator implements IWebpackConfigurator {
|
|
|
8
8
|
protected createWrapPlugin(): RspackPluginInstance;
|
|
9
9
|
protected createBundleAnalyzerPlugin(): any;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* 生成entry
|
|
12
|
+
* 1. 通过读取 manifest.json 生成 entry
|
|
13
|
+
* 2. 通过自动化测试的entry配置生成entry
|
|
12
14
|
* @returns
|
|
13
15
|
*/
|
|
14
16
|
createEntry(): string | EntryObject | string[];
|
|
@@ -9,6 +9,7 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
9
9
|
var _UxFileUtils = _interopRequireDefault(require("../../../utils/ux/UxFileUtils"));
|
|
10
10
|
var _WrapPlugin = _interopRequireDefault(require("./plugin/WrapPlugin"));
|
|
11
11
|
var _UxCompileUtil = _interopRequireDefault(require("./utils/UxCompileUtil"));
|
|
12
|
+
var _UxUtil = _interopRequireDefault(require("@aiot-toolkit/parser/lib/ux/utils/UxUtil"));
|
|
12
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
14
|
class VelaWebpackConfigurator {
|
|
14
15
|
createPlugins() {
|
|
@@ -34,7 +35,9 @@ class VelaWebpackConfigurator {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
|
-
*
|
|
38
|
+
* 生成entry
|
|
39
|
+
* 1. 通过读取 manifest.json 生成 entry
|
|
40
|
+
* 2. 通过自动化测试的entry配置生成entry
|
|
38
41
|
* @returns
|
|
39
42
|
*/
|
|
40
43
|
createEntry() {
|
|
@@ -44,7 +47,19 @@ class VelaWebpackConfigurator {
|
|
|
44
47
|
} = this.param;
|
|
45
48
|
const configFilePath = _UxFileUtils.default.getManifestFilePath(this.param.projectPath, this.param.sourceRoot);
|
|
46
49
|
if (_fsExtra.default.existsSync(configFilePath)) {
|
|
50
|
+
// 1
|
|
47
51
|
const config = _fsExtra.default.readJSONSync(configFilePath);
|
|
52
|
+
// 2
|
|
53
|
+
if (this.param.e2eConfigPath && this.param.enableE2e) {
|
|
54
|
+
const e2eConfig = _UxUtil.default.getE2eConfig({
|
|
55
|
+
projectPath: this.param.projectPath,
|
|
56
|
+
e2eConfigPath: this.param.e2eConfigPath
|
|
57
|
+
});
|
|
58
|
+
const testPagePath = _path.default.parse(_path.default.relative(_path.default.join(this.param.projectPath, sourceRoot), _path.default.join(e2eConfig.dir, e2eConfig.entry.path)).replaceAll(_path.default.sep, _path.default.posix.sep));
|
|
59
|
+
config.router.pages[testPagePath.dir] = {
|
|
60
|
+
component: testPagePath.name
|
|
61
|
+
};
|
|
62
|
+
}
|
|
48
63
|
return _UxCompileUtil.default.resolveEntries(config, _path.default.resolve(projectPath, sourceRoot), projectPath);
|
|
49
64
|
} else {
|
|
50
65
|
throw new Error(`Configuration file does not exist: ${configFilePath}`);
|
|
@@ -29,13 +29,26 @@ export default interface IManifest {
|
|
|
29
29
|
entry: string;
|
|
30
30
|
pages: Dictionary<{
|
|
31
31
|
component?: string;
|
|
32
|
+
launchMode?: string;
|
|
32
33
|
}>;
|
|
34
|
+
floatingWindows?: any;
|
|
33
35
|
};
|
|
36
|
+
services: IService[] | Record<string, IService>;
|
|
34
37
|
minAPILevel?: number;
|
|
35
38
|
packageInfo?: Dictionary<string | number>;
|
|
36
39
|
icon: string;
|
|
40
|
+
workers?: {
|
|
41
|
+
entries: {
|
|
42
|
+
file: string;
|
|
43
|
+
}[];
|
|
44
|
+
};
|
|
37
45
|
}
|
|
38
46
|
export interface IFeatures {
|
|
39
47
|
name: string;
|
|
40
48
|
}
|
|
49
|
+
export interface IService {
|
|
50
|
+
name: string;
|
|
51
|
+
autoStart?: boolean;
|
|
52
|
+
path: string;
|
|
53
|
+
}
|
|
41
54
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Dictionary } from '@aiot-toolkit/shared-utils';
|
|
2
|
+
import IManifest from '../interface/IManifest';
|
|
2
3
|
declare class UxCompileUtil {
|
|
3
4
|
static readonly DIGEST_ZIP_DIR = "META-INF";
|
|
4
5
|
static clean(dirList: string[]): void;
|
|
@@ -7,9 +8,9 @@ declare class UxCompileUtil {
|
|
|
7
8
|
* @param config 项目配置文件的内容,应为json对象
|
|
8
9
|
* @param codeDir 源码目录
|
|
9
10
|
* @param projectPath 项目目录
|
|
10
|
-
* @returns {[
|
|
11
|
+
* @returns `{[entryName]:entryPath}`
|
|
11
12
|
*/
|
|
12
|
-
static resolveEntries(config:
|
|
13
|
+
static resolveEntries(config: IManifest, codeDir: string, projectPath: string): Dictionary<string>;
|
|
13
14
|
/**
|
|
14
15
|
* 通过无后缀的文件名路径获取存在的文件路径
|
|
15
16
|
*
|
|
@@ -36,7 +36,7 @@ class UxCompileUtil {
|
|
|
36
36
|
* @param config 项目配置文件的内容,应为json对象
|
|
37
37
|
* @param codeDir 源码目录
|
|
38
38
|
* @param projectPath 项目目录
|
|
39
|
-
* @returns {[
|
|
39
|
+
* @returns `{[entryName]:entryPath}`
|
|
40
40
|
*/
|
|
41
41
|
static resolveEntries(config, codeDir, projectPath) {
|
|
42
42
|
const {
|
|
@@ -114,11 +114,10 @@ class UxCompileUtil {
|
|
|
114
114
|
if (Array.isArray(services)) {
|
|
115
115
|
services.forEach(item => {
|
|
116
116
|
const {
|
|
117
|
-
name,
|
|
118
117
|
path
|
|
119
118
|
} = item;
|
|
120
|
-
if (
|
|
121
|
-
result[
|
|
119
|
+
if (path) {
|
|
120
|
+
result[path] = './src/' + path + `?uxType=${_EntryType.default.APP}`;
|
|
122
121
|
}
|
|
123
122
|
});
|
|
124
123
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { IFileLaneContext } from 'file-lane';
|
|
2
2
|
import IJavascriptCompileOption from '../../../interface/IJavascriptCompileOption';
|
|
3
3
|
import { ILog } from '@aiot-toolkit/shared-utils';
|
|
4
|
+
import FileLaneCompilation from 'file-lane/lib/FileLaneCompilation';
|
|
4
5
|
/**
|
|
5
6
|
* IWebpackLoaderOption
|
|
6
7
|
*/
|
|
7
8
|
export default interface IWebpackLoaderOption {
|
|
8
9
|
compileParam: IJavascriptCompileOption;
|
|
9
10
|
context: IFileLaneContext;
|
|
11
|
+
compilation: FileLaneCompilation;
|
|
10
12
|
onLog: (log: ILog[]) => void;
|
|
11
13
|
}
|
|
@@ -20,7 +20,7 @@ async function _default(source) {
|
|
|
20
20
|
projectPath: this.rootContext,
|
|
21
21
|
onLog: log => onLog?.([log]),
|
|
22
22
|
projectType: _sharedUtils.ProjectType.VELA_UX
|
|
23
|
-
}, compileParam, context).translate({
|
|
23
|
+
}, compileParam, context, true).translate({
|
|
24
24
|
content: source
|
|
25
25
|
}, []);
|
|
26
26
|
callback(null, result.targetTree.getFullText());
|
|
@@ -11,7 +11,8 @@ async function _default(source) {
|
|
|
11
11
|
const {
|
|
12
12
|
onLog,
|
|
13
13
|
compileParam,
|
|
14
|
-
context
|
|
14
|
+
context,
|
|
15
|
+
compilation
|
|
15
16
|
} = options;
|
|
16
17
|
const callback = this.async();
|
|
17
18
|
const {
|
|
@@ -20,7 +21,7 @@ async function _default(source) {
|
|
|
20
21
|
} = await _UxLoaderUtils.default.compileUxToJavascript({
|
|
21
22
|
path: this.resourcePath,
|
|
22
23
|
content: source
|
|
23
|
-
}, context, false, compileParam);
|
|
24
|
+
}, context, false, compileParam, compilation);
|
|
24
25
|
onLog?.(logs);
|
|
25
26
|
callback(null, compiledFiles[0].content, compiledFiles[1].content);
|
|
26
27
|
}
|
package/lib/config/UxConfig.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import PngLoader from '../loader/ux/PngLoader';
|
|
|
5
5
|
import AppUxLoader from '../loader/ux/vela/AppUxLoader';
|
|
6
6
|
import HmlLoader from '../loader/ux/vela/HmlLoader';
|
|
7
7
|
import UxLoader from '../loader/ux/vela/UxLoader';
|
|
8
|
+
import AndroidUxLoader from '../loader/ux/android/UxLoader';
|
|
8
9
|
import UxBeforeWorks from '../beforeWorks/ux/UxBeforeWorks';
|
|
9
10
|
import UxAfterWorks from '../afterWorks/ux/UxAfterWorks';
|
|
10
11
|
import { IChangedFile } from 'file-lane/lib/interface/IChangedFile';
|
|
@@ -34,7 +35,7 @@ declare class UxConfig implements IFileLaneConfig<IJavascriptCompileOption> {
|
|
|
34
35
|
workerDescribe: string;
|
|
35
36
|
})[];
|
|
36
37
|
afterWorks: (typeof UxAfterWorks.cleanOutput)[];
|
|
37
|
-
watchIgnores:
|
|
38
|
+
watchIgnores: string[];
|
|
38
39
|
/**
|
|
39
40
|
* 通过项目类型,返回模块配置
|
|
40
41
|
*/
|
|
@@ -46,11 +47,7 @@ declare class UxConfig implements IFileLaneConfig<IJavascriptCompileOption> {
|
|
|
46
47
|
} | {
|
|
47
48
|
test: RegExp[];
|
|
48
49
|
exclude: RegExp[];
|
|
49
|
-
loader: (typeof UxLoader)[];
|
|
50
|
-
} | {
|
|
51
|
-
test: RegExp[];
|
|
52
50
|
loader: (typeof HmlLoader | typeof UxLoader)[];
|
|
53
|
-
exclude?: undefined;
|
|
54
51
|
} | {
|
|
55
52
|
test: RegExp[];
|
|
56
53
|
loader: (typeof JsLoader)[];
|
|
@@ -60,6 +57,14 @@ declare class UxConfig implements IFileLaneConfig<IJavascriptCompileOption> {
|
|
|
60
57
|
loader: (typeof PngLoader)[];
|
|
61
58
|
exclude?: undefined;
|
|
62
59
|
})[];
|
|
60
|
+
} | {
|
|
61
|
+
rules: ({
|
|
62
|
+
test: RegExp[];
|
|
63
|
+
loader: (typeof AndroidUxLoader)[];
|
|
64
|
+
} | {
|
|
65
|
+
test: RegExp[];
|
|
66
|
+
loader: (typeof PngLoader)[];
|
|
67
|
+
})[];
|
|
63
68
|
};
|
|
64
69
|
/**
|
|
65
70
|
* 判断项目类型
|
package/lib/config/UxConfig.js
CHANGED
|
@@ -111,7 +111,7 @@ class UxConfig {
|
|
|
111
111
|
workerDescribe: 'Check resource'
|
|
112
112
|
}])();
|
|
113
113
|
afterWorks = (() => [_UxAfterWorks.default.cleanOutput])();
|
|
114
|
-
watchIgnores = [
|
|
114
|
+
watchIgnores = ['**/node_modules/**', '**/build/**', '**/dist/**'];
|
|
115
115
|
|
|
116
116
|
/**
|
|
117
117
|
* 通过项目类型,返回模块配置
|
|
@@ -123,11 +123,8 @@ class UxConfig {
|
|
|
123
123
|
test: ['app.ux'],
|
|
124
124
|
loader: [_AppUxLoader.default]
|
|
125
125
|
}, {
|
|
126
|
-
test: [/.+\.ux$/],
|
|
126
|
+
test: [/.+\.(ux|hml)$/],
|
|
127
127
|
exclude: [/app\.ux/],
|
|
128
|
-
loader: [_UxLoader.default]
|
|
129
|
-
}, {
|
|
130
|
-
test: [/.+\.hml$/],
|
|
131
128
|
loader: [_HmlLoader.default, _UxLoader.default]
|
|
132
129
|
}, {
|
|
133
130
|
test: [/.+\.js$/],
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { IFileLaneContext, IFileParam, ILoader } from 'file-lane';
|
|
2
2
|
import IJavascriptCompileOption from '../../compiler/javascript/interface/IJavascriptCompileOption';
|
|
3
|
+
import { ILog } from '@aiot-toolkit/shared-utils';
|
|
4
|
+
import FileLaneCompilation from 'file-lane/lib/FileLaneCompilation';
|
|
3
5
|
/**
|
|
4
6
|
* JsLoader
|
|
5
7
|
*/
|
|
6
8
|
declare class JsLoader implements ILoader {
|
|
7
9
|
context: IFileLaneContext;
|
|
8
10
|
compilerOption: IJavascriptCompileOption;
|
|
11
|
+
compilation: FileLaneCompilation;
|
|
12
|
+
logs: ILog[];
|
|
9
13
|
parser(files: IFileParam<any>[]): Promise<IFileParam<any>[]>;
|
|
10
14
|
}
|
|
11
15
|
export default JsLoader;
|
|
@@ -6,12 +6,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _parser = require("@aiot-toolkit/parser");
|
|
8
8
|
var _sharedUtils = require("@aiot-toolkit/shared-utils");
|
|
9
|
+
var _UxLoaderUtils = _interopRequireDefault(require("../../utils/ux/UxLoaderUtils"));
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
11
|
/**
|
|
10
12
|
* JsLoader
|
|
11
13
|
*/
|
|
12
14
|
class JsLoader {
|
|
15
|
+
logs = [];
|
|
13
16
|
async parser(files) {
|
|
14
|
-
const onLog = () => {};
|
|
15
17
|
const result = [];
|
|
16
18
|
for (const item of files) {
|
|
17
19
|
if (!item.content) {
|
|
@@ -25,13 +27,22 @@ class JsLoader {
|
|
|
25
27
|
projectPath: this.context.projectPath,
|
|
26
28
|
content: item.content.toString(),
|
|
27
29
|
projectType: _sharedUtils.ProjectType.getProjectType(this.context.projectPath),
|
|
28
|
-
onLog
|
|
30
|
+
onLog: log => {
|
|
31
|
+
this.logs.push(log);
|
|
32
|
+
}
|
|
29
33
|
};
|
|
34
|
+
const scriptTree = await new _parser.ScriptToTypescript(options, this.compilerOption, this.context).translate({
|
|
35
|
+
content: new _parser.ScriptParser(options).parser(item.content.toString()).ast.content
|
|
36
|
+
}, []);
|
|
37
|
+
const isService = _UxLoaderUtils.default.isServiceFile(item.path, {
|
|
38
|
+
compilation: this.compilation,
|
|
39
|
+
compilerOption: this.compilerOption,
|
|
40
|
+
context: this.context
|
|
41
|
+
});
|
|
42
|
+
const content = isService ? _UxLoaderUtils.default.createServiceWrapper(scriptTree.targetTree).filter(Boolean).join('\n') : scriptTree.targetTree.getFullText();
|
|
30
43
|
result.push({
|
|
31
44
|
path: item.path,
|
|
32
|
-
content
|
|
33
|
-
content: new _parser.ScriptParser(options).parser(item.content.toString()).ast.content
|
|
34
|
-
}, [])).targetTree.getFullText()
|
|
45
|
+
content
|
|
35
46
|
});
|
|
36
47
|
}
|
|
37
48
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { ILog } from '@aiot-toolkit/shared-utils';
|
|
2
2
|
import { IFileLaneContext, IFileParam, ILoader } from 'file-lane';
|
|
3
3
|
import IJavascriptCompileOption from '../../../compiler/javascript/interface/IJavascriptCompileOption';
|
|
4
|
+
import FileLaneCompilation from 'file-lane/lib/FileLaneCompilation';
|
|
4
5
|
/**
|
|
5
6
|
* UxLoader
|
|
6
7
|
*/
|
|
7
8
|
declare class UxLoader implements ILoader {
|
|
8
9
|
context: IFileLaneContext;
|
|
9
10
|
compilerOption: IJavascriptCompileOption;
|
|
11
|
+
compilation: FileLaneCompilation;
|
|
10
12
|
logs?: ILog[] | undefined;
|
|
11
13
|
parser(files: IFileParam<any>[]): Promise<IFileParam<any>[]>;
|
|
12
14
|
}
|
|
@@ -19,7 +19,8 @@ class UxLoader {
|
|
|
19
19
|
} = await new _AndroidUx.default().compileUx({
|
|
20
20
|
context: this.context,
|
|
21
21
|
file: item,
|
|
22
|
-
compilerOption: this.compilerOption
|
|
22
|
+
compilerOption: this.compilerOption,
|
|
23
|
+
compilation: this.compilation
|
|
23
24
|
});
|
|
24
25
|
this.logs = logs;
|
|
25
26
|
result.push(...files);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ILog } from '@aiot-toolkit/shared-utils';
|
|
2
2
|
import { IFileLaneContext, IFileParam, ILoader } from 'file-lane';
|
|
3
3
|
import IJavascriptCompileOption from '../../../compiler/javascript/interface/IJavascriptCompileOption';
|
|
4
|
+
import FileLaneCompilation from 'file-lane/lib/FileLaneCompilation';
|
|
4
5
|
/**
|
|
5
6
|
* 处理app.ux的Loader
|
|
6
7
|
* AppUxLoader
|
|
@@ -8,6 +9,7 @@ import IJavascriptCompileOption from '../../../compiler/javascript/interface/IJa
|
|
|
8
9
|
declare class AppUxLoader implements ILoader {
|
|
9
10
|
context: IFileLaneContext;
|
|
10
11
|
compilerOption: IJavascriptCompileOption;
|
|
12
|
+
compilation: FileLaneCompilation;
|
|
11
13
|
logs?: ILog[] | undefined;
|
|
12
14
|
parser(files: IFileParam<any>[]): Promise<IFileParam<any>[]>;
|
|
13
15
|
}
|
|
@@ -15,7 +15,7 @@ class AppUxLoader {
|
|
|
15
15
|
const {
|
|
16
16
|
files: resultFiles,
|
|
17
17
|
logs
|
|
18
|
-
} = await _UxLoaderUtils.default.compileAppUxToJavascript(files[0], this.context, this.compilerOption);
|
|
18
|
+
} = await _UxLoaderUtils.default.compileAppUxToJavascript(files[0], this.context, this.compilerOption, this.compilation);
|
|
19
19
|
this.logs = logs;
|
|
20
20
|
return resultFiles;
|
|
21
21
|
}
|
|
@@ -9,16 +9,16 @@ declare class HmlLoader implements ILoader {
|
|
|
9
9
|
/**
|
|
10
10
|
* 包裹 hml 文件
|
|
11
11
|
*
|
|
12
|
-
* # 路径
|
|
13
|
-
* 如果存在同路径的 ux 后缀,报错;否则转换为同路径的 ux 后缀
|
|
14
|
-
*
|
|
15
12
|
* # 内容
|
|
16
|
-
* 1.
|
|
17
|
-
* 2.
|
|
18
|
-
*
|
|
13
|
+
* 1. 全文模式(存在template、script、style任一节点),保留原内容不变
|
|
14
|
+
* 2. 否则,则进行如下包装
|
|
15
|
+
* 1. hml的内容: import放到最前,其它内容使用<template></template>包裹
|
|
16
|
+
* 2. 如果存在同路径同名的 script文件,则加到<script></script>中
|
|
17
|
+
* 3. 如果存在同路径同名的 style文件,则加到<style></style>中
|
|
19
18
|
*
|
|
20
19
|
* @param file
|
|
21
20
|
*/
|
|
22
21
|
private wrapHml;
|
|
22
|
+
private nodesToString;
|
|
23
23
|
}
|
|
24
24
|
export default HmlLoader;
|
|
@@ -7,6 +7,9 @@ exports.default = void 0;
|
|
|
7
7
|
var _path = _interopRequireDefault(require("path"));
|
|
8
8
|
var _fs = _interopRequireDefault(require("fs"));
|
|
9
9
|
var _parser = require("@aiot-toolkit/parser");
|
|
10
|
+
var parse5 = _interopRequireWildcard(require("aiot-parse5"));
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
10
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
14
|
/**
|
|
12
15
|
* HmlLoader
|
|
@@ -21,13 +24,12 @@ class HmlLoader {
|
|
|
21
24
|
/**
|
|
22
25
|
* 包裹 hml 文件
|
|
23
26
|
*
|
|
24
|
-
* # 路径
|
|
25
|
-
* 如果存在同路径的 ux 后缀,报错;否则转换为同路径的 ux 后缀
|
|
26
|
-
*
|
|
27
27
|
* # 内容
|
|
28
|
-
* 1.
|
|
29
|
-
* 2.
|
|
30
|
-
*
|
|
28
|
+
* 1. 全文模式(存在template、script、style任一节点),保留原内容不变
|
|
29
|
+
* 2. 否则,则进行如下包装
|
|
30
|
+
* 1. hml的内容: import放到最前,其它内容使用<template></template>包裹
|
|
31
|
+
* 2. 如果存在同路径同名的 script文件,则加到<script></script>中
|
|
32
|
+
* 3. 如果存在同路径同名的 style文件,则加到<style></style>中
|
|
31
33
|
*
|
|
32
34
|
* @param file
|
|
33
35
|
*/
|
|
@@ -36,32 +38,47 @@ class HmlLoader {
|
|
|
36
38
|
path,
|
|
37
39
|
content
|
|
38
40
|
} = file;
|
|
39
|
-
const
|
|
41
|
+
const uxAst = parse5.parseFragment(content?.toString() || '', {
|
|
42
|
+
scriptingEnabled: false,
|
|
43
|
+
sourceCodeLocationInfo: true
|
|
44
|
+
});
|
|
45
|
+
const fullMode = uxAst.childNodes.some(node => {
|
|
46
|
+
return ['template', 'script', 'style'].includes(node.nodeName);
|
|
47
|
+
});
|
|
48
|
+
if (fullMode) {
|
|
49
|
+
return file;
|
|
50
|
+
}
|
|
40
51
|
const getFilePath = ext => {
|
|
41
52
|
const pathParsed = _path.default.parse(path);
|
|
42
53
|
pathParsed.ext = ext;
|
|
43
54
|
pathParsed.base = pathParsed.name + ext;
|
|
44
55
|
return _path.default.format(pathParsed);
|
|
45
56
|
};
|
|
46
|
-
const uxPath = getFilePath(uxExt);
|
|
47
|
-
if (_fs.default.existsSync(uxPath)) {
|
|
48
|
-
throw new Error(`${uxPath} already exists`);
|
|
49
|
-
}
|
|
50
57
|
const scriptExts = _parser.ExtensionConfig.SCRIPTS;
|
|
51
58
|
const styleExts = _parser.ExtensionConfig.STYLES;
|
|
52
59
|
const scriptPath = scriptExts.map(item => getFilePath(item)).find(item => _fs.default.existsSync(item));
|
|
53
60
|
const stylePath = styleExts.map(item => getFilePath(item)).find(item => _fs.default.existsSync(item));
|
|
54
|
-
|
|
61
|
+
const importNodes = uxAst.childNodes.filter(node => node.nodeName === 'import');
|
|
62
|
+
const otherNodes = uxAst.childNodes.filter(node => node.nodeName !== 'import');
|
|
63
|
+
let uxContent = this.nodesToString(importNodes);
|
|
64
|
+
uxContent += ['<template>', this.nodesToString(otherNodes), '</template>'].join('\n');
|
|
55
65
|
if (scriptPath) {
|
|
56
66
|
uxContent += ['<script>', _fs.default.readFileSync(scriptPath, 'utf-8'), '</script>'].join('\n');
|
|
57
67
|
}
|
|
58
68
|
if (stylePath) {
|
|
59
|
-
|
|
69
|
+
const styleExt = _path.default.extname(stylePath).toLowerCase();
|
|
70
|
+
uxContent += [`<style lang="${styleExt.slice(1)}">`, _fs.default.readFileSync(stylePath, 'utf-8'), '</style>'].join('\n');
|
|
60
71
|
}
|
|
61
72
|
return {
|
|
62
73
|
path,
|
|
63
74
|
content: uxContent
|
|
64
75
|
};
|
|
65
76
|
}
|
|
77
|
+
nodesToString(nodes) {
|
|
78
|
+
return parse5.serialize({
|
|
79
|
+
nodeName: '#document-fragment',
|
|
80
|
+
childNodes: nodes
|
|
81
|
+
});
|
|
82
|
+
}
|
|
66
83
|
}
|
|
67
84
|
var _default = exports.default = HmlLoader;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { IFileLaneContext, IFileParam, ILoader } from 'file-lane';
|
|
2
2
|
import IJavascriptCompileOption from '../../../compiler/javascript/interface/IJavascriptCompileOption';
|
|
3
3
|
import { ILog } from '@aiot-toolkit/shared-utils/lib/interface/ILog';
|
|
4
|
+
import FileLaneCompilation from 'file-lane/lib/FileLaneCompilation';
|
|
4
5
|
declare class UxLoader implements ILoader {
|
|
5
6
|
context: IFileLaneContext;
|
|
6
7
|
compilerOption: IJavascriptCompileOption;
|
|
8
|
+
compilation: FileLaneCompilation;
|
|
7
9
|
logs?: ILog[] | undefined;
|
|
8
10
|
parser(files: IFileParam<any>[]): Promise<IFileParam<any>[]>;
|
|
9
11
|
}
|
|
@@ -11,7 +11,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
11
11
|
class UxLoader {
|
|
12
12
|
async parser(files) {
|
|
13
13
|
const resultFiles = [];
|
|
14
|
-
const liteCardList = this.
|
|
14
|
+
const liteCardList = this.compilation.liteCards?.map(item => _path.default.join(this.context.projectPath, this.compilerOption.sourceRoot, `${item}${_parser.ExtensionConfig.UX}`)) || [];
|
|
15
15
|
for (const file of files) {
|
|
16
16
|
// 轻卡ux不转换
|
|
17
17
|
if (liteCardList.includes(file.path)) {
|
|
@@ -21,7 +21,7 @@ class UxLoader {
|
|
|
21
21
|
const {
|
|
22
22
|
files: compiledFiles,
|
|
23
23
|
logs
|
|
24
|
-
} = await _UxLoaderUtils.default.compileUxToJavascript(file, this.context, false, this.compilerOption);
|
|
24
|
+
} = await _UxLoaderUtils.default.compileUxToJavascript(file, this.context, false, this.compilerOption, this.compilation);
|
|
25
25
|
this.logs = logs.map(item => {
|
|
26
26
|
return {
|
|
27
27
|
...item,
|
|
@@ -6,13 +6,11 @@ import IJavascriptCompileOption from '../compiler/javascript/interface/IJavascri
|
|
|
6
6
|
declare class BeforeCompileUtils {
|
|
7
7
|
/**
|
|
8
8
|
* 获取ux项目的路由入口
|
|
9
|
-
* context.entries中存放ux页面路由
|
|
10
|
-
* context.liteCards中存放轻卡路由
|
|
11
9
|
* @param context
|
|
12
10
|
* @param fileList
|
|
13
11
|
* @returns
|
|
14
12
|
*/
|
|
15
|
-
static getEntries: PreWork
|
|
13
|
+
static getEntries: PreWork<IJavascriptCompileOption>;
|
|
16
14
|
static clean: PreWork;
|
|
17
15
|
/**
|
|
18
16
|
* 获取项目的全局样式变量配置
|
|
@@ -11,6 +11,7 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
11
11
|
var _TranslateCache = _interopRequireDefault(require("@aiot-toolkit/parser/lib/ux/translate/vela/TranslateCache"));
|
|
12
12
|
var _UxFileUtils = _interopRequireDefault(require("./ux/UxFileUtils"));
|
|
13
13
|
var _IManifest = require("../compiler/javascript/vela/interface/IManifest");
|
|
14
|
+
var _UxUtil = _interopRequireDefault(require("@aiot-toolkit/parser/lib/ux/utils/UxUtil"));
|
|
14
15
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
16
|
const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
|
|
16
17
|
|
|
@@ -20,8 +21,6 @@ const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobu
|
|
|
20
21
|
class BeforeCompileUtils {
|
|
21
22
|
/**
|
|
22
23
|
* 获取ux项目的路由入口
|
|
23
|
-
* context.entries中存放ux页面路由
|
|
24
|
-
* context.liteCards中存放轻卡路由
|
|
25
24
|
* @param context
|
|
26
25
|
* @param fileList
|
|
27
26
|
* @returns
|
|
@@ -29,7 +28,8 @@ class BeforeCompileUtils {
|
|
|
29
28
|
static getEntries = params => {
|
|
30
29
|
const {
|
|
31
30
|
context,
|
|
32
|
-
compilerOption
|
|
31
|
+
compilerOption,
|
|
32
|
+
compilation
|
|
33
33
|
} = params;
|
|
34
34
|
const {
|
|
35
35
|
projectPath
|
|
@@ -41,8 +41,12 @@ class BeforeCompileUtils {
|
|
|
41
41
|
let entryList = [];
|
|
42
42
|
// 存储轻卡路由
|
|
43
43
|
let liteCardList = [];
|
|
44
|
+
|
|
45
|
+
// services 路由
|
|
46
|
+
let serviceList = [];
|
|
44
47
|
const {
|
|
45
|
-
router
|
|
48
|
+
router,
|
|
49
|
+
services
|
|
46
50
|
} = manifestContent;
|
|
47
51
|
if (router) {
|
|
48
52
|
const {
|
|
@@ -85,22 +89,37 @@ class BeforeCompileUtils {
|
|
|
85
89
|
// 没有router配置
|
|
86
90
|
_sharedUtils.ColorConsole.throw(`### manifest ### No router configuration`);
|
|
87
91
|
}
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
|
|
93
|
+
// e2e测试入口
|
|
94
|
+
if (compilerOption?.enableE2e && compilerOption?.e2eConfigPath) {
|
|
95
|
+
const e2eConfig = _UxUtil.default.getE2eConfig({
|
|
96
|
+
projectPath: context.projectPath,
|
|
97
|
+
e2eConfigPath: compilerOption.e2eConfigPath
|
|
98
|
+
});
|
|
99
|
+
entryList.push(_path.default.join(e2eConfig.dir, e2eConfig.entry.path));
|
|
100
|
+
}
|
|
101
|
+
if (services) {
|
|
102
|
+
serviceList = Array.isArray(services) ? services : Object.values(services);
|
|
103
|
+
}
|
|
104
|
+
if (compilation) {
|
|
105
|
+
compilation['entries'] = entryList;
|
|
106
|
+
compilation['liteCards'] = liteCardList;
|
|
107
|
+
compilation['services'] = serviceList;
|
|
108
|
+
}
|
|
90
109
|
return Promise.resolve();
|
|
91
110
|
};
|
|
92
111
|
static clean = async params => {
|
|
93
112
|
const {
|
|
94
113
|
context,
|
|
95
114
|
compilerOption,
|
|
96
|
-
|
|
115
|
+
compilation
|
|
97
116
|
} = params;
|
|
98
117
|
if (compilerOption) {
|
|
99
118
|
// 存储build中的文件列表
|
|
100
119
|
const buildPath = _path.default.join(context.projectPath, compilerOption.outputPath);
|
|
101
120
|
const buildFileList = _fsExtra.default.existsSync(buildPath) ? _sharedUtils.FileUtil.readAlldirSync(buildPath).map(filePath => _path.default.relative(buildPath, filePath)) : [];
|
|
102
|
-
if (
|
|
103
|
-
|
|
121
|
+
if (compilation) {
|
|
122
|
+
compilation.buildFileList = buildFileList;
|
|
104
123
|
}
|
|
105
124
|
}
|
|
106
125
|
context.translateCache = new _TranslateCache.default();
|
|
@@ -3,6 +3,7 @@ import { ILog } from '@aiot-toolkit/shared-utils';
|
|
|
3
3
|
import { IFileLaneContext, IFileParam } from 'file-lane';
|
|
4
4
|
import { SourceFile } from 'ts-morph';
|
|
5
5
|
import IJavascriptCompileOption from '../../compiler/javascript/interface/IJavascriptCompileOption';
|
|
6
|
+
import FileLaneCompilation from 'file-lane/lib/FileLaneCompilation';
|
|
6
7
|
/**
|
|
7
8
|
* UxLoaderUtils
|
|
8
9
|
*/
|
|
@@ -15,7 +16,7 @@ declare class UxLoaderUtils {
|
|
|
15
16
|
* @param project
|
|
16
17
|
* @returns
|
|
17
18
|
*/
|
|
18
|
-
static compileUxToJavascript(file: IFileParam, context: IFileLaneContext, isAppUx: boolean, compilerOption: IJavascriptCompileOption): Promise<{
|
|
19
|
+
static compileUxToJavascript(file: IFileParam, context: IFileLaneContext, isAppUx: boolean, compilerOption: IJavascriptCompileOption, compilation: FileLaneCompilation): Promise<{
|
|
19
20
|
files: IFileParam[];
|
|
20
21
|
logs: ILog[];
|
|
21
22
|
}>;
|
|
@@ -25,7 +26,7 @@ declare class UxLoaderUtils {
|
|
|
25
26
|
* @param resultFiles
|
|
26
27
|
* @param context
|
|
27
28
|
*/
|
|
28
|
-
static compileAppUxToJavascript(file: IFileParam, context: IFileLaneContext, compileOption: IJavascriptCompileOption): Promise<{
|
|
29
|
+
static compileAppUxToJavascript(file: IFileParam, context: IFileLaneContext, compileOption: IJavascriptCompileOption, compilation: FileLaneCompilation): Promise<{
|
|
29
30
|
files: IFileParam[];
|
|
30
31
|
logs: ILog[];
|
|
31
32
|
}>;
|
|
@@ -41,7 +42,7 @@ declare class UxLoaderUtils {
|
|
|
41
42
|
* @param filePath
|
|
42
43
|
* @returns
|
|
43
44
|
*/
|
|
44
|
-
static isPageUx(
|
|
45
|
+
static isPageUx(compilation: FileLaneCompilation, filePath: string): boolean;
|
|
45
46
|
/**
|
|
46
47
|
* 获取app.ux的内容,且只返回script和style内容
|
|
47
48
|
* @param fileContent
|
|
@@ -64,5 +65,11 @@ declare class UxLoaderUtils {
|
|
|
64
65
|
*/
|
|
65
66
|
static wrapScript(isPageUx: boolean, appScriptTree: SourceFile): string;
|
|
66
67
|
static getReturnType(isPageUx: boolean): "$app_exports$['entry'] =" | "module.exports = ";
|
|
68
|
+
static createServiceWrapper(appScriptTree: SourceFile): string[];
|
|
69
|
+
static isServiceFile(filePath: string, option: {
|
|
70
|
+
compilation: FileLaneCompilation;
|
|
71
|
+
context: IFileLaneContext;
|
|
72
|
+
compilerOption: IJavascriptCompileOption;
|
|
73
|
+
}): boolean;
|
|
67
74
|
}
|
|
68
75
|
export default UxLoaderUtils;
|
|
@@ -12,6 +12,7 @@ var parse5 = _interopRequireWildcard(require("aiot-parse5"));
|
|
|
12
12
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
13
13
|
var _path = _interopRequireDefault(require("path"));
|
|
14
14
|
var _QuickAppDocHelp = require("@aiot-toolkit/shared-utils/lib/utils/QuickAppDocHelp");
|
|
15
|
+
var _StyleUtil = _interopRequireDefault(require("@aiot-toolkit/parser/lib/ux/utils/StyleUtil"));
|
|
15
16
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
16
17
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
18
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -54,7 +55,7 @@ class UxLoaderUtils {
|
|
|
54
55
|
* @param project
|
|
55
56
|
* @returns
|
|
56
57
|
*/
|
|
57
|
-
static async compileUxToJavascript(file, context, isAppUx, compilerOption) {
|
|
58
|
+
static async compileUxToJavascript(file, context, isAppUx, compilerOption, compilation) {
|
|
58
59
|
const logs = [];
|
|
59
60
|
const {
|
|
60
61
|
path: filePath,
|
|
@@ -77,7 +78,7 @@ class UxLoaderUtils {
|
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
// 区分页面组件和子组件
|
|
80
|
-
const isPageUx = UxLoaderUtils.isPageUx(
|
|
81
|
+
const isPageUx = UxLoaderUtils.isPageUx(compilation, filePath);
|
|
81
82
|
// 配置转换参数
|
|
82
83
|
const options = {
|
|
83
84
|
projectPath: context.projectPath,
|
|
@@ -145,8 +146,26 @@ class UxLoaderUtils {
|
|
|
145
146
|
const integrateFunction = (appImport, appStyleTree, appTemplateTree, appScriptTree) => {
|
|
146
147
|
const scriptCode = appScriptTree.getText();
|
|
147
148
|
const hasScript = Boolean(scriptCode) && scriptCode !== '""';
|
|
149
|
+
const isService = UxLoaderUtils.isServiceFile(filePath, {
|
|
150
|
+
compilation,
|
|
151
|
+
context,
|
|
152
|
+
compilerOption
|
|
153
|
+
});
|
|
154
|
+
|
|
148
155
|
// script代码放在第三个位置不能变化,影响更新source map
|
|
149
|
-
|
|
156
|
+
const createAppWrapper = () => {
|
|
157
|
+
return [`${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()];
|
|
158
|
+
};
|
|
159
|
+
const createComponentWrapper = () => {
|
|
160
|
+
return [`${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$;`, `}`];
|
|
161
|
+
};
|
|
162
|
+
if (isAppUx) {
|
|
163
|
+
return createAppWrapper();
|
|
164
|
+
} else if (isService) {
|
|
165
|
+
return UxLoaderUtils.createServiceWrapper(appScriptTree);
|
|
166
|
+
} else {
|
|
167
|
+
return createComponentWrapper();
|
|
168
|
+
}
|
|
150
169
|
};
|
|
151
170
|
const {
|
|
152
171
|
targetTree,
|
|
@@ -179,7 +198,7 @@ class UxLoaderUtils {
|
|
|
179
198
|
* @param resultFiles
|
|
180
199
|
* @param context
|
|
181
200
|
*/
|
|
182
|
-
static async compileAppUxToJavascript(file, context, compileOption) {
|
|
201
|
+
static async compileAppUxToJavascript(file, context, compileOption, compilation) {
|
|
183
202
|
const {
|
|
184
203
|
path: filePath,
|
|
185
204
|
content
|
|
@@ -194,7 +213,7 @@ class UxLoaderUtils {
|
|
|
194
213
|
const compileResult = await UxLoaderUtils.compileUxToJavascript({
|
|
195
214
|
path: filePath,
|
|
196
215
|
content: appContent
|
|
197
|
-
}, context, isAppUx, compileOption);
|
|
216
|
+
}, context, isAppUx, compileOption, compilation);
|
|
198
217
|
return compileResult;
|
|
199
218
|
}
|
|
200
219
|
/**
|
|
@@ -213,8 +232,8 @@ class UxLoaderUtils {
|
|
|
213
232
|
* @param filePath
|
|
214
233
|
* @returns
|
|
215
234
|
*/
|
|
216
|
-
static isPageUx(
|
|
217
|
-
return Boolean(
|
|
235
|
+
static isPageUx(compilation, filePath) {
|
|
236
|
+
return Boolean(compilation.entries?.includes(filePath));
|
|
218
237
|
}
|
|
219
238
|
/**
|
|
220
239
|
* 获取app.ux的内容,且只返回script和style内容
|
|
@@ -334,7 +353,19 @@ class UxLoaderUtils {
|
|
|
334
353
|
return result;
|
|
335
354
|
}
|
|
336
355
|
static wrapStyle(styleNodes, file, compilerOption) {
|
|
337
|
-
|
|
356
|
+
// 排序,媒体查询放到最后
|
|
357
|
+
const sortedNodes = [...styleNodes];
|
|
358
|
+
sortedNodes.sort((a, b) => {
|
|
359
|
+
const conditionA = _StyleUtil.default.isConditionStyleItem(a[0]);
|
|
360
|
+
const conditionB = _StyleUtil.default.isConditionStyleItem(b[0]);
|
|
361
|
+
if (conditionA && !conditionB) {
|
|
362
|
+
return 1;
|
|
363
|
+
} else if (!conditionA && conditionB) {
|
|
364
|
+
return -1;
|
|
365
|
+
}
|
|
366
|
+
return 0;
|
|
367
|
+
});
|
|
368
|
+
const code = JSON.stringify(sortedNodes);
|
|
338
369
|
if (compilerOption.enableProtobuf) {
|
|
339
370
|
if (styleNodes?.length) {
|
|
340
371
|
const result = BinaryPlugin.addStyle(file.path, file.path, code);
|
|
@@ -360,5 +391,13 @@ class UxLoaderUtils {
|
|
|
360
391
|
static getReturnType(isPageUx) {
|
|
361
392
|
return isPageUx ? `$app_exports$['entry'] =` : 'module.exports = ';
|
|
362
393
|
}
|
|
394
|
+
static createServiceWrapper(appScriptTree) {
|
|
395
|
+
return ['', '', `var $app_script$ = ${UxLoaderUtils.wrapScript(false, appScriptTree)}`, `$app_script$({}, $app_exports$, $app_require$);`, `module.exports = $app_exports$.default;`];
|
|
396
|
+
}
|
|
397
|
+
static isServiceFile(filePath, option) {
|
|
398
|
+
const services = option.compilation['services'];
|
|
399
|
+
const relativeFilePath = _path.default.relative(_path.default.join(option.context.projectPath, option.compilerOption.sourceRoot), filePath).replace(/\\/g, _path.default.posix.sep);
|
|
400
|
+
return services?.some(service => relativeFilePath.startsWith(service.path));
|
|
401
|
+
}
|
|
363
402
|
}
|
|
364
403
|
var _default = exports.default = UxLoaderUtils;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ILog } from '@aiot-toolkit/shared-utils';
|
|
2
2
|
import { IFileLaneContext, IFileParam } from 'file-lane';
|
|
3
3
|
import IJavascriptCompileOption from '../../../compiler/javascript/interface/IJavascriptCompileOption';
|
|
4
|
+
import FileLaneCompilation from 'file-lane/lib/FileLaneCompilation';
|
|
4
5
|
/**
|
|
5
6
|
* AndroidUx
|
|
6
7
|
*/
|
|
@@ -18,6 +19,7 @@ declare class AndroidUx {
|
|
|
18
19
|
context: IFileLaneContext;
|
|
19
20
|
file: IFileParam;
|
|
20
21
|
compilerOption: IJavascriptCompileOption;
|
|
22
|
+
compilation: FileLaneCompilation;
|
|
21
23
|
}): Promise<{
|
|
22
24
|
files: IFileParam[];
|
|
23
25
|
logs: ILog[];
|
|
@@ -28,7 +28,8 @@ class AndroidUx {
|
|
|
28
28
|
const {
|
|
29
29
|
context,
|
|
30
30
|
file,
|
|
31
|
-
compilerOption
|
|
31
|
+
compilerOption,
|
|
32
|
+
compilation
|
|
32
33
|
} = params;
|
|
33
34
|
const {
|
|
34
35
|
path: filePath,
|
|
@@ -37,7 +38,7 @@ class AndroidUx {
|
|
|
37
38
|
const {
|
|
38
39
|
projectPath
|
|
39
40
|
} = context;
|
|
40
|
-
const fileType = this.getFileType(filePath,
|
|
41
|
+
const fileType = this.getFileType(filePath, compilation);
|
|
41
42
|
|
|
42
43
|
// 无内容的文件,添加空内容警告
|
|
43
44
|
if (!content) {
|
|
@@ -84,10 +85,10 @@ class AndroidUx {
|
|
|
84
85
|
logs
|
|
85
86
|
};
|
|
86
87
|
}
|
|
87
|
-
getFileType(filePath,
|
|
88
|
+
getFileType(filePath, compilation) {
|
|
88
89
|
const {
|
|
89
90
|
entries
|
|
90
|
-
} =
|
|
91
|
+
} = compilation;
|
|
91
92
|
if (_path.default.basename(filePath) === 'app.ux') {
|
|
92
93
|
return 'app';
|
|
93
94
|
} else if (entries.includes(filePath)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiot-toolkit/aiotpack",
|
|
3
|
-
"version": "2.0.6-beta.
|
|
3
|
+
"version": "2.0.6-beta.20",
|
|
4
4
|
"description": "The process tool for packaging aiot projects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aiotpack"
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
"test": "node ./__tests__/aiotpack.test.js"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@aiot-toolkit/generator": "2.0.6-beta.
|
|
23
|
-
"@aiot-toolkit/parser": "2.0.6-beta.
|
|
24
|
-
"@aiot-toolkit/shared-utils": "2.0.6-beta.
|
|
22
|
+
"@aiot-toolkit/generator": "2.0.6-beta.20",
|
|
23
|
+
"@aiot-toolkit/parser": "2.0.6-beta.20",
|
|
24
|
+
"@aiot-toolkit/shared-utils": "2.0.6-beta.20",
|
|
25
25
|
"@hap-toolkit/aaptjs": "^2.0.0",
|
|
26
26
|
"@rspack/core": "^1.3.9",
|
|
27
27
|
"aiot-parse5": "^1.0.2",
|
|
28
28
|
"babel-loader": "^9.1.3",
|
|
29
|
-
"file-lane": "2.0.6-beta.
|
|
29
|
+
"file-lane": "2.0.6-beta.20",
|
|
30
30
|
"file-loader": "^6.2.0",
|
|
31
31
|
"fs-extra": "^11.2.0",
|
|
32
32
|
"jsrsasign": "^11.1.0",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"@types/jsrsasign": "^10.5.12",
|
|
43
43
|
"@types/webpack-sources": "^3.2.3"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "b2a85a11db9ff9e51e63bfca5643f3e6e0eeb15c"
|
|
46
46
|
}
|