@aiot-toolkit/aiotpack 2.0.6-beta.9 → 2.1.0-prender.2

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 (31) hide show
  1. package/lib/afterCompile/ux/UxAfterCompile.js +25 -2
  2. package/lib/compiler/javascript/JavascriptCompiler.js +11 -4
  3. package/lib/compiler/javascript/TemplateCompiler.d.ts +29 -0
  4. package/lib/compiler/javascript/TemplateCompiler.js +564 -0
  5. package/lib/compiler/javascript/ViteCompiler.d.ts +13 -0
  6. package/lib/compiler/javascript/ViteCompiler.js +449 -0
  7. package/lib/compiler/javascript/interface/IJavascriptCompileOption.d.ts +9 -0
  8. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.d.ts +3 -1
  9. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js +16 -1
  10. package/lib/compiler/javascript/vela/interface/IManifest.d.ts +12 -0
  11. package/lib/compiler/javascript/vela/plugin/WrapPlugin.d.ts +10 -1
  12. package/lib/compiler/javascript/vela/plugin/WrapPlugin.js +241 -57
  13. package/lib/compiler/javascript/vela/utils/UxCompileUtil.d.ts +3 -2
  14. package/lib/compiler/javascript/vela/utils/UxCompileUtil.js +12 -4
  15. package/lib/compiler/javascript/vela/utils/VruUtil.d.ts +50 -0
  16. package/lib/compiler/javascript/vela/utils/VruUtil.js +128 -0
  17. package/lib/compiler/javascript/vela/utils/ZipUtil.d.ts +9 -0
  18. package/lib/compiler/javascript/vela/utils/ZipUtil.js +112 -6
  19. package/lib/compiler/javascript/vela/utils/webpackLoader/WebpackJsLoader.js +1 -1
  20. package/lib/config/UxConfig.d.ts +12 -5
  21. package/lib/config/UxConfig.js +4 -6
  22. package/lib/loader/ux/JsLoader.d.ts +7 -0
  23. package/lib/loader/ux/JsLoader.js +38 -8
  24. package/lib/loader/ux/vela/HmlLoader.d.ts +6 -6
  25. package/lib/loader/ux/vela/HmlLoader.js +30 -13
  26. package/lib/utils/BeforeCompileUtils.d.ts +1 -1
  27. package/lib/utils/BeforeCompileUtils.js +52 -9
  28. package/lib/utils/ux/ManifestSchema.js +0 -1
  29. package/lib/utils/ux/UxFileUtils.js +1 -1
  30. package/lib/utils/ux/UxLoaderUtils.js +8 -3
  31. package/package.json +9 -6
