@aiot-toolkit/aiotpack 2.0.6-beta.1 → 2.0.6-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 +50 -16
- package/lib/compiler/javascript/interface/IJavascriptCompileOption.d.ts +5 -0
- package/lib/compiler/javascript/vela/interface/IManifest.d.ts +7 -0
- 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/loader/ux/JsLoader.d.ts +2 -0
- package/lib/loader/ux/JsLoader.js +12 -3
- 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/UxLoader.d.ts +2 -0
- package/lib/loader/ux/vela/UxLoader.js +2 -2
- package/lib/utils/BeforeCompileUtils.d.ts +0 -2
- package/lib/utils/BeforeCompileUtils.js +18 -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,27 @@ class UxAfterCompile {
|
|
|
228
240
|
});
|
|
229
241
|
}
|
|
230
242
|
}
|
|
243
|
+
|
|
244
|
+
// e2e
|
|
245
|
+
// 1. 修改entry
|
|
246
|
+
// 2. 设置launchMode
|
|
247
|
+
if (compilerOption.enableE2e) {
|
|
248
|
+
const testConfig = _UxUtil.default.getE2eConfig({
|
|
249
|
+
projectPath: compilerOption.projectPath,
|
|
250
|
+
e2eConfigPath: compilerOption.e2eConfigPath
|
|
251
|
+
});
|
|
252
|
+
const entryName = testConfig.entry?.name;
|
|
253
|
+
const launchMode = testConfig.entry?.launchMode;
|
|
254
|
+
if (entryName) {
|
|
255
|
+
content.router.entry = entryName;
|
|
256
|
+
}
|
|
257
|
+
if (launchMode) {
|
|
258
|
+
const entryPage = content.router.pages?.[content.router.entry];
|
|
259
|
+
if (entryPage) {
|
|
260
|
+
entryPage.launchMode = launchMode;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
231
264
|
_fsExtra.default.writeJSONSync(_path.default.join(projectPath, outputPath, _UxFileUtils.default.CONFIG_FILE_NAME), content, {
|
|
232
265
|
spaces: 2
|
|
233
266
|
});
|
|
@@ -304,13 +337,13 @@ class UxAfterCompile {
|
|
|
304
337
|
static generateDiff = async params => {
|
|
305
338
|
const {
|
|
306
339
|
compilerOption,
|
|
307
|
-
|
|
340
|
+
compilation,
|
|
308
341
|
context
|
|
309
342
|
} = params;
|
|
310
|
-
if (!compilerOption || !
|
|
343
|
+
if (!compilerOption || !compilation) {
|
|
311
344
|
return;
|
|
312
345
|
}
|
|
313
|
-
if (
|
|
346
|
+
if (compilation.trigger === _FileLaneTriggerType.default.START) {
|
|
314
347
|
return;
|
|
315
348
|
}
|
|
316
349
|
// 读取临时项目build文件夹中所有文件路径
|
|
@@ -318,7 +351,7 @@ class UxAfterCompile {
|
|
|
318
351
|
// 待优化,map文件跟随源文件变化,与时间戳有关文件无需对比
|
|
319
352
|
const tempFileList = _sharedUtils.FileUtil.readAlldirSync(tempBuildDir);
|
|
320
353
|
const buildDir = _path.default.join(context.projectPath, compilerOption.outputPath);
|
|
321
|
-
const diffList = _UxFileUtils.default.getDiffJSON(
|
|
354
|
+
const diffList = _UxFileUtils.default.getDiffJSON(compilation.buildFileList, tempFileList, buildDir, tempBuildDir);
|
|
322
355
|
|
|
323
356
|
// 所有差异文件,压缩到 .diff.rpk 中
|
|
324
357
|
if (diffList?.length) {
|
|
@@ -330,8 +363,8 @@ class UxAfterCompile {
|
|
|
330
363
|
filePath: _path.default.join(buildFold, item),
|
|
331
364
|
zipFilePath: item
|
|
332
365
|
})));
|
|
333
|
-
|
|
334
|
-
|
|
366
|
+
compilation.info.diffList = diffList;
|
|
367
|
+
compilation.info.diffFile = _path.default.join(context.projectPath, compilerOption.releasePath, diffFileName);
|
|
335
368
|
}
|
|
336
369
|
};
|
|
337
370
|
|
|
@@ -411,10 +444,11 @@ class UxAfterCompile {
|
|
|
411
444
|
static compileLiteCard = async params => {
|
|
412
445
|
const {
|
|
413
446
|
compilerOption,
|
|
414
|
-
context
|
|
447
|
+
context,
|
|
448
|
+
compilation
|
|
415
449
|
} = params;
|
|
416
450
|
try {
|
|
417
|
-
if (
|
|
451
|
+
if (compilation && compilation?.liteCards?.length > 0 && compilerOption) {
|
|
418
452
|
const {
|
|
419
453
|
projectPath: tempProjectPath,
|
|
420
454
|
outputPath: LITE_OUTPUT_PATH
|
|
@@ -425,7 +459,7 @@ class UxAfterCompile {
|
|
|
425
459
|
// 1.
|
|
426
460
|
await new _LiteCard.default(projectPath).compileLiteCard();
|
|
427
461
|
// 2.
|
|
428
|
-
|
|
462
|
+
compilation.liteCards.forEach(card => {
|
|
429
463
|
// hap-toolkit的产物在项目的build文件夹下
|
|
430
464
|
const fromPath = _path.default.join(projectPath, LITE_OUTPUT_PATH, card);
|
|
431
465
|
// aiot-toolkit的产物在临时项目的build文件夹下
|
|
@@ -29,8 +29,10 @@ export default interface IManifest {
|
|
|
29
29
|
entry: string;
|
|
30
30
|
pages: Dictionary<{
|
|
31
31
|
component?: string;
|
|
32
|
+
launchMode: string;
|
|
32
33
|
}>;
|
|
33
34
|
};
|
|
35
|
+
services: IService[] | Record<string, IService>;
|
|
34
36
|
minAPILevel?: number;
|
|
35
37
|
packageInfo?: Dictionary<string | number>;
|
|
36
38
|
icon: string;
|
|
@@ -38,4 +40,9 @@ export default interface IManifest {
|
|
|
38
40
|
export interface IFeatures {
|
|
39
41
|
name: string;
|
|
40
42
|
}
|
|
43
|
+
export interface IService {
|
|
44
|
+
name: string;
|
|
45
|
+
autoStart?: boolean;
|
|
46
|
+
path: string;
|
|
47
|
+
}
|
|
41
48
|
export {};
|
|
@@ -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
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { IFileLaneContext, IFileParam, ILoader } from 'file-lane';
|
|
2
2
|
import IJavascriptCompileOption from '../../compiler/javascript/interface/IJavascriptCompileOption';
|
|
3
|
+
import FileLaneCompilation from 'file-lane/lib/FileLaneCompilation';
|
|
3
4
|
/**
|
|
4
5
|
* JsLoader
|
|
5
6
|
*/
|
|
6
7
|
declare class JsLoader implements ILoader {
|
|
7
8
|
context: IFileLaneContext;
|
|
8
9
|
compilerOption: IJavascriptCompileOption;
|
|
10
|
+
compilation: FileLaneCompilation;
|
|
9
11
|
parser(files: IFileParam<any>[]): Promise<IFileParam<any>[]>;
|
|
10
12
|
}
|
|
11
13
|
export default JsLoader;
|
|
@@ -6,6 +6,8 @@ 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
|
*/
|
|
@@ -27,11 +29,18 @@ class JsLoader {
|
|
|
27
29
|
projectType: _sharedUtils.ProjectType.getProjectType(this.context.projectPath),
|
|
28
30
|
onLog
|
|
29
31
|
};
|
|
32
|
+
const scriptTree = await new _parser.ScriptToTypescript(options, this.compilerOption, this.context).translate({
|
|
33
|
+
content: new _parser.ScriptParser(options).parser(item.content.toString()).ast.content
|
|
34
|
+
}, []);
|
|
35
|
+
const isService = _UxLoaderUtils.default.isServiceFile(item.path, {
|
|
36
|
+
compilation: this.compilation,
|
|
37
|
+
compilerOption: this.compilerOption,
|
|
38
|
+
context: this.context
|
|
39
|
+
});
|
|
40
|
+
const content = isService ? _UxLoaderUtils.default.createServiceWrapper(scriptTree.targetTree).filter(Boolean).join('\n') : scriptTree.targetTree.getFullText();
|
|
30
41
|
result.push({
|
|
31
42
|
path: item.path,
|
|
32
|
-
content
|
|
33
|
-
content: new _parser.ScriptParser(options).parser(item.content.toString()).ast.content
|
|
34
|
-
}, [])).targetTree.getFullText()
|
|
43
|
+
content
|
|
35
44
|
});
|
|
36
45
|
}
|
|
37
46
|
}
|
|
@@ -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
|
}
|
|
@@ -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,
|
|
@@ -20,8 +20,6 @@ const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobu
|
|
|
20
20
|
class BeforeCompileUtils {
|
|
21
21
|
/**
|
|
22
22
|
* 获取ux项目的路由入口
|
|
23
|
-
* context.entries中存放ux页面路由
|
|
24
|
-
* context.liteCards中存放轻卡路由
|
|
25
23
|
* @param context
|
|
26
24
|
* @param fileList
|
|
27
25
|
* @returns
|
|
@@ -29,7 +27,8 @@ class BeforeCompileUtils {
|
|
|
29
27
|
static getEntries = params => {
|
|
30
28
|
const {
|
|
31
29
|
context,
|
|
32
|
-
compilerOption
|
|
30
|
+
compilerOption,
|
|
31
|
+
compilation
|
|
33
32
|
} = params;
|
|
34
33
|
const {
|
|
35
34
|
projectPath
|
|
@@ -41,8 +40,12 @@ class BeforeCompileUtils {
|
|
|
41
40
|
let entryList = [];
|
|
42
41
|
// 存储轻卡路由
|
|
43
42
|
let liteCardList = [];
|
|
43
|
+
|
|
44
|
+
// services 路由
|
|
45
|
+
let serviceList = [];
|
|
44
46
|
const {
|
|
45
|
-
router
|
|
47
|
+
router,
|
|
48
|
+
services
|
|
46
49
|
} = manifestContent;
|
|
47
50
|
if (router) {
|
|
48
51
|
const {
|
|
@@ -85,22 +88,28 @@ class BeforeCompileUtils {
|
|
|
85
88
|
// 没有router配置
|
|
86
89
|
_sharedUtils.ColorConsole.throw(`### manifest ### No router configuration`);
|
|
87
90
|
}
|
|
88
|
-
|
|
89
|
-
|
|
91
|
+
if (services) {
|
|
92
|
+
serviceList = Array.isArray(services) ? services : Object.values(services);
|
|
93
|
+
}
|
|
94
|
+
if (compilation) {
|
|
95
|
+
compilation['entries'] = entryList;
|
|
96
|
+
compilation['liteCards'] = liteCardList;
|
|
97
|
+
compilation['services'] = serviceList;
|
|
98
|
+
}
|
|
90
99
|
return Promise.resolve();
|
|
91
100
|
};
|
|
92
101
|
static clean = async params => {
|
|
93
102
|
const {
|
|
94
103
|
context,
|
|
95
104
|
compilerOption,
|
|
96
|
-
|
|
105
|
+
compilation
|
|
97
106
|
} = params;
|
|
98
107
|
if (compilerOption) {
|
|
99
108
|
// 存储build中的文件列表
|
|
100
109
|
const buildPath = _path.default.join(context.projectPath, compilerOption.outputPath);
|
|
101
110
|
const buildFileList = _fsExtra.default.existsSync(buildPath) ? _sharedUtils.FileUtil.readAlldirSync(buildPath).map(filePath => _path.default.relative(buildPath, filePath)) : [];
|
|
102
|
-
if (
|
|
103
|
-
|
|
111
|
+
if (compilation) {
|
|
112
|
+
compilation.buildFileList = buildFileList;
|
|
104
113
|
}
|
|
105
114
|
}
|
|
106
115
|
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.10",
|
|
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.10",
|
|
23
|
+
"@aiot-toolkit/parser": "2.0.6-beta.10",
|
|
24
|
+
"@aiot-toolkit/shared-utils": "2.0.6-beta.10",
|
|
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.10",
|
|
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": "b6a63385af95a6ba445e65225a92014026ce3144"
|
|
46
46
|
}
|