@aiot-toolkit/aiotpack 2.0.5-beta.9 → 2.0.5-widget-provider-beta.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 (79) hide show
  1. package/README.md +46 -46
  2. package/lib/afterCompile/ux/UxAfterCompile.d.ts +28 -1
  3. package/lib/afterCompile/ux/UxAfterCompile.js +186 -38
  4. package/lib/afterWorks/ux/UxAfterWorks.js +1 -1
  5. package/lib/beforeCompile/ux/UxBeforeCompile.js +2 -2
  6. package/lib/compiler/enum/CompileMode.js +2 -2
  7. package/lib/compiler/javascript/JavascriptCompiler.d.ts +14 -0
  8. package/lib/compiler/javascript/JavascriptCompiler.js +91 -5
  9. package/lib/compiler/javascript/android/AndroidWebpackConfigurator.js +2 -2
  10. package/lib/compiler/javascript/android/plugin/WrapPlugin.js +7 -7
  11. package/lib/compiler/javascript/interface/IJavascriptCompileOption.d.ts +17 -1
  12. package/lib/compiler/javascript/interface/IJavascriptCompileOption.js +5 -1
  13. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js +3 -3
  14. package/lib/compiler/javascript/vela/enum/BuildNameFormatType.js +2 -2
  15. package/lib/compiler/javascript/vela/enum/EntryType.js +2 -2
  16. package/lib/compiler/javascript/vela/interface/IManifest.d.ts +16 -0
  17. package/lib/compiler/javascript/vela/interface/IManifest.js +11 -1
  18. package/lib/compiler/javascript/vela/model/Package.js +28 -28
  19. package/lib/compiler/javascript/vela/plugin/WrapPlugin.js +1 -2
  20. package/lib/compiler/javascript/vela/utils/Jsc.js +2 -2
  21. package/lib/compiler/javascript/vela/utils/UxCompileUtil.js +31 -17
  22. package/lib/compiler/javascript/vela/utils/ZipUtil.js +62 -62
  23. package/lib/compiler/javascript/vela/utils/signature/Base64.js +2 -2
  24. package/lib/compiler/javascript/vela/utils/signature/CRC32.js +2 -2
  25. package/lib/compiler/javascript/vela/utils/signature/SignUtil.js +68 -68
  26. package/lib/compiler/javascript/vela/utils/signature/Signer.js +6 -6
  27. package/lib/compiler/javascript/vela/utils/signature/pem/certificate.pem +26 -26
  28. package/lib/compiler/javascript/vela/utils/signature/pem/private.pem +50 -50
  29. package/lib/compiler/javascript/vela/utils/webpackLoader/IWebpackLoaderOption.d.ts +11 -0
  30. package/lib/compiler/javascript/vela/utils/webpackLoader/IWebpackLoaderOption.js +1 -0
  31. package/lib/compiler/javascript/vela/utils/webpackLoader/WebpackJsLoader.d.ts +2 -0
  32. package/lib/compiler/javascript/vela/utils/webpackLoader/WebpackJsLoader.js +27 -0
  33. package/lib/compiler/javascript/vela/utils/webpackLoader/WebpackUxLoader.d.ts +2 -0
  34. package/lib/compiler/javascript/vela/utils/webpackLoader/WebpackUxLoader.js +26 -0
  35. package/lib/compiler/tools/icu/ImageIcu.d.ts +37 -0
  36. package/lib/compiler/tools/icu/ImageIcu.js +110 -0
  37. package/lib/compiler/tools/icu/icu_darwin_arm64 +0 -0
  38. package/lib/compiler/tools/icu/icu_darwin_x64 +0 -0
  39. package/lib/compiler/tools/icu/icu_linux_arm64 +0 -0
  40. package/lib/compiler/tools/icu/icu_linux_x64 +0 -0
  41. package/lib/compiler/tools/icu/icu_win32_x64.exe +0 -0
  42. package/lib/config/UxConfig.d.ts +9 -4
  43. package/lib/config/UxConfig.js +29 -17
  44. package/lib/index.d.ts +1 -3
  45. package/lib/index.js +2 -28
  46. package/lib/loader/ux/JsLoader.d.ts +5 -0
  47. package/lib/loader/ux/JsLoader.js +33 -7
  48. package/lib/loader/ux/PngLoader.js +2 -2
  49. package/lib/loader/ux/android/UxLoader.js +2 -2
  50. package/lib/loader/ux/vela/AppUxLoader.js +3 -3
  51. package/lib/loader/ux/vela/HmlLoader.js +14 -14
  52. package/lib/loader/ux/vela/UxLoader.js +7 -0
  53. package/lib/utils/BeforeCompileUtils.d.ts +2 -0
  54. package/lib/utils/BeforeCompileUtils.js +54 -13
  55. package/lib/utils/PngUtils.js +11 -11
  56. package/lib/utils/ux/ManifestSchema.js +6 -3
  57. package/lib/utils/ux/UxFileUtils.d.ts +1 -0
  58. package/lib/utils/ux/UxFileUtils.js +56 -45
  59. package/lib/utils/ux/UxLoaderUtils.js +35 -35
  60. package/lib/utils/ux/android/AndroidUx.js +10 -10
  61. package/package.json +8 -11
  62. package/lib/afterCompile/xts/entryTemplate.d.ts +0 -21
  63. package/lib/afterCompile/xts/entryTemplate.js +0 -182
  64. package/lib/afterCompile/xts/generateRpk.d.ts +0 -3
  65. package/lib/afterCompile/xts/generateRpk.js +0 -28
  66. package/lib/afterCompile/xts/ts2wasm.d.ts +0 -8
  67. package/lib/afterCompile/xts/ts2wasm.js +0 -69
  68. package/lib/beforeCompile/xts/preInstall.d.ts +0 -3
  69. package/lib/beforeCompile/xts/preInstall.js +0 -54
  70. package/lib/config/XtsConfig.d.ts +0 -22
  71. package/lib/config/XtsConfig.js +0 -36
  72. package/lib/interface/ICompileOptions.d.ts +0 -6
  73. package/lib/interface/ICompileOptions.js +0 -7
  74. package/lib/loader/xts/XtsLoader.d.ts +0 -9
  75. package/lib/loader/xts/XtsLoader.js +0 -62
  76. package/lib/utils/xts/XtsFileLaneUtils.d.ts +0 -10
  77. package/lib/utils/xts/XtsFileLaneUtils.js +0 -61
  78. package/lib/utils/xts/XtsFollowWorks.d.ts +0 -34
  79. package/lib/utils/xts/XtsFollowWorks.js +0 -134
