@aiot-toolkit/aiotpack 2.0.5-beta.2 → 2.0.5-beta.21
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.
- package/lib/afterCompile/ux/UxAfterCompile.d.ts +28 -1
- package/lib/afterCompile/ux/UxAfterCompile.js +172 -17
- package/lib/afterWorks/ux/UxAfterWorks.js +1 -1
- package/lib/compiler/javascript/JavascriptCompiler.d.ts +14 -0
- package/lib/compiler/javascript/JavascriptCompiler.js +91 -5
- package/lib/compiler/javascript/interface/IJavascriptCompileOption.d.ts +21 -1
- package/lib/compiler/javascript/interface/IJavascriptCompileOption.js +5 -1
- package/lib/compiler/javascript/vela/interface/IManifest.d.ts +11 -0
- package/lib/compiler/javascript/vela/interface/IManifest.js +11 -1
- package/lib/compiler/javascript/vela/plugin/WrapPlugin.js +1 -4
- package/lib/compiler/javascript/vela/utils/UxCompileUtil.js +5 -0
- package/lib/compiler/javascript/vela/utils/webpackLoader/IWebpackLoaderOption.d.ts +11 -0
- package/lib/compiler/javascript/vela/utils/webpackLoader/IWebpackLoaderOption.js +1 -0
- package/lib/compiler/javascript/vela/utils/webpackLoader/WebpackJsLoader.d.ts +2 -0
- package/lib/compiler/javascript/vela/utils/webpackLoader/WebpackJsLoader.js +27 -0
- package/lib/compiler/javascript/vela/utils/webpackLoader/WebpackUxLoader.d.ts +2 -0
- package/lib/compiler/javascript/vela/utils/webpackLoader/WebpackUxLoader.js +26 -0
- package/lib/compiler/tools/icu/ImageIcu.d.ts +37 -0
- package/lib/compiler/tools/icu/ImageIcu.js +110 -0
- package/lib/compiler/tools/icu/icu_darwin_arm64 +0 -0
- package/lib/compiler/tools/icu/icu_darwin_x64 +0 -0
- package/lib/compiler/tools/icu/icu_linux_arm64 +0 -0
- package/lib/compiler/tools/icu/icu_linux_x64 +0 -0
- package/lib/compiler/tools/icu/icu_win32_x64.exe +0 -0
- package/lib/config/UxConfig.d.ts +5 -2
- package/lib/config/UxConfig.js +13 -2
- package/lib/index.d.ts +1 -3
- package/lib/index.js +2 -28
- package/lib/loader/ux/JsLoader.d.ts +1 -1
- package/lib/loader/ux/JsLoader.js +20 -17
- package/lib/loader/ux/vela/UxLoader.js +7 -0
- package/lib/utils/BeforeCompileUtils.d.ts +2 -0
- package/lib/utils/BeforeCompileUtils.js +25 -10
- package/lib/utils/ux/FileCompare.d.ts +12 -0
- package/lib/utils/ux/FileCompare.js +47 -0
- package/lib/utils/ux/ManifestSchema.js +6 -3
- package/lib/utils/ux/UxFileUtils.d.ts +11 -8
- package/lib/utils/ux/UxFileUtils.js +48 -27
- package/lib/utils/ux/UxLoaderUtils.js +28 -1
- package/package.json +9 -12
- package/lib/afterCompile/xts/entryTemplate.d.ts +0 -21
- package/lib/afterCompile/xts/entryTemplate.js +0 -182
- package/lib/afterCompile/xts/generateRpk.d.ts +0 -3
- package/lib/afterCompile/xts/generateRpk.js +0 -28
- package/lib/afterCompile/xts/ts2wasm.d.ts +0 -8
- package/lib/afterCompile/xts/ts2wasm.js +0 -69
- package/lib/beforeCompile/xts/preInstall.d.ts +0 -3
- package/lib/beforeCompile/xts/preInstall.js +0 -54
- package/lib/config/XtsConfig.d.ts +0 -22
- package/lib/config/XtsConfig.js +0 -36
- package/lib/interface/ICompileOptions.d.ts +0 -6
- package/lib/interface/ICompileOptions.js +0 -7
- package/lib/loader/xts/XtsLoader.d.ts +0 -9
- package/lib/loader/xts/XtsLoader.js +0 -62
- package/lib/utils/xts/XtsFileLaneUtils.d.ts +0 -10
- package/lib/utils/xts/XtsFileLaneUtils.js +0 -61
- package/lib/utils/xts/XtsFollowWorks.d.ts +0 -34
- package/lib/utils/xts/XtsFollowWorks.js +0 -134
|
@@ -8,6 +8,7 @@ var _CommonUtil = _interopRequireDefault(require("@aiot-toolkit/shared-utils/lib
|
|
|
8
8
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
9
9
|
var _path = _interopRequireDefault(require("path"));
|
|
10
10
|
var _ManifestSchema = _interopRequireDefault(require("./ManifestSchema"));
|
|
11
|
+
var _FileCompare = require("./FileCompare");
|
|
11
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
13
|
/**
|
|
13
14
|
* FileUtils
|
|
@@ -42,6 +43,7 @@ class UxFileUtils {
|
|
|
42
43
|
* 1. TypeError: Error
|
|
43
44
|
* 2. 其它: Warn
|
|
44
45
|
* 2. 检查 router.entry 是否存在于 router.pages
|
|
46
|
+
* 3. 检查icon是否存在
|
|
45
47
|
*
|
|
46
48
|
* @param projectPath 项目路径
|
|
47
49
|
* @param sourceRoot 源码路径--相对项目根目录
|
|
@@ -60,15 +62,25 @@ class UxFileUtils {
|
|
|
60
62
|
const errors = _CommonUtil.default.validateJson(jsonData, schema) || [];
|
|
61
63
|
|
|
62
64
|
// 2
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
if (jsonData.router) {
|
|
66
|
+
const {
|
|
67
|
+
entry,
|
|
68
|
+
pages
|
|
69
|
+
} = jsonData.router;
|
|
70
|
+
if (!pages[entry]) {
|
|
71
|
+
errors.push(new TypeError(`router.entry content: ${entry}, is missing in router.pages`));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 3
|
|
76
|
+
if (jsonData.icon) {
|
|
77
|
+
const iconPath = _path.default.join(projectPath, sourceRoot, jsonData.icon);
|
|
78
|
+
if (!_fsExtra.default.existsSync(iconPath)) {
|
|
79
|
+
errors.push(new Error(`icon: "${jsonData.icon}" is missing in project`));
|
|
80
|
+
}
|
|
69
81
|
}
|
|
70
82
|
if (errors?.length) {
|
|
71
|
-
const message = `
|
|
83
|
+
const message = `error in ${path}: ${errors.map((item, index) => {
|
|
72
84
|
return `\r\n${index + 1}. ${item.message}`;
|
|
73
85
|
})}`;
|
|
74
86
|
throw new Error(message);
|
|
@@ -101,39 +113,48 @@ class UxFileUtils {
|
|
|
101
113
|
}
|
|
102
114
|
}
|
|
103
115
|
}
|
|
116
|
+
|
|
104
117
|
/**
|
|
118
|
+
* 比较新旧文件列表差异
|
|
105
119
|
* 1. 遍历旧文件列表
|
|
106
|
-
* 1.1 若文件路径在新文件列表
|
|
107
|
-
* 1.2 若文件路径在新文件列表
|
|
120
|
+
* 1.1 若文件路径在新文件列表remainingNewFilest中,且内容一致时,从remainingNewFiles中移除该项
|
|
121
|
+
* 1.2 若文件路径在新文件列表remainingNewFiles中,且内容不一致时,添加到diffList中表示待更新,从remainingNewFiles中移除该项
|
|
108
122
|
* 1.3 若文件路径不在新文件列表中,表示该文件待删除(热更新时,可以不做删除,删除耗费性能)
|
|
109
|
-
* 2. 若遍历完旧文件列表后,
|
|
110
|
-
* @param oldFileList
|
|
111
|
-
* @param newFileList
|
|
112
|
-
* @
|
|
123
|
+
* 2. 若遍历完旧文件列表后,remainingNewFiles长度不为0,表示有文件待新增
|
|
124
|
+
* @param oldFileList 旧文件路径列表(相对路径)
|
|
125
|
+
* @param newFileList 新文件路径列表(绝对路径)
|
|
126
|
+
* @param oldDir 旧文件所在目录(绝对路径)
|
|
127
|
+
* @param newDir 新文件所在目录(绝对路径)
|
|
128
|
+
* @returns 返回差异文件路径列表(相对路径)
|
|
113
129
|
*/
|
|
114
|
-
static getDiffJSON(
|
|
115
|
-
|
|
116
|
-
if (!oldFileList.length) {
|
|
130
|
+
static getDiffJSON(oldFileList, newFileList, oldDir, newDir) {
|
|
131
|
+
if (!oldFileList.length && !newFileList.length) {
|
|
117
132
|
return [];
|
|
118
133
|
}
|
|
119
134
|
let diffList = [];
|
|
135
|
+
// 剩余待处理的新文件列表
|
|
136
|
+
const remainingNewFiles = [...newFileList];
|
|
120
137
|
// 1.
|
|
121
|
-
for (
|
|
122
|
-
const index =
|
|
123
|
-
|
|
138
|
+
for (const oldFile of oldFileList) {
|
|
139
|
+
const index = remainingNewFiles.findIndex(newFile => {
|
|
140
|
+
const relativePath = _path.default.relative(newDir, newFile);
|
|
141
|
+
return relativePath === oldFile;
|
|
142
|
+
});
|
|
124
143
|
if (index !== -1) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
144
|
+
const oldFilePath = _path.default.join(oldDir, oldFile);
|
|
145
|
+
// 比较文件内容
|
|
146
|
+
const {
|
|
147
|
+
isEqual
|
|
148
|
+
} = (0, _FileCompare.compareFiles)(oldFilePath, newFileList[index]);
|
|
149
|
+
if (!isEqual) {
|
|
150
|
+
diffList.push(_path.default.relative(newDir, remainingNewFiles[index]));
|
|
130
151
|
}
|
|
131
|
-
//
|
|
132
|
-
|
|
152
|
+
// 从新文件列表中移除已比较过的文件
|
|
153
|
+
remainingNewFiles.splice(index, 1);
|
|
133
154
|
}
|
|
134
155
|
}
|
|
135
156
|
// 2.
|
|
136
|
-
|
|
157
|
+
diffList.push(...remainingNewFiles.map(file => _path.default.relative(newDir, file)));
|
|
137
158
|
return diffList;
|
|
138
159
|
}
|
|
139
160
|
}
|
|
@@ -115,11 +115,38 @@ class UxLoaderUtils {
|
|
|
115
115
|
// 区分app.ux和一般ux
|
|
116
116
|
// app.ux解析结果中加上manifest.json的内容
|
|
117
117
|
const manifestJson = `require('./manifest.json')`;
|
|
118
|
+
function translateStyleFunc() {
|
|
119
|
+
return `
|
|
120
|
+
var $translateStyle$ = function (value) {
|
|
121
|
+
if (typeof value === 'string') {
|
|
122
|
+
return Object.fromEntries(
|
|
123
|
+
value
|
|
124
|
+
.split(';')
|
|
125
|
+
.filter((item) => Boolean(item && item.trim()))
|
|
126
|
+
.map((item) => {
|
|
127
|
+
const matchs = item.match(/([^:]+):(.*)/);
|
|
128
|
+
if (matchs && matchs.length > 2) {
|
|
129
|
+
return [
|
|
130
|
+
matchs[1]
|
|
131
|
+
.trim()
|
|
132
|
+
.replace(/-([a-z])/g, (_, match) => match.toUpperCase()),
|
|
133
|
+
matchs[2].trim(),
|
|
134
|
+
];
|
|
135
|
+
}
|
|
136
|
+
return [];
|
|
137
|
+
})
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
return value;
|
|
141
|
+
};
|
|
142
|
+
global.$translateStyle$ = $translateStyle$
|
|
143
|
+
`;
|
|
144
|
+
}
|
|
118
145
|
const integrateFunction = (appImport, appStyleTree, appTemplateTree, appScriptTree) => {
|
|
119
146
|
const scriptCode = appScriptTree.getText();
|
|
120
147
|
const hasScript = Boolean(scriptCode) && scriptCode !== '""';
|
|
121
148
|
// script代码放在第三个位置不能变化,影响更新source map
|
|
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}
|
|
149
|
+
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}`, translateStyleFunc()] : [`${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$;`, `}`];
|
|
123
150
|
};
|
|
124
151
|
const {
|
|
125
152
|
targetTree,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiot-toolkit/aiotpack",
|
|
3
|
-
"version": "2.0.5-beta.
|
|
3
|
+
"version": "2.0.5-beta.21",
|
|
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.
|
|
23
|
-
"@aiot-toolkit/parser": "2.0.5-beta.
|
|
24
|
-
"@aiot-toolkit/shared-utils": "2.0.5-beta.
|
|
22
|
+
"@aiot-toolkit/generator": "2.0.5-beta.21",
|
|
23
|
+
"@aiot-toolkit/parser": "2.0.5-beta.21",
|
|
24
|
+
"@aiot-toolkit/shared-utils": "2.0.5-beta.21",
|
|
25
25
|
"@hap-toolkit/aaptjs": "^2.0.0",
|
|
26
|
-
"@rspack/core": "^1.
|
|
27
|
-
"aiot-parse5": "^1.0.
|
|
28
|
-
"archiver": "^7.0.1",
|
|
26
|
+
"@rspack/core": "^1.3.9",
|
|
27
|
+
"aiot-parse5": "^1.0.2",
|
|
29
28
|
"babel-loader": "^9.1.3",
|
|
30
|
-
"
|
|
31
|
-
"file-lane": "2.0.5-beta.2",
|
|
29
|
+
"file-lane": "2.0.5-beta.21",
|
|
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": "
|
|
46
|
+
"gitHead": "bd68bd780bf1d12ca6f2bb4179b2759316d958a7"
|
|
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,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,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;
|
package/lib/config/XtsConfig.js
DELETED
|
@@ -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;
|