@aiot-toolkit/aiotpack 2.0.2-beta.10 → 2.0.2-beta.12

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 (59) hide show
  1. package/lib/compiler/interface/ICompileParam.d.ts +1 -1
  2. package/lib/compiler/javascript/JavascriptCompiler.js +19 -6
  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 +7 -0
  8. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.d.ts +2 -0
  9. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js +14 -10
  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.js +2 -5
  21. package/lib/config/UxConfig.d.ts +40 -7
  22. package/lib/config/UxConfig.js +67 -35
  23. package/lib/config/XtsConfig.d.ts +2 -3
  24. package/lib/followWorks/ux/UxFollowWorks.d.ts +1 -1
  25. package/lib/followWorks/ux/UxFollowWorks.js +19 -24
  26. package/lib/followWorks/xts/entryTemplate.d.ts +1 -1
  27. package/lib/followWorks/xts/entryTemplate.js +10 -10
  28. package/lib/followWorks/xts/generateRpk.d.ts +1 -1
  29. package/lib/followWorks/xts/generateRpk.js +2 -2
  30. package/lib/followWorks/xts/ts2wasm.d.ts +1 -1
  31. package/lib/followWorks/xts/ts2wasm.js +4 -4
  32. package/lib/index.d.ts +9 -1
  33. package/lib/index.js +35 -1
  34. package/lib/loader/ux/JsLoader.js +5 -9
  35. package/lib/loader/ux/PngLoader.js +4 -5
  36. package/lib/loader/ux/android/UxLoader.d.ts +11 -0
  37. package/lib/loader/ux/android/UxLoader.js +39 -0
  38. package/lib/loader/ux/{AppUxLoader.d.ts → vela/AppUxLoader.d.ts} +1 -1
  39. package/lib/loader/ux/{AppUxLoader.js → vela/AppUxLoader.js} +3 -12
  40. package/lib/loader/ux/{UxLoader.d.ts → vela/UxLoader.d.ts} +1 -1
  41. package/lib/loader/ux/{UxLoader.js → vela/UxLoader.js} +2 -11
  42. package/lib/loader/xts/XtsLoader.js +6 -7
  43. package/lib/preWorks/ux/UxPreWorks.d.ts +1 -1
  44. package/lib/preWorks/xts/preInstall.d.ts +1 -1
  45. package/lib/preWorks/xts/preInstall.js +4 -4
  46. package/lib/utils/PreWorkUtils.d.ts +1 -2
  47. package/lib/utils/PreWorkUtils.js +27 -32
  48. package/lib/utils/ux/ManifestSchema.d.ts +1 -1
  49. package/lib/utils/ux/UxFileUtils.js +11 -13
  50. package/lib/utils/ux/UxLoaderUtils.d.ts +3 -3
  51. package/lib/utils/ux/UxLoaderUtils.js +14 -14
  52. package/lib/utils/ux/android/AndroidUx.d.ts +27 -0
  53. package/lib/utils/ux/android/AndroidUx.js +98 -0
  54. package/lib/utils/xts/XtsFileLaneUtils.d.ts +10 -0
  55. package/lib/utils/xts/XtsFileLaneUtils.js +68 -0
  56. package/lib/utils/xts/XtsFollowWorks.js +7 -7
  57. package/package.json +6 -5
  58. /package/lib/loader/ux/{HmlLoader.d.ts → vela/HmlLoader.d.ts} +0 -0
  59. /package/lib/loader/ux/{HmlLoader.js → vela/HmlLoader.js} +0 -0
@@ -1,4 +1,4 @@
1
- import { Dictionary } from '@aiot-toolkit/shared-utils/lib/type/Type';
1
+ import { Dictionary } from '@aiot-toolkit/shared-utils';
2
2
  import CompileMode from '../enum/CompileMode';
