@aiot-toolkit/aiotpack 2.1.0-prender.2 → 2.1.0-prender.3

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.
@@ -11,6 +11,33 @@ var _UxCompileUtil = _interopRequireDefault(require("./vela/utils/UxCompileUtil"
11
11
  var _UxFileUtils = _interopRequireDefault(require("../../utils/ux/UxFileUtils"));
12
12
  var _UxLoaderUtils = _interopRequireDefault(require("../../utils/ux/UxLoaderUtils"));
13
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ function extractAppStyleLiteral(code) {
15
+ const m = code.match(/var\s+\$app_style\$\s*=\s*\[/);
16
+ if (!m) return null;
17
+ let i = m.index + m[0].length - 1;
18
+ let depth = 0;
19
+ let inStr = null;
20
+ for (; i < code.length; i++) {
21
+ const c = code[i];
22
+ if (inStr) {
23
+ if (c === '\\') {
24
+ i++;
25
+ continue;
26
+ }
27
+ if (c === inStr) inStr = null;
28
+ continue;
29
+ }
30
+ if (c === '"' || c === "'") {
31
+ inStr = c;
32
+ continue;
33
+ }
34
+ if (c === '[') depth++;else if (c === ']') {
35
+ depth--;
36
+ if (depth === 0) return code.slice(m.index + m[0].length - 1, i + 1);
37
+ }
38
+ }
39
+ return null;
40
+ }
14
41
  class ViteCompiler {
15
42
  constructor(context, onLog) {
16
43
  this.context = context;
@@ -148,11 +175,9 @@ class ViteCompiler {
148
175
  const compiledCode = compFiles[0]?.content || '';
149
176
  // Extract $app_style$ array from compiled code
150
177
  let styleSheet = {};
151
- const styleMatch = compiledCode.match(/var \$app_style\$ = (\[[\s\S]*?\]);?\s*(?:import|export|var |const |$)/);
152
- if (styleMatch) {
153
- if (styleMatch) {
154
- styleSheet = (0, _TemplateCompiler.parseStyleArray)(styleMatch[1]);
155
- }
178
+ const styleLiteral = extractAppStyleLiteral(compiledCode);
179
+ if (styleLiteral) {
180
+ styleSheet = (0, _TemplateCompiler.parseStyleArray)(styleLiteral);
156
181
  }
157
182
  // Write css.json
158
183
  const cssPath = _path.default.join(buildPath, `${isApp ? 'app' : pageName}.css.json`);
@@ -226,9 +251,9 @@ class ViteCompiler {
226
251
  }, false, param, compilation);
227
252
  let compStyleSheet = {};
228
253
  const compCode = compResult.files[0]?.content || '';
229
- const csm = compCode.match(/var \$app_style\$ = (\[[\s\S]*?\]);?\s*(?:import|export|var |const |$)/);
254
+ const csm = extractAppStyleLiteral(compCode);
230
255
  if (csm) {
231
- compStyleSheet = (0, _TemplateCompiler.parseStyleArray)(csm[1]);
256
+ compStyleSheet = (0, _TemplateCompiler.parseStyleArray)(csm);
232
257
  }
233
258
  const compSid = (0, _TemplateCompiler.getStyleObjectId)(compPath);
234
259
  _fsExtra.default.writeJSONSync(compTplPath, (0, _TemplateCompiler.uxToTemplateJson)(compTpl, compSid, compStyleSheet, compImportMap, _path.default.dirname(compPath)), param.mode === 'production' ? undefined : {
@@ -337,9 +362,9 @@ class ViteCompiler {
337
362
  const compCode = files[0]?.content || '';
338
363
  // Extract style
339
364
  let styleSheet = {};
340
- const csm = compCode.match(/var \$app_style\$ = (\[[\s\S]*?\]);?\s*(?:import|export|var |const |$)/);
365
+ const csm = extractAppStyleLiteral(compCode);
341
366
  if (csm) {
342
- styleSheet = (0, _TemplateCompiler.parseStyleArray)(csm[1]);
367
+ styleSheet = (0, _TemplateCompiler.parseStyleArray)(csm);
343
368
  }
344
369
  // Generate template.json
345
370
  if (templateNode) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/aiotpack",
3
- "version": "2.1.0-prender.2",
3
+ "version": "2.1.0-prender.3",
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.1.0-prender.2",
23
- "@aiot-toolkit/parser": "2.1.0-prender.2",
24
- "@aiot-toolkit/shared-utils": "2.1.0-prender.2",
22
+ "@aiot-toolkit/generator": "2.1.0-prender.3",
23
+ "@aiot-toolkit/parser": "2.1.0-prender.3",
24
+ "@aiot-toolkit/shared-utils": "2.1.0-prender.3",
25
25
  "@hap-toolkit/aaptjs": "^2.0.0",
26
26
  "@rspack/core": "^1.3.9",
27
27
  "acorn": "^8.16.0",
28
28
  "aiot-parse5": "^1.0.2",
29
29
  "astring": "^1.9.0",
30
30
  "babel-loader": "^9.1.3",
31
- "file-lane": "2.1.0-prender.2",
31
+ "file-lane": "2.1.0-prender.3",
32
32
  "file-loader": "^6.2.0",
33
33
  "fs-extra": "^11.2.0",
34
34
  "jsrsasign": "^11.1.0",