@aiot-toolkit/aiotpack 2.0.5-alpha.1 → 2.0.5-beta.1

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.
@@ -164,7 +164,7 @@ class UxAfterCompile {
164
164
  outputPath,
165
165
  completeFeature
166
166
  } = compilerOption;
167
- const content = _UxFileUtils.default.getMainfestInfo(projectPath, sourceRoot);
167
+ const content = _UxFileUtils.default.getManifestInfo(projectPath, sourceRoot);
168
168
  const translateCache = context.translateCache;
169
169
  if (!content.minAPILevel) {
170
170
  content.minAPILevel = 1;
@@ -232,7 +232,7 @@ class UxAfterCompile {
232
232
  const content = Object.keys(comment).map(key => `${key}=${comment[key]}`).join('\n');
233
233
  _fsExtra.default.outputFileSync(_path.default.join(outputAbsPath, _ZipUtil.default.BUILD_FILE_PATH), content);
234
234
  // cert
235
- const files = _ZipUtil.default.getSortedFiles(outputAbsPath, compilerOption, _UxFileUtils.default.getMainfestInfo(projectPath, sourceRoot));
235
+ const files = _ZipUtil.default.getSortedFiles(outputAbsPath, compilerOption, _UxFileUtils.default.getManifestInfo(projectPath, sourceRoot));
236
236
  const digestDic = Object.fromEntries(files.map(item => [item, _sharedUtils.CommonUtil.calcDataDigest(_fsExtra.default.readFileSync(_path.default.join(outputAbsPath, item))).toString('hex')]));
237
237
  const hashJson = [{
238
238
  path: _ZipUtil.default.DIGEST_HASH_JSON,
@@ -16,31 +16,37 @@ class JavascriptCompiler {
16
16
  QUICKAPP_CONFIG = 'quickapp.config.js';
17
17
  async compile(param) {
18
18
  return new Promise(async (resolve, reject) => {
19
- await this.clean(param);
20
- const config = this.createWebpackConfig(param);
21
- (0, _core.rspack)(config, (error, stats) => {
22
- if (error) {
23
- reject({
24
- errors: [error]
25
- });
26
- } else {
27
- const statsObj = stats?.toJson({});
28
- if (statsObj) {
29
- const {
30
- errors,
31
- warnings
32
- } = statsObj;
33
- if (errors?.length || warnings?.length) {
34
- reject({
19
+ try {
20
+ await this.clean(param);
21
+ const config = this.createWebpackConfig(param);
22
+ (0, _core.rspack)(config, (error, stats) => {
23
+ if (error) {
24
+ reject({
25
+ errors: [error]
26
+ });
27
+ } else {
28
+ const statsObj = stats?.toJson({});
29
+ if (statsObj) {
30
+ const {
35
31
  errors,
36
32
  warnings
37
- });
38
- } else {
39
- resolve();
33
+ } = statsObj;
34
+ if (errors?.length || warnings?.length) {
35
+ reject({
36
+ errors,
37
+ warnings
38
+ });
39
+ } else {
40
+ resolve();
41
+ }
40
42
  }
41
43
  }
42
- }
43
- });
44
+ });
45
+ } catch (error) {
46
+ reject({
47
+ errors: [error]
48
+ });
49
+ }
44
50
  });
45
51
  }
46
52
  createWebpackConfig(param) {
@@ -62,7 +68,7 @@ class JavascriptCompiler {
62
68
  } = param;
63
69
  const buildPath = _path.default.resolve(projectPath, outputPath);
64
70
  const quickAppConfig = _sharedUtils.CommonUtil.requireModule(_path.default.join(param.projectPath, this.QUICKAPP_CONFIG));
65
- const result = {
71
+ let result = {
66
72
  context: projectPath,
67
73
  mode,
68
74
  devtool: devtool,
@@ -128,12 +134,19 @@ class JavascriptCompiler {
128
134
  configurator.hook(result);
129
135
  }
130
136
 
131
- // 数组,则全部数组(默认合并数组中相同序号的项)
132
- return _lodash.default.mergeWith({}, result, quickAppConfig?.webpack, (source, target) => {
137
+ // 合并用户自定义的webpack配置
138
+ // 数组,则合并数组(默认合并数组中相同序号的项)
139
+ result = _lodash.default.mergeWith({}, result, quickAppConfig?.webpack, (source, target) => {
133
140
  if (Array.isArray(target) && Array.isArray(source)) {
134
141
  return [...target, ...source];
135
142
  }
136
143
  });
144
+
145
+ // 触发用户配置的posthook
146
+ if (quickAppConfig?.postHook) {
147
+ quickAppConfig.postHook(result);
148
+ }
149
+ return result;
137
150
  }
138
151
  getConfigurator(param) {
139
152
  const {
@@ -77,7 +77,7 @@ class WrapPlugin {
77
77
  return new _webpackSources.ConcatSource(`
78
78
  (function () {
79
79
  var $app_define_wrap$ = $app_define_wrap$ || function () {};
80
- var manifestJson =${JSON.stringify(_UxFileUtils.default.getMainfestInfo(projectPath, sourceRoot))}
80
+ var manifestJson =${JSON.stringify(_UxFileUtils.default.getManifestInfo(projectPath, sourceRoot))}
81
81
  var createAppHandler = function () {
82
82
  `, source, `
83
83
  }
@@ -56,4 +56,17 @@ export default interface IJavascriptCompileOption extends ICompileParam {
56
56
  * 是否自动补全 manifest.json 中的 features 配置
57
57
  */
58
58
  completeFeature?: boolean;
59
+ /**
60
+ * 获取远程证书
61
+ */
62
+ signRequest?: () => Promise<{
63
+ /**
64
+ * 证书私钥
65
+ */
66
+ privatekey: Buffer;
67
+ /**
68
+ * 证书
69
+ */
70
+ certificate: Buffer;
71
+ }>;
59
72
  }
@@ -5,5 +5,6 @@ declare class WrapPlugin {
5
5
  constructor(compilerOption: IJavascriptCompileOption);
6
6
  apply(compiler: Compiler): void;
7
7
  private wrap;
8
+ private translateStyleFunc;
8
9
  }
9
10
  export default WrapPlugin;
@@ -31,6 +31,8 @@ class WrapPlugin {
31
31
  entrys.forEach(entry => {
32
32
  if (compilation.assets[entry]) {
33
33
  const source = compilation.assets[entry];
34
+ const isApp = entry === 'app.js';
35
+ const createFuncnName = isApp ? 'createAppHandler' : 'createPageHandler';
34
36
  compilation.assets[entry] = new _webpackSources.ConcatSource(`
35
37
  export default function(global, globalThis, window, $app_exports$, $app_evaluate$){
36
38
  var org_app_require = $app_require$;
@@ -43,30 +45,44 @@ class WrapPlugin {
43
45
  var $app_require$ = global.$app_require$ || org_app_require
44
46
 
45
47
  ${enableE2e ? `globalThis = undefined; \n global = typeof window === "undefined" ? global.__proto__ : window;` : ''}
46
-
47
48
  // 转换动态 style 的函数
48
- var $translateStyle$ = function (value) {
49
- if (typeof value === 'string') {
50
- return Object.fromEntries(value.split(';').filter(item => Boolean(item && item.trim())).map(
51
- item => {
52
- const matchs = item.match(/([^:]+):(.*)/)
53
- if (matchs && matchs.length> 2) {
54
- return [matchs[1].trim().replace(/-([a-z])/g, (_, match) => match.toUpperCase()), matchs[2].trim()]
55
- }
56
- return []
57
- }))}
58
- return value
59
- }
60
-
61
- var createPageHandler = function() {
49
+ ${isApp ? this.translateStyleFunc() : ''}
50
+ var ${createFuncnName} = function() {
62
51
  return `, source, `
63
52
  }
64
53
 
65
- return createPageHandler();
54
+ return ${createFuncnName}();
66
55
  })(global, globalThis, window, $app_exports$, $app_evaluate$)
67
56
  }`);
68
57
  }
69
58
  });
70
59
  }
60
+ translateStyleFunc() {
61
+ return `
62
+ var $translateStyle$ = function (value) {
63
+ if (typeof value === 'string') {
64
+ return Object.fromEntries(
65
+ value
66
+ .split(';')
67
+ .filter((item) => Boolean(item && item.trim()))
68
+ .map((item) => {
69
+ const matchs = item.match(/([^:]+):(.*)/);
70
+ if (matchs && matchs.length > 2) {
71
+ return [
72
+ matchs[1]
73
+ .trim()
74
+ .replace(/-([a-z])/g, (_, match) => match.toUpperCase()),
75
+ matchs[2].trim(),
76
+ ];
77
+ }
78
+ return [];
79
+ })
80
+ );
81
+ }
82
+ return value;
83
+ };
84
+ global.$translateStyle$ = $translateStyle$
85
+ `;
86
+ }
71
87
  }
72
88
  var _default = exports.default = WrapPlugin;
@@ -72,9 +72,10 @@ declare class ZipUtil {
72
72
  *
73
73
  * @param dist 打包后的文件目录的绝对路径
74
74
  * @param param 打包参数
75
+ * @param manifest manifest.json内容的json对象
75
76
  * @returns
76
77
  */
77
- static getSortedFiles(dist: string, param: IJavascriptCompileOption, config: IManifest): string[];
78
+ static getSortedFiles(dist: string, param: IJavascriptCompileOption, manifest: IManifest): string[];
78
79
  /**
79
80
  * 根据 **固定规则**、**manifest.json入口配置**,获取压缩文件时使用的排序规则
80
81
  *
@@ -58,7 +58,7 @@ class ZipUtil {
58
58
  * @returns 生成的 rpk 文件名
59
59
  */
60
60
  static async createRpk(dist, param) {
61
- const config = _UxFileUtils.default.getMainfestInfo(param.projectPath, param.sourceRoot);
61
+ const config = _UxFileUtils.default.getManifestInfo(param.projectPath, param.sourceRoot);
62
62
 
63
63
  // 1
64
64
  const files = this.getSortedFiles(dist, param, config);
@@ -73,7 +73,7 @@ class ZipUtil {
73
73
  } = await this.createPackagesDefinition(param, config, files);
74
74
 
75
75
  // 生产出带签名的rpk文件buffer
76
- const signConfig = _SignUtil.default.getProjectSignConfig(param);
76
+ const signConfig = await _SignUtil.default.getProjectSignConfig(param);
77
77
  const rpkBuffer = await ZipUtil.buildProjectAndOutput(fullPackage, signConfig);
78
78
  // 3
79
79
  return this.generateDistFile(rpkBuffer, param, this.getFileName(param, config, 'rpk'));
@@ -117,7 +117,7 @@ class ZipUtil {
117
117
  } = param;
118
118
  const filePath = _path.default.join(projectPath, releasePath, fileName);
119
119
  _fsExtra.default.outputFileSync(filePath, buffer);
120
- _sharedUtils.ColorConsole.success(`Project build and generate files:${fileName}`);
120
+ _sharedUtils.ColorConsole.success(`Project build and generate files:${filePath}`);
121
121
  return fileName;
122
122
  }
123
123
 
@@ -196,10 +196,11 @@ class ZipUtil {
196
196
  *
197
197
  * @param dist 打包后的文件目录的绝对路径
198
198
  * @param param 打包参数
199
+ * @param manifest manifest.json内容的json对象
199
200
  * @returns
200
201
  */
201
- static getSortedFiles(dist, param, config) {
202
- const priorities = this.getPriorities(config);
202
+ static getSortedFiles(dist, param, manifest) {
203
+ const priorities = this.getPriorities(manifest);
203
204
  const getFileIndex = file => {
204
205
  const result = priorities.findIndex(item => {
205
206
  if (typeof item === 'string') {
@@ -234,11 +235,11 @@ class ZipUtil {
234
235
  * @param param
235
236
  * @returns
236
237
  */
237
- static getPriorities(config) {
238
+ static getPriorities(manifest) {
238
239
  const entrySkFiles = []; // todo
239
240
  const {
240
241
  entry
241
- } = config.router;
242
+ } = manifest.router;
242
243
  const result = ['META-INF/CERT',
243
244
  // 多语言配置文件要在 manifest 之前
244
245
  /^i18n\/.+\.json$/i,
@@ -9,10 +9,10 @@ declare class SignUtil {
9
9
  * @param param IJavascriptCompileOption参数中获取签名目录等内容
10
10
  * @returns
11
11
  */
12
- static getProjectSignConfig(param: IJavascriptCompileOption): {
12
+ static getProjectSignConfig(param: IJavascriptCompileOption): Promise<{
13
13
  privatekey: Buffer;
14
14
  certificate: Buffer;
15
- };
15
+ }>;
16
16
  /**
17
17
  * 对二进制zipBuffer签名
18
18
  *
@@ -25,12 +25,16 @@ class SignUtil {
25
25
  * @param param IJavascriptCompileOption参数中获取签名目录等内容
26
26
  * @returns
27
27
  */
28
- static getProjectSignConfig(param) {
28
+ static async getProjectSignConfig(param) {
29
29
  const {
30
30
  mode,
31
31
  projectPath,
32
- signRoot
32
+ signRoot,
33
+ signRequest
33
34
  } = param;
35
+ if (signRequest) {
36
+ return signRequest();
37
+ }
34
38
  const signPathFolder = _path.default.join(projectPath, signRoot || 'sign');
35
39
  const signPathConfig = {
36
40
  debug: {
@@ -55,7 +59,6 @@ class SignUtil {
55
59
  // release模式 优先sign/release/证书 其次sign/证书
56
60
  const releaseSignConfig = [signPathConfig.oldRelease, signPathConfig.sign];
57
61
  let modeSignConfig = [];
58
- let signConfig;
59
62
  switch (mode) {
60
63
  case _CompileMode.default.DEVELOPMENT:
61
64
  modeSignConfig = developmentSignConfig;
@@ -87,7 +90,7 @@ class SignUtil {
87
90
  word: certificatePath
88
91
  });
89
92
  // 读取证书内容
90
- signConfig = {
93
+ return {
91
94
  privatekey: _fsExtra.default.readFileSync(privatekeyPath),
92
95
  certificate: _fsExtra.default.readFileSync(certificatePath)
93
96
  };
@@ -95,7 +98,6 @@ class SignUtil {
95
98
  // 抛出错误,在指定模式下未找到证书
96
99
  throw new Error(`The current mode is ${mode}, and there is a problem with the certification path`);
97
100
  }
98
- return signConfig;
99
101
  }
100
102
 
101
103
  /**
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _path = _interopRequireDefault(require("path"));
8
7
  var _AndroidUx = _interopRequireDefault(require("../../../utils/ux/android/AndroidUx"));
9
8
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
9
  /**
@@ -13,9 +12,6 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
13
12
  class UxLoader {
14
13
  async parser(files) {
15
14
  const result = [];
16
- const {
17
- projectPath
18
- } = this.context;
19
15
  for (let item of files) {
20
16
  const {
21
17
  files,
@@ -25,10 +21,7 @@ class UxLoader {
25
21
  file: item,
26
22
  compilerOption: this.compilerOption
27
23
  });
28
- this.logs = logs.map(item => ({
29
- ...item,
30
- filePath: item.filePath ? _path.default.relative(projectPath, item.filePath) : ''
31
- }));
24
+ this.logs = logs;
32
25
  result.push(...files);
33
26
  }
34
27
  return result;
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _path = _interopRequireDefault(require("path"));
8
7
  var _UxLoaderUtils = _interopRequireDefault(require("../../../utils/ux/UxLoaderUtils"));
9
8
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
9
  /**
@@ -13,17 +12,11 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
13
12
  */
14
13
  class AppUxLoader {
15
14
  async parser(files) {
16
- const {
17
- projectPath
18
- } = this.context;
19
15
  const {
20
16
  files: resultFiles,
21
17
  logs
22
18
  } = await _UxLoaderUtils.default.compileAppUxToJavascript(files[0], this.context, this.compilerOption);
23
- this.logs = logs.map(item => ({
24
- ...item,
25
- filePath: item.filePath ? _path.default.relative(projectPath, item.filePath) : ''
26
- }));
19
+ this.logs = logs;
27
20
  return resultFiles;
28
21
  }
29
22
  }
@@ -4,15 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _path = _interopRequireDefault(require("path"));
8
7
  var _UxLoaderUtils = _interopRequireDefault(require("../../../utils/ux/UxLoaderUtils"));
9
8
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
9
  class UxLoader {
11
10
  async parser(files) {
12
11
  const resultFiles = [];
13
- const {
14
- projectPath
15
- } = this.context;
16
12
  for (const file of files) {
17
13
  // 转换每个文件
18
14
  const {
@@ -22,7 +18,7 @@ class UxLoader {
22
18
  this.logs = logs.map(item => {
23
19
  return {
24
20
  ...item,
25
- filePath: item.position?.source ? item.position.source : item.filePath ? _path.default.relative(projectPath, item.filePath) : ''
21
+ filePath: item.position?.source || item.filePath
26
22
  };
27
23
  });
28
24
  resultFiles.push(...compiledFiles);
@@ -33,7 +33,7 @@ class BeforeCompileUtils {
33
33
  } = context;
34
34
  const srcPath = _path.default.join(projectPath, compilerOption.sourceRoot);
35
35
  // 判断路径是否真实存在
36
- const manifestContent = _UxFileUtils.default.getMainfestInfo(projectPath);
36
+ const manifestContent = _UxFileUtils.default.getManifestInfo(projectPath);
37
37
  // 存储entries
38
38
  let entryList = [];
39
39
  const {
@@ -15,7 +15,7 @@ export declare class UxFileUtils {
15
15
  * @param sourceRoot
16
16
  * @returns
17
17
  */
18
- static getMainfestInfo(projectPath: string, sourceRoot?: string): IManifest;
18
+ static getManifestInfo(projectPath: string, sourceRoot?: string): IManifest;
19
19
  /**
20
20
  * 检查 manifest文件,并显示错误信息
21
21
  *
@@ -30,7 +30,7 @@ class UxFileUtils {
30
30
  * @param sourceRoot
31
31
  * @returns
32
32
  */
33
- static getMainfestInfo(projectPath) {
33
+ static getManifestInfo(projectPath) {
34
34
  let sourceRoot = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'src';
35
35
  return _fsExtra.default.readJSONSync(UxFileUtils.getManifestFilePath(projectPath, sourceRoot));
36
36
  }
@@ -55,7 +55,7 @@ class UxFileUtils {
55
55
  }
56
56
 
57
57
  // 1
58
- const jsonData = this.getMainfestInfo(projectPath, sourceRoot);
58
+ const jsonData = this.getManifestInfo(projectPath, sourceRoot);
59
59
  const schema = _ManifestSchema.default;
60
60
  const errors = _CommonUtil.default.validateJson(jsonData, schema) || [];
61
61
 
@@ -87,7 +87,7 @@ class UxFileUtils {
87
87
  const sitemapPath = _path.default.join(projectPath, sourceRoot, 'sitemap.json');
88
88
  if (_fsExtra.default.existsSync(sitemapPath)) {
89
89
  const rules = _fsExtra.default.readJSONSync(sitemapPath).rules;
90
- const manifest = this.getMainfestInfo(projectPath, sourceRoot);
90
+ const manifest = this.getManifestInfo(projectPath, sourceRoot);
91
91
  const pages = Object.keys(manifest.router.pages || {});
92
92
  const errorList = [];
93
93
  rules.forEach((item, index) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/aiotpack",
3
- "version": "2.0.5-alpha.1",
3
+ "version": "2.0.5-beta.1",
4
4
  "description": "The process tool for packaging aiot projects.",
5
5
  "keywords": [
6
6
  "aiotpack"
@@ -19,16 +19,16 @@
19
19
  "test": "node ./__tests__/aiotpack.test.js"
20
20
  },
21
21
  "dependencies": {
22
- "@aiot-toolkit/generator": "2.0.5-alpha.1",
23
- "@aiot-toolkit/parser": "2.0.5-alpha.1",
24
- "@aiot-toolkit/shared-utils": "2.0.5-alpha.1",
22
+ "@aiot-toolkit/generator": "2.0.5-beta.1",
23
+ "@aiot-toolkit/parser": "2.0.5-beta.1",
24
+ "@aiot-toolkit/shared-utils": "2.0.5-beta.1",
25
25
  "@hap-toolkit/aaptjs": "^2.0.0",
26
26
  "@rspack/core": "^1.1.8",
27
27
  "aiot-parse5": "^1.0.0",
28
28
  "archiver": "^7.0.1",
29
29
  "babel-loader": "^9.1.3",
30
30
  "fast-glob": "^3.3.2",
31
- "file-lane": "2.0.5-alpha.1",
31
+ "file-lane": "2.0.5-beta.1",
32
32
  "file-loader": "^6.2.0",
33
33
  "fs-extra": "^11.2.0",
34
34
  "jsrsasign": "^11.1.0",
@@ -46,5 +46,5 @@
46
46
  "@types/jsrsasign": "^10.5.12",
47
47
  "@types/webpack-sources": "^3.2.3"
48
48
  },
49
- "gitHead": "8c8033a7a52e7cdb83606298ed8c4d6a585ba3ec"
49
+ "gitHead": "44f8c6ee763bc01bd53c655b93e09c698057fc3e"
50
50
  }