3
3
  /**
4
4
  * 编译参数
@@ -12,10 +12,11 @@ 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 CommonUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/CommonUtil"));
15
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
16
16
  const lodash_1 = __importDefault(require("lodash"));
17
17
  const path_1 = __importDefault(require("path"));
18
18
  const webpack_1 = require("webpack");
19
+ const AndroidWebpackConfigurator_1 = __importDefault(require("./android/AndroidWebpackConfigurator"));
19
20
  const VelaWebpackConfigurator_1 = __importDefault(require("./vela/VelaWebpackConfigurator"));
20
21
  const UxCompileUtil_1 = __importDefault(require("./vela/utils/UxCompileUtil"));
21
22
  class JavascriptCompiler {
@@ -29,7 +30,7 @@ class JavascriptCompiler {
29
30
  const config = this.createWebpackConfig(param);
30
31
  (0, webpack_1.webpack)(config, (error, stats) => {
31
32
  if (error) {
32
- reject([error]);
33
+ reject({ errors: [error] });
33
34
  }
34
35
  else {
35
36
  const statsObj = stats === null || stats === void 0 ? void 0 : stats.toJson();
@@ -51,7 +52,7 @@ class JavascriptCompiler {
51
52
  });
52
53
  }
53
54
  createWebpackConfig(param) {
54
- const configurator = this.getConfigurator();
55
+ const configurator = this.getConfigurator(param);
55
56
  if (!configurator) {
56
57
  throw new Error(`This project is not supported`);
57
58
  }
@@ -63,7 +64,7 @@ class JavascriptCompiler {
63
64
  }
64
65
  const { projectPath, mode, devtool, outputPath } = param;
65
66
  const buildPath = path_1.default.resolve(projectPath, outputPath);
66
- const quickAppConfig = CommonUtil_1.default.requireModule(path_1.default.join(param.projectPath, this.QUICKAPP_CONFIG));
67
+ const quickAppConfig = shared_utils_1.CommonUtil.requireModule(path_1.default.join(param.projectPath, this.QUICKAPP_CONFIG));
67
68
  const result = {
68
69
  context: projectPath,
69
70
  mode,
@@ -86,6 +87,9 @@ class JavascriptCompiler {
86
87
  }
87
88
  ]
88
89
  },
90
+ resolve: {
91
+ extensions: ['.js', '.ts', '.ux']
92
+ },
89
93
  stats: {
90
94
  builtAt: false,
91
95
  entrypoints: false,
@@ -128,8 +132,17 @@ class JavascriptCompiler {
128
132
  }
129
133
  return lodash_1.default.merge({}, result, quickAppConfig === null || quickAppConfig === void 0 ? void 0 : quickAppConfig.webpack);
130
134
  }
131
- getConfigurator() {
132
- return new VelaWebpackConfigurator_1.default();
135
+ getConfigurator(param) {
136
+ const { projectPath, sourceRoot } = param;
137
+ const projectType = shared_utils_1.ProjectType.getProjectType(projectPath, sourceRoot);
138
+ switch (projectType) {
139
+ case shared_utils_1.ProjectType.VELA_UX:
140
+ return new VelaWebpackConfigurator_1.default();
141
+ case shared_utils_1.ProjectType.ANDDROID_UX:
142
+ return new AndroidWebpackConfigurator_1.default();
143
+ default:
144
+ break;
145
+ }
133
146
  }
134
147
  clean(param) {
135
148
  return __awaiter(this, void 0, void 0, function* () {
@@ -0,0 +1,9 @@
1
+ import VelaWebpackConfigurator from '../vela/VelaWebpackConfigurator';
2
+ import WrapPlugin from './plugin/WrapPlugin';
3
+ /**
4
+ * AndroidWebpackConfigurator
5
+ */
6
+ declare class AndroidWebpackConfigurator extends VelaWebpackConfigurator {
7
+ protected createWrapPlugin(): WrapPlugin;
8
+ }
9
+ export default AndroidWebpackConfigurator;
@@ -0,0 +1,16 @@
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 VelaWebpackConfigurator_1 = __importDefault(require("../vela/VelaWebpackConfigurator"));
7
+ const WrapPlugin_1 = __importDefault(require("./plugin/WrapPlugin"));
8
+ /**
9
+ * AndroidWebpackConfigurator
10
+ */
11
+ class AndroidWebpackConfigurator extends VelaWebpackConfigurator_1.default {
12
+ createWrapPlugin() {
13
+ return new WrapPlugin_1.default(this.param);
14
+ }
15
+ }
16
+ exports.default = AndroidWebpackConfigurator;
@@ -0,0 +1,20 @@
1
+ import { Compiler } from 'webpack';
2
+ import IJavascriptCompileOption from '../../interface/IJavascriptCompileOption';
3
+ /**
4
+ * WrapPlugin
5
+ */
6
+ declare class WrapPlugin {
7
+ private readonly param;
8
+ constructor(param: IJavascriptCompileOption);
9
+ apply(compiler: Compiler): void;
10
+ /**
11
+ * 添加包含代码
12
+ *
13
+ * 1. 仅 page 文件添加
14
+ * @param compilation
15
+ */
16
+ private wrap;
17
+ private wrapPage;
18
+ private wrapApp;
19
+ }
20
+ export default WrapPlugin;
@@ -0,0 +1,78 @@
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 webpack_1 = require("webpack");
7
+ const webpack_sources_1 = require("webpack-sources");
8
+ const UxFileUtils_1 = __importDefault(require("../../../../utils/ux/UxFileUtils"));
9
+ /**
10
+ * WrapPlugin
11
+ */
12
+ class WrapPlugin {
13
+ constructor(param) {
14
+ this.param = param;
15
+ }
16
+ apply(compiler) {
17
+ compiler.hooks.compilation.tap('WrapPlugin', (compilation) => {
18
+ compilation.hooks.processAssets.tap({
19
+ name: 'WrapPlugin',
20
+ stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE
21
+ }, () => {
22
+ this.wrap(compilation);
23
+ });
24
+ });
25
+ }
26
+ /**
27
+ * 添加包含代码
28
+ *
29
+ * 1. 仅 page 文件添加
30
+ * @param compilation
31
+ */
32
+ wrap(compilation) {
33
+ // 获取入口文件
34
+ const entrys = Object.keys(compilation.options.entry).map((item) => `${item}.js`);
35
+ entrys.forEach((entry) => {
36
+ if (compilation.assets[entry]) {
37
+ const source = compilation.assets[entry];
38
+ const isApp = entry === 'app.js';
39
+ compilation.assets[entry] = isApp
40
+ ? this.wrapApp(source)
41
+ : this.wrapPage(source);
42
+ }
43
+ });
44
+ }
45
+ wrapPage(source) {
46
+ return new webpack_sources_1.ConcatSource(`
47
+ (function () {
48
+ var createPageHandler = function () {
49
+ return`, source, `;
50
+ };
51
+ if (typeof window === "undefined") {
52
+ return createPageHandler();
53
+ } else {
54
+ window.createPageHandler = createPageHandler;
55
+ }
56
+ })();`);
57
+ }
58
+ wrapApp(source) {
59
+ const { projectPath, sourceRoot } = this.param;
60
+ return new webpack_sources_1.ConcatSource(`
61
+ (function () {
62
+ var $app_define_wrap$ = $app_define_wrap$ || function () {};
63
+ var manifestJson =${JSON.stringify(UxFileUtils_1.default.getMainfestInfo(projectPath, sourceRoot))}
64
+ var createAppHandler = function () {
65
+ `, source, `
66
+ }
67
+ if (typeof window === "undefined") {
68
+ return createAppHandler();
69
+ } else {
70
+ window.createAppHandler = createAppHandler;
71
+ // H5注入manifest以获取features
72
+ global.manifest = manifestJson;
73
+ }
74
+ })();
75
+ `);
76
+ }
77
+ }
78
+ exports.default = WrapPlugin;
@@ -22,6 +22,9 @@ export default interface IJavascriptCompileOption extends ICompileParam {
22
22
  * 项目运行的代码覆盖率数据
23
23
  */
24
24
  dataCoverage: string;
25
+ /**
26
+ * 记录“连接过的设备信息”的文件地址
27
+ */
25
28
  clientRecordPath: string;
26
29
  /**
27
30
  * 运行端口
@@ -49,4 +52,8 @@ export default interface IJavascriptCompileOption extends ICompileParam {
49
52
  * 启用代码体积分析,会生成 report.html 文件,可查看打包后各模块占用体积
50
53
  */
51
54
  enableStats?: boolean;
55
+ /**
56
+ * 是否自动补全 manifest.json 中的 features 配置
57
+ */
58
+ completeFeature?: boolean;
52
59
  }
