@aiot-toolkit/aiotpack 2.0.2-beta.1 → 2.0.2-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.
Files changed (66) hide show
  1. package/lib/compiler/interface/ICompileParam.d.ts +1 -1
  2. package/lib/compiler/javascript/JavascriptCompiler.js +32 -8
  3. package/lib/compiler/javascript/android/AndroidWebpackConfigurator.d.ts +9 -0
  4. package/lib/compiler/javascript/android/AndroidWebpackConfigurator.js +16 -0
  5. package/lib/compiler/javascript/android/plugin/WrapPlugin.d.ts +20 -0
  6. package/lib/compiler/javascript/android/plugin/WrapPlugin.js +78 -0
  7. package/lib/compiler/javascript/interface/IJavascriptCompileOption.d.ts +16 -1
  8. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.d.ts +2 -0
  9. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js +18 -5
  10. package/lib/compiler/javascript/vela/interface/IManifest.d.ts +1 -1
  11. package/lib/compiler/javascript/vela/model/Package.d.ts +1 -1
  12. package/lib/compiler/javascript/vela/model/Package.js +2 -5
  13. package/lib/compiler/javascript/vela/utils/Jsc.js +3 -4
  14. package/lib/compiler/javascript/vela/utils/UxCompileUtil.d.ts +1 -1
  15. package/lib/compiler/javascript/vela/utils/UxCompileUtil.js +3 -3
  16. package/lib/compiler/javascript/vela/utils/ZipUtil.d.ts +1 -1
  17. package/lib/compiler/javascript/vela/utils/ZipUtil.js +7 -9
  18. package/lib/compiler/javascript/vela/utils/signature/SignUtil.d.ts +3 -5
  19. package/lib/compiler/javascript/vela/utils/signature/SignUtil.js +53 -28
  20. package/lib/compiler/javascript/vela/utils/webpackLoader/addColSourceMap.d.ts +3 -0
  21. package/lib/compiler/javascript/vela/utils/webpackLoader/addColSourceMap.js +56 -0
  22. package/lib/compiler/javascript/vela/utils/webpackLoader/extractMapData.d.ts +3 -0
  23. package/lib/compiler/javascript/vela/utils/webpackLoader/{splitMap.js → extractMapData.js} +2 -2
  24. package/lib/config/UxConfig.d.ts +29 -7
  25. package/lib/config/UxConfig.js +110 -33
  26. package/lib/config/XtsConfig.d.ts +5 -3
  27. package/lib/config/XtsConfig.js +12 -3
  28. package/lib/{utils → followWorks}/ux/UxFollowWorks.d.ts +1 -1
  29. package/lib/{utils → followWorks}/ux/UxFollowWorks.js +31 -31
  30. package/lib/followWorks/xts/entryTemplate.d.ts +1 -1
  31. package/lib/followWorks/xts/entryTemplate.js +10 -10
  32. package/lib/followWorks/xts/generateRpk.d.ts +1 -1
  33. package/lib/followWorks/xts/generateRpk.js +2 -2
  34. package/lib/followWorks/xts/ts2wasm.d.ts +1 -1
  35. package/lib/followWorks/xts/ts2wasm.js +4 -4
  36. package/lib/index.d.ts +9 -1
  37. package/lib/index.js +35 -1
  38. package/lib/loader/ux/JsLoader.d.ts +2 -0
  39. package/lib/loader/ux/JsLoader.js +6 -9
  40. package/lib/loader/ux/PngLoader.js +4 -5
  41. package/lib/loader/ux/android/UxLoader.d.ts +11 -0
  42. package/lib/loader/ux/android/UxLoader.js +39 -0
  43. package/lib/loader/ux/{AppUxLoader.d.ts → vela/AppUxLoader.d.ts} +1 -1
  44. package/lib/loader/ux/{AppUxLoader.js → vela/AppUxLoader.js} +6 -3
  45. package/lib/loader/ux/vela/HmlLoader.d.ts +24 -0
  46. package/lib/loader/ux/vela/HmlLoader.js +63 -0
  47. package/lib/loader/ux/{UxLoader.d.ts → vela/UxLoader.d.ts} +1 -1
  48. package/lib/loader/ux/{UxLoader.js → vela/UxLoader.js} +4 -13
  49. package/lib/loader/xts/XtsLoader.js +6 -7
  50. package/lib/{utils → preWorks}/ux/UxPreWorks.d.ts +1 -1
  51. package/lib/{utils → preWorks}/ux/UxPreWorks.js +1 -1
  52. package/lib/preWorks/xts/preInstall.d.ts +1 -1
  53. package/lib/preWorks/xts/preInstall.js +4 -4
  54. package/lib/utils/PreWorkUtils.d.ts +1 -2
  55. package/lib/utils/PreWorkUtils.js +28 -30
  56. package/lib/utils/ux/ManifestSchema.d.ts +1 -1
  57. package/lib/utils/ux/UxFileUtils.js +11 -13
  58. package/lib/utils/ux/UxLoaderUtils.d.ts +7 -4
  59. package/lib/utils/ux/UxLoaderUtils.js +43 -23
  60. package/lib/utils/ux/android/AndroidUx.d.ts +27 -0
  61. package/lib/utils/ux/android/AndroidUx.js +98 -0
  62. package/lib/utils/xts/XtsFileLaneUtils.d.ts +10 -0
  63. package/lib/utils/xts/XtsFileLaneUtils.js +68 -0
  64. package/lib/utils/xts/XtsFollowWorks.js +7 -7
  65. package/package.json +9 -5
  66. package/lib/compiler/javascript/vela/utils/webpackLoader/splitMap.d.ts +0 -3
