@aiot-toolkit/aiotpack 2.0.6-beta.1 → 2.0.6-beta.11

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.
@@ -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
- _sharedUtils.ColorConsole.info(`webpack complete`);
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
- _sharedUtils.ColorConsole.throw(...messages);
71
+ onLog?.([{
72
+ level: _sharedUtils.Loglevel.THROW,
73
+ message: messages
74
+ }]);
68
75
  throw new Error();
69
76
  } else {
70
- _sharedUtils.ColorConsole.warn(...messages);
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
- compalition,
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 (compalition && fileName) {
100
- compalition.info.rpk = _path.default.join(context.projectPath, compilerOption.releasePath, fileName);
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,29 @@ class UxAfterCompile {
228
240
  });
229
241
  }
230
242
  }
243
+
244
+ // e2e
245
+ //
246
+ if (compilerOption.e2eConfigPath && compilerOption.enableE2e) {
247
+ const testConfig = _UxUtil.default.getE2eConfig({
248
+ projectPath: compilerOption.projectPath,
249
+ e2eConfigPath: compilerOption.e2eConfigPath
250
+ });
251
+ const testPagePath = _path.default.parse(_path.default.relative(_path.default.join(compilerOption.projectPath, sourceRoot), _path.default.join(testConfig.dir, testConfig.entry.path)));
252
+ // 1. 修改entry
253
+ const entryName = testPagePath.dir;
254
+ const launchMode = testConfig.entry?.launchMode;
255
+ if (entryName) {
256
+ content.router.entry = entryName;
257
+ }
258
+ // 2. 添加测试页到router.pages
259
+ if (content.router.pages) {
260
+ content.router.pages[entryName] = {
261
+ component: testPagePath.name,
262
+ launchMode
263
+ };
264
+ }
265
+ }
231
266
  _fsExtra.default.writeJSONSync(_path.default.join(projectPath, outputPath, _UxFileUtils.default.CONFIG_FILE_NAME), content, {
232
267
  spaces: 2
233
268
  });
@@ -304,13 +339,13 @@ class UxAfterCompile {
304
339
  static generateDiff = async params => {
305
340
  const {
306
341
  compilerOption,
307
- compalition,
342
+ compilation,
308
343
  context
309
344
  } = params;
310
- if (!compilerOption || !compalition) {
345
+ if (!compilerOption || !compilation) {
311
346
  return;
312
347
  }
313
- if (compalition.trigger === _FileLaneTriggerType.default.START) {
348
+ if (compilation.trigger === _FileLaneTriggerType.default.START) {
314
349
  return;
315
350
  }
316
351
  // 读取临时项目build文件夹中所有文件路径
@@ -318,7 +353,7 @@ class UxAfterCompile {
318
353
  // 待优化,map文件跟随源文件变化,与时间戳有关文件无需对比
319
354
  const tempFileList = _sharedUtils.FileUtil.readAlldirSync(tempBuildDir);
320
355
  const buildDir = _path.default.join(context.projectPath, compilerOption.outputPath);
321
- const diffList = _UxFileUtils.default.getDiffJSON(compalition.buildFileList, tempFileList, buildDir, tempBuildDir);
356
+ const diffList = _UxFileUtils.default.getDiffJSON(compilation.buildFileList, tempFileList, buildDir, tempBuildDir);
322
357
 
323
358
  // 所有差异文件,压缩到 .diff.rpk 中
324
359
  if (diffList?.length) {
@@ -330,8 +365,8 @@ class UxAfterCompile {
330
365
  filePath: _path.default.join(buildFold, item),
331
366
  zipFilePath: item
332
367
  })));
333
- compalition.info.diffList = diffList;
334
- compalition.info.diffFile = _path.default.join(context.projectPath, compilerOption.releasePath, diffFileName);
368
+ compilation.info.diffList = diffList;
369
+ compilation.info.diffFile = _path.default.join(context.projectPath, compilerOption.releasePath, diffFileName);
335
370
  }
336
371
  };
337
372
 
@@ -411,10 +446,11 @@ class UxAfterCompile {
411
446
  static compileLiteCard = async params => {
412
447
  const {
413
448
  compilerOption,
414
- context
449
+ context,
450
+ compilation
415
451
  } = params;
416
452
  try {
417
- if (context?.liteCards?.length > 0 && compilerOption) {
453
+ if (compilation && compilation?.liteCards?.length > 0 && compilerOption) {
418
454
  const {
419
455
  projectPath: tempProjectPath,
420
456
  outputPath: LITE_OUTPUT_PATH
@@ -425,7 +461,7 @@ class UxAfterCompile {
425
461
  // 1.
426
462
  await new _LiteCard.default(projectPath).compileLiteCard();
427
463
  // 2.
428
- context.liteCards.forEach(card => {
464
+ compilation.liteCards.forEach(card => {
429
465
  // hap-toolkit的产物在项目的build文件夹下
430
466
  const fromPath = _path.default.join(projectPath, LITE_OUTPUT_PATH, card);
431
467
  // aiot-toolkit的产物在临时项目的build文件夹下
@@ -48,6 +48,11 @@ interface IJavascriptCompileOption extends ICompileParam {
48
48
  * 启用应用自动化测试
49
49
  */
50
50
  enableE2e?: boolean;
51
+ /**
52
+ * 自动化测试配置文件路径
53
+ *
54
+ */
55
+ e2eConfigPath?: string;
51
56
  /**
52
57
  * 启用 png8 压缩
53
58
  */
@@ -8,7 +8,9 @@ declare class VelaWebpackConfigurator implements IWebpackConfigurator {
8
8
  protected createWrapPlugin(): RspackPluginInstance;
9
9
  protected createBundleAnalyzerPlugin(): any;
10
10
  /**
11
- * 通过读取 manifest.json 生成 entry
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
- * 通过读取 manifest.json 生成 entry
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)));
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: any, codeDir: string, projectPath: string): Dictionary<string>;
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 {
@@ -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: (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()
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.context.liteCards?.map(item => _path.default.join(this.context.projectPath, this.compilerOption.sourceRoot, `${item}${_parser.ExtensionConfig.UX}`)) || [];
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,8 +6,6 @@ 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
@@ -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
- context['entries'] = entryList;
89
- context['liteCards'] = liteCardList;
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
- compalition
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 (compalition) {
103
- compalition.buildFileList = buildFileList;
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(context: IFileLaneContext, filePath: string): boolean;
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(context, filePath);
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
- 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$;`, `}`];
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(context, filePath) {
217
- return Boolean(context.entries?.includes(filePath));
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
- const code = JSON.stringify(styleNodes);
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, context);
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, context) {
88
+ getFileType(filePath, compilation) {
88
89
  const {
89
90
  entries
90
- } = context;
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.1",
3
+ "version": "2.0.6-beta.11",
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.1",
23
- "@aiot-toolkit/parser": "2.0.6-beta.1",
24
- "@aiot-toolkit/shared-utils": "2.0.6-beta.1",
22
+ "@aiot-toolkit/generator": "2.0.6-beta.11",
23
+ "@aiot-toolkit/parser": "2.0.6-beta.11",
24
+ "@aiot-toolkit/shared-utils": "2.0.6-beta.11",
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.1",
29
+ "file-lane": "2.0.6-beta.11",
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": "892743ccc51408960e6cee86675538501b3e47f1"
45
+ "gitHead": "acecf0ae5d6991619051dbbeda770a602f215dd6"
46
46
  }