@aiot-toolkit/aiotpack 2.0.6-beta.22 → 2.0.6-beta.24

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.
@@ -8,6 +8,10 @@ interface IWidget {
8
8
  sizes: string[];
9
9
  type?: string;
10
10
  }
11
+ interface IWidgetProvider {
12
+ name: string;
13
+ path: string;
14
+ }
11
15
  /**
12
16
  * vela manifest文件对应的数据结构
13
17
  */
@@ -36,6 +40,7 @@ export default interface IManifest {
36
40
  services: IService[] | Record<string, IService>;
37
41
  minAPILevel?: number;
38
42
  packageInfo?: Dictionary<string | number>;
43
+ widgetProvider?: IWidgetProvider[];
39
44
  icon: string;
40
45
  workers?: {
41
46
  entries: {
@@ -129,6 +129,15 @@ class UxCompileUtil {
129
129
  }
130
130
  }
131
131
  }
132
+ // 5. 添加 widget_provider
133
+ const {
134
+ widgetProvider
135
+ } = config;
136
+ if (widgetProvider?.length) {
137
+ for (const widgetItem of widgetProvider) {
138
+ result[widgetItem.path] = './src/' + widgetItem.path;
139
+ }
140
+ }
132
141
  return result;
133
142
  }
134
143
 
@@ -29,10 +29,12 @@ declare class UxConfig implements IFileLaneConfig<IJavascriptCompileOption> {
29
29
  beforeCompile: import("file-lane").PreWork<IJavascriptCompileOption>[];
30
30
  afterCompile: ({
31
31
  worker: import("file-lane").FollowWork<IJavascriptCompileOption>;
32
+ workDescribe: string;
32
33
  workerDescribe?: undefined;
33
34
  } | {
34
35
  worker: import("file-lane").FollowWork<IJavascriptCompileOption>;
35
36
  workerDescribe: string;
37
+ workDescribe?: undefined;
36
38
  })[];
37
39
  afterWorks: (typeof UxAfterWorks.cleanOutput)[];
38
40
  watchIgnores: string[];
@@ -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'
@@ -10,6 +10,11 @@ declare class JsLoader implements ILoader {
10
10
  compilerOption: IJavascriptCompileOption;
11
11
  compilation: FileLaneCompilation;
12
12
  logs: ILog[];
13
+ /**
14
+ * 解析文件内容
15
+ * @param files files 待处理的文件数组
16
+ * @returns 处理后的文件数组
17
+ */
13
18
  parser(files: IFileParam<any>[]): Promise<IFileParam<any>[]>;
14
19
  }
15
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 {
15
16
  logs = [];
17
+ /**
18
+ * 解析文件内容
19
+ * @param files files 待处理的文件数组
20
+ * @returns 处理后的文件数组
21
+ */
16
22
  async parser(files) {
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,7 +37,7 @@ 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
43
  onLog: log => {
@@ -39,11 +52,26 @@ class JsLoader {
39
52
  compilerOption: this.compilerOption,
40
53
  context: this.context
41
54
  });
42
- const content = isService ? _UxLoaderUtils.default.createServiceWrapper(scriptTree.targetTree).filter(Boolean).join('\n') : scriptTree.targetTree.getFullText();
43
- result.push({
44
- path: item.path,
45
- content
46
- });
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
+ }
47
75
  }
48
76
  }
49
77
  return result;
@@ -29,7 +29,8 @@ class BeforeCompileUtils {
29
29
  const {
30
30
  context,
31
31
  compilerOption,
32
- compilation
32
+ compilation,
33
+ onLog
33
34
  } = params;
34
35
  const {
35
36
  projectPath
@@ -46,8 +47,11 @@ class BeforeCompileUtils {
46
47
  let serviceList = [];
47
48
  const {
48
49
  router,
49
- services
50
+ services,
51
+ widgetProvider
50
52
  } = manifestContent;
53
+ // 存储widgetProvider
54
+ let widgetProviderList = [];
51
55
  if (router) {
52
56
  const {
53
57
  pages,
@@ -63,7 +67,12 @@ class BeforeCompileUtils {
63
67
  entryList.push(_path.default.join(entryDir, entry));
64
68
  } else {
65
69
  // 路径不存在
66
- _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
+ }]);
67
76
  }
68
77
  });
69
78
  }
@@ -76,15 +85,22 @@ class BeforeCompileUtils {
76
85
  if (_fsExtra.default.existsSync(cardPath)) {
77
86
  liteCardList.push(card + _path.default.posix.sep + cardContent.component);
78
87
  } else {
79
- // 报错
80
- _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
+ }]);
81
94
  }
82
95
  }
83
96
  });
84
97
  }
85
98
  } else {
86
99
  // 没有router配置
87
- _sharedUtils.ColorConsole.throw(`### manifest ### No router configuration`);
100
+ onLog?.([{
101
+ level: _sharedUtils.Loglevel.THROW,
102
+ message: ['### manifest ### No router configuration']
103
+ }]);
88
104
  }
89
105
 
90
106
  // e2e测试入口
@@ -98,10 +114,30 @@ class BeforeCompileUtils {
98
114
  if (services) {
99
115
  serviceList = Array.isArray(services) ? services : Object.values(services);
100
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
+ }
101
136
  if (compilation) {
102
137
  compilation['entries'] = entryList;
103
138
  compilation['liteCards'] = liteCardList;
104
139
  compilation['services'] = serviceList;
140
+ context['widgetProvider'] = widgetProviderList;
105
141
  }
106
142
  return Promise.resolve();
107
143
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/aiotpack",
3
- "version": "2.0.6-beta.22",
3
+ "version": "2.0.6-beta.24",
4
4
  "description": "The process tool for packaging aiot projects.",
5
5
  "keywords": [
6
6
  "aiotpack"
@@ -19,14 +19,14 @@
19
19
  "test": "node ./__tests__/aiotpack.test.js"
20
20
  },
21
21
  "dependencies": {
22
- "@aiot-toolkit/generator": "2.0.6-beta.22",
23
- "@aiot-toolkit/parser": "2.0.6-beta.22",
24
- "@aiot-toolkit/shared-utils": "2.0.6-beta.22",
22
+ "@aiot-toolkit/generator": "2.0.6-beta.24",
23
+ "@aiot-toolkit/parser": "2.0.6-beta.24",
24
+ "@aiot-toolkit/shared-utils": "2.0.6-beta.24",
25
25
  "@hap-toolkit/aaptjs": "^2.0.0",
26
26
  "@rspack/core": "^1.3.9",
27
27
  "aiot-parse5": "^1.0.2",
28
28
  "babel-loader": "^9.1.3",
29
- "file-lane": "2.0.6-beta.22",
29
+ "file-lane": "2.0.6-beta.24",
30
30
  "file-loader": "^6.2.0",
31
31
  "fs-extra": "^11.2.0",
32
32
  "jsrsasign": "^11.1.0",
@@ -42,5 +42,5 @@
42
42
  "@types/jsrsasign": "^10.5.12",
43
43
  "@types/webpack-sources": "^3.2.3"
44
44
  },
45
- "gitHead": "36e03348be739bca8665d981ce33d4d3f8cc4df5"
45
+ "gitHead": "1f581c8e2d25fd2bdc0cbf79970df196c8b38e26"
46
46
  }