@@ -13,9 +13,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const shared_utils_1 = require("@aiot-toolkit/shared-utils");
16
- const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
17
16
  const path_1 = __importDefault(require("path"));
18
- const UxLoaderUtils_1 = __importDefault(require("../../utils/ux/UxLoaderUtils"));
17
+ const UxLoaderUtils_1 = __importDefault(require("../../../utils/ux/UxLoaderUtils"));
19
18
  class UxLoader {
20
19
  parser(files) {
21
20
  return __awaiter(this, void 0, void 0, function* () {
@@ -23,17 +22,9 @@ class UxLoader {
23
22
  const { projectPath } = this.context;
24
23
  for (const file of files) {
25
24
  // 转换每个文件
26
- const { files, logs } = yield UxLoaderUtils_1.default.compileUxToJavascript(file, this.context, false, this.compilerOption);
27
- if (logs) {
28
- logs.forEach((item) => {
29
- ColorConsole_1.default.logger(Object.assign(Object.assign({}, item), { filePath: item.filePath ? path_1.default.relative(projectPath, item.filePath) : '' }));
30
- });
31
- // 如果有 error throw,则停止
32
- if (logs.some((item) => item.level && [shared_utils_1.LOG_LEVEL.Throw].includes(item.level))) {
33
- throw new Error('stop!');
34
- }
35
- }
36
- resultFiles.push(...files);
25
+ const { files: compiledFiles, logs } = yield UxLoaderUtils_1.default.compileUxToJavascript(file, this.context, false, this.compilerOption);
26
+ shared_utils_1.CommonUtil.processingLogsInTerminal(logs.map((item) => (Object.assign(Object.assign({}, item), { filePath: item.filePath ? path_1.default.relative(projectPath, item.filePath) : '' }))));
27
+ resultFiles.push(...compiledFiles);
37
28
  }
38
29
  return resultFiles;
39
30
  });
@@ -5,8 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const generator_1 = require("@aiot-toolkit/generator");
7
7
  const parser_1 = require("@aiot-toolkit/parser");
8
- const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
9
- const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
8
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
10
9
  const path_1 = __importDefault(require("path"));
11
10
  const ts_morph_1 = require("ts-morph");
12
11
  /**
@@ -23,11 +22,11 @@ class XtsLoader {
23
22
  const newFileName = `${name}.ts`;
24
23
  //判断文本,空文本则结束该文件处理
25
24
  if (!content) {
26
- ColorConsole_1.default.warn(`The file '${fullName}' under the path '${path}' has no content `);
25
+ shared_utils_1.ColorConsole.warn(`The file '${fullName}' under the path '${path}' has no content `);
27
26
  return [];
28
27
  }
29
- const parserResult = new parser_1.XtsParser(project, ColorConsole_1.default.logger).parser(content.toString(), fullName);
30
- const { ast, mapList } = new parser_1.XtsToTypescript(project, ColorConsole_1.default.logger, this.context, path).translate(parserResult.ast, parserResult.offsetList);
28
+ const parserResult = new parser_1.XtsParser(project, shared_utils_1.ColorConsole.logger).parser(content.toString(), fullName);
29
+ const { ast, mapList } = new parser_1.XtsToTypescript(project, shared_utils_1.ColorConsole.logger, this.context, path).translate(parserResult.ast, parserResult.offsetList);
31
30
  const { code, sourcemap } = new generator_1.TypescriptGenerator().generate({
32
31
  sourceFilePath: fullName,
33
32
  targetFilePath: newFileName,
@@ -35,10 +34,10 @@ class XtsLoader {
35
34
  mapList
36
35
  });
37
36
  resultFiles.push({
38
- path: FileUtil_1.default.updatePath(path, newFileName),
37
+ path: shared_utils_1.FileUtil.updateFileName(path, newFileName),
39
38
  content: code
40
39
  }, {
41
- path: FileUtil_1.default.updatePath(path, `${name}.map.ts`),
40
+ path: shared_utils_1.FileUtil.updateFileName(path, `${name}.map.ts`),
42
41
  content: sourcemap
43
42
  });
44
43
  }
@@ -1,4 +1,4 @@
1
- import { PreWork } from 'file-lane/lib/interface/IFileLaneConfig';
1
+ import { PreWork } from 'file-lane';
2
2
  import IJavascriptCompileOption from '../../compiler/javascript/interface/IJavascriptCompileOption';
3
3
  /**
4
4
  * UxPreWorks
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  var _a;
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- const UxFileUtils_1 = __importDefault(require("./UxFileUtils"));
16
+ const UxFileUtils_1 = __importDefault(require("../../utils/ux/UxFileUtils"));
17
17
  /**
18
18
  * UxPreWorks
19
19
  */
@@ -1,3 +1,3 @@
1
- import { PreWork } from 'file-lane/lib/interface/IFileLaneConfig';
1
+ import { PreWork } from 'file-lane';
2
2
  import { IXtsCompileOptions } from '../../interface/ICompileOptions';
3
3
  export declare const preInstall: PreWork<IXtsCompileOptions>;
@@ -13,14 +13,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.preInstall = void 0;
16
- const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
16
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
17
17
  const child_process_1 = require("child_process");
18
18
  const fs_1 = __importDefault(require("fs"));
19
19
  const path_1 = __importDefault(require("path"));
20
20
  const preInstall = (context, _, __, compilerOption) => __awaiter(void 0, void 0, void 0, function* () {
21
21
  var _a;
22
22
  if ((_a = compilerOption === null || compilerOption === void 0 ? void 0 : compilerOption.skip) === null || _a === void 0 ? void 0 : _a.includes('install')) {
23
- ColorConsole_1.default.info(`### skip install pre-dependencies due to --skip ${compilerOption === null || compilerOption === void 0 ? void 0 : compilerOption.skip.join(',')}`);
23
+ shared_utils_1.ColorConsole.info(`### skip install pre-dependencies due to --skip ${compilerOption === null || compilerOption === void 0 ? void 0 : compilerOption.skip.join(',')}`);
24
24
  return;
25
25
  }
26
26
  const { projectPath } = context;
@@ -47,12 +47,12 @@ const preInstall = (context, _, __, compilerOption) => __awaiter(void 0, void 0,
47
47
  });
48
48
  }
49
49
  }
50
- ColorConsole_1.default.info('### Installing pre-dependencies. The initial build may take some time, please be patient...');
50
+ shared_utils_1.ColorConsole.info('### Installing pre-dependencies. The initial build may take some time, please be patient...');
51
51
  (0, child_process_1.execSync)('npm install', {
52
52
  cwd: projectPath
53
53
  });
54
54
  // 目前ts2wasm不支持@符号
55
55
  fs_1.default.renameSync(path_1.default.resolve(projectPath, 'node_modules/@mi'), path_1.default.resolve(projectPath, 'node_modules/mi'));
56
- ColorConsole_1.default.info('### Dependencies installation complete.');
56
+ shared_utils_1.ColorConsole.info('### Dependencies installation complete.');
57
57
  });
