@aiot-toolkit/aiotpack 2.0.1-alpha.0
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/README.md +46 -0
- package/lib/compiler/c/README.md +1 -0
- package/lib/compiler/c++/README.md +1 -0
- package/lib/compiler/enum/CompileMode.d.ts +22 -0
- package/lib/compiler/enum/CompileMode.js +30 -0
- package/lib/compiler/enum/CompileMode.js.map +1 -0
- package/lib/compiler/interface/ICompileParam.d.ts +24 -0
- package/lib/compiler/interface/ICompileParam.js +4 -0
- package/lib/compiler/interface/ICompileParam.js.map +1 -0
- package/lib/compiler/interface/ICompiler.d.ts +5 -0
- package/lib/compiler/interface/ICompiler.js +4 -0
- package/lib/compiler/interface/ICompiler.js.map +1 -0
- package/lib/compiler/interface/ISignConfig.d.ts +8 -0
- package/lib/compiler/interface/ISignConfig.js +4 -0
- package/lib/compiler/interface/ISignConfig.js.map +1 -0
- package/lib/compiler/javascript/JavascriptCompiler.d.ts +11 -0
- package/lib/compiler/javascript/JavascriptCompiler.js +108 -0
- package/lib/compiler/javascript/JavascriptCompiler.js.map +1 -0
- package/lib/compiler/javascript/JavascriptDefaultCompileOption.d.ts +3 -0
- package/lib/compiler/javascript/JavascriptDefaultCompileOption.js +21 -0
- package/lib/compiler/javascript/JavascriptDefaultCompileOption.js.map +1 -0
- package/lib/compiler/javascript/interface/IJavascriptCompileOption.d.ts +40 -0
- package/lib/compiler/javascript/interface/IJavascriptCompileOption.js +4 -0
- package/lib/compiler/javascript/interface/IJavascriptCompileOption.js.map +1 -0
- package/lib/compiler/javascript/interface/IWebpackConfigurator.d.ts +40 -0
- package/lib/compiler/javascript/interface/IWebpackConfigurator.js +4 -0
- package/lib/compiler/javascript/interface/IWebpackConfigurator.js.map +1 -0
- package/lib/compiler/javascript/vela/VelaWebpackConfigurator.d.ts +16 -0
- package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js +74 -0
- package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js.map +1 -0
- package/lib/compiler/javascript/vela/enum/BuildNameFormatType.d.ts +25 -0
- package/lib/compiler/javascript/vela/enum/BuildNameFormatType.js +47 -0
- package/lib/compiler/javascript/vela/enum/BuildNameFormatType.js.map +1 -0
- package/lib/compiler/javascript/vela/enum/EntryType.d.ts +30 -0
- package/lib/compiler/javascript/vela/enum/EntryType.js +35 -0
- package/lib/compiler/javascript/vela/enum/EntryType.js.map +1 -0
- package/lib/compiler/javascript/vela/interface/IChunk.d.ts +29 -0
- package/lib/compiler/javascript/vela/interface/IChunk.js +4 -0
- package/lib/compiler/javascript/vela/interface/IChunk.js.map +1 -0
- package/lib/compiler/javascript/vela/interface/IManifest.d.ts +27 -0
- package/lib/compiler/javascript/vela/interface/IManifest.js +4 -0
- package/lib/compiler/javascript/vela/interface/IManifest.js.map +1 -0
- package/lib/compiler/javascript/vela/interface/IQuickAppConfig.d.ts +11 -0
- package/lib/compiler/javascript/vela/interface/IQuickAppConfig.js +4 -0
- package/lib/compiler/javascript/vela/interface/IQuickAppConfig.js.map +1 -0
- package/lib/compiler/javascript/vela/model/Package.d.ts +75 -0
- package/lib/compiler/javascript/vela/model/Package.js +62 -0
- package/lib/compiler/javascript/vela/model/Package.js.map +1 -0
- package/lib/compiler/javascript/vela/plugin/WrapPlugin.d.ts +7 -0
- package/lib/compiler/javascript/vela/plugin/WrapPlugin.js +51 -0
- package/lib/compiler/javascript/vela/plugin/WrapPlugin.js.map +1 -0
- package/lib/compiler/javascript/vela/utils/Jsc.d.ts +10 -0
- package/lib/compiler/javascript/vela/utils/Jsc.js +34 -0
- package/lib/compiler/javascript/vela/utils/Jsc.js.map +1 -0
- package/lib/compiler/javascript/vela/utils/UxCompileUtil.d.ts +29 -0
- package/lib/compiler/javascript/vela/utils/UxCompileUtil.js +144 -0
- package/lib/compiler/javascript/vela/utils/UxCompileUtil.js.map +1 -0
- package/lib/compiler/javascript/vela/utils/ZipUtil.d.ts +75 -0
- package/lib/compiler/javascript/vela/utils/ZipUtil.js +278 -0
- package/lib/compiler/javascript/vela/utils/ZipUtil.js.map +1 -0
- package/lib/compiler/javascript/vela/utils/signature/Base64.d.ts +11 -0
- package/lib/compiler/javascript/vela/utils/signature/Base64.js +77 -0
- package/lib/compiler/javascript/vela/utils/signature/Base64.js.map +1 -0
- package/lib/compiler/javascript/vela/utils/signature/CRC32.d.ts +9 -0
- package/lib/compiler/javascript/vela/utils/signature/CRC32.js +45 -0
- package/lib/compiler/javascript/vela/utils/signature/CRC32.js.map +1 -0
- package/lib/compiler/javascript/vela/utils/signature/SignUtil.d.ts +94 -0
- package/lib/compiler/javascript/vela/utils/signature/SignUtil.js +713 -0
- package/lib/compiler/javascript/vela/utils/signature/SignUtil.js.map +1 -0
- package/lib/compiler/javascript/vela/utils/signature/Signer.d.ts +16 -0
- package/lib/compiler/javascript/vela/utils/signature/Signer.js +30 -0
- package/lib/compiler/javascript/vela/utils/signature/Signer.js.map +1 -0
- package/lib/compiler/javascript/vela/utils/signature/pem/certificate.pem +27 -0
- package/lib/compiler/javascript/vela/utils/signature/pem/private.pem +51 -0
- package/lib/config/UxConfig.d.ts +30 -0
- package/lib/config/UxConfig.js +52 -0
- package/lib/config/UxConfig.js.map +1 -0
- package/lib/config/XtsConfig.d.ts +18 -0
- package/lib/config/XtsConfig.js +28 -0
- package/lib/config/XtsConfig.js.map +1 -0
- package/lib/followWorks/xts/entryTemplate.d.ts +21 -0
- package/lib/followWorks/xts/entryTemplate.js +166 -0
- package/lib/followWorks/xts/entryTemplate.js.map +1 -0
- package/lib/followWorks/xts/ts2wasm.d.ts +6 -0
- package/lib/followWorks/xts/ts2wasm.js +31 -0
- package/lib/followWorks/xts/ts2wasm.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +10 -0
- package/lib/index.js.map +1 -0
- package/lib/interface/IDeviceList.d.ts +7 -0
- package/lib/interface/IDeviceList.js +4 -0
- package/lib/interface/IDeviceList.js.map +1 -0
- package/lib/loader/ux/AppUxLoader.d.ts +10 -0
- package/lib/loader/ux/AppUxLoader.js +31 -0
- package/lib/loader/ux/AppUxLoader.js.map +1 -0
- package/lib/loader/ux/PngLoader.d.ts +10 -0
- package/lib/loader/ux/PngLoader.js +70 -0
- package/lib/loader/ux/PngLoader.js.map +1 -0
- package/lib/loader/ux/UxLoader.d.ts +6 -0
- package/lib/loader/ux/UxLoader.js +31 -0
- package/lib/loader/ux/UxLoader.js.map +1 -0
- package/lib/loader/xts/XtsLoader.d.ts +9 -0
- package/lib/loader/xts/XtsLoader.js +55 -0
- package/lib/loader/xts/XtsLoader.js.map +1 -0
- package/lib/utils/PngUtils.d.ts +20 -0
- package/lib/utils/PngUtils.js +45 -0
- package/lib/utils/PngUtils.js.map +1 -0
- package/lib/utils/PreWorkUtils.d.ts +17 -0
- package/lib/utils/PreWorkUtils.js +76 -0
- package/lib/utils/PreWorkUtils.js.map +1 -0
- package/lib/utils/ux/UxFileUtils.d.ts +22 -0
- package/lib/utils/ux/UxFileUtils.js +34 -0
- package/lib/utils/ux/UxFileUtils.js.map +1 -0
- package/lib/utils/ux/UxFollowWorks.d.ts +35 -0
- package/lib/utils/ux/UxFollowWorks.js +200 -0
- package/lib/utils/ux/UxFollowWorks.js.map +1 -0
- package/lib/utils/ux/UxLoaderUtils.d.ts +60 -0
- package/lib/utils/ux/UxLoaderUtils.js +241 -0
- package/lib/utils/ux/UxLoaderUtils.js.map +1 -0
- package/lib/utils/xts/XtsFollowWorks.d.ts +29 -0
- package/lib/utils/xts/XtsFollowWorks.js +149 -0
- package/lib/utils/xts/XtsFollowWorks.js.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 入口类型枚举
|
|
3
|
+
*/
|
|
4
|
+
declare enum EntryType {
|
|
5
|
+
/**
|
|
6
|
+
* 应用程序
|
|
7
|
+
*/
|
|
8
|
+
APP = "app",
|
|
9
|
+
/**
|
|
10
|
+
* 页面
|
|
11
|
+
*/
|
|
12
|
+
PAGE = "page",
|
|
13
|
+
/**
|
|
14
|
+
* 组件
|
|
15
|
+
*/
|
|
16
|
+
COMPONENT = "comp",
|
|
17
|
+
/**
|
|
18
|
+
* 卡片
|
|
19
|
+
*/
|
|
20
|
+
CARD = "card",
|
|
21
|
+
/**
|
|
22
|
+
* 悬浮窗口
|
|
23
|
+
*/
|
|
24
|
+
FLOAT = "float",
|
|
25
|
+
/**
|
|
26
|
+
* JavaScript
|
|
27
|
+
*/
|
|
28
|
+
JS = "js"
|
|
29
|
+
}
|
|
30
|
+
export default EntryType;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* 入口类型枚举
|
|
5
|
+
*/
|
|
6
|
+
var EntryType;
|
|
7
|
+
(function (EntryType) {
|
|
8
|
+
/**
|
|
9
|
+
* 应用程序
|
|
10
|
+
*/
|
|
11
|
+
EntryType["APP"] = "app";
|
|
12
|
+
/**
|
|
13
|
+
* 页面
|
|
14
|
+
*/
|
|
15
|
+
EntryType["PAGE"] = "page";
|
|
16
|
+
/**
|
|
17
|
+
* 组件
|
|
18
|
+
*/
|
|
19
|
+
EntryType["COMPONENT"] = "comp";
|
|
20
|
+
/**
|
|
21
|
+
* 卡片
|
|
22
|
+
*/
|
|
23
|
+
EntryType["CARD"] = "card";
|
|
24
|
+
/**
|
|
25
|
+
* 悬浮窗口
|
|
26
|
+
*/
|
|
27
|
+
EntryType["FLOAT"] = "float";
|
|
28
|
+
/**
|
|
29
|
+
* JavaScript
|
|
30
|
+
*/
|
|
31
|
+
EntryType["JS"] = "js";
|
|
32
|
+
})(EntryType || (EntryType = {}));
|
|
33
|
+
exports.default = EntryType;
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=EntryType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["compiler/javascript/vela/enum/EntryType.ts"],"names":[],"mappings":";;AAAA;;GAEG;AACH,IAAK,SA8BJ;AA9BD,WAAK,SAAS;IACZ;;OAEG;IACH,wBAAW,CAAA;IAEX;;OAEG;IACH,0BAAa,CAAA;IAEb;;OAEG;IACH,+BAAkB,CAAA;IAElB;;OAEG;IACH,0BAAa,CAAA;IAEb;;OAEG;IACH,4BAAe,CAAA;IAEf;;OAEG;IACH,sBAAS,CAAA;AACX,CAAC,EA9BI,SAAS,KAAT,SAAS,QA8Bb;AAED,kBAAe,SAAS,CAAA","file":"EntryType.js","sourcesContent":["/**\n * 入口类型枚举\n */\nenum EntryType {\n /**\n * 应用程序\n */\n APP = 'app',\n\n /**\n * 页面\n */\n PAGE = 'page',\n\n /**\n * 组件\n */\n COMPONENT = 'comp',\n\n /**\n * 卡片\n */\n CARD = 'card',\n\n /**\n * 悬浮窗口\n */\n FLOAT = 'float',\n\n /**\n * JavaScript\n */\n JS = 'js',\n}\n\nexport default EntryType"],"sourceRoot":"../../../../../src"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* IChunk
|
|
4
|
+
*/
|
|
5
|
+
export type IFileHash = {
|
|
6
|
+
name: string;
|
|
7
|
+
hash: Buffer;
|
|
8
|
+
};
|
|
9
|
+
export type IChunkOptions = {
|
|
10
|
+
files: IFileHash[];
|
|
11
|
+
};
|
|
12
|
+
export type IPartChunk = {
|
|
13
|
+
tag: boolean;
|
|
14
|
+
startIndex: number;
|
|
15
|
+
len: number;
|
|
16
|
+
previous: number;
|
|
17
|
+
sign?: Buffer;
|
|
18
|
+
};
|
|
19
|
+
export interface IChunk {
|
|
20
|
+
signchunk: Buffer;
|
|
21
|
+
tag: boolean;
|
|
22
|
+
length: number;
|
|
23
|
+
options: IChunkOptions;
|
|
24
|
+
sections: {
|
|
25
|
+
header: IPartChunk;
|
|
26
|
+
central: IPartChunk;
|
|
27
|
+
footer: IPartChunk;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["compiler/javascript/vela/interface/IChunk.ts"],"names":[],"mappings":"","file":"IChunk.js","sourcesContent":["/**\n * IChunk\n */\nexport type IFileHash = {\n name: string\n hash: Buffer\n}\nexport type IChunkOptions = {\n files: IFileHash[]\n}\nexport type IPartChunk = {\n tag: boolean\n startIndex: number\n len: number\n previous: number\n sign?: Buffer\n}\nexport interface IChunk {\n signchunk: Buffer\n tag: boolean\n length: number\n options: IChunkOptions\n sections: {\n header: IPartChunk\n central: IPartChunk\n footer: IPartChunk\n }\n}\n"],"sourceRoot":"../../../../../src"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Dictionary } from '@aiot-toolkit/shared-utils/lib/type/Type';
|
|
2
|
+
/**
|
|
3
|
+
* vela manifest文件对应的数据结构
|
|
4
|
+
*/
|
|
5
|
+
export default interface IManifest {
|
|
6
|
+
package: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
versionName?: string;
|
|
9
|
+
minPlatformVersion?: number;
|
|
10
|
+
deviceId?: string;
|
|
11
|
+
deviceTypeList?: string[];
|
|
12
|
+
features?: IFeatures[];
|
|
13
|
+
config?: {
|
|
14
|
+
logLevel: string;
|
|
15
|
+
designWidth?: string | number;
|
|
16
|
+
};
|
|
17
|
+
router: {
|
|
18
|
+
entry: string;
|
|
19
|
+
pages: Dictionary<{
|
|
20
|
+
component?: string;
|
|
21
|
+
}>;
|
|
22
|
+
};
|
|
23
|
+
minAPILevel?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface IFeatures {
|
|
26
|
+
name: string;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["compiler/javascript/vela/interface/IManifest.ts"],"names":[],"mappings":"","file":"IManifest.js","sourcesContent":["import { Dictionary } from '@aiot-toolkit/shared-utils/lib/type/Type'\n\n/**\n * vela manifest文件对应的数据结构\n */\nexport default interface IManifest {\n package: string\n name?: string\n versionName?: string\n minPlatformVersion?: number\n deviceId?: string\n deviceTypeList?: string[]\n features?: IFeatures[]\n config?: {\n logLevel: string\n designWidth?: string | number\n }\n router: {\n entry: string\n pages: Dictionary<{ component?: string }>\n }\n minAPILevel?: number\n}\n\nexport interface IFeatures {\n name: string\n}\n"],"sourceRoot":"../../../../../src"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Configuration } from 'webpack';
|
|
2
|
+
import IJavascriptCompileOption from '../../interface/IJavascriptCompileOption';
|
|
3
|
+
/**
|
|
4
|
+
* IQuickAppConfig
|
|
5
|
+
*
|
|
6
|
+
* 项目中 quickapp.config.js 的对象结构
|
|
7
|
+
*/
|
|
8
|
+
export default interface IQuickAppConfig {
|
|
9
|
+
cli: Partial<IJavascriptCompileOption>;
|
|
10
|
+
webpack: Partial<Configuration>;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["compiler/javascript/vela/interface/IQuickAppConfig.ts"],"names":[],"mappings":"","file":"IQuickAppConfig.js","sourcesContent":["import { Configuration } from 'webpack'\nimport IJavascriptCompileOption from '../../interface/IJavascriptCompileOption'\n\n/**\n * IQuickAppConfig\n *\n * 项目中 quickapp.config.js 的对象结构\n */\nexport default interface IQuickAppConfig {\n cli: Partial<IJavascriptCompileOption>\n webpack: Partial<Configuration>\n}\n"],"sourceRoot":"../../../../../src"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Dictionary } from '@aiot-toolkit/shared-utils/lib/type/Type';
|
|
3
|
+
/**
|
|
4
|
+
* 文件资源
|
|
5
|
+
*/
|
|
6
|
+
export interface IFileResource {
|
|
7
|
+
/**
|
|
8
|
+
* 文件路径
|
|
9
|
+
*/
|
|
10
|
+
fileBuildPath: string;
|
|
11
|
+
/**
|
|
12
|
+
* 文件内容
|
|
13
|
+
*/
|
|
14
|
+
fileContentBuffer: Buffer;
|
|
15
|
+
/**
|
|
16
|
+
* 文件摘要
|
|
17
|
+
* 文件内容生成的 hash 值
|
|
18
|
+
*/
|
|
19
|
+
fileContentDigest?: Uint8Array;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 定义文件包
|
|
23
|
+
*
|
|
24
|
+
* 相当于虚拟的 rpk 包
|
|
25
|
+
*/
|
|
26
|
+
declare class Package {
|
|
27
|
+
/**
|
|
28
|
+
* 包前缀
|
|
29
|
+
*/
|
|
30
|
+
filePrefix?: string;
|
|
31
|
+
/**
|
|
32
|
+
* 子包名称;整包没有
|
|
33
|
+
*/
|
|
34
|
+
fileSubname?: string;
|
|
35
|
+
/**
|
|
36
|
+
* 是否为独立包
|
|
37
|
+
*/
|
|
38
|
+
standalone: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* 后缀名
|
|
41
|
+
*/
|
|
42
|
+
fileSuffix?: string;
|
|
43
|
+
icon?: string;
|
|
44
|
+
banner?: string;
|
|
45
|
+
comment?: string;
|
|
46
|
+
/**
|
|
47
|
+
* 资源路径匹配
|
|
48
|
+
*/
|
|
49
|
+
subMatch?: RegExp;
|
|
50
|
+
readonly fileName: string;
|
|
51
|
+
private _resourceList;
|
|
52
|
+
/**
|
|
53
|
+
* 资源文件列表
|
|
54
|
+
*/
|
|
55
|
+
get resourceList(): IFileResource[];
|
|
56
|
+
private _resourceDic;
|
|
57
|
+
/**
|
|
58
|
+
* 资源文件字典,以高效检查资源是否存在
|
|
59
|
+
*/
|
|
60
|
+
get resourceDic(): Dictionary<boolean>;
|
|
61
|
+
/**
|
|
62
|
+
* 是否已包含指定文件
|
|
63
|
+
* @param filePath 文件路径
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
include(filePath: string): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* 添加资源
|
|
69
|
+
* @param data
|
|
70
|
+
* @returns
|
|
71
|
+
*/
|
|
72
|
+
addResource(data: IFileResource): void;
|
|
73
|
+
constructor(data: Partial<Package>);
|
|
74
|
+
}
|
|
75
|
+
export default Package;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const ColorConsole2_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole2"));
|
|
7
|
+
/**
|
|
8
|
+
* 定义文件包
|
|
9
|
+
*
|
|
10
|
+
* 相当于虚拟的 rpk 包
|
|
11
|
+
*/
|
|
12
|
+
class Package {
|
|
13
|
+
/**
|
|
14
|
+
* 资源文件列表
|
|
15
|
+
*/
|
|
16
|
+
get resourceList() {
|
|
17
|
+
return this._resourceList;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 资源文件字典,以高效检查资源是否存在
|
|
21
|
+
*/
|
|
22
|
+
get resourceDic() {
|
|
23
|
+
return this._resourceDic;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 是否已包含指定文件
|
|
27
|
+
* @param filePath 文件路径
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
include(filePath) {
|
|
31
|
+
return this.resourceDic[filePath];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 添加资源
|
|
35
|
+
* @param data
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
addResource(data) {
|
|
39
|
+
const { fileBuildPath } = data;
|
|
40
|
+
if (this.include(fileBuildPath)) {
|
|
41
|
+
ColorConsole2_1.default.throw(`File ${fileBuildPath} is added repeatedly`);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
this._resourceDic[fileBuildPath] = true;
|
|
45
|
+
this._resourceList.push(data);
|
|
46
|
+
}
|
|
47
|
+
constructor(data) {
|
|
48
|
+
/**
|
|
49
|
+
* 是否为独立包
|
|
50
|
+
*/
|
|
51
|
+
this.standalone = false;
|
|
52
|
+
this._resourceList = [];
|
|
53
|
+
this._resourceDic = {};
|
|
54
|
+
Object.assign(this, data);
|
|
55
|
+
this.fileName = [this.filePrefix, this.fileSubname, this.fileSuffix]
|
|
56
|
+
.filter((item) => Boolean(item))
|
|
57
|
+
.join('.');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.default = Package;
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=Package.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["compiler/javascript/vela/model/Package.ts"],"names":[],"mappings":";;;;;AAAA,iGAAwE;AAwBxE;;;;GAIG;AACH,MAAM,OAAO;IAoCX;;OAEG;IACH,IAAW,YAAY;QACrB,OAAO,IAAI,CAAC,aAAa,CAAA;IAC3B,CAAC;IAID;;OAEG;IACH,IAAW,WAAW;QACpB,OAAO,IAAI,CAAC,YAAY,CAAA;IAC1B,CAAC;IAED;;;;OAIG;IACI,OAAO,CAAC,QAAgB;QAC7B,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;IACnC,CAAC;IAED;;;;OAIG;IACI,WAAW,CAAC,IAAmB;QACpC,MAAM,EAAE,aAAa,EAAE,GAAG,IAAI,CAAA;QAC9B,IAAI,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE;YAC/B,uBAAa,CAAC,KAAK,CAAC,QAAQ,aAAa,sBAAsB,CAAC,CAAA;YAChE,OAAM;SACP;QACD,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,GAAG,IAAI,CAAA;QACvC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC/B,CAAC;IAED,YAAY,IAAsB;QAjElC;;WAEG;QACH,eAAU,GAAY,KAAK,CAAA;QAoBnB,kBAAa,GAAoB,EAAE,CAAA;QASnC,iBAAY,GAAwB,EAAE,CAAA;QAkC5C,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAEzB,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,UAAU,CAAC;aACjE,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;aAC/B,IAAI,CAAC,GAAG,CAAC,CAAA;IACd,CAAC;CACF;AACD,kBAAe,OAAO,CAAA","file":"Package.js","sourcesContent":["import ColorConsole2 from '@aiot-toolkit/shared-utils/lib/ColorConsole2'\nimport { Dictionary } from '@aiot-toolkit/shared-utils/lib/type/Type'\n\n/**\n * 文件资源\n */\nexport interface IFileResource {\n /**\n * 文件路径\n */\n fileBuildPath: string\n\n /**\n * 文件内容\n */\n fileContentBuffer: Buffer\n\n /**\n * 文件摘要\n * 文件内容生成的 hash 值\n */\n fileContentDigest?: Uint8Array\n}\n\n/**\n * 定义文件包\n *\n * 相当于虚拟的 rpk 包\n */\nclass Package {\n /**\n * 包前缀\n */\n filePrefix?: string\n\n /**\n * 子包名称;整包没有\n */\n fileSubname?: string\n\n /**\n * 是否为独立包\n */\n standalone: boolean = false\n\n /**\n * 后缀名\n */\n fileSuffix?: string\n\n icon?: string\n\n banner?: string\n\n comment?: string\n\n /**\n * 资源路径匹配\n */\n subMatch?: RegExp\n\n readonly fileName: string\n\n private _resourceList: IFileResource[] = []\n\n /**\n * 资源文件列表\n */\n public get resourceList(): IFileResource[] {\n return this._resourceList\n }\n\n private _resourceDic: Dictionary<boolean> = {}\n\n /**\n * 资源文件字典,以高效检查资源是否存在\n */\n public get resourceDic(): Dictionary<boolean> {\n return this._resourceDic\n }\n\n /**\n * 是否已包含指定文件\n * @param filePath 文件路径\n * @returns\n */\n public include(filePath: string) {\n return this.resourceDic[filePath]\n }\n\n /**\n * 添加资源\n * @param data\n * @returns\n */\n public addResource(data: IFileResource) {\n const { fileBuildPath } = data\n if (this.include(fileBuildPath)) {\n ColorConsole2.throw(`File ${fileBuildPath} is added repeatedly`)\n return\n }\n this._resourceDic[fileBuildPath] = true\n this._resourceList.push(data)\n }\n\n constructor(data: Partial<Package>) {\n Object.assign(this, data)\n\n this.fileName = [this.filePrefix, this.fileSubname, this.fileSuffix]\n .filter((item) => Boolean(item))\n .join('.')\n }\n}\nexport default Package\n"],"sourceRoot":"../../../../../src"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const webpack_1 = require("webpack");
|
|
4
|
+
const webpack_sources_1 = require("webpack-sources");
|
|
5
|
+
class WrapPlugin {
|
|
6
|
+
apply(compiler) {
|
|
7
|
+
// 给入口文件加上包裹函数
|
|
8
|
+
compiler.hooks.compilation.tap('WrapPlugin', (compilation) => {
|
|
9
|
+
compilation.hooks.processAssets.tap({
|
|
10
|
+
name: 'WrapPlugin',
|
|
11
|
+
stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE
|
|
12
|
+
}, () => {
|
|
13
|
+
this.wrap(compilation);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
wrap(compilation) {
|
|
18
|
+
// 获取入口文件
|
|
19
|
+
const entrys = Object.keys(compilation.options.entry).map((item) => `${item}.js`);
|
|
20
|
+
// 从chunk找到所有入口文件,添加包裹函数
|
|
21
|
+
entrys.forEach((entry) => {
|
|
22
|
+
if (compilation.assets[entry]) {
|
|
23
|
+
const content = compilation.assets[entry].source().toString();
|
|
24
|
+
compilation.assets[entry] = new webpack_sources_1.ConcatSource(this.wrapFunction(content));
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
wrapFunction(code) {
|
|
29
|
+
return `
|
|
30
|
+
export default function(global, globalThis, window, $app_exports$, $app_evaluate$){
|
|
31
|
+
var org_app_require = $app_require$;
|
|
32
|
+
|
|
33
|
+
(function(global, globalThis, window, $app_exports$, $app_evaluate$){
|
|
34
|
+
var setTimeout = global.setTimeout;
|
|
35
|
+
var setInterval = global.setInterval;
|
|
36
|
+
var clearTimeout = global.clearTimeout;
|
|
37
|
+
var clearInterval = global.clearInterval;
|
|
38
|
+
var $app_require$ = global.$app_require$ || org_app_require
|
|
39
|
+
|
|
40
|
+
var createPageHandler = function() {
|
|
41
|
+
return ${code}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return createPageHandler();
|
|
45
|
+
})(global, globalThis, window, $app_exports$, $app_evaluate$)
|
|
46
|
+
}`;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.default = WrapPlugin;
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=WrapPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["compiler/javascript/vela/plugin/WrapPlugin.ts"],"names":[],"mappings":";;AAAA,qCAA+C;AAC/C,qDAA8C;AAE9C,MAAM,UAAU;IACd,KAAK,CAAC,QAAkB;QACtB,cAAc;QACd,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC,WAAW,EAAE,EAAE;YAC3D,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,CACjC;gBACE,IAAI,EAAE,YAAY;gBAClB,KAAK,EAAE,qBAAW,CAAC,6BAA6B;aACjD,EACD,GAAG,EAAE;gBACH,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;YACxB,CAAC,CACF,CAAA;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;IAEO,IAAI,CAAC,WAAwB;QACnC,SAAS;QACT,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,KAAK,CAAC,CAAA;QAEjF,wBAAwB;QACxB,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YACvB,IAAI,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;gBAC7B,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAA;gBAC7D,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,8BAAY,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAQ,CAAA;aAChF;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;IAEO,YAAY,CAAC,IAAY;QAC/B,OAAO;;;;;;;;;;;;eAYI,IAAI;;;;;EAKjB,CAAA;IACA,CAAC;CACF;AAED,kBAAe,UAAU,CAAA","file":"WrapPlugin.js","sourcesContent":["import { Compilation, Compiler } from 'webpack'\nimport { ConcatSource } from 'webpack-sources'\n\nclass WrapPlugin {\n apply(compiler: Compiler) {\n // 给入口文件加上包裹函数\n compiler.hooks.compilation.tap('WrapPlugin', (compilation) => {\n compilation.hooks.processAssets.tap(\n {\n name: 'WrapPlugin',\n stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE\n },\n () => {\n this.wrap(compilation)\n }\n )\n })\n }\n\n private wrap(compilation: Compilation) {\n // 获取入口文件\n const entrys = Object.keys(compilation.options.entry).map((item) => `${item}.js`)\n\n // 从chunk找到所有入口文件,添加包裹函数\n entrys.forEach((entry) => {\n if (compilation.assets[entry]) {\n const content = compilation.assets[entry].source().toString()\n compilation.assets[entry] = new ConcatSource(this.wrapFunction(content)) as any\n }\n })\n }\n\n private wrapFunction(code: string) {\n return `\nexport default function(global, globalThis, window, $app_exports$, $app_evaluate$){\n var org_app_require = $app_require$;\n\n (function(global, globalThis, window, $app_exports$, $app_evaluate$){\n var setTimeout = global.setTimeout;\n var setInterval = global.setInterval;\n var clearTimeout = global.clearTimeout;\n var clearInterval = global.clearInterval;\n var $app_require$ = global.$app_require$ || org_app_require\n\n var createPageHandler = function() {\n return ${code}\n }\n\n return createPageHandler();\n })(global, globalThis, window, $app_exports$, $app_evaluate$)\n}`\n }\n}\n\nexport default WrapPlugin\n"],"sourceRoot":"../../../../../src"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const ColorConsole2_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole2"));
|
|
7
|
+
const CommonUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/CommonUtil"));
|
|
8
|
+
const del_1 = __importDefault(require("del"));
|
|
9
|
+
/**
|
|
10
|
+
* Jsc
|
|
11
|
+
*/
|
|
12
|
+
class Jsc {
|
|
13
|
+
constructor(projectPath, buildPath) {
|
|
14
|
+
this.projectPath = projectPath;
|
|
15
|
+
this.buildPath = buildPath;
|
|
16
|
+
}
|
|
17
|
+
jsc() {
|
|
18
|
+
const { projectPath, buildPath } = this;
|
|
19
|
+
return CommonUtil_1.default.requireModule(projectPath, `@aiot-toolkit/jsc`)
|
|
20
|
+
.then((module) => {
|
|
21
|
+
return module.default(buildPath);
|
|
22
|
+
})
|
|
23
|
+
.then(() => {
|
|
24
|
+
return (0, del_1.default)(`${buildPath}/**/*.js`);
|
|
25
|
+
})
|
|
26
|
+
.catch((error) => {
|
|
27
|
+
ColorConsole2_1.default.error(error.message);
|
|
28
|
+
process.exit();
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.default = Jsc;
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=Jsc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["compiler/javascript/vela/utils/Jsc.ts"],"names":[],"mappings":";;;;;AAAA,iGAAwE;AACxE,iGAAwE;AACxE,8CAAqB;AACrB;;GAEG;AACH,MAAM,GAAG;IACP,YACkB,WAAmB,EACnB,SAAiB;QADjB,gBAAW,GAAX,WAAW,CAAQ;QACnB,cAAS,GAAT,SAAS,CAAQ;IAChC,CAAC;IAEJ,GAAG;QACD,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,IAAI,CAAA;QACvC,OAAO,oBAAU,CAAC,aAAa,CAAC,WAAW,EAAE,mBAAmB,CAAC;aAC9D,IAAI,CAAC,CAAC,MAAW,EAAE,EAAE;YACpB,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;QAClC,CAAC,CAAC;aACD,IAAI,CAAC,GAAG,EAAE;YACT,OAAO,IAAA,aAAG,EAAC,GAAG,SAAS,UAAU,CAAC,CAAA;QACpC,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAY,EAAE,EAAE;YACtB,uBAAa,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;YAClC,OAAO,CAAC,IAAI,EAAE,CAAA;QAChB,CAAC,CAAC,CAAA;IACN,CAAC;CACF;AACD,kBAAe,GAAG,CAAA","file":"Jsc.js","sourcesContent":["import ColorConsole2 from '@aiot-toolkit/shared-utils/lib/ColorConsole2'\nimport CommonUtil from '@aiot-toolkit/shared-utils/lib/utils/CommonUtil'\nimport del from 'del'\n/**\n * Jsc\n */\nclass Jsc {\n constructor(\n public readonly projectPath: string,\n public readonly buildPath: string\n ) {}\n\n jsc() {\n const { projectPath, buildPath } = this\n return CommonUtil.requireModule(projectPath, `@aiot-toolkit/jsc`)\n .then((module: any) => {\n return module.default(buildPath)\n })\n .then(() => {\n return del(`${buildPath}/**/*.js`)\n })\n .catch((error: Error) => {\n ColorConsole2.error(error.message)\n process.exit()\n })\n }\n}\nexport default Jsc\n"],"sourceRoot":"../../../../../src"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Dictionary } from '@aiot-toolkit/shared-utils/lib/type/Type';
|
|
2
|
+
declare class UxCompileUtil {
|
|
3
|
+
static readonly DIGEST_ZIP_DIR = "META-INF";
|
|
4
|
+
static clean(dirList: string[]): void;
|
|
5
|
+
/**
|
|
6
|
+
* 从项目配置文件中解析出入口文件
|
|
7
|
+
* @param config 项目配置文件的内容,应为json对象
|
|
8
|
+
* @param codeDir 源码目录
|
|
9
|
+
* @param projectPath 项目目录
|
|
10
|
+
* @returns {[入口名]:源文件路径}
|
|
11
|
+
*/
|
|
12
|
+
static resolveEntries(config: any, codeDir: string, projectPath: string): Dictionary<string>;
|
|
13
|
+
/**
|
|
14
|
+
* 通过无后缀的文件名路径获取存在的文件路径
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const path = resolveFile('/project/a')
|
|
18
|
+
* // path = '/project/a.ux'
|
|
19
|
+
* @param filePath
|
|
20
|
+
*/
|
|
21
|
+
static resolveFile(filePath: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* 获取ux文件支持的后缀列表
|
|
24
|
+
* @param withDot
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
static getExtensionList(withDot?: boolean): string[];
|
|
28
|
+
}
|
|
29
|
+
export default UxCompileUtil;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const EntryType_1 = __importDefault(require("../enum/EntryType"));
|
|
9
|
+
class UxCompileUtil {
|
|
10
|
+
static clean(dirList) {
|
|
11
|
+
if (!dirList) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
dirList.forEach((item) => {
|
|
15
|
+
if (fs_extra_1.default.existsSync(item)) {
|
|
16
|
+
if (fs_extra_1.default.statSync(item).isFile()) {
|
|
17
|
+
fs_extra_1.default.unlinkSync(item);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
fs_extra_1.default.rmdirSync(item, { recursive: true });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 从项目配置文件中解析出入口文件
|
|
27
|
+
* @param config 项目配置文件的内容,应为json对象
|
|
28
|
+
* @param codeDir 源码目录
|
|
29
|
+
* @param projectPath 项目目录
|
|
30
|
+
* @returns {[入口名]:源文件路径}
|
|
31
|
+
*/
|
|
32
|
+
static resolveEntries(config, codeDir, projectPath) {
|
|
33
|
+
const { router } = config;
|
|
34
|
+
if (!router) {
|
|
35
|
+
throw Error('No routing configured in manifest.json!');
|
|
36
|
+
}
|
|
37
|
+
const appFile = this.resolveFile(path_1.default.join(codeDir, 'app'));
|
|
38
|
+
if (!fs_extra_1.default.existsSync(appFile)) {
|
|
39
|
+
console.log(`app file does not exist`);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
const { pages = {}, widgets = {}, floatingWindows = {} } = router;
|
|
43
|
+
const confsList = [
|
|
44
|
+
{
|
|
45
|
+
confs: pages,
|
|
46
|
+
type: EntryType_1.default.PAGE
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
confs: floatingWindows,
|
|
50
|
+
type: EntryType_1.default.FLOAT
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
confs: widgets,
|
|
54
|
+
type: EntryType_1.default.CARD
|
|
55
|
+
}
|
|
56
|
+
];
|
|
57
|
+
// 1. 添加app
|
|
58
|
+
const result = {
|
|
59
|
+
app: `./${path_1.default.relative(projectPath, appFile)}?uxType=${EntryType_1.default.APP}`
|
|
60
|
+
};
|
|
61
|
+
// 2. 添加 route 配置的文件
|
|
62
|
+
confsList.forEach((item) => {
|
|
63
|
+
const { confs, type } = item;
|
|
64
|
+
Object.keys(confs).forEach((routePath) => {
|
|
65
|
+
if (/^\//.test(routePath)) {
|
|
66
|
+
throw new Error(`Compilation failed: please confirm that '${routePath}' configured by router.pages in manifest.json is the directory name`);
|
|
67
|
+
}
|
|
68
|
+
const conf = confs[routePath];
|
|
69
|
+
const entryKey = path_1.default.join(routePath, conf.component);
|
|
70
|
+
const filePath = this.resolveFile(path_1.default.join(codeDir, entryKey));
|
|
71
|
+
if (!filePath) {
|
|
72
|
+
throw new Error(`Compilation failed: please confirm that the file path ${entryKey} configured in manifest.json exists`);
|
|
73
|
+
}
|
|
74
|
+
let sourceFile = `./${path_1.default.relative(projectPath, filePath)}?uxType=${type}`;
|
|
75
|
+
sourceFile = sourceFile.replace(/\\/g, '/');
|
|
76
|
+
result[entryKey] = sourceFile;
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
// 3. 添加 workers
|
|
80
|
+
const { workers } = config;
|
|
81
|
+
if (workers && workers.entries && Array.isArray(workers.entries)) {
|
|
82
|
+
workers.entries
|
|
83
|
+
.filter((worker) => worker.file)
|
|
84
|
+
.forEach((worker) => {
|
|
85
|
+
result[worker.file.replace(/\.js$/, '')] = './src/' + worker.file;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
// 4. 添加 services
|
|
89
|
+
const { services } = config;
|
|
90
|
+
// 数组格式
|
|
91
|
+
if (Array.isArray(services)) {
|
|
92
|
+
services.forEach((item) => {
|
|
93
|
+
const { name, path } = item;
|
|
94
|
+
if (name && path) {
|
|
95
|
+
result['services/' + name] = './src/' + path + `?uxType=${EntryType_1.default.APP}`;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
// 字典格式
|
|
100
|
+
else {
|
|
101
|
+
for (const key in services) {
|
|
102
|
+
if (Object.hasOwnProperty.call(services, key)) {
|
|
103
|
+
result['services/' + key] = './src/' + services[key].path + `?uxType=${EntryType_1.default.APP}`;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* 通过无后缀的文件名路径获取存在的文件路径
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* const path = resolveFile('/project/a')
|
|
114
|
+
* // path = '/project/a.ux'
|
|
115
|
+
* @param filePath
|
|
116
|
+
*/
|
|
117
|
+
static resolveFile(filePath) {
|
|
118
|
+
const extensionList = this.getExtensionList();
|
|
119
|
+
for (const item of extensionList) {
|
|
120
|
+
const currentPath = `${filePath}${item}`;
|
|
121
|
+
if (fs_extra_1.default.existsSync(currentPath)) {
|
|
122
|
+
return currentPath;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return '';
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 获取ux文件支持的后缀列表
|
|
129
|
+
* @param withDot
|
|
130
|
+
* @returns
|
|
131
|
+
*/
|
|
132
|
+
static getExtensionList(withDot = true) {
|
|
133
|
+
const result = ['js'];
|
|
134
|
+
if (withDot) {
|
|
135
|
+
return result.map((item) => `.${item}`);
|
|
136
|
+
}
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// 摘要文件夹
|
|
141
|
+
UxCompileUtil.DIGEST_ZIP_DIR = 'META-INF';
|
|
142
|
+
exports.default = UxCompileUtil;
|
|
143
|
+
|
|
144
|
+
//# sourceMappingURL=UxCompileUtil.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["compiler/javascript/vela/utils/UxCompileUtil.ts"],"names":[],"mappings":";;;;;AACA,wDAAyB;AACzB,gDAAuB;AACvB,kEAAyC;AAEzC,MAAM,aAAa;IAIjB,MAAM,CAAC,KAAK,CAAC,OAAiB;QAC5B,IAAI,CAAC,OAAO,EAAE;YACZ,OAAM;SACP;QAED,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACvB,IAAI,kBAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;gBACvB,IAAI,kBAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;oBAC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,CAAA;aACnB;SACF;QACD,OAAO,EAAE,CAAA;IACX,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,gBAAgB,CAAC,OAAO,GAAG,IAAI;QACpC,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC,CAAA;QAErB,IAAI,OAAO,EAAE;YACX,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAA;SACxC;QAED,OAAO,MAAM,CAAA;IACf,CAAC;;AAnJD,QAAQ;AACQ,4BAAc,GAAG,UAAU,CAAA;AAqJ7C,kBAAe,aAAa,CAAA","file":"UxCompileUtil.js","sourcesContent":["import { Dictionary } from '@aiot-toolkit/shared-utils/lib/type/Type'\nimport fs from 'fs-extra'\nimport path from 'path'\nimport EntryType from '../enum/EntryType'\n\nclass UxCompileUtil {\n // 摘要文件夹\n static readonly DIGEST_ZIP_DIR = 'META-INF'\n\n static clean(dirList: string[]) {\n if (!dirList) {\n return\n }\n\n dirList.forEach((item) => {\n if (fs.existsSync(item)) {\n if (fs.statSync(item).isFile()) {\n fs.unlinkSync(item)\n } else {\n fs.rmdirSync(item, { recursive: true })\n }\n }\n })\n }\n\n /**\n * 从项目配置文件中解析出入口文件\n * @param config 项目配置文件的内容,应为json对象\n * @param codeDir 源码目录\n * @param projectPath 项目目录\n * @returns {[入口名]:源文件路径}\n */\n static resolveEntries(config: any, codeDir: string, projectPath: string): Dictionary<string> {\n const { router } = config\n if (!router) {\n throw Error('No routing configured in manifest.json!')\n }\n\n const appFile = this.resolveFile(path.join(codeDir, 'app'))\n if (!fs.existsSync(appFile)) {\n console.log(`app file does not exist`)\n process.exit(1)\n }\n\n const { pages = {}, widgets = {}, floatingWindows = {} } = router\n const confsList = [\n {\n confs: pages,\n type: EntryType.PAGE\n },\n {\n confs: floatingWindows,\n type: EntryType.FLOAT\n },\n {\n confs: widgets,\n type: EntryType.CARD\n }\n ]\n\n // 1. 添加app\n const result: { [key: string]: any } = {\n app: `./${path.relative(projectPath, appFile)}?uxType=${EntryType.APP}`\n }\n\n // 2. 添加 route 配置的文件\n confsList.forEach((item) => {\n const { confs, type } = item\n Object.keys(confs).forEach((routePath) => {\n if (/^\\//.test(routePath)) {\n throw new Error(\n `Compilation failed: please confirm that '${routePath}' configured by router.pages in manifest.json is the directory name`\n )\n }\n const conf = confs[routePath]\n const entryKey = path.join(routePath, conf.component)\n const filePath = this.resolveFile(path.join(codeDir, entryKey))\n if (!filePath) {\n throw new Error(\n `Compilation failed: please confirm that the file path ${entryKey} configured in manifest.json exists`\n )\n }\n\n let sourceFile = `./${path.relative(projectPath, filePath)}?uxType=${type}`\n sourceFile = sourceFile.replace(/\\\\/g, '/')\n result[entryKey] = sourceFile\n })\n })\n\n // 3. 添加 workers\n const { workers } = config\n if (workers && workers.entries && Array.isArray(workers.entries)) {\n workers.entries\n .filter((worker: any) => worker.file)\n .forEach((worker: any) => {\n result[worker.file.replace(/\\.js$/, '')] = './src/' + worker.file\n })\n }\n\n // 4. 添加 services\n const { services } = config\n // 数组格式\n if (Array.isArray(services)) {\n services.forEach((item) => {\n const { name, path } = item\n if (name && path) {\n result['services/' + name] = './src/' + path + `?uxType=${EntryType.APP}`\n }\n })\n }\n // 字典格式\n else {\n for (const key in services) {\n if (Object.hasOwnProperty.call(services, key)) {\n result['services/' + key] = './src/' + services[key].path + `?uxType=${EntryType.APP}`\n }\n }\n }\n return result\n }\n\n /**\n * 通过无后缀的文件名路径获取存在的文件路径\n *\n * @example\n * const path = resolveFile('/project/a')\n * // path = '/project/a.ux'\n * @param filePath\n */\n static resolveFile(filePath: string) {\n const extensionList = this.getExtensionList()\n for (const item of extensionList) {\n const currentPath = `${filePath}${item}`\n if (fs.existsSync(currentPath)) {\n return currentPath\n }\n }\n return ''\n }\n\n /**\n * 获取ux文件支持的后缀列表\n * @param withDot\n * @returns\n */\n static getExtensionList(withDot = true) {\n const result = ['js']\n\n if (withDot) {\n return result.map((item) => `.${item}`)\n }\n\n return result\n }\n}\n\nexport default UxCompileUtil\n"],"sourceRoot":"../../../../../src"}
|