@@ -14,6 +14,7 @@ var _BuildNameFormatType = _interopRequireDefault(require("../enum/BuildNameForm
14
14
  var _Package = _interopRequireDefault(require("../model/Package"));
15
15
  var _UxCompileUtil = _interopRequireDefault(require("./UxCompileUtil"));
16
16
  var _SignUtil = _interopRequireDefault(require("./signature/SignUtil"));
17
+ var _VruUtil = require("./VruUtil");
17
18
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
18
19
  /**
19
20
  * Zip 用于将打包成功的 build 目录按特定规则压缩成 rpk
@@ -66,17 +67,122 @@ class ZipUtil {
66
67
  _sharedUtils.ColorConsole.error(`The build file is missing, stop generating the application package, please check carefully`);
67
68
  return;
68
69
  }
70
+ const signConfig = await _SignUtil.default.getProjectSignConfig(param);
71
+ const rpkFileName = this.getFileName(param, config, 'rpk');
72
+
73
+ // VRU mode: produce wrapped RPK (manifest + logo + CERT + inner-vru)
74
+ if (param.enableVru) {
75
+ const wrappedRpkBuffer = await this.createWrappedReleaseRpk(param, config, files, signConfig);
76
+ return await this.generateDistFile(wrappedRpkBuffer, param, rpkFileName);
77
+ }
69
78
 
70
- // 2
79
+ // Flat mode (default): all build files directly in RPK
71
80
  const {
72
81
  fullPackage
73
82
  } = await this.createPackagesDefinition(param, config, files);
74
-
75
- // 生产出带签名的rpk文件buffer
76
- const signConfig = await _SignUtil.default.getProjectSignConfig(param);
77
83
  const rpkBuffer = await ZipUtil.buildProjectAndOutput(fullPackage, signConfig);
78
- // 3
79
- return this.generateDistFile(rpkBuffer, param, this.getFileName(param, config, 'rpk'));
84
+ return await this.generateDistFile(rpkBuffer, param, rpkFileName);
85
+ }
86
+
87
+ /**
88
+ * Build the blueos-pack compatible "wrapped release" RPK.
89
+ * Outer RPK (zip) contains:
90
+ * - manifest.json (top-level metadata)
91
+ * - logo.<ext> (icon - kept as png since VUG conversion is out of scope)
92
+ * - META-INF/CERT (signature)
93
+ * - <package>.vru (multi-file VRU containing all build artifacts)
94
+ */
95
+ static async createWrappedReleaseRpk(param, config, files, signConfig) {
96
+ const {
97
+ projectPath,
98
+ outputPath
99
+ } = param;
100
+ const buildDir = _path.default.join(projectPath, outputPath);
101
+
102
+ // 1. Pack all build files into VRU
103
+ const vruEntries = [];
104
+ for (const f of files) {
105
+ // Skip top-level manifest.json and CERT — those go in outer rpk
106
+ if (f === 'manifest.json' || f === ZipUtil.CERT_PATH) continue;
107
+ const absPath = _path.default.join(buildDir, f);
108
+ vruEntries.push({
109
+ name: f,
110
+ data: _fsExtra.default.readFileSync(absPath)
111
+ });
112
+ }
113
+ // Add packageInfo.json for build metadata
114
+ const packageInfo = {
115
+ originType: 'native',
116
+ toolkit: 'aiot-toolkit',
117
+ buildTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
118
+ node: process.version,
119
+ platform: process.platform,
120
+ arch: process.arch
121
+ };
122
+ vruEntries.push({
123
+ name: 'packageInfo.json',
124
+ data: Buffer.from(JSON.stringify(packageInfo, null, 2), 'utf-8')
125
+ });
126
+ // Sort entries alphabetically (matches blueos-pack ordering)
127
+ vruEntries.sort((a, b) => a.name.localeCompare(b.name));
128
+ const vruBuffer = _VruUtil.VruUtil.pack(vruEntries, config.package);
129
+
130
+ // 2. Build the outer RPK
131
+ const outerPackage = new _Package.default({
132
+ filePrefix: config.package,
133
+ fileSuffix: 'rpk',
134
+ standalone: true,
135
+ comment: JSON.stringify(this.createComment(param))
136
+ });
137
+
138
+ // Add manifest.json
139
+ const manifestPath = _path.default.join(buildDir, 'manifest.json');
140
+ if (_fsExtra.default.existsSync(manifestPath)) {
141
+ const manifestBuf = _fsExtra.default.readFileSync(manifestPath);
142
+ outerPackage.addResource({
143
+ fileBuildPath: 'manifest.json',
144
+ fileContentBuffer: manifestBuf,
145
+ fileContentDigest: _sharedUtils.CommonUtil.calcDataDigest(manifestBuf)
146
+ });
147
+ }
148
+
149
+ // Add icon (as-is, no VUG conversion)
150
+ if (config.icon) {
151
+ const iconPath = _path.default.join(buildDir, config.icon.replace(/^\//, ''));
152
+ if (_fsExtra.default.existsSync(iconPath)) {
153
+ const iconBuf = _fsExtra.default.readFileSync(iconPath);
154
+ const iconExt = _path.default.extname(iconPath) || '.png';
155
+ outerPackage.addResource({
156
+ fileBuildPath: `logo${iconExt}`,
157
+ fileContentBuffer: iconBuf,
158
+ fileContentDigest: _sharedUtils.CommonUtil.calcDataDigest(iconBuf)
159
+ });
160
+ }
161
+ }
162
+
163
+ // Add inner VRU
164
+ outerPackage.addResource({
165
+ fileBuildPath: _VruUtil.VruUtil.getVruName(config.package),
166
+ fileContentBuffer: vruBuffer,
167
+ fileContentDigest: _sharedUtils.CommonUtil.calcDataDigest(vruBuffer)
168
+ });
169
+
170
+ // Add CERT if present
171
+ const certAbsPath = _path.default.join(buildDir, ZipUtil.CERT_PATH);
172
+ if (_fsExtra.default.existsSync(certAbsPath)) {
173
+ let certBuf = _fsExtra.default.readFileSync(certAbsPath);
174
+ const metaZip = await _jszip.default.loadAsync(certBuf);
175
+ certBuf = await metaZip.generateAsync({
176
+ ...ZipUtil.ZIP_OPTION,
177
+ comment: null
178
+ });
179
+ outerPackage.addResource({
180
+ fileBuildPath: ZipUtil.CERT_PATH,
181
+ fileContentBuffer: certBuf,
182
+ fileContentDigest: _sharedUtils.CommonUtil.calcDataDigest(certBuf)
183
+ });
184
+ }
185
+ return await ZipUtil.buildProjectAndOutput(outerPackage, signConfig);
80
186
  }
81
187
  static getFileName(param, config, ext) {
82
188
  const {
@@ -20,7 +20,7 @@ async function _default(source) {
20
20
  projectPath: this.rootContext,
21
21
  onLog: log => onLog?.([log]),
22
22
  projectType: _sharedUtils.ProjectType.VELA_UX
23
- }, compileParam, context).translate({
23
+ }, compileParam, context, true).translate({
24
24
  content: source
25
25
  }, []);
26
26
  callback(null, result.targetTree.getFullText());
@@ -5,6 +5,7 @@ import PngLoader from '../loader/ux/PngLoader';
5
5
  import AppUxLoader from '../loader/ux/vela/AppUxLoader';
6
6
  import HmlLoader from '../loader/ux/vela/HmlLoader';
7
7
  import UxLoader from '../loader/ux/vela/UxLoader';
8
+ import AndroidUxLoader from '../loader/ux/android/UxLoader';
8
9
  import UxBeforeWorks from '../beforeWorks/ux/UxBeforeWorks';
9
10
  import UxAfterWorks from '../afterWorks/ux/UxAfterWorks';
10
11
  import { IChangedFile } from 'file-lane/lib/interface/IChangedFile';
@@ -28,13 +29,15 @@ declare class UxConfig implements IFileLaneConfig<IJavascriptCompileOption> {
28
29
  beforeCompile: import("file-lane").PreWork<IJavascriptCompileOption>[];
29
30
  afterCompile: ({
30
31
  worker: import("file-lane").FollowWork<IJavascriptCompileOption>;
32
+ workDescribe: string;
31
33
  workerDescribe?: undefined;
32
34
  } | {
33
35
  worker: import("file-lane").FollowWork<IJavascriptCompileOption>;
34
36
  workerDescribe: string;
37
+ workDescribe?: undefined;
35
38
  })[];
36
39
  afterWorks: (typeof UxAfterWorks.cleanOutput)[];
37
- watchIgnores: RegExp[];
40
+ watchIgnores: string[];
38
41
  /**
39
42
  * 通过项目类型,返回模块配置
40
43
  */
@@ -46,11 +49,7 @@ declare class UxConfig implements IFileLaneConfig<IJavascriptCompileOption> {
46
49
  } | {
47
50
  test: RegExp[];
48
51
  exclude: RegExp[];
49
- loader: (typeof UxLoader)[];
50
- } | {
51
- test: RegExp[];
52
52
  loader: (typeof HmlLoader | typeof UxLoader)[];
53
- exclude?: undefined;
54
53
  } | {
55
54
  test: RegExp[];
56
55
  loader: (typeof JsLoader)[];
@@ -60,6 +59,14 @@ declare class UxConfig implements IFileLaneConfig<IJavascriptCompileOption> {
60
59
  loader: (typeof PngLoader)[];
61
60
  exclude?: undefined;
62
61
  })[];
62
+ } | {
63
+ rules: ({
64
+ test: RegExp[];
65
+ loader: (typeof AndroidUxLoader)[];
66
+ } | {
67
+ test: RegExp[];
68
+ loader: (typeof PngLoader)[];
69
+ })[];
63
70
  };
64
71
  /**
65
72
  * 判断项目类型
@@ -75,7 +75,8 @@ class UxConfig {
75
75
  beforeWorks = (() => [_UxBeforeWorks.default.cleanOutput])();
76
76
  beforeCompile = (() => [_UxBeforeCompile.default.validateManifest, _UxBeforeCompile.default.validateSitemap, _BeforeCompileUtils.default.clean, _BeforeCompileUtils.default.getEntries, _BeforeCompileUtils.default.getGlobalVar])();
77
77
  afterCompile = (() => [{
78
- worker: _UxAfterCompile.default.writeGitIgnore
78
+ worker: _UxAfterCompile.default.writeGitIgnore,
79
+ workDescribe: 'Write .gitignore'
79
80
  }, {
80
81
  worker: _UxAfterCompile.default.symlinkNodeModule,
81
82
  workerDescribe: 'Create a soft link to the node_modules folder'
@@ -111,7 +112,7 @@ class UxConfig {
111
112
  workerDescribe: 'Check resource'
112
113
  }])();
113
114
  afterWorks = (() => [_UxAfterWorks.default.cleanOutput])();
114
- watchIgnores = [/node_modules/, /build/, /dist/];
115
+ watchIgnores = ['**/node_modules/**', '**/build/**', '**/dist/**'];
115
116
 
116
117
  /**
117
118
  * 通过项目类型,返回模块配置
@@ -123,11 +124,8 @@ class UxConfig {
123
124
  test: ['app.ux'],
124
125
  loader: [_AppUxLoader.default]
125
126
  }, {
126
- test: [/.+\.ux$/],
127
+ test: [/.+\.(ux|hml)$/],
127
128
  exclude: [/app\.ux/],
128
- loader: [_UxLoader.default]
129
- }, {
130
- test: [/.+\.hml$/],
131
129
  loader: [_HmlLoader.default, _UxLoader.default]
132
130
  }, {
133
131
  test: [/.+\.js$/],
@@ -1,5 +1,6 @@
1
1
  import { IFileLaneContext, IFileParam, ILoader } from 'file-lane';
2
2
  import IJavascriptCompileOption from '../../compiler/javascript/interface/IJavascriptCompileOption';
3
+ import { ILog } from '@aiot-toolkit/shared-utils';
3
4
  import FileLaneCompilation from 'file-lane/lib/FileLaneCompilation';
4
5
  /**
5
6
  * JsLoader
@@ -8,6 +9,12 @@ declare class JsLoader implements ILoader {
8
9
  context: IFileLaneContext;
9
10
  compilerOption: IJavascriptCompileOption;
10
11
  compilation: FileLaneCompilation;
12
+ logs: ILog[];
13
+ /**
14
+ * 解析文件内容
15
+ * @param files files 待处理的文件数组
16
+ * @returns 处理后的文件数组
17
+ */
11
18
  parser(files: IFileParam<any>[]): Promise<IFileParam<any>[]>;
12
19
  }
13
20
  export default JsLoader;
@@ -7,14 +7,27 @@ exports.default = void 0;
7
7
  var _parser = require("@aiot-toolkit/parser");
8
8
  var _sharedUtils = require("@aiot-toolkit/shared-utils");
9
9
  var _UxLoaderUtils = _interopRequireDefault(require("../../utils/ux/UxLoaderUtils"));
10
+ var _path = _interopRequireDefault(require("path"));
10
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
12
  /**
12
13
  * JsLoader
13
14
  */
14
15
  class JsLoader {
16
+ logs = [];
17
+ /**
18
+ * 解析文件内容
19
+ * @param files files 待处理的文件数组
20
+ * @returns 处理后的文件数组
21
+ */
15
22
  async parser(files) {
16
- const onLog = () => {};
17
23
  const result = [];
24
+ const {
25
+ projectPath,
26
+ widgetProvider
27
+ } = this.context;
28
+ const {
29
+ sourceRoot
30
+ } = this.compilerOption;
18
31
  for (const item of files) {
19
32
  if (!item.content) {
20
33
  result.push({
@@ -24,10 +37,12 @@ class JsLoader {
24
37
  } else {
25
38
  const options = {
26
39
  filePath: item.path,
27
- projectPath: this.context.projectPath,
40
+ projectPath,
28
41
  content: item.content.toString(),
29
42
  projectType: _sharedUtils.ProjectType.getProjectType(this.context.projectPath),
30
- onLog
43
+ onLog: log => {
44
+ this.logs.push(log);
45
+ }
31
46
  };
32
47
  const scriptTree = await new _parser.ScriptToTypescript(options, this.compilerOption, this.context).translate({
33
48
  content: new _parser.ScriptParser(options).parser(item.content.toString()).ast.content
@@ -37,11 +52,26 @@ class JsLoader {
37
52
  compilerOption: this.compilerOption,
38
53
  context: this.context
39
54
  });
40
- const content = isService ? _UxLoaderUtils.default.createServiceWrapper(scriptTree.targetTree).filter(Boolean).join('\n') : scriptTree.targetTree.getFullText();
41
- result.push({
42
- path: item.path,
43
- content
44
- });
55
+ if (isService) {
56
+ result.push({
57
+ path: item.path,
58
+ content: _UxLoaderUtils.default.createServiceWrapper(scriptTree.targetTree).filter(Boolean).join('\n')
59
+ });
60
+ } else {
61
+ const isWidgetProvider = widgetProvider?.includes(_path.default.relative(_path.default.join(projectPath, sourceRoot), item.path).replace(/\\/g, '/'));
62
+ let content = scriptTree.targetTree.getFullText();
63
+ if (isWidgetProvider) {
64
+ const {
65
+ newScriptTree,
66
+ scriptSourceMap
67
+ } = _parser.SourceMapUtil.splitSourceMap(scriptTree.targetTree);
68
+ content = _parser.SourceMapUtil.concatSourceMap(`${newScriptTree.getFullText()}\n$app_exports$.default = exports["default"]\n`, scriptSourceMap);
69
+ }
70
+ result.push({
71
+ path: item.path,
72
+ content: content
73
+ });
74
+ }
45
75
  }
46
76
  }
47
77
  return result;
@@ -9,16 +9,16 @@ declare class HmlLoader implements ILoader {
9
9
  /**
10
10
  * 包裹 hml 文件
11
11
  *
12
- * # 路径
13
- * 如果存在同路径的 ux 后缀,报错;否则转换为同路径的 ux 后缀
14
- *
15
12
  * # 内容
16
- * 1. 给hml的内容加上<template></template>
17
- * 2. 如果存在同路径同名的 script文件,则加到<script></script>中
18
- * 3. 如果存在同路径同名的 style文件,则加到<style></style>中
13
+ * 1. 全文模式(存在template、script、style任一节点),保留原内容不变
14
+ * 2. 否则,则进行如下包装
15
+ * 1. hml的内容: import放到最前,其它内容使用<template></template>包裹
16
+ * 2. 如果存在同路径同名的 script文件,则加到<script></script>中
17
+ * 3. 如果存在同路径同名的 style文件,则加到<style></style>中
19
18
  *
20
19
  * @param file
21
20
  */
22
21
  private wrapHml;
22
+ private nodesToString;
23
23
  }
24
24
  export default HmlLoader;
@@ -7,6 +7,9 @@ exports.default = void 0;
7
7
  var _path = _interopRequireDefault(require("path"));
8
8
  var _fs = _interopRequireDefault(require("fs"));
9
9
  var _parser = require("@aiot-toolkit/parser");
10
+ var parse5 = _interopRequireWildcard(require("aiot-parse5"));
11
+ 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); }
12
+ 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; }
10
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
14
  /**
12
15
  * HmlLoader
@@ -21,13 +24,12 @@ class HmlLoader {
21
24
  /**
22
25
  * 包裹 hml 文件
23
26
  *
24
- * # 路径
25
- * 如果存在同路径的 ux 后缀,报错;否则转换为同路径的 ux 后缀
26
- *
27
27
  * # 内容
28
- * 1. 给hml的内容加上<template></template>
29
- * 2. 如果存在同路径同名的 script文件,则加到<script></script>中
30
- * 3. 如果存在同路径同名的 style文件,则加到<style></style>中
28
+ * 1. 全文模式(存在template、script、style任一节点),保留原内容不变
29
+ * 2. 否则,则进行如下包装
30
+ * 1. hml的内容: import放到最前,其它内容使用<template></template>包裹
31
+ * 2. 如果存在同路径同名的 script文件,则加到<script></script>中
32
+ * 3. 如果存在同路径同名的 style文件,则加到<style></style>中
31
33
  *
32
34
  * @param file
33
35
  */
@@ -36,32 +38,47 @@ class HmlLoader {
36
38
  path,
37
39
  content
38
40
  } = file;
39
- const uxExt = _parser.ExtensionConfig.UX;
41
+ const uxAst = parse5.parseFragment(content?.toString() || '', {
42
+ scriptingEnabled: false,
43
+ sourceCodeLocationInfo: true
44
+ });
45
+ const fullMode = uxAst.childNodes.some(node => {
46
+ return ['template', 'script', 'style'].includes(node.nodeName);
47
+ });
48
+ if (fullMode) {
49
+ return file;
50
+ }
40
51
  const getFilePath = ext => {
41
52
  const pathParsed = _path.default.parse(path);
42
53
  pathParsed.ext = ext;
43
54
  pathParsed.base = pathParsed.name + ext;
44
55
  return _path.default.format(pathParsed);
45
56
  };
46
- const uxPath = getFilePath(uxExt);
47
- if (_fs.default.existsSync(uxPath)) {
48
- throw new Error(`${uxPath} already exists`);
49
- }
50
57
  const scriptExts = _parser.ExtensionConfig.SCRIPTS;
51
58
  const styleExts = _parser.ExtensionConfig.STYLES;
52
59
  const scriptPath = scriptExts.map(item => getFilePath(item)).find(item => _fs.default.existsSync(item));
53
60
  const stylePath = styleExts.map(item => getFilePath(item)).find(item => _fs.default.existsSync(item));
54
- let uxContent = ['<template>', content, '</template>'].join('\n');
61
+ const importNodes = uxAst.childNodes.filter(node => node.nodeName === 'import');
62
+ const otherNodes = uxAst.childNodes.filter(node => node.nodeName !== 'import');
63
+ let uxContent = this.nodesToString(importNodes);
64
+ uxContent += ['<template>', this.nodesToString(otherNodes), '</template>'].join('\n');
55
65
  if (scriptPath) {
56
66
  uxContent += ['<script>', _fs.default.readFileSync(scriptPath, 'utf-8'), '</script>'].join('\n');
57
67
  }
58
68
  if (stylePath) {
59
- uxContent += ['<style>', _fs.default.readFileSync(stylePath, 'utf-8'), '</style>'].join('\n');
69
+ const styleExt = _path.default.extname(stylePath).toLowerCase();
70
+ uxContent += [`<style lang="${styleExt.slice(1)}">`, _fs.default.readFileSync(stylePath, 'utf-8'), '</style>'].join('\n');
60
71
  }
61
72
  return {
62
73
  path,
63
74
  content: uxContent
64
75
  };
65
76
  }
77
+ nodesToString(nodes) {
78
+ return parse5.serialize({
79
+ nodeName: '#document-fragment',
80
+ childNodes: nodes
81
+ });
82
+ }
66
83
  }
67
84
  var _default = exports.default = HmlLoader;
@@ -10,7 +10,7 @@ declare class BeforeCompileUtils {
10
10
  * @param fileList
11
11
  * @returns
12
12
  */
13
- static getEntries: PreWork;
13
+ static getEntries: PreWork<IJavascriptCompileOption>;
14
14
  static clean: PreWork;
15
15
  /**
16
16
  * 获取项目的全局样式变量配置
@@ -11,6 +11,7 @@ var _path = _interopRequireDefault(require("path"));
11
11
  var _TranslateCache = _interopRequireDefault(require("@aiot-toolkit/parser/lib/ux/translate/vela/TranslateCache"));
12
12
  var _UxFileUtils = _interopRequireDefault(require("./ux/UxFileUtils"));
13
13
  var _IManifest = require("../compiler/javascript/vela/interface/IManifest");
14
+ var _UxUtil = _interopRequireDefault(require("@aiot-toolkit/parser/lib/ux/utils/UxUtil"));
14
15
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
16
  const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
16
17
 
@@ -28,7 +29,8 @@ class BeforeCompileUtils {
28
29
  const {
29
30
  context,
30
31
  compilerOption,
31
- compilation
32
+ compilation,
33
+ onLog
32
34
  } = params;
33
35
  const {
34
36
  projectPath
@@ -45,8 +47,11 @@ class BeforeCompileUtils {
45
47
  let serviceList = [];
46
48
  const {
47
49
  router,
48
- services
50
+ services,
51
+ widgetProvider
49
52
  } = manifestContent;
53
+ // 存储widgetProvider
54
+ let widgetProviderList = [];
50
55
  if (router) {
51
56
  const {
52
57
  pages,
@@ -62,12 +67,14 @@ class BeforeCompileUtils {
62
67
  entryList.push(_path.default.join(entryDir, entry));
63
68
  } else {
64
69
  // 路径不存在
65
- _sharedUtils.ColorConsole.throw(`### manifest ### path '${_path.default.join(entryDir, entryPages.join(' | '))}' does not exist`);
70
+ onLog?.([{
71
+ level: _sharedUtils.Loglevel.THROW,
72
+ message: ['### manifest ### path', {
73
+ word: _path.default.join(entryDir, entryPages.join(' | '))
74
+ }, 'does not exist']
75
+ }]);
66
76
  }
67
77
  });
68
- } else {
69
- // 没有pages配置
70
- _sharedUtils.ColorConsole.throw(`### manifest ### No pages configuration`);
71
78
  }
72
79
  //获取轻卡路由
73
80
  if (widgets) {
@@ -78,23 +85,59 @@ class BeforeCompileUtils {
78
85
  if (_fsExtra.default.existsSync(cardPath)) {
79
86
  liteCardList.push(card + _path.default.posix.sep + cardContent.component);
80
87
  } else {
81
- // 报错
82
- _sharedUtils.ColorConsole.throw(`### manifest ### lite card path '${cardPath}' does not exist`);
88
+ onLog?.([{
89
+ level: _sharedUtils.Loglevel.THROW,
90
+ message: [`### manifest ### lite card path`, {
91
+ word: cardPath
92
+ }, `does not exist`]
93
+ }]);
83
94
  }
84
95
  }
85
96
  });
86
97
  }
87
98
  } else {
88
99
  // 没有router配置
89
- _sharedUtils.ColorConsole.throw(`### manifest ### No router configuration`);
100
+ onLog?.([{
101
+ level: _sharedUtils.Loglevel.THROW,
102
+ message: ['### manifest ### No router configuration']
103
+ }]);
104
+ }
105
+
106
+ // e2e测试入口
107
+ if (compilerOption?.enableE2e && compilerOption?.e2eConfigPath) {
108
+ const e2eConfig = _UxUtil.default.getE2eConfig({
109
+ projectPath: context.projectPath,
110
+ e2eConfigPath: compilerOption.e2eConfigPath
111
+ });
112
+ entryList.push(_path.default.join(e2eConfig.dir, e2eConfig.entry.path));
90
113
  }
91
114
  if (services) {
92
115
  serviceList = Array.isArray(services) ? services : Object.values(services);
93
116
  }
117
+ if (widgetProvider) {
118
+ const EXTENSION_JS = '.js';
119
+ for (const providerItem of widgetProvider) {
120
+ const {
121
+ path
122
+ } = providerItem;
123
+ const itemPath = _path.default.join(srcPath, path + EXTENSION_JS);
124
+ if (_fsExtra.default.existsSync(itemPath)) {
125
+ widgetProviderList.push(path + EXTENSION_JS);
126
+ } else {
127
+ onLog?.([{
128
+ level: _sharedUtils.Loglevel.THROW,
129
+ message: ['### manifest ### widgetProvider path', {
130
+ word: itemPath
131
+ }, 'does not exist']
132
+ }]);
133
+ }
134
+ }
135
+ }
94
136
  if (compilation) {
95
137
  compilation['entries'] = entryList;
96
138
  compilation['liteCards'] = liteCardList;
97
139
  compilation['services'] = serviceList;
140
+ context['widgetProvider'] = widgetProviderList;
98
141
  }
99
142
  return Promise.resolve();
100
143
  };
@@ -69,7 +69,6 @@ const ManifestSchema = {
69
69
  router: {
70
70
  // TODO 更详细的后台运行配置信息,
71
71
  type: 'object',
72
- required: ['entry', 'pages'],
73
72
  properties: {
74
73
  entry: {
75
74
  type: 'string'
@@ -67,7 +67,7 @@ class UxFileUtils {
67
67
  entry,
68
68
  pages
69
69
  } = jsonData.router;
70
- if (!pages[entry]) {
70
+ if (entry && !pages?.[entry]) {
71
71
  errors.push(new TypeError(`router.entry content: ${entry}, is missing in router.pages`));
72
72
  }
73
73
  }
@@ -115,7 +115,12 @@ class UxLoaderUtils {
115
115
  const parserResult = await new _parser.UxParser(options, compilerOption, globalVar, collectImageResource).parser();
116
116
  // 区分app.ux和一般ux
117
117
  // app.ux解析结果中加上manifest.json的内容
118
- const manifestJson = `require('./manifest.json')`;
118
+ const manifestPath = _path.default.join(_path.default.dirname(filePath), 'manifest.json');
119
+ let manifestContent = '{}';
120
+ if (_fsExtra.default.existsSync(manifestPath)) {
121
+ manifestContent = _fsExtra.default.readFileSync(manifestPath, 'utf-8').trim();
122
+ }
123
+ const manifestJson = `JSON.parse('${manifestContent.replace(/'/g, "\\'").replace(/\n/g, '')}')`;
119
124
  function translateStyleFunc() {
120
125
  return `
121
126
  var $translateStyle$ = function (value) {
@@ -154,10 +159,10 @@ class UxLoaderUtils {
154
159
 
155
160
  // script代码放在第三个位置不能变化,影响更新source map
156
161
  const createAppWrapper = () => {
157
- return [`${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}`, translateStyleFunc()];
162
+ return [`${appImport.join('\n')}`, `var $app_style$ = ${UxLoaderUtils.wrapStyle(appStyleTree, file, compilerOption)}`, hasScript ? appScriptTree.getFullText() : 'export default {};'];
158
163
  };
159
164
  const createComponentWrapper = () => {
160
- return [`${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$;`, `}`];
165
+ return [`${appImport.join('\n')}`, `var $app_style$ = ${UxLoaderUtils.wrapStyle(appStyleTree, file, compilerOption)}`, hasScript ? appScriptTree.getFullText() : 'export default {};'];
161
166
  };
162
167
  if (isAppUx) {
163
168
  return createAppWrapper();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/aiotpack",
3
- "version": "2.0.6-beta.9",
3
+ "version": "2.1.0-prender.2",
4
4
  "description": "The process tool for packaging aiot projects.",
5
5
  "keywords": [
6
6
  "aiotpack"
@@ -19,14 +19,16 @@
19
19
  "test": "node ./__tests__/aiotpack.test.js"
20
20
  },
21
21
  "dependencies": {
22
- "@aiot-toolkit/generator": "2.0.6-beta.9",
23
- "@aiot-toolkit/parser": "2.0.6-beta.9",
24
- "@aiot-toolkit/shared-utils": "2.0.6-beta.9",
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",
25
25
  "@hap-toolkit/aaptjs": "^2.0.0",
26
26
  "@rspack/core": "^1.3.9",
27
+ "acorn": "^8.16.0",
27
28
  "aiot-parse5": "^1.0.2",
29
+ "astring": "^1.9.0",
28
30
  "babel-loader": "^9.1.3",
29
- "file-lane": "2.0.6-beta.9",
31
+ "file-lane": "2.1.0-prender.2",
30
32
  "file-loader": "^6.2.0",
31
33
  "fs-extra": "^11.2.0",
32
34
  "jsrsasign": "^11.1.0",
@@ -34,6 +36,7 @@
34
36
  "lodash": "^4.17.21",
35
37
  "ts-morph": "^19.0.0",
36
38
  "url-loader": "^4.1.1",
39
+ "vite": "^8.0.14",
37
40
  "webpack-bundle-analyzer": "^4.10.2",
38
41
  "webpack-sources": "^3.2.3"
39
42
  },
@@ -42,5 +45,5 @@
42
45
  "@types/jsrsasign": "^10.5.12",
43
46
  "@types/webpack-sources": "^3.2.3"
44
47
  },
45
- "gitHead": "18718f09f1ee7f1d7361022c5fb7858c87cee2bd"
48
+ "gitHead": "a0849da638ea3a9a6abb95a9cbcad400cbb6903a"
46
49
  }