58
58
  exports.preInstall = preInstall;
@@ -1,5 +1,4 @@
1
- import { IFileLaneContext } from 'file-lane';
2
- import { PreWork } from 'file-lane/lib/interface/IFileLaneConfig';
1
+ import { IFileLaneContext, PreWork } from 'file-lane';
3
2
  import IJavascriptCompileOption from '../compiler/javascript/interface/IJavascriptCompileOption';
4
3
  /**
5
4
  * PreWorkUtils
@@ -13,7 +13,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  var _a;
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
16
+ const parser_1 = require("@aiot-toolkit/parser");
17
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
17
18
  const del_1 = __importDefault(require("del"));
18
19
  const fs_extra_1 = __importDefault(require("fs-extra"));
19
20
  const path_1 = __importDefault(require("path"));
@@ -37,37 +38,35 @@ class PreWorkUtils {
37
38
  const manifestContent = UxFileUtils_1.default.getMainfestInfo(projectPath);
38
39
  // 存储entries
39
40
  let entryList = [];
40
- if (manifestContent) {
41
- const { router } = manifestContent;
42
- if (!router) {
43
- // 没有router配置
44
- ColorConsole_1.default.throw(`### manifest ### No router configuration`);
45
- }
41
+ const { router } = manifestContent;
42
+ if (router) {
46
43
  const { pages } = router;
47
- if (!pages) {
44
+ if (pages) {
45
+ Object.keys(pages).map((page) => {
46
+ const pageContent = pages[page];
47
+ const entryDir = path_1.default.join(srcPath, page);
48
+ const entryPages = parser_1.ExtensionConfig.TEMPLATES.map((item) => `${pageContent.component}${item}`);
49
+ const entry = entryPages.find((item) => fs_extra_1.default.existsSync(path_1.default.join(entryDir, item)));
50
+ if (entry) {
51
+ entryList.push(path_1.default.join(entryDir, entry));
52
+ }
53
+ else {
54
+ // 路径不存在
55
+ shared_utils_1.ColorConsole.throw(`### manifest ### path '${entryDir}/${entryPages.join(' | ')}' does not exist`);
56
+ }
57
+ });
58
+ }
59
+ else {
48
60
  // 没有pages配置
49
- ColorConsole_1.default.throw(`### manifest ### No pages configuration`);
61
+ shared_utils_1.ColorConsole.throw(`### manifest ### No pages configuration`);
50
62
  }
51
- Object.keys(pages).map((page) => {
52
- const pageContent = pages[page];
53
- const entryDir = path_1.default.join(srcPath, page);
54
- const entryPage = path_1.default.join(entryDir, `${pageContent.component}.ux`);
55
- if (fs_extra_1.default.existsSync(entryPage)) {
56
- entryList.push(entryPage);
57
- }
58
- else {
59
- // 路径不存在
60
- ColorConsole_1.default.throw(`### manifest ### path '${entryPage}' does not exist`);
61
- }
62
- });
63
- context['entries'] = entryList;
64
- return Promise.resolve();
65
63
  }
66
64
  else {
67
- // manifest.json文件无有效内容
68
- ColorConsole_1.default.error(`### manifest ### File has no valid content`);
69
- return Promise.reject();
65
+ // 没有router配置
66
+ shared_utils_1.ColorConsole.throw(`### manifest ### No router configuration`);
70
67
  }
68
+ context['entries'] = entryList;
69
+ return Promise.resolve();
71
70
  }
72
71
  /**
73
72
  * 获取项目的全局样式变量配置
@@ -88,17 +87,16 @@ class PreWorkUtils {
88
87
  }
89
88
  _a = PreWorkUtils;
90
89
  PreWorkUtils.clean = (context, _, config, compileOption) => __awaiter(void 0, void 0, void 0, function* () {
91
- yield (0, del_1.default)(path_1.default.join(context.projectPath, context.output));
90
+ yield (0, del_1.default)(path_1.default.join(context.projectPath, context.output), { force: true });
92
91
  if (compileOption) {
93
- yield (0, del_1.default)(path_1.default.join(compileOption.projectPath, compileOption.outputPath));
94
- yield (0, del_1.default)(path_1.default.join(compileOption.projectPath, compileOption.releasePath));
95
92
  yield (0, del_1.default)(path_1.default.join(context.projectPath, compileOption.outputPath));
96
93
  yield (0, del_1.default)(path_1.default.join(context.projectPath, compileOption.releasePath));
97
94
  }
98
- TranslateCache_1.default.featureCache.clear();
95
+ context.translateCache = new TranslateCache_1.default();
99
96
  BinaryPlugin.reset();
100
97
  BinaryPlugin.config = {
101
98
  projectPath: context.projectPath,
99
+ outputProjectPath: path_1.default.join(context.projectPath, context.output),
102
100
  source: compileOption === null || compileOption === void 0 ? void 0 : compileOption.sourceRoot,
103
101
  output: compileOption === null || compileOption === void 0 ? void 0 : compileOption.outputPath
104
102
  };
@@ -1,3 +1,3 @@
1
- import { JSONSchemaType } from '@aiot-toolkit/shared-utils/lib/utils/CommonUtil';
1
+ import { JSONSchemaType } from '@aiot-toolkit/shared-utils';
2
2
  declare const ManifestSchema: JSONSchemaType;
3
3
  export default ManifestSchema;
@@ -5,8 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.UxFileUtils = void 0;
7
7
  const shared_utils_1 = require("@aiot-toolkit/shared-utils");
8
- const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
9
- const CommonUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/CommonUtil"));
10
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
11
9
  const path_1 = __importDefault(require("path"));
12
10
  const ManifestSchema_1 = __importDefault(require("./ManifestSchema"));
@@ -43,28 +41,28 @@ class UxFileUtils {
43
41
  static validateManifest(projectPath, sourceRoot = 'src') {
44
42
  const path = UxFileUtils.getManifestFilePath(projectPath, sourceRoot);
45
43
  if (!fs_extra_1.default.existsSync(path)) {
46
- ColorConsole_1.default.throw(`file is missing`, {
44
+ shared_utils_1.ColorConsole.throw(`file is missing`, {
47
45
  word: path,
48
- style: ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Throw)
46
+ style: shared_utils_1.ColorConsole.getStyle(shared_utils_1.Loglevel.THROW)
49
47
  });
50
48
  }
51
49
  const jsonData = this.getMainfestInfo(projectPath, sourceRoot);
52
50
  const schema = ManifestSchema_1.default;
53
- const errors = CommonUtil_1.default.validateJson(jsonData, schema);
51
+ const errors = shared_utils_1.CommonUtil.validateJson(jsonData, schema);
54
52
  if (errors) {
55
- ColorConsole_1.default.warn(`Manefest.json error: `, ...errors.map((item, index) => {
53
+ shared_utils_1.ColorConsole.warn(`Manefest.json error: `, ...errors.map((item, index) => {
56
54
  return {
57
- word: `\r\n${index + 1}. ${item.message}`,
55
+ word: `\r\n${index + 1}.${item.message}`,
58
56
  style: item instanceof TypeError
59
- ? ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Error)
60
- : ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Warn)
57
+ ? shared_utils_1.ColorConsole.getStyle(shared_utils_1.Loglevel.ERROR)
58
+ : shared_utils_1.ColorConsole.getStyle(shared_utils_1.Loglevel.WARN)
61
59
  };
62
60
  }));
63
61
  const stop = Boolean(errors.find((item) => item instanceof TypeError));
64
62
  if (stop) {
65
- ColorConsole_1.default.throw({
63
+ shared_utils_1.ColorConsole.throw({
66
64
  word: `missing required content, program stoped`,
67
- style: ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Throw)
65
+ style: shared_utils_1.ColorConsole.getStyle(shared_utils_1.Loglevel.THROW)
68
66
  });
69
67
  }
70
68
  }
@@ -87,13 +85,13 @@ class UxFileUtils {
87
85
  rules.forEach((item, index) => {
88
86
  const page = item.page;
89
87
  if (page !== '*' && !pages.includes(page)) {
90
- ColorConsole_1.default.throw(`The ${index + 1}th item of sitemap rules is configured incorrectly, the page ${page} does not exist`);
88
+ shared_utils_1.ColorConsole.throw(`The ${index + 1}th item of sitemap rules is configured incorrectly, the page ${page} does not exist`);
91
89
  }
92
90
  return page;
93
91
  });
94
92
  }
95
93
  catch (error) {
96
- ColorConsole_1.default.warn(error === null || error === void 0 ? void 0 : error.toString());
94
+ shared_utils_1.ColorConsole.warn(error === null || error === void 0 ? void 0 : error.toString());
97
95
  }
98
96
  }
99
97
  }
@@ -24,7 +24,10 @@ declare class UxLoaderUtils {
24
24
  * @param resultFiles
25
25
  * @param context
26
26
  */