@@ -19,8 +19,8 @@ const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobu
19
19
  const {
20
20
  extractFunctions
21
21
  } = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/protobufControl');
22
- /**
23
- * UxLoaderUtils
22
+ /**
23
+ * UxLoaderUtils
24
24
  */
25
25
  class UxLoaderUtils {
26
26
  // 页面组件需要添加ViewModel数据校验和处理代码
@@ -47,12 +47,12 @@ class UxLoaderUtils {
47
47
  }
48
48
  })
49
49
  }`;
50
- /**
51
- * 转换单个ux文件为js文件
52
- * @param file ux文件内容
53
- * @param context 文件所在项目上下文
54
- * @param project
55
- * @returns
50
+ /**
51
+ * 转换单个ux文件为js文件
52
+ * @param file ux文件内容
53
+ * @param context 文件所在项目上下文
54
+ * @param project
55
+ * @returns
56
56
  */
57
57
  static async compileUxToJavascript(file, context, isAppUx, compilerOption) {
58
58
  const logs = [];
@@ -173,11 +173,11 @@ class UxLoaderUtils {
173
173
  logs
174
174
  };
175
175
  }
176
- /**
177
- * 转换app.ux文件为js文件
178
- * @param file
179
- * @param resultFiles
180
- * @param context
176
+ /**
177
+ * 转换app.ux文件为js文件
178
+ * @param file
179
+ * @param resultFiles
180
+ * @param context
181
181
  */
182
182
  static async compileAppUxToJavascript(file, context, compileOption) {
183
183
  const {
@@ -197,29 +197,29 @@ class UxLoaderUtils {
197
197
  }, context, isAppUx, compileOption);
198
198
  return compileResult;
199
199
  }
200
- /**
201
- * 判断是否为src/app.ux
202
- * @param filePath
203
- * @returns
200
+ /**
201
+ * 判断是否为src/app.ux
202
+ * @param filePath
203
+ * @returns
204
204
  */
205
205
  static isAppUx(filePath) {
206
206
  const parentDirName = _path.default.basename(_path.default.dirname(filePath));
207
207
  const fileName = _path.default.basename(filePath);
208
208
  return parentDirName === 'src' && fileName === 'app.ux';
209
209
  }
210
- /**
211
- * 判断是否为页面组件
212
- * @param context
213
- * @param filePath
214
- * @returns
210
+ /**
211
+ * 判断是否为页面组件
212
+ * @param context
213
+ * @param filePath
214
+ * @returns
215
215
  */
216
216
  static isPageUx(context, filePath) {
217
217
  return Boolean(context.entries?.includes(filePath));
218
218
  }
219
- /**
220
- * 获取app.ux的内容,且只返回script和style内容
221
- * @param fileContent
222
- * @returns
219
+ /**
220
+ * 获取app.ux的内容,且只返回script和style内容
221
+ * @param fileContent
222
+ * @returns
223
223
  */
224
224
  static getAppUxContent(fileContent) {
225
225
  const appUxAst = parse5.parseFragment(fileContent, {
@@ -318,10 +318,10 @@ class UxLoaderUtils {
318
318
  return result;
319
319
  }
320
320
 
321
- /**
322
- * 给template增加外层包裹内容
323
- * @param templateTree
324
- * @returns
321
+ /**
322
+ * 给template增加外层包裹内容
323
+ * @param templateTree
324
+ * @returns
325
325
  */
326
326
  static wrapTempalte(templateTree, file, compilerOption) {
327
327
  const result = `function (vm) {
@@ -344,11 +344,11 @@ class UxLoaderUtils {
344
344
  return code;
345
345
  }
346
346
 
347
- /**
348
- * 给script增加外层包裹内容
349
- * @param isPageUx
350
- * @param appScriptTree
351
- * @returns
347
+ /**
348
+ * 给script增加外层包裹内容
349
+ * @param isPageUx
350
+ * @param appScriptTree
351
+ * @returns
352
352
  */
353
353
  static wrapScript(isPageUx, appScriptTree) {
354
354
  if (isPageUx) {
@@ -11,18 +11,18 @@ var _generator = require("@aiot-toolkit/generator");
11
11
  var _path = _interopRequireDefault(require("path"));
12
12
  var _QuickAppDocHelp = require("@aiot-toolkit/shared-utils/lib/utils/QuickAppDocHelp");
13
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
- /**
15
- * AndroidUx
14
+ /**
15
+ * AndroidUx
16
16
  */
17
17
  class AndroidUx {
18
- /**
19
- *
20
- * 编译 ux 文件
21
- * 1. 获取文件类型:app page 普通ux
22
- * 2. 使用`UxParse`解析
23
- * 3. 使用`UxToTypeScript`转换
24
- * 4. 使用`TypeScriptGenerator`生成
25
- * @param params
18
+ /**
19
+ *
20
+ * 编译 ux 文件
21
+ * 1. 获取文件类型:app page 普通ux
22
+ * 2. 使用`UxParse`解析
23
+ * 3. 使用`UxToTypeScript`转换
24
+ * 4. 使用`TypeScriptGenerator`生成
25
+ * @param params
26
26
  */
27
27
  async compileUx(params) {
28
28
  const {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/aiotpack",
3
- "version": "2.0.5-beta.9",
3
+ "version": "2.0.5-widget-provider-beta.2",
4
4
  "description": "The process tool for packaging aiot projects.",
5
5
  "keywords": [
6
6
  "aiotpack"
@@ -19,32 +19,29 @@
19
19
  "test": "node ./__tests__/aiotpack.test.js"
20
20
  },
21
21
  "dependencies": {
22
- "@aiot-toolkit/generator": "2.0.5-beta.9",
23
- "@aiot-toolkit/parser": "2.0.5-beta.9",
24
- "@aiot-toolkit/shared-utils": "2.0.5-beta.9",
22
+ "@aiot-toolkit/generator": "2.0.5-widget-provider-beta.2",
23
+ "@aiot-toolkit/parser": "2.0.5-widget-provider-beta.2",
24
+ "@aiot-toolkit/shared-utils": "2.0.5-widget-provider-beta.2",
25
25
  "@hap-toolkit/aaptjs": "^2.0.0",
26
- "@rspack/core": "^1.1.8",
26
+ "@rspack/core": "^1.3.9",
27
27
  "aiot-parse5": "^1.0.2",
28
- "archiver": "^7.0.1",
29
28
  "babel-loader": "^9.1.3",
30
- "fast-glob": "^3.3.2",
31
- "file-lane": "2.0.5-beta.9",
29
+ "file-lane": "2.0.5-widget-provider-beta.2",
32
30
  "file-loader": "^6.2.0",
33
31
  "fs-extra": "^11.2.0",
32
+ "hap-toolkit": "^2.0.0",
34
33
  "jsrsasign": "^11.1.0",
35
34
  "jszip": "^3.10.1",
36
35
  "lodash": "^4.17.21",
37
36
  "ts-morph": "^19.0.0",
38
37
  "url-loader": "^4.1.1",
39
- "webpack": "^5.97.1",
40
38
  "webpack-bundle-analyzer": "^4.10.2",
41
39
  "webpack-sources": "^3.2.3"
42
40
  },
43
41
  "devDependencies": {
44
- "@types/archiver": "^6.0.2",
45
42
  "@types/fs-extra": "^11.0.4",
46
43
  "@types/jsrsasign": "^10.5.12",
47
44
  "@types/webpack-sources": "^3.2.3"
48
45
  },
49
- "gitHead": "c8c79fa9f882b5dcdac5f0dadb5863343eda44b1"
46
+ "gitHead": "4a8894bc66a9c78cd835ed6c1af74d054300e064"
50
47
  }
@@ -1,21 +0,0 @@
1
- import { FollowWork } from 'file-lane';
2
- export interface Aspects {
3
- path: string;
4
- name: string;
5
- routes?: {
6
- importPath: string;
7
- name: string;
8
- route: string;
9
- }[];
10
- }
11
- export interface GenerateEntryParams {
12
- appPath: string;
13
- aspects?: Aspects[];
14
- }
15
- export declare const entryTemplate: (options: GenerateEntryParams) => string;
16
- export declare const XtsEntryFileName = "__entry__.ts";
17
- /**
18
- * 生成 __entry__.ts 文件
19
- * @param context
20
- */
21
- export declare const generateEntryFile: FollowWork;
@@ -1,182 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.generateEntryFile = exports.entryTemplate = exports.XtsEntryFileName = void 0;
7
- var _parser = require("@aiot-toolkit/parser");
8
- var _sharedUtils = require("@aiot-toolkit/shared-utils");
9
- var _fsExtra = _interopRequireDefault(require("fs-extra"));
10
- var _path = _interopRequireDefault(require("path"));
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- const entryTemplate = options => {
13
- const {
14
- aspects = []
15
- } = options;
16
- function generatImportAspects() {
17
- if (!aspects) return '';
18
- let imports = '// import aspects\n';
19
- for (let i = 0; i < aspects.length; i++) {
20
- const aspect = aspects[i];
21
- imports += `import AspectClass${i + 1} from './${aspect.path}'\n`;
22
- const {
23
- routes = []
24
- } = aspect;
25
- for (let r = 0; r < routes?.length; r++) {
26
- const route = routes[r];
27
- imports += `import Page${i + 1}_${r + 1}, { ${_parser.HomeState.interface} as ${_parser.HomeState.interface}${i + 1}_${r + 1}_ } from './${route.importPath}'\n`;
28
- }
29
- }
30
- return imports;
31
- }
32
- function generateDefs() {
33
- let res = '// aspects\n';
34
- for (let i = 0; i < aspects.length; i++) {
35
- const aspect = aspects[i];
36
- const {
37
- routes = []
38
- } = aspect;
39
- res += `
40
- const aspectName_${i + 1} = '${aspect.name}'
41
- const pathPages_${i + 1} = new Map()`;
42
- for (let r = 0; r < routes.length; r++) {
43
- const route = routes[r];
44
- res += `
45
- pathPages_${i + 1}.set('${route.route}', function (params?: ${_parser.HomeState.interface}${i + 1}_${r + 1}_): Page {
46
- return new Page${i + 1}_${r + 1}(params)
47
- })
48
- `;
49
- }
50
- res += `
51
- const aspectDef_${i + 1}: AspectDefinition = {
52
- newFn: (): ViewAspect => new AspectClass${i + 1}(),
53
- pathPages: pathPages_${i + 1}
54
- }
55
- aspectDefs.set(aspectName_${i + 1}, aspectDef_${i + 1})
56
- `;
57
- }
58
- return res;
59
- }
60
- return `import {
61
- // class
62
- App,
63
- AppDefinition,
64
- AppContainer,
65
- AspectDefinition,
66
- ViewAspect,
67
- Page,
68
- Route,
69
- RouteInfo,
70
- // framework
71
- context,
72
- getInfoFromRoute,
73
-
74
- // export function
75
- on
76
- } from '../node_modules/${_parser.tsFrameWork.name}/index'
77
-
78
- // import app
79
- import AppClass from './${options.appPath}'
80
- ${generatImportAspects()}
81
- console.log('startApp-start timeEnd:', Date.now())
82
-
83
- function getAspectDefs() {
84
- const aspectDefs = new Map()
85
- ${generateDefs()}
86
- return aspectDefs
87
- }
88
-
89
- function entry(path: string): void {
90
- console.log('~~~~~~~~~entry path', path)
91
- const route: Route = { uri: path }
92
- const routeInfo: RouteInfo = getInfoFromRoute(route)
93
- // app
94
- let appName: string = ''
95
- if (routeInfo?.appName) appName = routeInfo.appName
96
- let app = context.getApp(appName)
97
- if (app === null) {
98
- const appDef: AppDefinition = {
99
- newFn: (): App => new AppClass()
100
- }
101
- const aspectDefs = getAspectDefs()
102
- app = new AppContainer(appDef, aspectDefs)
103
- }
104
- context.openApp(app, routeInfo)
105
- }
106
-
107
- // export api to native
108
- export { entry, on }
109
- `;
110
- };
111
- exports.entryTemplate = entryTemplate;
112
- function getManifest(manifestPath) {
113
- const content = _fsExtra.default.readFileSync(manifestPath, 'utf-8');
114
- const data = JSON.parse(content);
115
- return data;
116
- }
117
- const XtsEntryFileName = exports.XtsEntryFileName = '__entry__.ts';
118
- /**
119
- * 生成 __entry__.ts 文件
120
- * @param context
121
- */
122
- const generateEntryFile = exports.generateEntryFile = async function generateEntryFile(params) {
123
- const {
124
- context,
125
- compilerOption
126
- } = params;
127
- const {
128
- projectPath,
129
- output
130
- } = context;
131
- if (compilerOption?.skip?.includes('xts2ts')) {
132
- _sharedUtils.ColorConsole.info(`### skip generate entry file due to --skip xts2ts}`);
133
- return;
134
- }
135
- _sharedUtils.ColorConsole.info(`Generating entry file`);
136
- const buildDir = _path.default.resolve(projectPath, output);
137
- const appManifestPath = _path.default.join(buildDir, 'app', 'manifest.json');
138
- const appManifest = getManifest(appManifestPath);
139
- if (!appManifest) {
140
- _sharedUtils.ColorConsole.throw('not find app/manifest.json file !');
141
- }
142
- const appTs = _path.default.join(buildDir, 'app', 'app.ts');
143
- if (!_fsExtra.default.existsSync(appTs)) {
144
- _sharedUtils.ColorConsole.throw('not find app/app.ts file !');
145
- }
146
- function relativeDist(tar) {
147
- return _path.default.join('.', _path.default.relative(buildDir, tar)).replace(_path.default.sep, '/');
148
- }
149
- let opt = {
150
- appPath: relativeDist(appTs.replace('.ts', '')),
151
- aspects: []
152
- };
153
- function getAspectRoutes(aspectPath) {
154
- const aspectManifestPath = _path.default.join(aspectPath, 'src', 'manifest.json');
155
- const aspectManifest = getManifest(aspectManifestPath);
156
- if (!aspectManifest?.router?.pages) return [];
157
- return Object.entries(aspectManifest.router.pages).map(_ref => {
158
- let [k, v] = _ref;
159
- return {
160
- importPath: relativeDist(_path.default.resolve(_path.default.dirname(aspectManifestPath), v.path)),
161
- name: k,
162
- route: v.path
163
- };
164
- });
165
- }
166
- if (appManifest?.router?.aspects) {
167
- Object.entries(appManifest.router.aspects).forEach(_ref2 => {
168
- let [name, aspects] = _ref2;
169
- aspects.forEach(aspect => {
170
- const aspectPath = _path.default.join(buildDir, aspect.path);
171
- opt.aspects?.push({
172
- name: name,
173
- path: relativeDist(_path.default.resolve(buildDir, aspect.path, 'src', 'aspect')),
174
- routes: getAspectRoutes(aspectPath)
175
- });
176
- });
177
- });
178
- }
179
- const template = entryTemplate(opt);
180
- _fsExtra.default.writeFileSync(_path.default.join(projectPath, output, XtsEntryFileName), template);
181
- _sharedUtils.ColorConsole.info(`entry file built`);
182
- };
@@ -1,3 +0,0 @@
1
- import { FollowWork } from 'file-lane';
2
- import { IXtsCompileOptions } from '../../interface/ICompileOptions';
3
- export declare const generateRpk: FollowWork<IXtsCompileOptions>;
@@ -1,28 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.generateRpk = void 0;
7
- var _path = _interopRequireDefault(require("path"));
8
- var _XtsFollowWorks = _interopRequireDefault(require("../../utils/xts/XtsFollowWorks"));
9
- var _sharedUtils = require("@aiot-toolkit/shared-utils");
10
- var _ts2wasm = require("./ts2wasm");
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- const generateRpk = async params => {
13
- const {
14
- context,
15
- compilerOption
16
- } = params;
17
- if (compilerOption?.skip?.includes('package')) {
18
- _sharedUtils.ColorConsole.info(`### skip package due to --skip ${compilerOption.skip.join(',')}`);
19
- return;
20
- }
21
- const manifestPath = _path.default.resolve(context.projectPath, 'app', 'manifest.json');
22
- const manifest = await import(manifestPath);
23
- return _XtsFollowWorks.default.defaultZipProject(context, {
24
- tarDir: _ts2wasm.wasmPackageName,
25
- packageName: manifest.package
26
- });
27
- };
28
- exports.generateRpk = generateRpk;
@@ -1,8 +0,0 @@
1
- import { FollowWork } from 'file-lane';
2
- import { IXtsCompileOptions } from '../../interface/ICompileOptions';
3
- export declare const wasmPackageName = "wasmUnpacked";
4
- /**
5
- * 将 __entry__.ts 文件打包成 warm 文件
6
- * @param context
7
- */
8
- export declare const ts2wasm: FollowWork<IXtsCompileOptions>;
@@ -1,69 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.wasmPackageName = exports.ts2wasm = void 0;
7
- var _sharedUtils = require("@aiot-toolkit/shared-utils");
8
- var _child_process = require("child_process");
9
- var _fastGlob = _interopRequireDefault(require("fast-glob"));
10
- var _fs = _interopRequireDefault(require("fs"));
11
- var _path = _interopRequireDefault(require("path"));
12
- var _entryTemplate = require("./entryTemplate");
13
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
- const wasmPackageName = exports.wasmPackageName = 'wasmUnpacked';
15
-
16
- /**
17
- * 将 __entry__.ts 文件打包成 warm 文件
18
- * @param context
19
- */
20
- const ts2wasm = async params => {
21
- const {
22
- context,
23
- compilerOption
24
- } = params;
25
- /** 1. 生成 app.wasm 文件 */
26
- const {
27
- projectPath,
28
- output
29
- } = context;
30
- const buildDir = _path.default.resolve(projectPath, output);
31
- const entryFile = _path.default.resolve(buildDir, _entryTemplate.XtsEntryFileName);
32
- const wasmDir = _path.default.resolve(projectPath, wasmPackageName);
33
- _fs.default.mkdirSync(wasmDir, {
34
- recursive: true
35
- });
36
- function compile() {
37
- // TODO: 后续修改为 @mi
38
- const ts2wasmpath = _path.default.resolve(projectPath, 'node_modules', 'mi/wasmnizer-ts');
39
- _sharedUtils.ColorConsole.info('### Waiting for generating app.wasm file.');
40
- const res = (0, _child_process.execSync)(`node ${ts2wasmpath}/build/cli/ts2wasm.js ${entryFile} -o ${wasmDir}/app.wasm`, {
41
- encoding: 'utf-8'
42
- });
43
- _sharedUtils.ColorConsole.info(`### ts2wasm ### ${res.toString()}`);
44
- }
45
- if (compilerOption?.skip?.includes('ts2wasm')) {
46
- _sharedUtils.ColorConsole.info(`### skip compile ts to wasm due to --skip ${compilerOption?.skip.join(',')}`);
47
- } else {
48
- compile();
49
- }
50
-
51
- /** 2. 拷贝静态资源 */
52
- // TODO: ignore 数组待优化
53
- const files = _fastGlob.default.sync(`${_fastGlob.default.convertPathToPattern(projectPath)}/${output}/**/*`, {
54
- absolute: true,
55
- ignore: ['**/*.ts', '**/*.xts', '**/package.json', '**/package-lock.json', '**/*.wasm'],
56
- onlyFiles: true
57
- });
58
- for (const from of files) {
59
- const to = from.replace('/src', '').replace(`/${output}`, `/${wasmPackageName}`);
60
- _fs.default.mkdirSync(_path.default.dirname(to), {
61
- recursive: true
62
- });
63
- _fs.default.copyFileSync(from, to);
64
- }
65
-
66
- /** 3. 特殊处理 app/manifest.json */
67
- _fs.default.copyFileSync(_path.default.resolve(_fastGlob.default.convertPathToPattern(projectPath), output, 'app', 'manifest.json'), _path.default.resolve(_fastGlob.default.convertPathToPattern(projectPath), wasmPackageName, 'manifest.json'));
68
- };
69
- exports.ts2wasm = ts2wasm;
@@ -1,3 +0,0 @@
1
- import { PreWork } from 'file-lane';
2
- import { IXtsCompileOptions } from '../../interface/ICompileOptions';
3
- export declare const preInstall: PreWork<IXtsCompileOptions>;
@@ -1,54 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.preInstall = void 0;
7
- var _sharedUtils = require("@aiot-toolkit/shared-utils");
8
- var _child_process = require("child_process");
9
- var _fs = _interopRequireDefault(require("fs"));
10
- var _path = _interopRequireDefault(require("path"));
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- const preInstall = async params => {
13
- const {
14
- context,
15
- compilerOption
16
- } = params;
17
- if (compilerOption?.skip?.includes('install')) {
18
- _sharedUtils.ColorConsole.info(`### skip install pre-dependencies due to --skip ${compilerOption?.skip.join(',')}`);
19
- return;
20
- }
21
- const {
22
- projectPath
23
- } = context;
24
- const packagePath = _path.default.resolve(projectPath, 'package.json');
25
- const preContent = {
26
- dependencies: {
27
- '@mi/ts-framework': 'https://pkgs.d.xiaomi.net:443/artifactory/api/npm/mi-npm/@mi/ts-framework/-/@mi/ts-framework-1.0.9.tgz',
28
- '@mi/wasmnizer-ts': 'https://pkgs.d.xiaomi.net:443/artifactory/api/npm/mi-npm/@mi/wasmnizer-ts/-/@mi/wasmnizer-ts-0.0.12.tgz'
29
- }
30
- };
31
- if (!_fs.default.existsSync(packagePath)) {
32
- /** 如果没有 package.json 则创建 */
33
- _fs.default.writeFileSync(packagePath, JSON.stringify(preContent, undefined, 2), {
34
- encoding: 'utf-8'
35
- });
36
- } else {
37
- const pckageContent = require(packagePath);
38
- if (!pckageContent.dependencies['@mi/ts-framework'] || !pckageContent.dependencies['@mi/wasmnizer-ts']) {
39
- Object.assign(pckageContent, preContent);
40
- _fs.default.writeFileSync(packagePath, JSON.stringify(pckageContent), {
41
- encoding: 'utf-8'
42
- });
43
- }
44
- }
45
- _sharedUtils.ColorConsole.info('### Installing pre-dependencies. The initial build may take some time, please be patient...');
46
- (0, _child_process.execSync)('npm install', {
47
- cwd: projectPath
48
- });
49
-
50
- // 目前ts2wasm不支持@符号
51
- _fs.default.renameSync(_path.default.resolve(projectPath, 'node_modules/@mi'), _path.default.resolve(projectPath, 'node_modules/mi'));
52
- _sharedUtils.ColorConsole.info('### Dependencies installation complete.');
53
- };
54
- exports.preInstall = preInstall;
@@ -1,22 +0,0 @@
1
- import { IFileLaneConfig, PreWork } from 'file-lane';
2
- import XtsLoader from '../loader/xts/XtsLoader';
3
- /**
4
- * XtsConfig
5
- */
6
- declare class XtsConfig implements IFileLaneConfig {
7
- projectPath: string;
8
- constructor(projectPath: string);
9
- exclude: string[];
10
- output: string;
11
- module: {
12
- rules: {
13
- test: RegExp[];
14
- loader: (typeof XtsLoader)[];
15
- }[];
16
- };
17
- beforeCompile: PreWork[];
18
- afterCompile: {
19
- worker: import("file-lane").FollowWork<import("..").IXtsCompileOptions>;
20
- }[];
21
- }
22
- export default XtsConfig;
@@ -1,36 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _entryTemplate = require("../afterCompile/xts/entryTemplate");
8
- var _generateRpk = require("../afterCompile/xts/generateRpk");
9
- var _ts2wasm = require("../afterCompile/xts/ts2wasm");
10
- var _XtsLoader = _interopRequireDefault(require("../loader/xts/XtsLoader"));
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- /**
13
- * XtsConfig
14
- */
15
- class XtsConfig {
16
- constructor(projectPath) {
17
- this.projectPath = projectPath;
18
- }
19
- exclude = ['**/node_modules{,/**}', '**/dist{,/**}', '**/build{,/**}', '**/.git{,/**}', '**/.wasmUnpacked{,/**}'];
20
- output = 'build';
21
- module = (() => ({
22
- rules: [{
23
- test: [/\.xts$/],
24
- loader: [_XtsLoader.default]
25
- }]
26
- }))();
27
- beforeCompile = [];
28
- afterCompile = (() => [{
29
- worker: _entryTemplate.generateEntryFile
30
- }, {
31
- worker: _ts2wasm.ts2wasm
32
- }, {
33
- worker: _generateRpk.generateRpk
34
- }])();
35
- }
36
- var _default = exports.default = XtsConfig;
@@ -1,6 +0,0 @@
1
- export declare const skipList: readonly ["xts2ts", "install", "ts2wasm", "package"];
2
- export type ISkipList = typeof skipList;
3
- export interface IXtsCompileOptions {
4
- watch?: boolean;
5
- skip?: ISkipList;
6
- }
@@ -1,7 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.skipList = void 0;
7
- const skipList = exports.skipList = ['xts2ts', 'install', 'ts2wasm', 'package'];
@@ -1,9 +0,0 @@
1
- import { IFileLaneContext, IFileParam, ILoader } from 'file-lane';
2
- /**
3
- * XtsLoader
4
- */
5
- declare class XtsLoader implements ILoader {
6
- context: IFileLaneContext;
7
- parser(files: IFileParam[]): IFileParam[];
8
- }
9
- export default XtsLoader;