@aiot-toolkit/aiotpack 2.0.5-beta.11 → 2.0.5-beta.14
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.js +6 -7
- package/lib/index.d.ts +1 -3
- package/lib/index.js +2 -28
- package/package.json +6 -9
- 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
|
@@ -91,12 +91,12 @@ class UxAfterCompile {
|
|
|
91
91
|
const {
|
|
92
92
|
compilerOption,
|
|
93
93
|
compalition,
|
|
94
|
-
|
|
94
|
+
context
|
|
95
95
|
} = params;
|
|
96
96
|
if (compilerOption) {
|
|
97
97
|
const fileName = await _ZipUtil.default.createRpk(_path.default.join(compilerOption.projectPath, compilerOption.outputPath), compilerOption);
|
|
98
98
|
if (compalition && fileName) {
|
|
99
|
-
compalition.info.rpk = _path.default.join(
|
|
99
|
+
compalition.info.rpk = _path.default.join(context.projectPath, compilerOption.releasePath, fileName);
|
|
100
100
|
}
|
|
101
101
|
return fileName;
|
|
102
102
|
}
|
|
@@ -263,7 +263,7 @@ class UxAfterCompile {
|
|
|
263
263
|
const {
|
|
264
264
|
compilerOption,
|
|
265
265
|
compalition,
|
|
266
|
-
|
|
266
|
+
context
|
|
267
267
|
} = params;
|
|
268
268
|
if (!compilerOption || !compalition) {
|
|
269
269
|
return;
|
|
@@ -292,7 +292,7 @@ class UxAfterCompile {
|
|
|
292
292
|
zipFilePath: item
|
|
293
293
|
})));
|
|
294
294
|
compalition.info.diffList = diffList;
|
|
295
|
-
compalition.info.diffFile = _path.default.join(
|
|
295
|
+
compalition.info.diffFile = _path.default.join(context.projectPath, compilerOption.releasePath, diffFileName);
|
|
296
296
|
}
|
|
297
297
|
};
|
|
298
298
|
|
|
@@ -374,7 +374,6 @@ class UxAfterCompile {
|
|
|
374
374
|
*/
|
|
375
375
|
static compileLiteCard = async params => {
|
|
376
376
|
const {
|
|
377
|
-
config,
|
|
378
377
|
compilerOption,
|
|
379
378
|
context
|
|
380
379
|
} = params;
|
|
@@ -392,7 +391,7 @@ class UxAfterCompile {
|
|
|
392
391
|
};
|
|
393
392
|
// 1.2
|
|
394
393
|
await HapToolkit.compile('native', 'dev', false, {
|
|
395
|
-
cwd:
|
|
394
|
+
cwd: context.projectPath,
|
|
396
395
|
signMode: 'BUILD',
|
|
397
396
|
enableCustomComponent: true
|
|
398
397
|
});
|
|
@@ -401,7 +400,7 @@ class UxAfterCompile {
|
|
|
401
400
|
// 2.
|
|
402
401
|
context.liteCards.forEach(card => {
|
|
403
402
|
// hap-toolkit的产物在项目的build文件夹下
|
|
404
|
-
const fromPath = _path.default.join(
|
|
403
|
+
const fromPath = _path.default.join(context.projectPath, LITE_OUTPUT_PATH, card);
|
|
405
404
|
// aiot-toolkit的产物在临时项目的build文件夹下
|
|
406
405
|
const toPath = _path.default.join(projectPath, LITE_OUTPUT_PATH, card);
|
|
407
406
|
//确定目标目录存在,若不存在则创建到父目录
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import XtsConfig from './config/XtsConfig';
|
|
2
1
|
import JavascriptDefaultCompileOption, { setServerPort } from './compiler/javascript/JavascriptDefaultCompileOption';
|
|
3
2
|
import UxConfig from './config/UxConfig';
|
|
4
3
|
import CompileMode from './compiler/enum/CompileMode';
|
|
@@ -6,5 +5,4 @@ import IJavascriptCompileOption from './compiler/javascript/interface/IJavascrip
|
|
|
6
5
|
import IQuickAppConfig from './compiler/javascript/vela/interface/IQuickAppConfig';
|
|
7
6
|
import UxFileUtils from './utils/ux/UxFileUtils';
|
|
8
7
|
import IManifest from './compiler/javascript/vela/interface/IManifest';
|
|
9
|
-
|
|
10
|
-
export { XtsConfig, UxConfig, JavascriptDefaultCompileOption, CompileMode, IJavascriptCompileOption, IQuickAppConfig, setServerPort, UxFileUtils, IManifest, skipList, IXtsCompileOptions, ISkipList };
|
|
8
|
+
export { UxConfig, JavascriptDefaultCompileOption, CompileMode, IJavascriptCompileOption, IQuickAppConfig, setServerPort, UxFileUtils, IManifest };
|
package/lib/index.js
CHANGED
|
@@ -27,18 +27,6 @@ Object.defineProperty(exports, "IQuickAppConfig", {
|
|
|
27
27
|
return _IQuickAppConfig.default;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
-
Object.defineProperty(exports, "ISkipList", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
get: function () {
|
|
33
|
-
return _ICompileOptions.ISkipList;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(exports, "IXtsCompileOptions", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
get: function () {
|
|
39
|
-
return _ICompileOptions.IXtsCompileOptions;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
30
|
Object.defineProperty(exports, "JavascriptDefaultCompileOption", {
|
|
43
31
|
enumerable: true,
|
|
44
32
|
get: function () {
|
|
@@ -57,25 +45,12 @@ Object.defineProperty(exports, "UxFileUtils", {
|
|
|
57
45
|
return _UxFileUtils.default;
|
|
58
46
|
}
|
|
59
47
|
});
|
|
60
|
-
Object.defineProperty(exports, "XtsConfig", {
|
|
61
|
-
enumerable: true,
|
|
62
|
-
get: function () {
|
|
63
|
-
return _XtsConfig.default;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
48
|
Object.defineProperty(exports, "setServerPort", {
|
|
67
49
|
enumerable: true,
|
|
68
50
|
get: function () {
|
|
69
51
|
return _JavascriptDefaultCompileOption.setServerPort;
|
|
70
52
|
}
|
|
71
53
|
});
|
|
72
|
-
Object.defineProperty(exports, "skipList", {
|
|
73
|
-
enumerable: true,
|
|
74
|
-
get: function () {
|
|
75
|
-
return _ICompileOptions.skipList;
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
var _XtsConfig = _interopRequireDefault(require("./config/XtsConfig"));
|
|
79
54
|
var _JavascriptDefaultCompileOption = _interopRequireWildcard(require("./compiler/javascript/JavascriptDefaultCompileOption"));
|
|
80
55
|
var _UxConfig = _interopRequireDefault(require("./config/UxConfig"));
|
|
81
56
|
var _CompileMode = _interopRequireDefault(require("./compiler/enum/CompileMode"));
|
|
@@ -83,7 +58,6 @@ var _IJavascriptCompileOption = _interopRequireDefault(require("./compiler/javas
|
|
|
83
58
|
var _IQuickAppConfig = _interopRequireDefault(require("./compiler/javascript/vela/interface/IQuickAppConfig"));
|
|
84
59
|
var _UxFileUtils = _interopRequireDefault(require("./utils/ux/UxFileUtils"));
|
|
85
60
|
var _IManifest = _interopRequireDefault(require("./compiler/javascript/vela/interface/IManifest"));
|
|
86
|
-
|
|
61
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
87
62
|
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); }
|
|
88
|
-
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; }
|
|
89
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
63
|
+
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; }
|
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.14",
|
|
4
4
|
"description": "The process tool for packaging aiot projects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aiotpack"
|
|
@@ -19,16 +19,14 @@
|
|
|
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.14",
|
|
23
|
+
"@aiot-toolkit/parser": "2.0.5-beta.14",
|
|
24
|
+
"@aiot-toolkit/shared-utils": "2.0.5-beta.14",
|
|
25
25
|
"@hap-toolkit/aaptjs": "^2.0.0",
|
|
26
26
|
"@rspack/core": "^1.1.8",
|
|
27
27
|
"aiot-parse5": "^1.0.2",
|
|
28
|
-
"archiver": "^7.0.1",
|
|
29
28
|
"babel-loader": "^9.1.3",
|
|
30
|
-
"
|
|
31
|
-
"file-lane": "2.0.5-beta.11",
|
|
29
|
+
"file-lane": "2.0.5-beta.14",
|
|
32
30
|
"file-loader": "^6.2.0",
|
|
33
31
|
"fs-extra": "^11.2.0",
|
|
34
32
|
"hap-toolkit": "^2.0.0",
|
|
@@ -42,10 +40,9 @@
|
|
|
42
40
|
"webpack-sources": "^3.2.3"
|
|
43
41
|
},
|
|
44
42
|
"devDependencies": {
|
|
45
|
-
"@types/archiver": "^6.0.2",
|
|
46
43
|
"@types/fs-extra": "^11.0.4",
|
|
47
44
|
"@types/jsrsasign": "^10.5.12",
|
|
48
45
|
"@types/webpack-sources": "^3.2.3"
|
|
49
46
|
},
|
|
50
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "63c6564afe9bedd9c034f03e8e457b6cfa6960ae"
|
|
51
48
|
}
|
|
@@ -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;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _generator = require("@aiot-toolkit/generator");
|
|
8
|
-
var _parser = require("@aiot-toolkit/parser");
|
|
9
|
-
var _sharedUtils = require("@aiot-toolkit/shared-utils");
|
|
10
|
-
var _path = _interopRequireDefault(require("path"));
|
|
11
|
-
var _tsMorph = require("ts-morph");
|
|
12
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
-
/**
|
|
14
|
-
* XtsLoader
|
|
15
|
-
*/
|
|
16
|
-
class XtsLoader {
|
|
17
|
-
parser(files) {
|
|
18
|
-
const project = new _tsMorph.Project();
|
|
19
|
-
const resultFiles = [];
|
|
20
|
-
for (const file in files) {
|
|
21
|
-
const {
|
|
22
|
-
path,
|
|
23
|
-
content
|
|
24
|
-
} = files[file];
|
|
25
|
-
const {
|
|
26
|
-
name,
|
|
27
|
-
ext
|
|
28
|
-
} = _path.default.parse(path);
|
|
29
|
-
const fullName = `${name}${ext}`;
|
|
30
|
-
const newFileName = `${name}.ts`;
|
|
31
|
-
//判断文本,空文本则结束该文件处理
|
|
32
|
-
if (!content) {
|
|
33
|
-
_sharedUtils.ColorConsole.warn(`The file '${fullName}' under the path '${path}' has no content `);
|
|
34
|
-
return [];
|
|
35
|
-
}
|
|
36
|
-
const parserResult = new _parser.XtsParser(project, _sharedUtils.ColorConsole.logger).parser(content.toString(), fullName);
|
|
37
|
-
const {
|
|
38
|
-
ast,
|
|
39
|
-
mapList
|
|
40
|
-
} = new _parser.XtsToTypescript(project, _sharedUtils.ColorConsole.logger, this.context, path).translate(parserResult.ast, parserResult.offsetList);
|
|
41
|
-
const {
|
|
42
|
-
code,
|
|
43
|
-
sourcemap
|
|
44
|
-
} = new _generator.TypescriptGenerator().generate({
|
|
45
|
-
sourceFilePath: fullName,
|
|
46
|
-
targetFilePath: newFileName,
|
|
47
|
-
ast,
|
|
48
|
-
mapList
|
|
49
|
-
});
|
|
50
|
-
resultFiles.push({
|
|
51
|
-
path: _sharedUtils.FileUtil.updateFileName(path, newFileName),
|
|
52
|
-
content: code
|
|
53
|
-
}, {
|
|
54
|
-
path: _sharedUtils.FileUtil.updateFileName(path, `${name}.map.ts`),
|
|
55
|
-
content: sourcemap
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
// 返回内容
|
|
59
|
-
return resultFiles;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
var _default = exports.default = XtsLoader;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
declare class XtsFileLaneUtils {
|
|
2
|
-
/**
|
|
3
|
-
* 将buildPath文件夹的内容压缩成zip包,放置于targetPath路径下
|
|
4
|
-
* @param buildPath
|
|
5
|
-
* @param targetPath
|
|
6
|
-
* @param zipRootDirNames 可自定义压缩包内最外层目录的名称
|
|
7
|
-
*/
|
|
8
|
-
static zipProject(buildPath: string[], targetFile: string, zipRootDirNames?: string[]): Promise<void>;
|
|
9
|
-
}
|
|
10
|
-
export default XtsFileLaneUtils;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _sharedUtils = require("@aiot-toolkit/shared-utils");
|
|
8
|
-
var _archiver = _interopRequireDefault(require("archiver"));
|
|
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
|
-
class XtsFileLaneUtils {
|
|
13
|
-
/**
|
|
14
|
-
* 将buildPath文件夹的内容压缩成zip包,放置于targetPath路径下
|
|
15
|
-
* @param buildPath
|
|
16
|
-
* @param targetPath
|
|
17
|
-
* @param zipRootDirNames 可自定义压缩包内最外层目录的名称
|
|
18
|
-
*/
|
|
19
|
-
static async zipProject(buildPath, targetFile, zipRootDirNames) {
|
|
20
|
-
return new Promise((resolve, reject) => {
|
|
21
|
-
const output = _fsExtra.default.createWriteStream(targetFile);
|
|
22
|
-
const archive = _archiver.default.create('zip', {
|
|
23
|
-
zlib: {
|
|
24
|
-
level: 9
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
// 监听错误
|
|
28
|
-
archive.on('error', err => {
|
|
29
|
-
_sharedUtils.ColorConsole.throw(`${err.message}`);
|
|
30
|
-
output.close();
|
|
31
|
-
reject();
|
|
32
|
-
});
|
|
33
|
-
// 监听写入流打开的事件
|
|
34
|
-
output.on('open', () => {
|
|
35
|
-
_sharedUtils.ColorConsole.info(`Write stream is open`);
|
|
36
|
-
});
|
|
37
|
-
output.on('close', () => {
|
|
38
|
-
_sharedUtils.ColorConsole.info(`Write stream is closed`);
|
|
39
|
-
resolve();
|
|
40
|
-
});
|
|
41
|
-
// 将压缩文件导入到输出流中
|
|
42
|
-
archive.pipe(output);
|
|
43
|
-
|
|
44
|
-
// 指定压缩目录
|
|
45
|
-
buildPath.forEach((folder, index) => {
|
|
46
|
-
const folderName = _path.default.basename(folder); // 获取文件夹名
|
|
47
|
-
if (zipRootDirNames && zipRootDirNames[index]) {
|
|
48
|
-
archive.directory(folder, zipRootDirNames[index]);
|
|
49
|
-
} else {
|
|
50
|
-
archive.directory(folder, folderName);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
archive.on('finish', () => {
|
|
54
|
-
_sharedUtils.ColorConsole.info('finish');
|
|
55
|
-
});
|
|
56
|
-
// 完成压缩,关闭输出流
|
|
57
|
-
archive.finalize();
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
var _default = exports.default = XtsFileLaneUtils;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { IFileLaneContext } from 'file-lane';
|
|
2
|
-
export interface DefaultZipProjectOptions {
|
|
3
|
-
tarDir?: string;
|
|
4
|
-
ext?: string;
|
|
5
|
-
packageName: string;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* XtsFollowWorks
|
|
9
|
-
*/
|
|
10
|
-
declare class XtsFollowWorks {
|
|
11
|
-
/**
|
|
12
|
-
* 将项目中build文件夹的内容压缩成zip包,并将压缩产物放到dist文件夹下
|
|
13
|
-
* @param context
|
|
14
|
-
*/
|
|
15
|
-
static defaultZipProject(context: IFileLaneContext, options: DefaultZipProjectOptions): Promise<void>;
|
|
16
|
-
/**
|
|
17
|
-
* 将分布式项目按照manifest.json中的配置打包,思路如下:
|
|
18
|
-
* 1. 获取manifest中aspect的路由配置
|
|
19
|
-
* 2. 对aspects中的所有路由信息进行遍历
|
|
20
|
-
* 3. 按照设备(设备+rule)对aspect分类
|
|
21
|
-
* 4. 按照设备列表分别进行打包
|
|
22
|
-
* @param context
|
|
23
|
-
*/
|
|
24
|
-
static zipDistributedQuickApp(context: IFileLaneContext): Promise<void>;
|
|
25
|
-
/**
|
|
26
|
-
* 根据项目路径,打包文件夹名和传入的压缩包名,生成压缩文件zip路径
|
|
27
|
-
* @param projectPath
|
|
28
|
-
* @param outputDir
|
|
29
|
-
* @param zipName
|
|
30
|
-
* @returns
|
|
31
|
-
*/
|
|
32
|
-
static getFilePath(projectPath: string, outputDir?: string, zipName?: string, ext?: string): string;
|
|
33
|
-
}
|
|
34
|
-
export default XtsFollowWorks;
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _sharedUtils = require("@aiot-toolkit/shared-utils");
|
|
8
|
-
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
9
|
-
var _path = _interopRequireDefault(require("path"));
|
|
10
|
-
var _UxFileUtils = _interopRequireDefault(require("./../ux/UxFileUtils"));
|
|
11
|
-
var _XtsFileLaneUtils = _interopRequireDefault(require("../../utils/xts/XtsFileLaneUtils"));
|
|
12
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
-
/**
|
|
14
|
-
* XtsFollowWorks
|
|
15
|
-
*/
|
|
16
|
-
class XtsFollowWorks {
|
|
17
|
-
/**
|
|
18
|
-
* 将项目中build文件夹的内容压缩成zip包,并将压缩产物放到dist文件夹下
|
|
19
|
-
* @param context
|
|
20
|
-
*/
|
|
21
|
-
static async defaultZipProject(context, options) {
|
|
22
|
-
const {
|
|
23
|
-
projectPath
|
|
24
|
-
} = context;
|
|
25
|
-
const output = options.tarDir || context.output;
|
|
26
|
-
const buildPath = _path.default.join(projectPath, output);
|
|
27
|
-
const zipPath = _path.default.join(projectPath, 'dist');
|
|
28
|
-
// buildPath必须是真实文件夹路径
|
|
29
|
-
if (!_fsExtra.default.existsSync(buildPath)) {
|
|
30
|
-
_sharedUtils.ColorConsole.throw(`buildPath: '${buildPath}' not exist`);
|
|
31
|
-
}
|
|
32
|
-
try {
|
|
33
|
-
// 确认文件夹是否存在,不存在则创建
|
|
34
|
-
_fsExtra.default.ensureDirSync(zipPath);
|
|
35
|
-
// 清空dist文件夹
|
|
36
|
-
_fsExtra.default.emptyDirSync(zipPath);
|
|
37
|
-
const filePath = XtsFollowWorks.getFilePath(projectPath, 'dist', options.packageName, 'rpk');
|
|
38
|
-
await _XtsFileLaneUtils.default.zipProject([buildPath], filePath, [options.packageName]);
|
|
39
|
-
} catch (err) {
|
|
40
|
-
_sharedUtils.ColorConsole.throw(`${err.message}`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* 将分布式项目按照manifest.json中的配置打包,思路如下:
|
|
45
|
-
* 1. 获取manifest中aspect的路由配置
|
|
46
|
-
* 2. 对aspects中的所有路由信息进行遍历
|
|
47
|
-
* 3. 按照设备(设备+rule)对aspect分类
|
|
48
|
-
* 4. 按照设备列表分别进行打包
|
|
49
|
-
* @param context
|
|
50
|
-
*/
|
|
51
|
-
static async zipDistributedQuickApp(context) {
|
|
52
|
-
const deviceList = [{
|
|
53
|
-
device: 'phone',
|
|
54
|
-
aspectList: []
|
|
55
|
-
}];
|
|
56
|
-
const {
|
|
57
|
-
projectPath,
|
|
58
|
-
output
|
|
59
|
-
} = context;
|
|
60
|
-
const manifestPath = _UxFileUtils.default.getManifestFilePath(projectPath, 'app');
|
|
61
|
-
if (_fsExtra.default.existsSync(manifestPath)) {
|
|
62
|
-
//获取manifest.json内容
|
|
63
|
-
const aspectsRule = _fsExtra.default.readJSONSync(manifestPath)?.router?.aspects;
|
|
64
|
-
if (aspectsRule) {
|
|
65
|
-
Object.keys(aspectsRule).forEach(aspectRule => {
|
|
66
|
-
// 分别处理每个aspectRule数组
|
|
67
|
-
for (let item of aspectsRule[aspectRule]) {
|
|
68
|
-
const {
|
|
69
|
-
devices,
|
|
70
|
-
rule,
|
|
71
|
-
path
|
|
72
|
-
} = item;
|
|
73
|
-
// 如果存在设备列表
|
|
74
|
-
if (devices && Array.isArray(devices) && devices.length > 0) {
|
|
75
|
-
for (let device of devices) {
|
|
76
|
-
// 设备名与rule组合为一个设备
|
|
77
|
-
if (rule) {
|
|
78
|
-
device = `${device}.${rule}`;
|
|
79
|
-
}
|
|
80
|
-
// 查找设备是否已存在于设备列表中
|
|
81
|
-
const index = device === 'phone' ? 0 : deviceList.findIndex(item => item.device === device);
|
|
82
|
-
if (index === -1) {
|
|
83
|
-
// 新设备
|
|
84
|
-
deviceList.push({
|
|
85
|
-
device,
|
|
86
|
-
aspectList: [path]
|
|
87
|
-
});
|
|
88
|
-
} else {
|
|
89
|
-
// 已存在的设备信息时,仅需添加aspect路由
|
|
90
|
-
deviceList[index].aspectList.push(path);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
} else {
|
|
94
|
-
// 设备值默认值为phone
|
|
95
|
-
deviceList[0].aspectList.push(path);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
const zipPath = _path.default.join(projectPath, 'dist');
|
|
101
|
-
_fsExtra.default.ensureDirSync(zipPath);
|
|
102
|
-
_fsExtra.default.emptyDirSync(zipPath);
|
|
103
|
-
// 根据deviceList进行打包
|
|
104
|
-
for (const item of deviceList) {
|
|
105
|
-
// 所有zip包都需要app信息
|
|
106
|
-
item.aspectList.push('app');
|
|
107
|
-
// 将路由转为真实路径
|
|
108
|
-
const buildPaths = item.aspectList.map(name => _path.default.join(projectPath, output, name));
|
|
109
|
-
const filePath = XtsFollowWorks.getFilePath(projectPath, 'dist', item.device);
|
|
110
|
-
try {
|
|
111
|
-
await _XtsFileLaneUtils.default.zipProject(buildPaths, filePath);
|
|
112
|
-
} catch (error) {}
|
|
113
|
-
}
|
|
114
|
-
} else {
|
|
115
|
-
_sharedUtils.ColorConsole.throw('not find manifest.json');
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* 根据项目路径,打包文件夹名和传入的压缩包名,生成压缩文件zip路径
|
|
120
|
-
* @param projectPath
|
|
121
|
-
* @param outputDir
|
|
122
|
-
* @param zipName
|
|
123
|
-
* @returns
|
|
124
|
-
*/
|
|
125
|
-
static getFilePath(projectPath) {
|
|
126
|
-
let outputDir = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'dist';
|
|
127
|
-
let zipName = arguments.length > 2 ? arguments[2] : undefined;
|
|
128
|
-
let ext = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'zip';
|
|
129
|
-
zipName = zipName ? `${zipName}.${ext}` : `${_path.default.basename(projectPath)}.${ext}`;
|
|
130
|
-
const zipPath = _path.default.join(projectPath, outputDir);
|
|
131
|
-
return _path.default.join(zipPath, zipName);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
var _default = exports.default = XtsFollowWorks;
|