@aiot-toolkit/aiotpack 2.0.3-beta.9 → 2.0.4-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.
@@ -14,8 +14,8 @@ var _JavascriptDefaultCompileOption = _interopRequireDefault(require("../../comp
14
14
  var _Jsc = _interopRequireDefault(require("../../compiler/javascript/vela/utils/Jsc"));
15
15
  var _ZipUtil = _interopRequireDefault(require("../../compiler/javascript/vela/utils/ZipUtil"));
16
16
  var _UxFileUtils = _interopRequireDefault(require("../../utils/ux/UxFileUtils"));
17
- var _archiver = _interopRequireDefault(require("archiver"));
18
17
  var _FileLaneTriggerType = _interopRequireDefault(require("file-lane/lib/enum/FileLaneTriggerType"));
18
+ var _ZipFileUtil = _interopRequireDefault(require("@aiot-toolkit/shared-utils/lib/utils/ZipFileUtil"));
19
19
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
20
20
  const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
21
21
 
@@ -172,13 +172,48 @@ class UxAfterCompile {
172
172
  if (!content.packageInfo) {
173
173
  content.packageInfo = _ZipUtil.default.createComment(compilerOption);
174
174
  }
175
- if (completeFeature && translateCache?.featureCache.size) {
175
+
176
+ // feature
177
+ if (translateCache?.featureCache.size) {
178
+ // 消息提示
179
+ // 1. 获取未手动配置的 feature
180
+ // 2. 如果开启自动填充,则 info;否则 warn
176
181
  const featureSet = new Set([...Array.from(translateCache.featureCache), ...(content.features || []).map(item => item.name)]);
177
- content.features = Array.from(featureSet).map(item => {
178
- return {
179
- name: item
182
+ const usedList = Array.from(featureSet).filter(Boolean);
183
+ const unSetList = usedList.filter(featureItem => !content.features?.find(item => item.name === featureItem));
184
+ if (unSetList?.length) {
185
+ const featureMessage = {
186
+ word: `\n${JSON.stringify(unSetList.map(item => ({
187
+ name: item
188
+ })), undefined, 2)}`,
189
+ style: _sharedUtils.ColorConsole.getStyle(_sharedUtils.Loglevel.INFO)
180
190
  };
181
- });
191
+ if (completeFeature) {
192
+ _sharedUtils.ColorConsole.logger({
193
+ level: _sharedUtils.Loglevel.WARN,
194
+ message: [`missing feature (will auto set in rpk):`, featureMessage, {
195
+ word: '\n\nplease copy to `src/manifest.json`'
196
+ }]
197
+ });
198
+ } else {
199
+ _sharedUtils.ColorConsole.logger({
200
+ level: _sharedUtils.Loglevel.THROW,
201
+ message: [`missing feature:`, featureMessage, `\n\nthere are tow ways to set`, {
202
+ word: ['copy to `src/manifest.json`', 'add build option `--complete-feature`'].map((item, index) => `\n${index + 1}. ${item}`).join('')
203
+ }]
204
+ });
205
+ throw new Error(`missing feature`);
206
+ }
207
+ }
208
+
209
+ // 填充feature
210
+ if (completeFeature) {
211
+ content.features = usedList.map(item => {
212
+ return {
213
+ name: item
214
+ };
215
+ });
216
+ }
182
217
  }
183
218
  _fsExtra.default.writeJSONSync(_path.default.join(projectPath, outputPath, _UxFileUtils.default.CONFIG_FILE_NAME), content, {
184
219
  spaces: 2
@@ -250,22 +285,10 @@ class UxAfterCompile {
250
285
  const distFold = _path.default.join(compilerOption.projectPath, compilerOption.releasePath);
251
286
  const diffFileName = `.diff.rpk`;
252
287
  const diffPath = _path.default.join(distFold, diffFileName);
253
- const diffStream = _fsExtra.default.createWriteStream(diffPath);
254
- const archiver = (0, _archiver.default)('zip', {
255
- zlib: {
256
- level: 9
257
- }
258
- });
259
- archiver.pipe(diffStream);
260
- diffList.forEach(item => {
261
- const filePath = _path.default.join(buildFold, item);
262
- archiver.append(_fsExtra.default.createReadStream(filePath), {
263
- name: item
264
- });
265
- });
266
- await archiver.finalize();
267
- diffStream.close();
268
- diffStream.destroy();
288
+ await _ZipFileUtil.default.createZipFile(diffPath, diffList.map(item => ({
289
+ filePath: _path.default.join(buildFold, item),
290
+ zipFilePath: item
291
+ })));
269
292
  compalition.info.diffList = diffList;
270
293
  compalition.info.diffFile = _path.default.join(config.projectPath, compilerOption.releasePath, diffFileName);
271
294
  }
@@ -326,7 +349,7 @@ class UxAfterCompile {
326
349
  return;
327
350
  }
328
351
  try {
329
- const foldList = ['node_modules'];
352
+ const foldList = ['node_modules', '.git'];
330
353
  foldList.forEach(item => {
331
354
  const sourcePath = _path.default.join(context.projectPath, item);
332
355
  const targetPath = _path.default.join(compilerOption.projectPath, item);
@@ -127,7 +127,13 @@ class JavascriptCompiler {
127
127
  if (configurator.hook) {
128
128
  configurator.hook(result);
129
129
  }
130
- return _lodash.default.merge({}, result, quickAppConfig?.webpack);
130
+
131
+ // 数组,则全部数组(默认合并数组中相同序号的项)
132
+ return _lodash.default.mergeWith({}, result, quickAppConfig?.webpack, (source, target) => {
133
+ if (Array.isArray(target) && Array.isArray(source)) {
134
+ return [...target, ...source];
135
+ }
136
+ });
131
137
  }
132
138
  getConfigurator(param) {
133
139
  const {
@@ -1,3 +1,4 @@
1
+ import { IStyleNode } from '@aiot-toolkit/parser';
1
2
  import { ILog } from '@aiot-toolkit/shared-utils';
2
3
  import { IFileLaneContext, IFileParam } from 'file-lane';
3
4
  import { SourceFile } from 'ts-morph';
@@ -54,7 +55,7 @@ declare class UxLoaderUtils {
54
55
  * @returns
55
56
  */
56
57
  static wrapTempalte(templateTree: SourceFile, file: IFileParam, compilerOption: IJavascriptCompileOption): string;
57
- static wrapStyle(code: string, file: IFileParam, compilerOption: IJavascriptCompileOption): string;
58
+ static wrapStyle(styleNodes: IStyleNode[], file: IFileParam, compilerOption: IJavascriptCompileOption): string;
58
59
  /**
59
60
  * 给script增加外层包裹内容
60
61
  * @param isPageUx
@@ -11,6 +11,7 @@ var _sharedUtils = require("@aiot-toolkit/shared-utils");
11
11
  var parse5 = _interopRequireWildcard(require("aiot-parse5"));
12
12
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
13
13
  var _path = _interopRequireDefault(require("path"));
14
+ var _QuickAppDocHelp = require("@aiot-toolkit/shared-utils/lib/utils/QuickAppDocHelp");
14
15
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
15
16
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
16
17
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -86,7 +87,8 @@ class UxLoaderUtils {
86
87
  content: content.toString(),
87
88
  onLog: log => {
88
89
  logs.push(log);
89
- }
90
+ },
91
+ docHelp: new _QuickAppDocHelp.VelaAppDocHelp()
90
92
  };
91
93
  // 收集图片资源
92
94
  const ImageResources = [];
@@ -114,8 +116,10 @@ class UxLoaderUtils {
114
116
  // app.ux解析结果中加上manifest.json的内容
115
117
  const manifestJson = `require('./manifest.json')`;
116
118
  const integrateFunction = (appImport, appStyleTree, appTemplateTree, appScriptTree) => {
119
+ const scriptCode = appScriptTree.getText();
120
+ const hasScript = Boolean(scriptCode) && scriptCode !== '""';
117
121
  // script代码放在第三个位置不能变化,影响更新source map
118
- return isAppUx ? [`${appImport.join('\n')}`, `var $app_style$ = ${UxLoaderUtils.wrapStyle(JSON.stringify(appStyleTree), file, compilerOption)}`, `var $app_script$ = ${UxLoaderUtils.wrapScript(false, appScriptTree)}`, `$app_script$({}, $app_exports$, $app_require$);`, `$app_exports$.default.style = $app_style$;`, `$app_exports$.default.manifest = ${manifestJson}`] : [`${appImport.join('\n')}`, `var $app_style$ = ${UxLoaderUtils.wrapStyle(JSON.stringify(appStyleTree), file, compilerOption)}`, `var $app_script$ = ${UxLoaderUtils.wrapScript(isPageUx, appScriptTree)}`, `var $app_template$ = ${UxLoaderUtils.wrapTempalte(appTemplateTree, file, compilerOption)}`, `${UxLoaderUtils.getReturnType(isPageUx)} function ($app_exports$) {`, `$app_script$({}, $app_exports$, $app_require$);`, `$app_exports$.default.template = $app_template$;`, `$app_exports$.default.style = $app_style$;`, `}`];
122
+ return isAppUx ? [`${appImport.join('\n')}`, `var $app_style$ = ${UxLoaderUtils.wrapStyle(appStyleTree, file, compilerOption)}`, hasScript ? `var $app_script$ = ${UxLoaderUtils.wrapScript(false, appScriptTree)}` : '', hasScript ? `$app_script$({}, $app_exports$, $app_require$);` : `$app_exports$.default = {}`, `$app_exports$.default.style = $app_style$;`, `$app_exports$.default.manifest = ${manifestJson}`] : [`${appImport.join('\n')}`, `var $app_style$ = ${UxLoaderUtils.wrapStyle(appStyleTree, file, compilerOption)}`, hasScript ? `var $app_script$ = ${UxLoaderUtils.wrapScript(isPageUx, appScriptTree)}` : '', `var $app_template$ = ${UxLoaderUtils.wrapTempalte(appTemplateTree, file, compilerOption)}`, `${UxLoaderUtils.getReturnType(isPageUx)} function ($app_exports$) {`, hasScript ? `$app_script$({}, $app_exports$, $app_require$);` : `$app_exports$.default = {}`, `$app_exports$.default.template = $app_template$;`, `$app_exports$.default.style = $app_style$;`, `}`];
119
123
  };
120
124
  const {
121
125
  targetTree,
@@ -302,10 +306,13 @@ class UxLoaderUtils {
302
306
  }
303
307
  return result;
304
308
  }
305
- static wrapStyle(code, file, compilerOption) {
309
+ static wrapStyle(styleNodes, file, compilerOption) {
310
+ const code = JSON.stringify(styleNodes);
306
311
  if (compilerOption.enableProtobuf) {
307
- const result = BinaryPlugin.addStyle(file.path, file.path, code);
308
- return `['${result.name}', ${result.index}]`;
312
+ if (styleNodes?.length) {
313
+ const result = BinaryPlugin.addStyle(file.path, file.path, code);
314
+ return `['${result.name}', ${result.index}]`;
315
+ }
309
316
  }
310
317
  return code;
311
318
  }
@@ -9,6 +9,7 @@ var _sharedUtils = require("@aiot-toolkit/shared-utils");
9
9
  var _UxToTypescript = _interopRequireDefault(require("@aiot-toolkit/parser/lib/ux/translate/android/UxToTypescript"));
10
10
  var _generator = require("@aiot-toolkit/generator");
11
11
  var _path = _interopRequireDefault(require("path"));
12
+ var _QuickAppDocHelp = require("@aiot-toolkit/shared-utils/lib/utils/QuickAppDocHelp");
12
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
14
  /**
14
15
  * AndroidUx
@@ -58,7 +59,8 @@ class AndroidUx {
58
59
  onLog: function (log) {
59
60
  logs.push(log);
60
61
  },
61
- content: content.toString()
62
+ content: content.toString(),
63
+ docHelp: new _QuickAppDocHelp.QuickAppDocHelper()
62
64
  };
63
65
  const uxAst = await new _parser.UxParser(option, compilerOption, {}, path => path).parser();
64
66
  const tsAst = await new _UxToTypescript.default(option, compilerOption, context).translate(uxAst.ast, uxAst.offsetList || []);
@@ -75,7 +77,7 @@ class AndroidUx {
75
77
  content: code.code
76
78
  }, {
77
79
  path: `${filePathParse.dir}/${filePathParse.base}.map`,
78
- content: code.sourcemap
80
+ content: tsAst.sourceMap.toString()
79
81
  }
80
82
  // resource todo
81
83
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/aiotpack",
3
- "version": "2.0.3-beta.9",
3
+ "version": "2.0.4-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.3-beta.9",
23
- "@aiot-toolkit/parser": "2.0.3-beta.9",
24
- "@aiot-toolkit/shared-utils": "2.0.3-beta.9",
22
+ "@aiot-toolkit/generator": "2.0.4-beta.1",
23
+ "@aiot-toolkit/parser": "2.0.4-beta.1",
24
+ "@aiot-toolkit/shared-utils": "2.0.4-beta.1",
25
25
  "@hap-toolkit/aaptjs": "^2.0.0",
26
- "@rspack/core": "^1.0.0",
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.3-beta.9",
31
+ "file-lane": "2.0.4-beta.1",
32
32
  "file-loader": "^6.2.0",
33
33
  "fs-extra": "^11.2.0",
34
34
  "jsrsasign": "^11.1.0",
@@ -36,6 +36,7 @@
36
36
  "lodash": "^4.17.21",
37
37
  "ts-morph": "^19.0.0",
38
38
  "url-loader": "^4.1.1",
39
+ "webpack": "^5.97.1",
39
40
  "webpack-bundle-analyzer": "^4.10.2",
40
41
  "webpack-sources": "^3.2.3"
41
42
  },
@@ -45,5 +46,5 @@
45
46
  "@types/jsrsasign": "^10.5.12",
46
47
  "@types/webpack-sources": "^3.2.3"
47
48
  },
48
- "gitHead": "d51c01beb50c17548d9ab5be522790d295b4c18d"
49
+ "gitHead": "85c4287c7b9468c83d468cfc39b147f4975f8285"
49
50
  }