@@ -5,6 +5,8 @@ import IWebpackConfigurator from '../interface/IWebpackConfigurator';
5
5
  declare class VelaWebpackConfigurator implements IWebpackConfigurator {
6
6
  param: ICompileParam & IJavascriptCompileOption;
7
7
  createPlugins(): WebpackPluginInstance[];
8
+ protected createWrapPlugin(): WebpackPluginInstance;
9
+ protected createBundleAnalyzerPlugin(): any;
8
10
  /**
9
11
  * 通过读取 manifest.json 生成 entry
10
12
  * @returns
@@ -10,21 +10,25 @@ const WrapPlugin_1 = __importDefault(require("./plugin/WrapPlugin"));
10
10
  const UxCompileUtil_1 = __importDefault(require("./utils/UxCompileUtil"));
11
11
  class VelaWebpackConfigurator {
12
12
  createPlugins() {
13
- const result = [
14
- // 入口js 添加包裹
15
- new WrapPlugin_1.default()
16
- ];
13
+ // 包裹代码的插件
14
+ const result = [this.createWrapPlugin()];
17
15
  // 如果开启 stats 参数,则添加 webpack-bundle-analyzer 插件
18
16
  if (this.param.enableStats) {
19
- const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
20
- result.push(new BundleAnalyzerPlugin({
21
- analyzerMode: 'static',
22
- openAnalyzer: false,
23
- excludeAssets: /^@(system|service)\./
24
- }));
17
+ result.push(this.createBundleAnalyzerPlugin());
25
18
  }
26
19
  return result;
27
20
  }
21
+ createWrapPlugin() {
22
+ return new WrapPlugin_1.default();
23
+ }
24
+ createBundleAnalyzerPlugin() {
25
+ const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
26
+ return new BundleAnalyzerPlugin({
27
+ analyzerMode: 'static',
28
+ openAnalyzer: false,
29
+ excludeAssets: /^@(system|service)\./
30
+ });
31
+ }
28
32
  /**
29
33
  * 通过读取 manifest.json 生成 entry
30
34
  * @returns
@@ -1,4 +1,4 @@
1
- import { Dictionary } from '@aiot-toolkit/shared-utils/lib/type/Type';
1
+ import { Dictionary } from '@aiot-toolkit/shared-utils';
2
2
  /**
3
3
  * vela manifest文件对应的数据结构
4
4
  */
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { Dictionary } from '@aiot-toolkit/shared-utils/lib/type/Type';
2
+ import { Dictionary } from '@aiot-toolkit/shared-utils';
3
3
  /**
4
4
  * 文件资源
5
5
  */
@@ -1,9 +1,6 @@
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 ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
3
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
7
4
  /**
8
5
  * 定义文件包
9
6
  *
@@ -38,7 +35,7 @@ class Package {
38
35
  addResource(data) {
39
36
  const { fileBuildPath } = data;
40
37
  if (this.include(fileBuildPath)) {
41
- ColorConsole_1.default.throw(`File ${fileBuildPath} is added repeatedly`);
38
+ shared_utils_1.ColorConsole.throw(`File ${fileBuildPath} is added repeatedly`);
42
39
  return;
43
40
  }
44
41
  this._resourceDic[fileBuildPath] = true;
@@ -3,8 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
7
- const CommonUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/CommonUtil"));
6
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
8
7
  const del_1 = __importDefault(require("del"));
9
8
  /**
10
9
  * Jsc
@@ -16,7 +15,7 @@ class Jsc {
16
15
  }
17
16
  jsc() {
18
17
  const { projectPath, buildPath } = this;
19
- return CommonUtil_1.default.requireNodeModule(projectPath, `@aiot-toolkit/jsc`)
18
+ return shared_utils_1.CommonUtil.requireNodeModule(projectPath, `@aiot-toolkit/jsc`)
20
19
  .then((module) => {
21
20
  return module.default(buildPath);
22
21
  })
@@ -24,7 +23,7 @@ class Jsc {
24
23
  return (0, del_1.default)(`${buildPath}/**/*.js`, { force: true });
25
24
  })
26
25
  .catch((error) => {
27
- ColorConsole_1.default.throw(error.message);
26
+ shared_utils_1.ColorConsole.throw(error.message);
28
27
  });
29
28
  }
30
29
  }
@@ -1,4 +1,4 @@
1
- import { Dictionary } from '@aiot-toolkit/shared-utils/lib/type/Type';
1
+ import { Dictionary } from '@aiot-toolkit/shared-utils';
2
2
  declare class UxCompileUtil {
3
3
  static readonly DIGEST_ZIP_DIR = "META-INF";
4
4
  static clean(dirList: string[]): void;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
6
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const EntryType_1 = __importDefault(require("../enum/EntryType"));
@@ -37,7 +37,7 @@ class UxCompileUtil {
37
37
  }
38
38
  const appFile = this.resolveFile(path_1.default.join(codeDir, 'app'));
39
39
  if (!fs_extra_1.default.existsSync(appFile)) {
40
- ColorConsole_1.default.throw(`App file does not exist`);
40
+ shared_utils_1.ColorConsole.throw(`App file does not exist`);
41
41
  }
42
42
  const { pages = {}, widgets = {}, floatingWindows = {} } = router;
43
43
  const confsList = [
@@ -130,7 +130,7 @@ class UxCompileUtil {
130
130
  * @returns
131
131
  */
132
132
  static getExtensionList(withDot = true) {
133
- const result = ['ux'];
133
+ const result = ['ux', 'hml'];
134
134
  if (withDot) {
135
135
  return result.map((item) => `.${item}`);
136
136
  }
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { Dictionary } from '@aiot-toolkit/shared-utils/lib/type/Type';
2
+ import { Dictionary } from '@aiot-toolkit/shared-utils';
3
3
  import JSZip from 'jszip';
4
4
  import IJavascriptCompileOption from '../../interface/IJavascriptCompileOption';
5
5
  import IManifest from '../interface/IManifest';
@@ -13,9 +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 ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
17
- const CommonUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/CommonUtil"));
18
- const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
16
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
19
17
  const fs_extra_1 = __importDefault(require("fs-extra"));
20
18
  const jszip_1 = __importDefault(require("jszip"));
21
19
  const path_1 = __importDefault(require("path"));
@@ -51,7 +49,7 @@ class ZipUtil {
51
49
  // 1
52
50
  const files = this.getSortedFiles(dist, param, config);
53
51
  if (!files.length) {
54
- ColorConsole_1.default.error(`The build file is missing, stop generating the application package, please check carefully`);
52
+ shared_utils_1.ColorConsole.error(`The build file is missing, stop generating the application package, please check carefully`);
55
53
  return;
56
54
  }
57
55
  // 2
@@ -72,7 +70,7 @@ class ZipUtil {
72
70
  return [
73
71
  packageName,
74
72
  mode === CompileMode_1.default.DEVELOPMENT ? 'debug' : 'release',
75
- buildNameFormat === BuildNameFormatType_1.default.DEFAULT ? config.versionName : '',
73
+ buildNameFormat === BuildNameFormatType_1.default.ORIGINAL ? '' : config.versionName,
76
74
  ext
77
75
  ]
78
76
  .filter(Boolean)
@@ -95,7 +93,7 @@ class ZipUtil {
95
93
  const { releasePath, projectPath } = param;
96
94
  const filePath = path_1.default.join(projectPath, releasePath, fileName);
97
95
  fs_extra_1.default.outputFileSync(filePath, buffer);
98
- ColorConsole_1.default.success(`Project build and generate files:${fileName}`);
96
+ shared_utils_1.ColorConsole.success(`Project build and generate files:${fileName}`);
99
97
  });
100
98
  }
101
99
  static createZipBufferFromFileList(fileList, comment) {
@@ -133,7 +131,7 @@ class ZipUtil {
133
131
  let metaZip = yield jszip_1.default.loadAsync(fileContentBuffer);
134
132
  fileContentBuffer = (yield metaZip.generateAsync(Object.assign(Object.assign({}, ZipUtil.ZIP_OPTION), { comment: null })));
135
133
  }
136
- const fileContentDigest = CommonUtil_1.default.calcDataDigest(fileContentBuffer);
134
+ const fileContentDigest = shared_utils_1.CommonUtil.calcDataDigest(fileContentBuffer);
137
135
  const resourceInfo = {
138
136
  fileBuildPath,
139
137
  fileContentBuffer,
@@ -174,7 +172,7 @@ class ZipUtil {
174
172
  // 1. 排除META-INF 目录下的文件
175
173
  // 2. 生产环境排除 .map 文件
176
174
  const mapReg = /\.map$/;
177
- let result = FileUtil_1.default.readAlldirSync(dist);
175
+ let result = shared_utils_1.FileUtil.readAlldirSync(dist);
178
176
  result = result
179
177
  .filter((item) => {
180
178
  return !(item.startsWith(UxCompileUtil_1.default.DIGEST_ZIP_DIR) ||
@@ -240,7 +238,7 @@ class ZipUtil {
240
238
  // fullPackageBuffer
241
239
  const fullPackageBuffer = yield SignUtil_1.default.signZipBufferForPackage(fullPackage, privatekey, certificate);
242
240
  if (fullPackageBuffer === false) {
243
- ColorConsole_1.default.throw('Fullpackage signature failed');
241
+ shared_utils_1.ColorConsole.throw('Fullpackage signature failed');
244
242
  }
245
243
  else {
246
244
  fullPackage = fullPackageBuffer;
@@ -1,5 +1,4 @@
1
1
  /// <reference types="node" />
2
- import ICompileParam from '../../../../interface/ICompileParam';
3
2
  import IJavascriptCompileOption from '../../../interface/IJavascriptCompileOption';
4
3
  /**
5
4
  * SignUtil
@@ -7,11 +6,10 @@ import IJavascriptCompileOption from '../../../interface/IJavascriptCompileOptio
7
6
  declare class SignUtil {
8
7
  /**
9
8
  * 获取签名相关的配置内容
10
- * 1. ICompileParam参数中获取编译模式是否为release
11
- * 2. IJavascriptCompileOption参数中获取签名目录等内容
12
- * @param param
9
+ * @param param IJavascriptCompileOption参数中获取签名目录等内容
10
+ * @returns
13
11
  */
14
- static getProjectSignConfig(param: ICompileParam & IJavascriptCompileOption): {
12
+ static getProjectSignConfig(param: IJavascriptCompileOption): {
15
13
  privatekey: Buffer;
16
14
  certificate: Buffer;
17
15
  };
@@ -12,9 +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 CommonUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/CommonUtil"));
17
- const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
15
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
18
16
  const crypto_1 = __importDefault(require("crypto"));
19
17
  const fs_extra_1 = __importDefault(require("fs-extra"));
20
18
  const jsrsasign_1 = __importDefault(require("jsrsasign"));
@@ -31,43 +29,70 @@ const Signer_1 = __importDefault(require("./Signer"));
31
29
  class SignUtil {
32
30
  /**
33
31
  * 获取签名相关的配置内容
34
- * 1. ICompileParam参数中获取编译模式是否为release
35
- * 2. IJavascriptCompileOption参数中获取签名目录等内容
36
- * @param param
32
+ * @param param IJavascriptCompileOption参数中获取签名目录等内容
33
+ * @returns
37
34
  */
38
35
  static getProjectSignConfig(param) {
39
36
  const { mode, projectPath, signRoot } = param;
37
+ const signPathFolder = path_1.default.join(projectPath, signRoot || 'sign');
38
+ const signPathConfig = {
39
+ debug: {
40
+ privatekey: path_1.default.join(signPathFolder, 'debug', 'private.pem'),
41
+ certificate: path_1.default.join(signPathFolder, 'debug', 'certificate.pem')
42
+ },
43
+ sign: {
44
+ privatekey: path_1.default.join(signPathFolder, 'private.pem'),
45
+ certificate: path_1.default.join(signPathFolder, 'certificate.pem')
46
+ },
47
+ defaultDevelopment: {
48
+ privatekey: path_1.default.join(__dirname, 'pem', 'private.pem'),
49
+ certificate: path_1.default.join(__dirname, 'pem', 'certificate.pem')
50
+ },
51
+ oldRelease: {
52
+ privatekey: path_1.default.join(signPathFolder, 'release', 'private.pem'),
53
+ certificate: path_1.default.join(signPathFolder, 'release', 'certificate.pem')
54
+ }
55
+ };
56
+ // build模式 优先sign/debug/证书 其次sign/证书 最后toolkit中默认的证书
57
+ const developmentSignConfig = [
58
+ signPathConfig.debug,
59
+ signPathConfig.sign,
60
+ signPathConfig.defaultDevelopment
61
+ ];
62
+ // release模式 优先sign/release/证书 其次sign/证书
63
+ const releaseSignConfig = [signPathConfig.oldRelease, signPathConfig.sign];
64
+ let modeSignConfig = [];
40
65
  let signConfig;
41
- let privatekeyPath;
42
- let certificatePath;
43
66
  switch (mode) {
44
67
  case CompileMode_1.default.DEVELOPMENT:
45
- privatekeyPath = path_1.default.join(__dirname, 'pem', 'private.pem');
46
- certificatePath = path_1.default.join(__dirname, 'pem', 'certificate.pem');
47
- ColorConsole_1.default.info(`User debug signature is enabled by project build`);
68
+ modeSignConfig = developmentSignConfig;
48
69
  break;
49
70
  case CompileMode_1.default.PRODUCTION:
50
- privatekeyPath = path_1.default.join(projectPath, signRoot, 'private.pem');
51
- certificatePath = path_1.default.join(projectPath, signRoot, 'certificate.pem');
52
- ColorConsole_1.default.info(`release signature is enabled by project build`);
71
+ modeSignConfig = releaseSignConfig;
53
72
  break;
54
73
  default:
55
74
  // 打印信息, 模式未定义
56
- ColorConsole_1.default.error(`Error: mode ${mode} undefined`);
75
+ shared_utils_1.ColorConsole.error(`Error: mode ${mode} undefined`);
57
76
  break;
58
77
  }
59
- // 检查路径是否真实存在
60
- if (privatekeyPath &&
61
- certificatePath &&
62
- FileUtil_1.default.checkFilePath([privatekeyPath, certificatePath])) {
78
+ // 寻找有效的证书路径
79
+ const findPath = modeSignConfig.find(({ privatekey, certificate }) => shared_utils_1.FileUtil.checkFilePath([privatekey, certificate]));
80
+ if (findPath) {
81
+ let { privatekey: privatekeyPath, certificate: certificatePath } = findPath;
82
+ shared_utils_1.ColorConsole.info('privatekeyPath is ', {
83
+ word: privatekeyPath
84
+ }, `\ncertificatePath is `, {
85
+ word: certificatePath
86
+ });
87
+ // 读取证书内容
63
88
  signConfig = {
64
89
  privatekey: fs_extra_1.default.readFileSync(privatekeyPath),
65
90
  certificate: fs_extra_1.default.readFileSync(certificatePath)
66
91
  };
67
92
  }
68
93
  else {
69
- // 结束程序
70
- process.exit();
94
+ // 抛出错误,在指定模式下未找到证书
95
+ throw new Error(`The current mode is ${mode}, and there is a problem with the certification path`);
71
96
  }
72
97
  return signConfig;
73
98
  }
@@ -83,12 +108,12 @@ class SignUtil {
83
108
  if (metaBuffer) {
84
109
  const metaHash = {
85
110
  name: ZipUtil_1.default.DIGEST_HASH_JSON,
86
- hash: CommonUtil_1.default.calcDataDigest(metaBuffer)
111
+ hash: shared_utils_1.CommonUtil.calcDataDigest(metaBuffer)
87
112
  };
88
113
  const signedMetaBuffer = SignUtil.doSign(metaBuffer, [metaHash], privatekey, certificate);
89
114
  if (signedMetaBuffer === false) {
90
115
  // META-INF/CERT签名失败
91
- ColorConsole_1.default.throw('META-INF/CERT signature failed');
116
+ shared_utils_1.ColorConsole.throw('META-INF/CERT signature failed');
92
117
  }
93
118
  else {
94
119
  fileList.push({
@@ -97,7 +122,7 @@ class SignUtil {
97
122
  });
98
123
  fileDigestHash.push({
99
124
  name: ZipUtil_1.default.CERT_PATH,
100
- hash: CommonUtil_1.default.calcDataDigest(signedMetaBuffer)
125
+ hash: shared_utils_1.CommonUtil.calcDataDigest(signedMetaBuffer)
101
126
  });
102
127
  }
103
128
  }
@@ -107,7 +132,7 @@ class SignUtil {
107
132
  fileList.push(item);
108
133
  fileDigestHash.push({
109
134
  name: item.path,
110
- hash: CommonUtil_1.default.calcDataDigest(item.content)
135
+ hash: shared_utils_1.CommonUtil.calcDataDigest(item.content)
111
136
  });
112
137
  });
113
138
  // 因为META变化,重新创建ZIP流
@@ -116,7 +141,7 @@ class SignUtil {
116
141
  const signedZipBuffer = SignUtil.doSign(newZipBuffer, fileDigestHash, privatekey, certificate);
117
142
  if (signedZipBuffer === false) {
118
143
  // 签名失败
119
- ColorConsole_1.default.throw('package signature failed');
144
+ shared_utils_1.ColorConsole.throw('package signature failed');
120
145
  }
121
146
  return signedZipBuffer;
122
147
  });
@@ -180,13 +205,13 @@ class SignUtil {
180
205
  static unZipFiles(fileBuffer, files) {
181
206
  // 1. 读取zip文件
182
207
  if (!fileBuffer || fileBuffer.length <= 4) {
183
- ColorConsole_1.default.error('Zip file open failed');
208
+ shared_utils_1.ColorConsole.error('Zip file open failed');
184
209
  return false;
185
210
  }
186
211
  // 2. 检查文件格式是否正确
187
212
  const fileMagic = fileBuffer.readInt32LE(0);
188
213
  if (fileMagic !== 0x4034b50) {
189
- ColorConsole_1.default.error('Zip file format is wrong');
214
+ shared_utils_1.ColorConsole.error('Zip file format is wrong');
190
215
  return false;
191
216
  }
192
217
  // 3. 解析数据块
@@ -8,18 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const SourceMapUtil_1 = __importDefault(require("@aiot-toolkit/parser/lib/ux/translate/vela/utils/SourceMapUtil"));
12
+ const parser_1 = require("@aiot-toolkit/parser");
16
13
  function addColSourceMap(source, map) {
17
14
  return __awaiter(this, void 0, void 0, function* () {
18
15
  const callback = this.async();
19
16
  if (!map) {
20
17
  callback(null, source, map);
21
18
  }
22
- let { consumer, tempGenerator } = yield SourceMapUtil_1.default.createConsumerAndGenerator(JSON.stringify(map));
19
+ let { consumer, tempGenerator } = yield parser_1.SourceMapUtil.createConsumerAndGenerator(JSON.stringify(map));
23
20
  let recordLine = -1;
24
21
  consumer.eachMapping((mapping) => {
25
22
  if (mapping.source === consumer.sources[consumer.sources.length - 1]) {