27
- static compileAppUxToJavascript(file: IFileParam, resultFiles: IFileParam[], context: IFileLaneContext, compileOption: IJavascriptCompileOption): Promise<void>;
27
+ static compileAppUxToJavascript(file: IFileParam, context: IFileLaneContext, compileOption: IJavascriptCompileOption): Promise<{
28
+ files: IFileParam<any>[];
29
+ logs: ILog[];
30
+ }>;
28
31
  /**
29
32
  * 判断是否为src/app.ux
30
33
  * @param filePath
@@ -37,7 +40,7 @@ declare class UxLoaderUtils {
37
40
  * @param filePath
38
41
  * @returns
39
42
  */
40
- static isPageUx(context: IFileLaneContext, filePath: string): any;
43
+ static isPageUx(context: IFileLaneContext, filePath: string): boolean;
41
44
  /**
42
45
  * 获取app.ux的内容,且只返回script和style内容
43
46
  * @param fileContent
@@ -51,14 +54,14 @@ declare class UxLoaderUtils {
51
54
  * @returns
52
55
  */
53
56
  static wrapTempalte(templateTree: SourceFile, file: IFileParam, compilerOption: IJavascriptCompileOption): string;
54
- private static wrapStyle;
57
+ static wrapStyle(code: string, file: IFileParam, compilerOption: IJavascriptCompileOption): string;
55
58
  /**
56
59
  * 给script增加外层包裹内容
57
60
  * @param isPageUx
58
61
  * @param appScriptTree
59
62
  * @returns
60
63
  */
