@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,11 +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 TranslateCache_1 = __importDefault(require("@aiot-toolkit/parser/lib//ux/translate/vela/TranslateCache"));
17
16
  const shared_utils_1 = require("@aiot-toolkit/shared-utils");
18
- const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
19
- const CommonUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/CommonUtil"));
20
- const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
21
17
  const fs_extra_1 = __importDefault(require("fs-extra"));
22
18
  const lodash_1 = __importDefault(require("lodash"));
23
19
  const path_1 = __importDefault(require("path"));
@@ -26,7 +22,7 @@ const JavascriptCompiler_1 = __importDefault(require("../../compiler/javascript/
26
22
  const JavascriptDefaultCompileOption_1 = __importDefault(require("../../compiler/javascript/JavascriptDefaultCompileOption"));
27
23
  const Jsc_1 = __importDefault(require("../../compiler/javascript/vela/utils/Jsc"));
28
24
  const ZipUtil_1 = __importDefault(require("../../compiler/javascript/vela/utils/ZipUtil"));
29
- const UxFileUtils_1 = __importDefault(require("./UxFileUtils"));
25
+ const UxFileUtils_1 = __importDefault(require("../../utils/ux/UxFileUtils"));
30
26
  const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
31
27
  /**
32
28
  * UxFollowWorks
@@ -38,7 +34,7 @@ UxFollowWorks.webpack = (context, config, compilerOption) => __awaiter(void 0, v
38
34
  return new JavascriptCompiler_1.default()
39
35
  .compile(Object.assign(Object.assign({ projectPath: path_1.default.join(context.projectPath, context.output), mode: CompileMode_1.default.DEVELOPMENT, devtool: false, platform: 'vela' }, JavascriptDefaultCompileOption_1.default), compilerOption))
40
36
  .then(() => {
41
- ColorConsole_1.default.info(`webpack complete`);
37
+ shared_utils_1.ColorConsole.info(`webpack complete`);
42
38
  })
43
39
  .catch(({ errors, warnings }) => {
44
40
  const errorLength = (errors === null || errors === void 0 ? void 0 : errors.length) || 0;
@@ -50,7 +46,7 @@ UxFollowWorks.webpack = (context, config, compilerOption) => __awaiter(void 0, v
50
46
  return `${index + 1}. ${item.message}`;
51
47
  })
52
48
  .join('\r\n'),
53
- style: ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Throw)
49
+ style: shared_utils_1.ColorConsole.getStyle(shared_utils_1.Loglevel.THROW)
54
50
  });
55
51
  }
56
52
  if (warnings === null || warnings === void 0 ? void 0 : warnings.length) {
@@ -60,15 +56,15 @@ UxFollowWorks.webpack = (context, config, compilerOption) => __awaiter(void 0, v
60
56
  return `${errorLength + index + 1}. ${item.message}`;
61
57
  })
62
58
  .join('\r\n'),
63
- style: ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Warn)
59
+ style: shared_utils_1.ColorConsole.getStyle(shared_utils_1.Loglevel.WARN)
64
60
  });
65
61
  }
66
62
  if (errors === null || errors === void 0 ? void 0 : errors.length) {
67
- ColorConsole_1.default.throw(...messages);
63
+ shared_utils_1.ColorConsole.throw(...messages);
68
64
  throw new Error();
69
65
  }
70
66
  else {
71
- ColorConsole_1.default.warn(...messages);
67
+ shared_utils_1.ColorConsole.warn(...messages);
72
68
  }
73
69
  });
74
70
  });
@@ -78,7 +74,7 @@ UxFollowWorks.protobuf = (context, config, compilerOption) => __awaiter(void 0,
78
74
  }
79
75
  });
80
76
  UxFollowWorks.jsc = (context, config, compilerOption) => __awaiter(void 0, void 0, void 0, function* () {
81
- if (compilerOption && compilerOption.disabledJSC === false) {
77
+ if (compilerOption && compilerOption.disabledJsc === false) {
82
78
  return new Jsc_1.default(context.projectPath, path_1.default.join(context.projectPath, context.output, compilerOption.outputPath)).jsc();
83
79
  }
84
80
  });
@@ -115,7 +111,7 @@ UxFollowWorks.copyResource = (context, config, compilerOption) => __awaiter(void
115
111
  const copyResourceFiles = (compilerOption) => {
116
112
  // 复制除 js/jsx/ts/tsx/json 外,但是包含manifest.json、sitemap.json的文件
117
113
  const { projectPath, sourceRoot, outputPath } = compilerOption;
118
- const includeList = ['sitemap.json', /i18n(.+)\.json/];
114
+ const includeList = [/sitemap\.json$/, /i18n(.+)\.json/];
119
115
  const excludeExtList = [
120
116
  'js',
121
117
  'jsx',
@@ -128,7 +124,6 @@ UxFollowWorks.copyResource = (context, config, compilerOption) => __awaiter(void
128
124
  'sass',
129
125
  'styl',
130
126
  'html',
131
- 'json',
132
127
  'md',
133
128
  'ux',
134
129
  'mix',
@@ -136,8 +131,8 @@ UxFollowWorks.copyResource = (context, config, compilerOption) => __awaiter(void
136
131
  'map'
137
132
  ];
138
133
  const excludeReg = `\.(${excludeExtList.join('|')})$`;
139
- FileUtil_1.default.copyFiles(path_1.default.join(projectPath, sourceRoot), path_1.default.join(projectPath, outputPath), new RegExp(excludeReg));
140
- FileUtil_1.default.copyFiles(path_1.default.join(projectPath, sourceRoot), path_1.default.join(projectPath, outputPath), undefined, includeList);
134
+ shared_utils_1.FileUtil.copyFiles(path_1.default.join(projectPath, sourceRoot), path_1.default.join(projectPath, outputPath), new RegExp(excludeReg));
135
+ shared_utils_1.FileUtil.copyFiles(path_1.default.join(projectPath, sourceRoot), path_1.default.join(projectPath, outputPath), undefined, includeList);
141
136
  };
142
137
  /**
143
138
  * 写入 manifest.json 文件
@@ -146,17 +141,18 @@ UxFollowWorks.copyResource = (context, config, compilerOption) => __awaiter(void
146
141
  * @param compilerOption
147
142
  */
148
143
  const updateManifest = (compilerOption) => {
149
- const { projectPath, sourceRoot, outputPath } = compilerOption;
144
+ const { projectPath, sourceRoot, outputPath, completeFeature } = compilerOption;
150
145
  const content = UxFileUtils_1.default.getMainfestInfo(projectPath, sourceRoot);
146
+ const translateCache = context.translateCache;
151
147
  if (!content.minAPILevel) {
152
148
  content.minAPILevel = 1;
153
149
  }
154
150
  if (!content.packageInfo) {
155
151
  content.packageInfo = ZipUtil_1.default.createComment(compilerOption);
156
152
  }
157
- if (TranslateCache_1.default.featureCache.size) {
153
+ if (completeFeature && (translateCache === null || translateCache === void 0 ? void 0 : translateCache.featureCache.size)) {
158
154
  const featureSet = new Set([
159
- ...Array.from(TranslateCache_1.default.featureCache),
155
+ ...Array.from(translateCache.featureCache),
160
156
  ...(content.features || []).map((item) => item.name)
161
157
  ]);
162
158
  content.features = Array.from(featureSet).map((item) => {
@@ -180,7 +176,7 @@ UxFollowWorks.copyResource = (context, config, compilerOption) => __awaiter(void
180
176
  const files = ZipUtil_1.default.getSortedFiles(outputAbsPath, compilerOption, UxFileUtils_1.default.getMainfestInfo(projectPath, sourceRoot));
181
177
  const digestDic = Object.fromEntries(files.map((item) => [
182
178
  item,
183
- CommonUtil_1.default.calcDataDigest(fs_extra_1.default.readFileSync(path_1.default.join(outputAbsPath, item))).toString('hex')
179
+ shared_utils_1.CommonUtil.calcDataDigest(fs_extra_1.default.readFileSync(path_1.default.join(outputAbsPath, item))).toString('hex')
184
180
  ]));
185
181
  const hashJson = [
186
182
  {
@@ -195,9 +191,9 @@ UxFollowWorks.copyResource = (context, config, compilerOption) => __awaiter(void
195
191
  fs_extra_1.default.outputFileSync(path_1.default.join(outputAbsPath, ZipUtil_1.default.CERT_PATH), buffer);
196
192
  });
197
193
  if (compilerOption) {
198
- copyResourceFiles(compilerOption);
199
- updateManifest(compilerOption);
200
- genDeviceManifests(compilerOption);
194
+ yield copyResourceFiles(compilerOption);
195
+ yield updateManifest(compilerOption);
196
+ yield genDeviceManifests(compilerOption);
201
197
  yield genMetaFiles(compilerOption);
202
198
  }
203
199
  });
@@ -228,9 +224,7 @@ UxFollowWorks.moveBackResult = (context, config, compilerOption) => __awaiter(vo
228
224
  ];
229
225
  targetList.forEach((item) => {
230
226
  fs_extra_1.default.moveSync(item.from, item.to, { overwrite: true });
231
- fs_extra_1.default.removeSync(item.from);
232
227
  });
233
- fs_extra_1.default.removeSync(projectPath);
234
228
  });
235
229
  /**
236
230
  * 创建 node_module 软链
@@ -242,12 +236,18 @@ UxFollowWorks.symlinkNodeModule = (context, config, compilerOption) => __awaiter
242
236
  if (!compilerOption) {
243
237
  return;
244
238
  }
245
- const foldList = ['node_modules'];
246
- foldList.forEach((item) => {
247
- const sourcePath = path_1.default.join(context.projectPath, item);
248
- if (fs_extra_1.default.existsSync(sourcePath)) {
249
- fs_extra_1.default.symlinkSync(sourcePath, path_1.default.join(compilerOption.projectPath, item), 'junction');
250
- }
251
- });
239
+ try {
240
+ const foldList = ['node_modules'];
241
+ foldList.forEach((item) => {
242
+ const sourcePath = path_1.default.join(context.projectPath, item);
243
+ const targetPath = path_1.default.join(compilerOption.projectPath, item);
244
+ if (fs_extra_1.default.existsSync(sourcePath) && !fs_extra_1.default.existsSync(targetPath)) {
245
+ fs_extra_1.default.symlinkSync(sourcePath, targetPath, 'junction');
246
+ }
247
+ });
248
+ }
249
+ catch (error) {
250
+ throw new Error(`${(error === null || error === void 0 ? void 0 : error.toString()) || 'unknown error'}. Please check whether the file system of the current disk supports the creation of soft links.`);
251
+ }
252
252
  });
253
253
  exports.default = UxFollowWorks;
@@ -1,4 +1,4 @@
1
- import { FollowWork } from 'file-lane/lib/interface/IFileLaneConfig';
1
+ import { FollowWork } from 'file-lane';
2
2
  export interface Aspects {
3
3
  path: string;
4
4
  name: string;
@@ -13,8 +13,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.generateEntryFile = exports.XtsEntryFileName = exports.entryTemplate = void 0;
16
- const Framework_1 = require("@aiot-toolkit/parser/lib/xts/enum/Framework");
17
- 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");
18
18
  const fs_extra_1 = __importDefault(require("fs-extra"));
19
19
  const path_1 = __importDefault(require("path"));
20
20
  const entryTemplate = (options) => {
@@ -29,7 +29,7 @@ const entryTemplate = (options) => {
29
29
  const { routes = [] } = aspect;
30
30
  for (let r = 0; r < (routes === null || routes === void 0 ? void 0 : routes.length); r++) {
31
31
  const route = routes[r];
32
- imports += `import Page${i + 1}_${r + 1}, { ${Framework_1.HomeState.interface} as ${Framework_1.HomeState.interface}${i + 1}_${r + 1}_ } from './${route.importPath}'\n`;
32
+ imports += `import Page${i + 1}_${r + 1}, { ${parser_1.HomeState.interface} as ${parser_1.HomeState.interface}${i + 1}_${r + 1}_ } from './${route.importPath}'\n`;
33
33
  }
34
34
  }
35
35
  return imports;
@@ -45,7 +45,7 @@ const entryTemplate = (options) => {
45
45
  for (let r = 0; r < routes.length; r++) {
46
46
  const route = routes[r];
47
47
  res += `
48
- pathPages_${i + 1}.set('${route.route}', function (params?: ${Framework_1.HomeState.interface}${i + 1}_${r + 1}_): Page {
48
+ pathPages_${i + 1}.set('${route.route}', function (params?: ${parser_1.HomeState.interface}${i + 1}_${r + 1}_): Page {
49
49
  return new Page${i + 1}_${r + 1}(params)
50
50
  })
51
51
  `;
@@ -76,7 +76,7 @@ const entryTemplate = (options) => {
76
76
 
77
77
  // export function
78
78
  on
79
- } from '../node_modules/${Framework_1.tsFrameWork.name}/index'
79
+ } from '../node_modules/${parser_1.tsFrameWork.name}/index'
80
80
 
81
81
  // import app
82
82
  import AppClass from './${options.appPath}'
@@ -127,19 +127,19 @@ const generateEntryFile = function generateEntryFile(context, _, compilerOptions
127
127
  return __awaiter(this, void 0, void 0, function* () {
128
128
  const { projectPath, output } = context;
129
129
  if ((_a = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.skip) === null || _a === void 0 ? void 0 : _a.includes('xts2ts')) {
130
- ColorConsole_1.default.info(`### skip generate entry file due to --skip xts2ts}`);
130
+ shared_utils_1.ColorConsole.info(`### skip generate entry file due to --skip xts2ts}`);
131
131
  return;
132
132
  }
133
- ColorConsole_1.default.info(`Generating entry file`);
133
+ shared_utils_1.ColorConsole.info(`Generating entry file`);
134
134
  const buildDir = path_1.default.resolve(projectPath, output);
135
135
  const appManifestPath = path_1.default.join(buildDir, 'app', 'manifest.json');
136
136
  const appManifest = getManifest(appManifestPath);
137
137
  if (!appManifest) {
138
- ColorConsole_1.default.throw('not find app/manifest.json file !');
138
+ shared_utils_1.ColorConsole.throw('not find app/manifest.json file !');
139
139
  }
140
140
  const appTs = path_1.default.join(buildDir, 'app', 'app.ts');
141
141
  if (!fs_extra_1.default.existsSync(appTs)) {
142
- ColorConsole_1.default.throw('not find app/app.ts file !');
142
+ shared_utils_1.ColorConsole.throw('not find app/app.ts file !');
143
143
  }
144
144
  function relativeDist(tar) {
145
145
  return path_1.default.join('.', path_1.default.relative(buildDir, tar)).replace(path_1.default.sep, '/');
@@ -177,7 +177,7 @@ const generateEntryFile = function generateEntryFile(context, _, compilerOptions
177
177
  }
178
178
  const template = (0, exports.entryTemplate)(opt);
179
179
  fs_extra_1.default.writeFileSync(path_1.default.join(projectPath, output, exports.XtsEntryFileName), template);
180
- ColorConsole_1.default.info(`entry file built`);
180
+ shared_utils_1.ColorConsole.info(`entry file built`);
181
181
  });
182
182
  };
183
183
  exports.generateEntryFile = generateEntryFile;
@@ -1,3 +1,3 @@
1
- import { FollowWork } from 'file-lane/lib/interface/IFileLaneConfig';
1
+ import { FollowWork } from 'file-lane';
2
2
  import { IXtsCompileOptions } from '../../interface/ICompileOptions';
3
3
  export declare const generateRpk: FollowWork<IXtsCompileOptions>;
@@ -38,12 +38,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
38
38
  exports.generateRpk = void 0;
39
39
  const path_1 = __importDefault(require("path"));
40
40
  const XtsFollowWorks_1 = __importDefault(require("../../utils/xts/XtsFollowWorks"));
41
- const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
41
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
42
42
  const ts2wasm_1 = require("./ts2wasm");
43
43
  const generateRpk = (context, _, compilerOptions) => __awaiter(void 0, void 0, void 0, function* () {
44
44
  var _a;
45
45
  if ((_a = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.skip) === null || _a === void 0 ? void 0 : _a.includes('package')) {
46
- ColorConsole_1.default.info(`### skip package due to --skip ${compilerOptions.skip.join(',')}`);
46
+ shared_utils_1.ColorConsole.info(`### skip package due to --skip ${compilerOptions.skip.join(',')}`);
47
47
  return;
48
48
  }
49
49
  const manifestPath = path_1.default.resolve(context.projectPath, 'app', 'manifest.json');
@@ -1,4 +1,4 @@
1
- import { FollowWork } from 'file-lane/lib/interface/IFileLaneConfig';
1
+ import { FollowWork } from 'file-lane';
2
2
  import { IXtsCompileOptions } from '../../interface/ICompileOptions';
3
3
  export declare const wasmPackageName = "wasmUnpacked";
4
4
  /**
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.ts2wasm = exports.wasmPackageName = 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 fast_glob_1 = __importDefault(require("fast-glob"));
19
19
  const fs_1 = __importDefault(require("fs"));
@@ -37,14 +37,14 @@ const ts2wasm = (context, _, compilerOptions) => __awaiter(void 0, void 0, void
37
37
  function compile() {
38
38
  // TODO: 后续修改为 @mi
39
39
  const ts2wasmpath = path_1.default.resolve(projectPath, 'node_modules', 'mi/wasmnizer-ts');
40
- ColorConsole_1.default.info('### Waiting for generating app.wasm file.');
40
+ shared_utils_1.ColorConsole.info('### Waiting for generating app.wasm file.');
41
41
  const res = (0, child_process_1.execSync)(`node ${ts2wasmpath}/build/cli/ts2wasm.js ${entryFile} -o ${wasmDir}/app.wasm`, {
42
42
  encoding: 'utf-8'
43
43
  });
44
- ColorConsole_1.default.info(`### ts2wasm ### ${res.toString()}`);
44
+ shared_utils_1.ColorConsole.info(`### ts2wasm ### ${res.toString()}`);
45
45
  }
46
46
  if ((_a = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.skip) === null || _a === void 0 ? void 0 : _a.includes('ts2wasm')) {
47
- ColorConsole_1.default.info(`### skip compile ts to wasm due to --skip ${compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.skip.join(',')}`);
47
+ shared_utils_1.ColorConsole.info(`### skip compile ts to wasm due to --skip ${compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.skip.join(',')}`);
48
48
  }
49
49
  else {
50
50
  compile();
package/lib/index.d.ts CHANGED
@@ -1,2 +1,10 @@
1
1
  import XtsConfig from './config/XtsConfig';
2
- export { XtsConfig };
2
+ import JavascriptDefaultCompileOption, { setServerPort } from './compiler/javascript/JavascriptDefaultCompileOption';
3
+ import UxConfig from './config/UxConfig';
4
+ import CompileMode from './compiler/enum/CompileMode';
5
+ import IJavascriptCompileOption from './compiler/javascript/interface/IJavascriptCompileOption';
6
+ import IQuickAppConfig from './compiler/javascript/vela/interface/IQuickAppConfig';
7
+ import UxFileUtils from './utils/ux/UxFileUtils';
8
+ import IManifest from './compiler/javascript/vela/interface/IManifest';
9
+ import { ISkipList, IXtsCompileOptions, skipList } from './interface/ICompileOptions';
10
+ export { XtsConfig, UxConfig, JavascriptDefaultCompileOption, CompileMode, IJavascriptCompileOption, IQuickAppConfig, setServerPort, UxFileUtils, IManifest, skipList, IXtsCompileOptions, ISkipList };
package/lib/index.js CHANGED
@@ -1,8 +1,42 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.XtsConfig = void 0;
29
+ exports.skipList = exports.UxFileUtils = exports.setServerPort = exports.CompileMode = exports.JavascriptDefaultCompileOption = exports.UxConfig = exports.XtsConfig = void 0;
7
30
  const XtsConfig_1 = __importDefault(require("./config/XtsConfig"));
8
31
  exports.XtsConfig = XtsConfig_1.default;
32
+ const JavascriptDefaultCompileOption_1 = __importStar(require("./compiler/javascript/JavascriptDefaultCompileOption"));
33
+ exports.JavascriptDefaultCompileOption = JavascriptDefaultCompileOption_1.default;
34
+ Object.defineProperty(exports, "setServerPort", { enumerable: true, get: function () { return JavascriptDefaultCompileOption_1.setServerPort; } });
35
+ const UxConfig_1 = __importDefault(require("./config/UxConfig"));
36
+ exports.UxConfig = UxConfig_1.default;
37
+ const CompileMode_1 = __importDefault(require("./compiler/enum/CompileMode"));
38
+ exports.CompileMode = CompileMode_1.default;
39
+ const UxFileUtils_1 = __importDefault(require("./utils/ux/UxFileUtils"));
40
+ exports.UxFileUtils = UxFileUtils_1.default;
41
+ const ICompileOptions_1 = require("./interface/ICompileOptions");
42
+ Object.defineProperty(exports, "skipList", { enumerable: true, get: function () { return ICompileOptions_1.skipList; } });
@@ -1,9 +1,11 @@
1
1
  import { IFileLaneContext, IFileParam, ILoader } from 'file-lane';
2
+ import IJavascriptCompileOption from '../../compiler/javascript/interface/IJavascriptCompileOption';
2
3
  /**
3
4
  * JsLoader
4
5
  */
5
6
  declare class JsLoader implements ILoader {
6
7
  context: IFileLaneContext;
8
+ compilerOption: IJavascriptCompileOption;
7
9
  parser(files: IFileParam<any>[]): IFileParam<any>[] | Promise<IFileParam<any>[]>;
8
10
  }
9
11
  export default JsLoader;
@@ -1,17 +1,12 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const ParserUtil_1 = __importDefault(require("@aiot-toolkit/parser/lib/utils/ParserUtil"));
7
- const ScriptParser_1 = __importDefault(require("@aiot-toolkit/parser/lib/ux/parser/ScriptParser"));
8
- const ScriptToTypescript_1 = __importDefault(require("@aiot-toolkit/parser/lib/ux/translate/vela/ScriptToTypescript"));
3
+ const parser_1 = require("@aiot-toolkit/parser");
4
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
9
5
  /**
10
6
  * JsLoader
11
7
  */
12
8
  class JsLoader {
13
9
  parser(files) {
14
- const project = ParserUtil_1.default.createProject();
15
10
  const onLog = () => { };
16
11
  return files.map((item) => {
17
12
  if (!item.content) {
@@ -23,13 +18,15 @@ class JsLoader {
23
18
  const options = {
24
19
  filePath: item.path,
25
20
  projectPath: this.context.projectPath,
21
+ content: item.content.toString(),
22
+ projectType: shared_utils_1.ProjectType.getProjectType(this.context.projectPath),
26
23
  onLog
27
24
  };
28
25
  return {
29
26
  path: item.path,
30
- content: new ScriptToTypescript_1.default(project, options)
27
+ content: new parser_1.ScriptToTypescript(options, this.compilerOption, this.context)
31
28
  .translate({
32
- content: new ScriptParser_1.default(options).parser(item.content.toString()).ast.content
29
+ content: new parser_1.ScriptParser(options).parser(item.content.toString()).ast.content
33
30
  }, [])
34
31
  .targetTree.getFullText()
35
32
  };
@@ -12,8 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
16
- const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
15
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
17
16
  const path_1 = __importDefault(require("path"));
18
17
  const PngUtils_1 = __importDefault(require("../../utils/PngUtils"));
19
18
  const aaptjs = require('@hap-toolkit/aaptjs');
@@ -30,11 +29,11 @@ class PngLoader {
30
29
  const fullName = `${name}${ext}`;
31
30
  //判断文本,空文本则结束该文件处理
32
31
  if (!content) {
33
- ColorConsole_1.default.warn(`The file '${fullName}' under the path '${filePath}' has no content `);
32
+ shared_utils_1.ColorConsole.warn(`The file '${fullName}' under the path '${filePath}' has no content `);
34
33
  return [];
35
34
  }
36
35
  // 判断传入的.png资源是不是.9.png资源
37
- if (FileUtil_1.default.match(filePath, /.+\.9\.png$/)) {
36
+ if (shared_utils_1.FileUtil.match(filePath, /.+\.9\.png$/)) {
38
37
  yield this.compile9Png(filePath);
39
38
  }
40
39
  else {
@@ -54,7 +53,7 @@ class PngLoader {
54
53
  yield aaptjs.singleCrunch(filePath, outputFile);
55
54
  }
56
55
  catch (error) {
57
- ColorConsole_1.default.throw(`.9.png resource file processing failed`);
56
+ shared_utils_1.ColorConsole.throw(`.9.png resource file processing failed`);
58
57
  }
59
58
  }
60
59
  });
@@ -0,0 +1,11 @@
1
+ import { IFileLaneContext, IFileParam, ILoader } from 'file-lane';
2
+ import IJavascriptCompileOption from '../../../compiler/javascript/interface/IJavascriptCompileOption';
3
+ /**
4
+ * UxLoader
5
+ */
6
+ declare class UxLoader implements ILoader {
7
+ context: IFileLaneContext;
8
+ compilerOption: IJavascriptCompileOption;
9
+ parser(files: IFileParam<any>[]): Promise<IFileParam<any>[]>;
10
+ }
11
+ export default UxLoader;
@@ -0,0 +1,39 @@
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 shared_utils_1 = require("@aiot-toolkit/shared-utils");
16
+ const path_1 = __importDefault(require("path"));
17
+ const AndroidUx_1 = __importDefault(require("../../../utils/ux/android/AndroidUx"));
18
+ /**
19
+ * UxLoader
20
+ */
21
+ class UxLoader {
22
+ parser(files) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const result = [];
25
+ const { projectPath } = this.context;
26
+ for (let item of files) {
27
+ const { files, logs } = yield new AndroidUx_1.default().compileUx({
28
+ context: this.context,
29
+ file: item,
30
+ compilerOption: this.compilerOption
31
+ });
32
+ shared_utils_1.CommonUtil.processingLogsInTerminal(logs.map((item) => (Object.assign(Object.assign({}, item), { filePath: item.filePath ? path_1.default.relative(projectPath, item.filePath) : '' }))));
33
+ result.push(...files);
34
+ }
35
+ return result;
36
+ });
37
+ }
38
+ }
39
+ exports.default = UxLoader;
@@ -1,5 +1,5 @@
1
1
  import { IFileLaneContext, IFileParam, ILoader } from 'file-lane';
2
- import IJavascriptCompileOption from '../../compiler/javascript/interface/IJavascriptCompileOption';
2
+ import IJavascriptCompileOption from '../../../compiler/javascript/interface/IJavascriptCompileOption';
3
3
  /**
4
4
  * 处理app.ux的Loader
5
5
  * AppUxLoader
@@ -12,7 +12,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const UxLoaderUtils_1 = __importDefault(require("../../utils/ux/UxLoaderUtils"));
15
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
16
+ const path_1 = __importDefault(require("path"));
17
+ const UxLoaderUtils_1 = __importDefault(require("../../../utils/ux/UxLoaderUtils"));
16
18
  /**
17
19
  * 处理app.ux的Loader
18
20
  * AppUxLoader
@@ -20,8 +22,9 @@ const UxLoaderUtils_1 = __importDefault(require("../../utils/ux/UxLoaderUtils"))
20
22
  class AppUxLoader {
21
23
  parser(files) {
22
24
  return __awaiter(this, void 0, void 0, function* () {
23
- const resultFiles = [];
24
- yield UxLoaderUtils_1.default.compileAppUxToJavascript(files[0], resultFiles, this.context, this.compilerOption);
25
+ const { projectPath } = this.context;
26
+ const { files: resultFiles, logs } = yield UxLoaderUtils_1.default.compileAppUxToJavascript(files[0], this.context, this.compilerOption);
27
+ shared_utils_1.CommonUtil.processingLogsInTerminal(logs.map((item) => (Object.assign(Object.assign({}, item), { filePath: item.filePath ? path_1.default.relative(projectPath, item.filePath) : '' }))));
25
28
  return resultFiles;
26
29
  });
27
30
  }
@@ -0,0 +1,24 @@
1
+ import { IFileLaneContext, IFileParam, ILoader } from 'file-lane';
2
+ /**
3
+ * HmlLoader
4
+ */
5
+ declare class HmlLoader implements ILoader {
6
+ context?: IFileLaneContext | undefined;
7
+ compilerOption?: any;
8
+ parser(files: IFileParam<any>[]): IFileParam<any>[] | Promise<IFileParam<any>[]>;
9
+ /**
10
+ * 包裹 hml 文件
11
+ *
12
+ * # 路径
13
+ * 如果存在同路径的 ux 后缀,报错;否则转换为同路径的 ux 后缀
14
+ *
15
+ * # 内容
16
+ * 1. 给hml的内容加上<template></template>
17
+ * 2. 如果存在同路径同名的 script文件,则加到<script></script>中
18
+ * 3. 如果存在同路径同名的 style文件,则加到<style></style>中
19
+ *
20
+ * @param file
21
+ */
22
+ private wrapHml;
23
+ }
24
+ export default HmlLoader;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const parser_1 = require("@aiot-toolkit/parser");
9
+ /**
10
+ * HmlLoader
11
+ */
12
+ class HmlLoader {
13
+ parser(files) {
14
+ return files.map((file) => {
15
+ return this.wrapHml(file);
16
+ });
17
+ }
18
+ /**
19
+ * 包裹 hml 文件
20
+ *
21
+ * # 路径
22
+ * 如果存在同路径的 ux 后缀,报错;否则转换为同路径的 ux 后缀
23
+ *
24
+ * # 内容
25
+ * 1. 给hml的内容加上<template></template>
26
+ * 2. 如果存在同路径同名的 script文件,则加到<script></script>中
27
+ * 3. 如果存在同路径同名的 style文件,则加到<style></style>中
28
+ *
29
+ * @param file
30
+ */
31
+ wrapHml(file) {
32
+ const { path, content } = file;
33
+ const uxExt = parser_1.ExtensionConfig.UX;
34
+ const getFilePath = (ext) => {
35
+ const pathParsed = path_1.default.parse(path);
36
+ pathParsed.ext = ext;
37
+ pathParsed.base = pathParsed.name + ext;
38
+ return path_1.default.format(pathParsed);
39
+ };
40
+ const uxPath = getFilePath(uxExt);
41
+ if (fs_1.default.existsSync(uxPath)) {
42
+ throw new Error(`${uxPath} already exists`);
43
+ }
44
+ const scriptExts = parser_1.ExtensionConfig.SCRIPTS;
45
+ const styleExts = parser_1.ExtensionConfig.STYLES;
46
+ const scriptPath = scriptExts
47
+ .map((item) => getFilePath(item))
48
+ .find((item) => fs_1.default.existsSync(item));
49
+ const stylePath = styleExts.map((item) => getFilePath(item)).find((item) => fs_1.default.existsSync(item));
50
+ let uxContent = ['<template>', content, '</template>'].join('\n');
51
+ if (scriptPath) {
52
+ uxContent += ['<script>', fs_1.default.readFileSync(scriptPath, 'utf-8'), '</script>'].join('\n');
53
+ }
54
+ if (stylePath) {
55
+ uxContent += ['<style>', fs_1.default.readFileSync(stylePath, 'utf-8'), '</style>'].join('\n');
56
+ }
57
+ return {
58
+ path,
59
+ content: uxContent
60
+ };
61
+ }
62
+ }
63
+ exports.default = HmlLoader;
@@ -1,5 +1,5 @@
1
1
  import { IFileLaneContext, IFileParam, ILoader } from 'file-lane';
2
- import IJavascriptCompileOption from '../../compiler/javascript/interface/IJavascriptCompileOption';
2
+ import IJavascriptCompileOption from '../../../compiler/javascript/interface/IJavascriptCompileOption';
3
3
  declare class UxLoader implements ILoader {
4
4
  context: IFileLaneContext;
5
5
  compilerOption: IJavascriptCompileOption;