61
- static handleScriptContent(isPageUx: boolean, appScriptTree: SourceFile): string;
64
+ static wrapScript(isPageUx: boolean, appScriptTree: SourceFile): string;
62
65
  static getReturnType(isPageUx: boolean): "$app_exports$['entry'] =" | "module.exports = ";
63
66
  }
64
67
  export default UxLoaderUtils;
@@ -36,12 +36,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  const generator_1 = require("@aiot-toolkit/generator");
39
- const UxParser_1 = __importDefault(require("@aiot-toolkit/parser/lib/ux/parser/UxParser"));
39
+ const parser_1 = require("@aiot-toolkit/parser");
40
40
  const UxToTypescript_1 = __importDefault(require("@aiot-toolkit/parser/lib/ux/translate/vela/UxToTypescript"));
41
- const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
42
- const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
43
- const StringUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/StringUtil"));
44
- const parse5 = __importStar(require("parse5"));
41
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
42
+ const parse5 = __importStar(require("aiot-parse5"));
43
+ const fs_extra_1 = __importDefault(require("fs-extra"));
45
44
  const path_1 = __importDefault(require("path"));
46
45
  const ts_morph_1 = require("ts-morph");
47
46
  const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
@@ -68,44 +67,63 @@ class UxLoaderUtils {
68
67
  const newFileName = `${name}.js`;
69
68
  //判断文本,空文本则结束该文件处理
70
69
  if (!content) {
71
- ColorConsole_1.default.warn(`The file '${fullName}' under the path '${filePath}' has no content `);
70
+ shared_utils_1.ColorConsole.warn(`The file '${fullName}' under the path '${filePath}' has no content `);
72
71
  return {
73
72
  files: [],
74
73
  logs
75
74
  };
76
75
  }
76
+ // 区分页面组件和子组件
77
+ const isPageUx = UxLoaderUtils.isPageUx(context, filePath);
77
78
  // 配置转换参数
78
79
  const options = {
79
80
  projectPath: context.projectPath,
81
+ projectType: shared_utils_1.ProjectType.VELA_UX,
80
82
  filePath,
83
+ fileType: isAppUx ? 'app' : isPageUx ? 'page' : '',
84
+ content: content.toString(),
81
85
  onLog: (log) => {
82
86
  logs.push(log);
83
87
  }
84
88
  };
89
+ // 收集图片资源
90
+ const ImageResources = [];
91
+ const collectImageResource = (originFilePath) => {
92
+ const assetDir = 'dynamicAssets';
93
+ const sourcePath = path_1.default.resolve(options.projectPath, compilerOption.sourceRoot);
94
+ const assetPath = path_1.default.resolve(sourcePath, assetDir);
95
+ const { name, ext } = path_1.default.parse(originFilePath);
96
+ const hashName = shared_utils_1.CommonUtil.calcImageDigest(originFilePath);
97
+ const newFilePath = path_1.default.join(assetPath, `${name}-${hashName}${ext}`);
98
+ const relativePath = path_1.default.posix.sep + path_1.default.relative(sourcePath, newFilePath).split(path_1.default.sep).join(path_1.default.posix.sep);
99
+ ImageResources.push({
100
+ path: newFilePath,
101
+ content: fs_extra_1.default.readFileSync(originFilePath)
102
+ });
103
+ return relativePath;
104
+ };
85
105
  // 开始转换
86
106
  const globalVar = ('globalVar' in context && context.globalVar) || {};
87
- const parserResult = yield new UxParser_1.default(options, globalVar).parser(content.toString(), fullName);
107
+ const parserResult = yield new parser_1.UxParser(options, compilerOption, globalVar, collectImageResource).parser();
88
108
  // 区分app.ux和一般ux
89
109
  // app.ux解析结果中加上manifest.json的内容
90
110
  const manifestJson = `require('./manifest.json')`;
91
- // 区分页面组件和子组件
92
- const isPageUx = UxLoaderUtils.isPageUx(context, filePath);
93
111
  const integrateFunction = (appImport, appStyleTree, appTemplateTree, appScriptTree) => {
94
112
  // script代码放在第三个位置不能变化,影响更新source map
95
113
  return isAppUx
96
114
  ? [
97
115
  `${appImport.join('\n')}`,
98
- `var $app_style$ = ${UxLoaderUtils.wrapStyle(StringUtil_1.default.arrayTostring(appStyleTree, true), file, compilerOption)}`,
99
- `var $app_script$ = ${UxLoaderUtils.handleScriptContent(false, appScriptTree)}\n`,
100
- `$app_script$({}, $app_exports$, $app_require$);\n\n`,
116
+ `var $app_style$ = ${UxLoaderUtils.wrapStyle(JSON.stringify(appStyleTree), file, compilerOption)}`,
117
+ `var $app_script$ = ${UxLoaderUtils.wrapScript(false, appScriptTree)}`,
118
+ `$app_script$({}, $app_exports$, $app_require$);`,
101
119
  `$app_exports$.default.style = $app_style$;`,
102
120
  `$app_exports$.default.manifest = ${manifestJson}`
103
121
  ]
104
122
  : [
105
123
  `${appImport.join('\n')}`,
106
- `var $app_style$ = ${UxLoaderUtils.wrapStyle(StringUtil_1.default.arrayTostring(appStyleTree, true), file, compilerOption)}\n`,
107
- `var $app_script$ = ${UxLoaderUtils.handleScriptContent(isPageUx, appScriptTree)}`,
108
- `var $app_template$ = ${UxLoaderUtils.wrapTempalte(appTemplateTree, file, compilerOption)}\n`,
124
+ `var $app_style$ = ${UxLoaderUtils.wrapStyle(JSON.stringify(appStyleTree), file, compilerOption)}`,
125
+ `var $app_script$ = ${UxLoaderUtils.wrapScript(isPageUx, appScriptTree)}`,
126
+ `var $app_template$ = ${UxLoaderUtils.wrapTempalte(appTemplateTree, file, compilerOption)}`,
109
127
  `${UxLoaderUtils.getReturnType(isPageUx)} function ($app_exports$) {`,
110
128
  `$app_script$({}, $app_exports$, $app_require$);`,
111
129
  `$app_exports$.default.template = $app_template$;`,
@@ -113,7 +131,7 @@ class UxLoaderUtils {
113
131
  `}`
114
132
  ];
115
133
  };
116
- const { targetTree, mapList, sourceMap } = yield new UxToTypescript_1.default(options, project, integrateFunction, compilerOption).translate(parserResult.ast, []);
134
+ const { targetTree, mapList, sourceMap } = yield new UxToTypescript_1.default(options, project, integrateFunction, compilerOption, context).translate(parserResult.ast, []);
117
135
  const { code } = new generator_1.TypescriptGenerator().generate({
118
136
  sourceFilePath: fullName,
119
137
  targetFilePath: newFileName,
@@ -124,13 +142,14 @@ class UxLoaderUtils {
124
142
  return {
125
143
  files: [
126
144
  {
127
- path: FileUtil_1.default.updatePath(filePath, newFileName),
145
+ path: filePath,
128
146
  content: code
129
147
  },
130
148
  {
131
- path: FileUtil_1.default.updatePath(filePath, `${name}.js.map`),
149
+ path: shared_utils_1.FileUtil.updateFileName(filePath, `${name}${ext}.map`),
132
150
  content: sourceMap.toString()
133
- }
151
+ },
152
+ ...ImageResources
134
153
  ],
135
154
  logs
136
155
  };
@@ -142,7 +161,7 @@ class UxLoaderUtils {
142
161
  * @param resultFiles
143
162
  * @param context
144
163
  */
145
- static compileAppUxToJavascript(file, resultFiles, context, compileOption) {
164
+ static compileAppUxToJavascript(file, context, compileOption) {
146
165
  return __awaiter(this, void 0, void 0, function* () {
147
166
  const { path: filePath, content } = file;
148
167
  let appContent = content;
@@ -153,7 +172,7 @@ class UxLoaderUtils {
153
172
  }
154
173
  // 解析script和style两部分
155
174
  const compileResult = yield UxLoaderUtils.compileUxToJavascript({ path: filePath, content: appContent }, context, isAppUx, compileOption);
156
- resultFiles.push(...compileResult.files);
175
+ return compileResult;
157
176
  });
158
177
  }
159
178
  /**
@@ -173,7 +192,8 @@ class UxLoaderUtils {
173
192
  * @returns
174
193
  */
175
194
  static isPageUx(context, filePath) {
176
- return ('entries' in context && context.entries.find((entryItem) => entryItem === filePath));
195
+ var _a;
196
+ return Boolean((_a = context.entries) === null || _a === void 0 ? void 0 : _a.includes(filePath));
177
197
  }
178
198
  /**
179
199
  * 获取app.ux的内容,且只返回script和style内容
@@ -289,7 +309,7 @@ class UxLoaderUtils {
289
309
  * @param appScriptTree
290
310
  * @returns
291
311
  */
292
- static handleScriptContent(isPageUx, appScriptTree) {
312
+ static wrapScript(isPageUx, appScriptTree) {
293
313
  if (isPageUx) {
294
314
  // 页面组件添加ViewModel处理代码
295
315
  appScriptTree.addStatements(UxLoaderUtils.contenAccess);
@@ -0,0 +1,27 @@
1
+ import { ILog } from '@aiot-toolkit/shared-utils';
2
+ import { IFileLaneContext, IFileParam } from 'file-lane';
3
+ import IJavascriptCompileOption from '../../../compiler/javascript/interface/IJavascriptCompileOption';
4
+ /**
5
+ * AndroidUx
6
+ */
7
+ declare class AndroidUx {
8
+ /**
9
+ *
10
+ * 编译 ux 文件
11
+ * 1. 获取文件类型:app page 普通ux
12
+ * 2. 使用`UxParse`解析
13
+ * 3. 使用`UxToTypeScript`转换
14
+ * 4. 使用`TypeScriptGenerator`生成
15
+ * @param params
16
+ */
17
+ compileUx(params: {
18
+ context: IFileLaneContext;
19
+ file: IFileParam;
20
+ compilerOption: IJavascriptCompileOption;
21
+ }): Promise<{
22
+ files: IFileParam[];
23
+ logs: ILog[];
24
+ }>;
25
+ private getFileType;
26
+ }
27
+ export default AndroidUx;
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const parser_1 = require("@aiot-toolkit/parser");
16
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
17
+ const UxToTypescript_1 = __importDefault(require("@aiot-toolkit/parser/lib/ux/translate/android/UxToTypescript"));
18
+ const generator_1 = require("@aiot-toolkit/generator");
19
+ const path_1 = __importDefault(require("path"));
20
+ /**
21
+ * AndroidUx
22
+ */
23
+ class AndroidUx {
24
+ /**
25
+ *
26
+ * 编译 ux 文件
27
+ * 1. 获取文件类型:app page 普通ux
28
+ * 2. 使用`UxParse`解析
29
+ * 3. 使用`UxToTypeScript`转换
30
+ * 4. 使用`TypeScriptGenerator`生成
31
+ * @param params
32
+ */
33
+ compileUx(params) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ const { context, file, compilerOption } = params;
36
+ const { path: filePath, content } = file;
37
+ const { projectPath } = context;
38
+ const fileType = this.getFileType(filePath, context);
39
+ // 无内容的文件,添加空内容警告
40
+ if (!content) {
41
+ return {
42
+ files: [],
43
+ logs: [
44
+ {
45
+ level: shared_utils_1.Loglevel.WARN,
46
+ message: `${filePath} is empty`,
47
+ filePath
48
+ }
49
+ ]
50
+ };
51
+ }
52
+ const logs = [];
53
+ const option = {
54
+ filePath,
55
+ projectPath,
56
+ projectType: shared_utils_1.ProjectType.ANDDROID_UX,
57
+ fileType,
58
+ onLog: function (log) {
59
+ logs.push(log);
60
+ },
61
+ content: content.toString()
62
+ };
63
+ const uxAst = yield new parser_1.UxParser(option, compilerOption, {}, (path) => path).parser();
64
+ const tsAst = yield new UxToTypescript_1.default(option, compilerOption, context).translate(uxAst.ast, uxAst.offsetList || []);
65
+ const filePathParse = path_1.default.parse(filePath);
66
+ const code = new generator_1.TypescriptGenerator().generate({
67
+ sourceFilePath: filePathParse.base,
68
+ targetFilePath: `${filePathParse.name}.js`,
69
+ ast: tsAst.targetTree,
70
+ mapList: tsAst.mapList
71
+ });
72
+ return {
73
+ files: [
74
+ {
75
+ path: filePath,
76
+ content: code.code
77
+ },
78
+ {
79
+ path: `${filePathParse.dir}/${filePathParse.base}.map`,
80
+ content: code.sourcemap
81
+ }
82
+ // resource todo
83
+ ],
84
+ logs
85
+ };
86
+ });
87
+ }
88
+ getFileType(filePath, context) {
89
+ const { entries } = context;
90
+ if (path_1.default.basename(filePath) === 'app.ux') {
91
+ return 'app';
92
+ }
93
+ else if (entries.includes(filePath)) {
94
+ return 'page';
95
+ }
96
+ }
97
+ }
98
+ exports.default = AndroidUx;
@@ -0,0 +1,10 @@
1
+ declare class XtsFileLaneUtils {
2
+ /**
3
+ * 将buildPath文件夹的内容压缩成zip包,放置于targetPath路径下
4
+ * @param buildPath
5
+ * @param targetPath
6
+ * @param zipRootDirNames 可自定义压缩包内最外层目录的名称
7
+ */
8
+ static zipProject(buildPath: string[], targetFile: string, zipRootDirNames?: string[]): Promise<void>;
9
+ }
10
+ export default XtsFileLaneUtils;