@aiot-toolkit/aiotpack 2.0.2-dev.8 → 2.0.3-beta.1
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/{utils/ux/UxFollowWorks.d.ts → afterCompile/ux/UxAfterCompile.d.ts} +11 -4
- package/lib/{utils/ux/UxFollowWorks.js → afterCompile/ux/UxAfterCompile.js} +95 -44
- package/lib/{followWorks → afterCompile}/xts/entryTemplate.d.ts +1 -1
- package/lib/{followWorks → afterCompile}/xts/entryTemplate.js +14 -13
- package/lib/{followWorks → afterCompile}/xts/generateRpk.d.ts +1 -1
- package/lib/{followWorks → afterCompile}/xts/generateRpk.js +5 -4
- package/lib/{followWorks → afterCompile}/xts/ts2wasm.d.ts +1 -1
- package/lib/{followWorks → afterCompile}/xts/ts2wasm.js +7 -6
- package/lib/afterWorks/ux/UxAfterWorks.d.ts +5 -0
- package/lib/afterWorks/ux/UxAfterWorks.js +22 -0
- package/lib/{utils/ux/UxPreWorks.d.ts → beforeCompile/ux/UxBeforeCompile.d.ts} +4 -4
- package/lib/{utils/ux/UxPreWorks.js → beforeCompile/ux/UxBeforeCompile.js} +11 -8
- package/lib/{preWorks → beforeCompile}/xts/preInstall.d.ts +1 -1
- package/lib/{preWorks → beforeCompile}/xts/preInstall.js +6 -5
- package/lib/beforeWorks/ux/UxBeforeWorks.d.ts +5 -0
- package/lib/beforeWorks/ux/UxBeforeWorks.js +22 -0
- package/lib/compiler/interface/ICompileParam.d.ts +1 -1
- package/lib/compiler/interface/ISignConfig.d.ts +6 -1
- package/lib/compiler/javascript/JavascriptCompiler.js +45 -12
- package/lib/compiler/javascript/JavascriptDefaultCompileOption.js +1 -2
- package/lib/compiler/javascript/android/AndroidWebpackConfigurator.d.ts +9 -0
- package/lib/compiler/javascript/android/AndroidWebpackConfigurator.js +16 -0
- package/lib/compiler/javascript/android/plugin/WrapPlugin.d.ts +20 -0
- package/lib/compiler/javascript/android/plugin/WrapPlugin.js +91 -0
- package/lib/compiler/javascript/interface/IJavascriptCompileOption.d.ts +16 -1
- package/lib/compiler/javascript/interface/IWebpackConfigurator.d.ts +4 -4
- package/lib/compiler/javascript/vela/VelaWebpackConfigurator.d.ts +4 -2
- package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js +18 -5
- package/lib/compiler/javascript/vela/interface/IChunk.d.ts +6 -1
- package/lib/compiler/javascript/vela/interface/IManifest.d.ts +1 -1
- package/lib/compiler/javascript/vela/interface/IQuickAppConfig.d.ts +1 -1
- package/lib/compiler/javascript/vela/model/Package.d.ts +2 -2
- package/lib/compiler/javascript/vela/model/Package.js +5 -5
- package/lib/compiler/javascript/vela/plugin/WrapPlugin.d.ts +1 -1
- package/lib/compiler/javascript/vela/plugin/WrapPlugin.js +16 -2
- package/lib/compiler/javascript/vela/utils/Jsc.d.ts +1 -1
- package/lib/compiler/javascript/vela/utils/Jsc.js +19 -11
- package/lib/compiler/javascript/vela/utils/UxCompileUtil.d.ts +1 -1
- package/lib/compiler/javascript/vela/utils/UxCompileUtil.js +4 -4
- package/lib/compiler/javascript/vela/utils/ZipUtil.d.ts +29 -5
- package/lib/compiler/javascript/vela/utils/ZipUtil.js +45 -31
- package/lib/compiler/javascript/vela/utils/signature/Base64.d.ts +0 -1
- package/lib/compiler/javascript/vela/utils/signature/SignUtil.d.ts +23 -7
- package/lib/compiler/javascript/vela/utils/signature/SignUtil.js +94 -45
- package/lib/compiler/javascript/vela/utils/signature/Signer.d.ts +0 -1
- package/lib/compiler/javascript/vela/utils/webpackLoader/addColSourceMap.d.ts +3 -0
- package/lib/compiler/javascript/vela/utils/webpackLoader/addColSourceMap.js +56 -0
- package/lib/compiler/javascript/vela/utils/webpackLoader/extractMapData.d.ts +3 -0
- package/lib/compiler/javascript/vela/utils/webpackLoader/{splitMap.js → extractMapData.js} +2 -2
- package/lib/config/UxConfig.d.ts +45 -7
- package/lib/config/UxConfig.js +156 -40
- package/lib/config/XtsConfig.d.ts +8 -4
- package/lib/config/XtsConfig.js +24 -8
- package/lib/index.d.ts +9 -1
- package/lib/index.js +35 -1
- package/lib/loader/ux/JsLoader.d.ts +2 -0
- package/lib/loader/ux/JsLoader.js +6 -9
- package/lib/loader/ux/PngLoader.js +4 -5
- package/lib/loader/ux/android/UxLoader.d.ts +13 -0
- package/lib/loader/ux/android/UxLoader.js +38 -0
- package/lib/loader/ux/{AppUxLoader.d.ts → vela/AppUxLoader.d.ts} +3 -1
- package/lib/loader/ux/{AppUxLoader.js → vela/AppUxLoader.js} +5 -3
- package/lib/loader/ux/vela/HmlLoader.d.ts +24 -0
- package/lib/loader/ux/vela/HmlLoader.js +63 -0
- package/lib/loader/ux/{UxLoader.d.ts → vela/UxLoader.d.ts} +3 -1
- package/lib/loader/ux/{UxLoader.js → vela/UxLoader.js} +11 -14
- package/lib/loader/xts/XtsLoader.js +6 -7
- package/lib/utils/BeforeCompileUtils.d.ts +21 -0
- package/lib/utils/BeforeCompileUtils.js +118 -0
- package/lib/utils/ux/ManifestSchema.d.ts +1 -1
- package/lib/utils/ux/UxFileUtils.d.ts +16 -3
- package/lib/utils/ux/UxFileUtils.js +53 -17
- package/lib/utils/ux/UxLoaderUtils.d.ts +7 -4
- package/lib/utils/ux/UxLoaderUtils.js +43 -25
- package/lib/utils/ux/android/AndroidUx.d.ts +27 -0
- package/lib/utils/ux/android/AndroidUx.js +98 -0
- package/lib/utils/xts/XtsFileLaneUtils.d.ts +10 -0
- package/lib/utils/xts/XtsFileLaneUtils.js +68 -0
- package/lib/utils/xts/XtsFollowWorks.js +8 -8
- package/package.json +15 -8
- package/lib/compiler/javascript/vela/utils/webpackLoader/splitMap.d.ts +0 -3
- package/lib/utils/PreWorkUtils.d.ts +0 -22
- package/lib/utils/PreWorkUtils.js +0 -106
|
@@ -0,0 +1,63 @@
|
|
|
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 path_1 = __importDefault(require("path"));
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const parser_1 = require("@aiot-toolkit/parser");
|
|
9
|
+
/**
|
|
10
|
+
* HmlLoader
|
|
11
|
+
*/
|
|
12
|
+
class HmlLoader {
|
|
13
|
+
parser(files) {
|
|
14
|
+
return files.map((file) => {
|
|
15
|
+
return this.wrapHml(file);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 包裹 hml 文件
|
|
20
|
+
*
|
|
21
|
+
* # 路径
|
|
22
|
+
* 如果存在同路径的 ux 后缀,报错;否则转换为同路径的 ux 后缀
|
|
23
|
+
*
|
|
24
|
+
* # 内容
|
|
25
|
+
* 1. 给hml的内容加上<template></template>
|
|
26
|
+
* 2. 如果存在同路径同名的 script文件,则加到<script></script>中
|
|
27
|
+
* 3. 如果存在同路径同名的 style文件,则加到<style></style>中
|
|
28
|
+
*
|
|
29
|
+
* @param file
|
|
30
|
+
*/
|
|
31
|
+
wrapHml(file) {
|
|
32
|
+
const { path, content } = file;
|
|
33
|
+
const uxExt = parser_1.ExtensionConfig.UX;
|
|
34
|
+
const getFilePath = (ext) => {
|
|
35
|
+
const pathParsed = path_1.default.parse(path);
|
|
36
|
+
pathParsed.ext = ext;
|
|
37
|
+
pathParsed.base = pathParsed.name + ext;
|
|
38
|
+
return path_1.default.format(pathParsed);
|
|
39
|
+
};
|
|
40
|
+
const uxPath = getFilePath(uxExt);
|
|
41
|
+
if (fs_1.default.existsSync(uxPath)) {
|
|
42
|
+
throw new Error(`${uxPath} already exists`);
|
|
43
|
+
}
|
|
44
|
+
const scriptExts = parser_1.ExtensionConfig.SCRIPTS;
|
|
45
|
+
const styleExts = parser_1.ExtensionConfig.STYLES;
|
|
46
|
+
const scriptPath = scriptExts
|
|
47
|
+
.map((item) => getFilePath(item))
|
|
48
|
+
.find((item) => fs_1.default.existsSync(item));
|
|
49
|
+
const stylePath = styleExts.map((item) => getFilePath(item)).find((item) => fs_1.default.existsSync(item));
|
|
50
|
+
let uxContent = ['<template>', content, '</template>'].join('\n');
|
|
51
|
+
if (scriptPath) {
|
|
52
|
+
uxContent += ['<script>', fs_1.default.readFileSync(scriptPath, 'utf-8'), '</script>'].join('\n');
|
|
53
|
+
}
|
|
54
|
+
if (stylePath) {
|
|
55
|
+
uxContent += ['<style>', fs_1.default.readFileSync(stylePath, 'utf-8'), '</style>'].join('\n');
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
path,
|
|
59
|
+
content: uxContent
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.default = HmlLoader;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { IFileLaneContext, IFileParam, ILoader } from 'file-lane';
|
|
2
|
-
import IJavascriptCompileOption from '
|
|
2
|
+
import IJavascriptCompileOption from '../../../compiler/javascript/interface/IJavascriptCompileOption';
|
|
3
|
+
import { ILog } from '@aiot-toolkit/shared-utils/lib/interface/ILog';
|
|
3
4
|
declare class UxLoader implements ILoader {
|
|
4
5
|
context: IFileLaneContext;
|
|
5
6
|
compilerOption: IJavascriptCompileOption;
|
|
7
|
+
logs?: ILog[] | undefined;
|
|
6
8
|
parser(files: IFileParam<any>[]): Promise<IFileParam<any>[]>;
|
|
7
9
|
}
|
|
8
10
|
export default UxLoader;
|
|
@@ -12,10 +12,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
16
|
-
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
17
15
|
const path_1 = __importDefault(require("path"));
|
|
18
|
-
const UxLoaderUtils_1 = __importDefault(require("
|
|
16
|
+
const UxLoaderUtils_1 = __importDefault(require("../../../utils/ux/UxLoaderUtils"));
|
|
19
17
|
class UxLoader {
|
|
20
18
|
parser(files) {
|
|
21
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -23,17 +21,16 @@ class UxLoader {
|
|
|
23
21
|
const { projectPath } = this.context;
|
|
24
22
|
for (const file of files) {
|
|
25
23
|
// 转换每个文件
|
|
26
|
-
const { files, logs } = yield UxLoaderUtils_1.default.compileUxToJavascript(file, this.context, false, this.compilerOption);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
resultFiles.push(...files);
|
|
24
|
+
const { files: compiledFiles, logs } = yield UxLoaderUtils_1.default.compileUxToJavascript(file, this.context, false, this.compilerOption);
|
|
25
|
+
this.logs = logs.map((item) => {
|
|
26
|
+
var _a;
|
|
27
|
+
return Object.assign(Object.assign({}, item), { filePath: ((_a = item.position) === null || _a === void 0 ? void 0 : _a.source)
|
|
28
|
+
? item.position.source
|
|
29
|
+
: item.filePath
|
|
30
|
+
? path_1.default.relative(projectPath, item.filePath)
|
|
31
|
+
: '' });
|
|
32
|
+
});
|
|
33
|
+
resultFiles.push(...compiledFiles);
|
|
37
34
|
}
|
|
38
35
|
return resultFiles;
|
|
39
36
|
});
|
|
@@ -5,8 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const generator_1 = require("@aiot-toolkit/generator");
|
|
7
7
|
const parser_1 = require("@aiot-toolkit/parser");
|
|
8
|
-
const
|
|
9
|
-
const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
|
|
8
|
+
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
10
9
|
const path_1 = __importDefault(require("path"));
|
|
11
10
|
const ts_morph_1 = require("ts-morph");
|
|
12
11
|
/**
|
|
@@ -23,11 +22,11 @@ class XtsLoader {
|
|
|
23
22
|
const newFileName = `${name}.ts`;
|
|
24
23
|
//判断文本,空文本则结束该文件处理
|
|
25
24
|
if (!content) {
|
|
26
|
-
|
|
25
|
+
shared_utils_1.ColorConsole.warn(`The file '${fullName}' under the path '${path}' has no content `);
|
|
27
26
|
return [];
|
|
28
27
|
}
|
|
29
|
-
const parserResult = new parser_1.XtsParser(project,
|
|
30
|
-
const { ast, mapList } = new parser_1.XtsToTypescript(project,
|
|
28
|
+
const parserResult = new parser_1.XtsParser(project, shared_utils_1.ColorConsole.logger).parser(content.toString(), fullName);
|
|
29
|
+
const { ast, mapList } = new parser_1.XtsToTypescript(project, shared_utils_1.ColorConsole.logger, this.context, path).translate(parserResult.ast, parserResult.offsetList);
|
|
31
30
|
const { code, sourcemap } = new generator_1.TypescriptGenerator().generate({
|
|
32
31
|
sourceFilePath: fullName,
|
|
33
32
|
targetFilePath: newFileName,
|
|
@@ -35,10 +34,10 @@ class XtsLoader {
|
|
|
35
34
|
mapList
|
|
36
35
|
});
|
|
37
36
|
resultFiles.push({
|
|
38
|
-
path:
|
|
37
|
+
path: shared_utils_1.FileUtil.updateFileName(path, newFileName),
|
|
39
38
|
content: code
|
|
40
39
|
}, {
|
|
41
|
-
path:
|
|
40
|
+
path: shared_utils_1.FileUtil.updateFileName(path, `${name}.map.ts`),
|
|
42
41
|
content: sourcemap
|
|
43
42
|
});
|
|
44
43
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PreWork } from 'file-lane';
|
|
2
|
+
import IJavascriptCompileOption from '../compiler/javascript/interface/IJavascriptCompileOption';
|
|
3
|
+
/**
|
|
4
|
+
* BeforeCompileUtils
|
|
5
|
+
*/
|
|
6
|
+
declare class BeforeCompileUtils {
|
|
7
|
+
/**
|
|
8
|
+
* 获取ux项目的路由入口
|
|
9
|
+
* @param context
|
|
10
|
+
* @param fileList
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
static getEntries: PreWork;
|
|
14
|
+
static clean: PreWork;
|
|
15
|
+
/**
|
|
16
|
+
* 获取项目的全局样式变量配置
|
|
17
|
+
* @param context
|
|
18
|
+
*/
|
|
19
|
+
static getGlobalVar: PreWork<IJavascriptCompileOption>;
|
|
20
|
+
}
|
|
21
|
+
export default BeforeCompileUtils;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
var _a;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
const parser_1 = require("@aiot-toolkit/parser");
|
|
17
|
+
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
18
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
19
|
+
const path_1 = __importDefault(require("path"));
|
|
20
|
+
const TranslateCache_1 = __importDefault(require("@aiot-toolkit/parser/lib/ux/translate/vela/TranslateCache"));
|
|
21
|
+
const UxFileUtils_1 = __importDefault(require("./ux/UxFileUtils"));
|
|
22
|
+
const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
|
|
23
|
+
/**
|
|
24
|
+
* BeforeCompileUtils
|
|
25
|
+
*/
|
|
26
|
+
class BeforeCompileUtils {
|
|
27
|
+
}
|
|
28
|
+
_a = BeforeCompileUtils;
|
|
29
|
+
/**
|
|
30
|
+
* 获取ux项目的路由入口
|
|
31
|
+
* @param context
|
|
32
|
+
* @param fileList
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
BeforeCompileUtils.getEntries = (params) => {
|
|
36
|
+
const { context, compilerOption } = params;
|
|
37
|
+
const { projectPath } = context;
|
|
38
|
+
const srcPath = path_1.default.join(projectPath, compilerOption.sourceRoot);
|
|
39
|
+
// 判断路径是否真实存在
|
|
40
|
+
const manifestContent = UxFileUtils_1.default.getMainfestInfo(projectPath);
|
|
41
|
+
// 存储entries
|
|
42
|
+
let entryList = [];
|
|
43
|
+
const { router } = manifestContent;
|
|
44
|
+
if (router) {
|
|
45
|
+
const { pages } = router;
|
|
46
|
+
if (pages) {
|
|
47
|
+
Object.keys(pages).map((page) => {
|
|
48
|
+
const pageContent = pages[page];
|
|
49
|
+
const entryDir = path_1.default.join(srcPath, page);
|
|
50
|
+
const entryPages = parser_1.ExtensionConfig.TEMPLATES.map((item) => `${pageContent.component}${item}`);
|
|
51
|
+
const entry = entryPages.find((item) => fs_extra_1.default.existsSync(path_1.default.join(entryDir, item)));
|
|
52
|
+
if (entry) {
|
|
53
|
+
entryList.push(path_1.default.join(entryDir, entry));
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
// 路径不存在
|
|
57
|
+
shared_utils_1.ColorConsole.throw(`### manifest ### path '${path_1.default.join(entryDir, entryPages.join(' | '))}' does not exist`);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
// 没有pages配置
|
|
63
|
+
shared_utils_1.ColorConsole.throw(`### manifest ### No pages configuration`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
// 没有router配置
|
|
68
|
+
shared_utils_1.ColorConsole.throw(`### manifest ### No router configuration`);
|
|
69
|
+
}
|
|
70
|
+
context['entries'] = entryList;
|
|
71
|
+
return Promise.resolve();
|
|
72
|
+
};
|
|
73
|
+
BeforeCompileUtils.clean = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
74
|
+
const { context, compilerOption, compalition } = params;
|
|
75
|
+
if (compilerOption) {
|
|
76
|
+
// 存储build中的文件列表
|
|
77
|
+
const buildPath = path_1.default.join(context.projectPath, compilerOption.outputPath);
|
|
78
|
+
const buildFileList = fs_extra_1.default.existsSync(buildPath)
|
|
79
|
+
? shared_utils_1.FileUtil.readAlldirSync(buildPath).map((filePath) => {
|
|
80
|
+
const relativePath = path_1.default.relative(buildPath, filePath);
|
|
81
|
+
const fileContent = fs_extra_1.default.readFileSync(filePath);
|
|
82
|
+
return { path: relativePath, content: fileContent };
|
|
83
|
+
})
|
|
84
|
+
: [];
|
|
85
|
+
if (compalition) {
|
|
86
|
+
compalition.buildFileList = buildFileList;
|
|
87
|
+
}
|
|
88
|
+
// 清空build文件夹、dist文件夹
|
|
89
|
+
yield shared_utils_1.FileUtil.del(path_1.default.join(context.projectPath, compilerOption.outputPath));
|
|
90
|
+
yield shared_utils_1.FileUtil.del(path_1.default.join(context.projectPath, compilerOption.releasePath));
|
|
91
|
+
}
|
|
92
|
+
context.translateCache = new TranslateCache_1.default();
|
|
93
|
+
BinaryPlugin.reset();
|
|
94
|
+
BinaryPlugin.config = {
|
|
95
|
+
projectPath: context.projectPath,
|
|
96
|
+
outputProjectPath: path_1.default.join(context.projectPath, context.output),
|
|
97
|
+
source: compilerOption === null || compilerOption === void 0 ? void 0 : compilerOption.sourceRoot,
|
|
98
|
+
output: compilerOption === null || compilerOption === void 0 ? void 0 : compilerOption.outputPath
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
/**
|
|
102
|
+
* 获取项目的全局样式变量配置
|
|
103
|
+
* @param context
|
|
104
|
+
*/
|
|
105
|
+
BeforeCompileUtils.getGlobalVar = (params) => {
|
|
106
|
+
const { context, compilerOption } = params;
|
|
107
|
+
const { projectPath } = context;
|
|
108
|
+
const filePath = path_1.default.join(projectPath, (compilerOption === null || compilerOption === void 0 ? void 0 : compilerOption.sourceRoot) || '', 'globalVar.json');
|
|
109
|
+
let globalVar = {};
|
|
110
|
+
// 判断文件是否存在
|
|
111
|
+
if (fs_extra_1.default.existsSync(filePath)) {
|
|
112
|
+
// 存在则取内容,否则内容为空
|
|
113
|
+
globalVar = fs_extra_1.default.readJSONSync(filePath);
|
|
114
|
+
}
|
|
115
|
+
context.globalVar = globalVar;
|
|
116
|
+
return Promise.resolve();
|
|
117
|
+
};
|
|
118
|
+
exports.default = BeforeCompileUtils;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import FileLaneCompilation from 'file-lane/lib/FileLaneCompilation';
|
|
1
2
|
import IManifest from '../../compiler/javascript/vela/interface/IManifest';
|
|
2
3
|
export declare class UxFileUtils {
|
|
3
4
|
static readonly CONFIG_FILE_NAME = "manifest.json";
|
|
@@ -18,9 +19,10 @@ export declare class UxFileUtils {
|
|
|
18
19
|
/**
|
|
19
20
|
* 检查 manifest文件,并显示错误信息
|
|
20
21
|
*
|
|
21
|
-
* 1.
|
|
22
|
-
*
|
|
23
|
-
*
|
|
22
|
+
* 1. 使用ManifestSchema 校验
|
|
23
|
+
* 1. TypeError: Error
|
|
24
|
+
* 2. 其它: Warn
|
|
25
|
+
* 2. 检查 router.entry 是否存在于 router.pages
|
|
24
26
|
*
|
|
25
27
|
* @param projectPath 项目路径
|
|
26
28
|
* @param sourceRoot 源码路径--相对项目根目录
|
|
@@ -35,5 +37,16 @@ export declare class UxFileUtils {
|
|
|
35
37
|
* @param sourceRoot
|
|
36
38
|
*/
|
|
37
39
|
static validateSitemap(projectPath: string, sourceRoot?: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* 1. 遍历旧文件列表
|
|
42
|
+
* 1.1 若文件路径在新文件列表newFileList中,且内容一致时,从newFileList中移除该项
|
|
43
|
+
* 1.2 若文件路径在新文件列表newFileList中,且内容不一致时,添加到diffList中表示待更新,从newFileList中移除该项
|
|
44
|
+
* 1.3 若文件路径不在新文件列表中,表示该文件待删除(热更新时,可以不做删除,删除耗费性能)
|
|
45
|
+
* 2. 若遍历完旧文件列表后,newFileList长度不为0,表示有文件待新增
|
|
46
|
+
* @param oldFileList 旧文件列表
|
|
47
|
+
* @param newFileList 新文件列表
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
static getDiffJSON(compilation: FileLaneCompilation, newFileList: string[], buildPath: string): string[];
|
|
38
51
|
}
|
|
39
52
|
export default UxFileUtils;
|
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.UxFileUtils = void 0;
|
|
7
|
-
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
8
7
|
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
8
|
+
const ILog_1 = require("@aiot-toolkit/shared-utils/lib/interface/ILog");
|
|
9
9
|
const CommonUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/CommonUtil"));
|
|
10
10
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
11
11
|
const path_1 = __importDefault(require("path"));
|
|
@@ -32,9 +32,10 @@ class UxFileUtils {
|
|
|
32
32
|
/**
|
|
33
33
|
* 检查 manifest文件,并显示错误信息
|
|
34
34
|
*
|
|
35
|
-
* 1.
|
|
36
|
-
*
|
|
37
|
-
*
|
|
35
|
+
* 1. 使用ManifestSchema 校验
|
|
36
|
+
* 1. TypeError: Error
|
|
37
|
+
* 2. 其它: Warn
|
|
38
|
+
* 2. 检查 router.entry 是否存在于 router.pages
|
|
38
39
|
*
|
|
39
40
|
* @param projectPath 项目路径
|
|
40
41
|
* @param sourceRoot 源码路径--相对项目根目录
|
|
@@ -45,30 +46,29 @@ class UxFileUtils {
|
|
|
45
46
|
if (!fs_extra_1.default.existsSync(path)) {
|
|
46
47
|
ColorConsole_1.default.throw(`file is missing`, {
|
|
47
48
|
word: path,
|
|
48
|
-
style: ColorConsole_1.default.getStyle(
|
|
49
|
+
style: ColorConsole_1.default.getStyle(ILog_1.Loglevel.THROW)
|
|
49
50
|
});
|
|
50
51
|
}
|
|
52
|
+
// 1
|
|
51
53
|
const jsonData = this.getMainfestInfo(projectPath, sourceRoot);
|
|
52
54
|
const schema = ManifestSchema_1.default;
|
|
53
|
-
const errors = CommonUtil_1.default.validateJson(jsonData, schema);
|
|
54
|
-
|
|
55
|
+
const errors = CommonUtil_1.default.validateJson(jsonData, schema) || [];
|
|
56
|
+
// 2
|
|
57
|
+
const { entry, pages } = jsonData.router;
|
|
58
|
+
if (!pages[entry]) {
|
|
59
|
+
errors.push(new TypeError(`router.entry content: ${entry}, is missing in router.pages`));
|
|
60
|
+
}
|
|
61
|
+
if (errors === null || errors === void 0 ? void 0 : errors.length) {
|
|
55
62
|
ColorConsole_1.default.warn(`Manefest.json error: `, ...errors.map((item, index) => {
|
|
56
63
|
return {
|
|
57
64
|
word: `\r\n${index + 1}. ${item.message}`,
|
|
58
65
|
style: item instanceof TypeError
|
|
59
|
-
? ColorConsole_1.default.getStyle(
|
|
60
|
-
: ColorConsole_1.default.getStyle(
|
|
66
|
+
? ColorConsole_1.default.getStyle(ILog_1.Loglevel.ERROR)
|
|
67
|
+
: ColorConsole_1.default.getStyle(ILog_1.Loglevel.WARN)
|
|
61
68
|
};
|
|
62
69
|
}));
|
|
63
|
-
const stop = Boolean(errors.find((item) => item instanceof TypeError));
|
|
64
|
-
if (stop) {
|
|
65
|
-
ColorConsole_1.default.throw({
|
|
66
|
-
word: `missing required content, program stoped`,
|
|
67
|
-
style: ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Throw)
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
70
|
}
|
|
71
|
-
return errors;
|
|
71
|
+
return errors.length ? errors : undefined;
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
74
|
* 检查 sitemap.json 文件,并显示错误信息
|
|
@@ -97,6 +97,42 @@ class UxFileUtils {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* 1. 遍历旧文件列表
|
|
102
|
+
* 1.1 若文件路径在新文件列表newFileList中,且内容一致时,从newFileList中移除该项
|
|
103
|
+
* 1.2 若文件路径在新文件列表newFileList中,且内容不一致时,添加到diffList中表示待更新,从newFileList中移除该项
|
|
104
|
+
* 1.3 若文件路径不在新文件列表中,表示该文件待删除(热更新时,可以不做删除,删除耗费性能)
|
|
105
|
+
* 2. 若遍历完旧文件列表后,newFileList长度不为0,表示有文件待新增
|
|
106
|
+
* @param oldFileList 旧文件列表
|
|
107
|
+
* @param newFileList 新文件列表
|
|
108
|
+
* @returns
|
|
109
|
+
*/
|
|
110
|
+
static getDiffJSON(compilation, newFileList, buildPath) {
|
|
111
|
+
var _a;
|
|
112
|
+
const oldFileList = compilation.buildFileList;
|
|
113
|
+
if (!oldFileList.length) {
|
|
114
|
+
return [];
|
|
115
|
+
}
|
|
116
|
+
let diffList = [];
|
|
117
|
+
// 1.
|
|
118
|
+
for (let i = 0; i < oldFileList.length; i++) {
|
|
119
|
+
const index = newFileList.findIndex((file) => file === oldFileList[i].path);
|
|
120
|
+
// 1.3
|
|
121
|
+
if (index !== -1) {
|
|
122
|
+
// 1.2
|
|
123
|
+
const oldContent = (_a = oldFileList[i].content) === null || _a === void 0 ? void 0 : _a.toString('utf-8');
|
|
124
|
+
const newContent = fs_extra_1.default.readFileSync(path_1.default.join(buildPath, newFileList[index]), 'utf-8');
|
|
125
|
+
if (oldContent !== newContent) {
|
|
126
|
+
diffList.push(newFileList[index]);
|
|
127
|
+
}
|
|
128
|
+
// 从newFileList中移除该项
|
|
129
|
+
newFileList.splice(index, 1);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// 2.
|
|
133
|
+
newFileList.length > 0 && newFileList.forEach((file) => diffList.push(file));
|
|
134
|
+
return diffList;
|
|
135
|
+
}
|
|
100
136
|
}
|
|
101
137
|
exports.UxFileUtils = UxFileUtils;
|
|
102
138
|
UxFileUtils.CONFIG_FILE_NAME = 'manifest.json';
|
|
@@ -24,7 +24,10 @@ declare class UxLoaderUtils {
|
|
|
24
24
|
* @param resultFiles
|
|
25
25
|
* @param context
|
|
26
26
|
*/
|
|
27
|
-
static compileAppUxToJavascript(file: IFileParam,
|
|
27
|
+
static compileAppUxToJavascript(file: IFileParam, context: IFileLaneContext, compileOption: IJavascriptCompileOption): Promise<{
|
|
28
|
+
files: IFileParam[];
|
|
29
|
+
logs: ILog[];
|
|
30
|
+
}>;
|
|
28
31
|
/**
|
|
29
32
|
* 判断是否为src/app.ux
|
|
30
33
|
* @param filePath
|
|
@@ -37,7 +40,7 @@ declare class UxLoaderUtils {
|
|
|
37
40
|
* @param filePath
|
|
38
41
|
* @returns
|
|
39
42
|
*/
|
|
40
|
-
static isPageUx(context: IFileLaneContext, filePath: string):
|
|
43
|
+
static isPageUx(context: IFileLaneContext, filePath: string): boolean;
|
|
41
44
|
/**
|
|
42
45
|
* 获取app.ux的内容,且只返回script和style内容
|
|
43
46
|
* @param fileContent
|
|
@@ -51,14 +54,14 @@ declare class UxLoaderUtils {
|
|
|
51
54
|
* @returns
|
|
52
55
|
*/
|
|
53
56
|
static wrapTempalte(templateTree: SourceFile, file: IFileParam, compilerOption: IJavascriptCompileOption): string;
|
|
54
|
-
|
|
57
|
+
static wrapStyle(code: string, file: IFileParam, compilerOption: IJavascriptCompileOption): string;
|
|
55
58
|
/**
|
|
56
59
|
* 给script增加外层包裹内容
|
|
57
60
|
* @param isPageUx
|
|
58
61
|
* @param appScriptTree
|
|
59
62
|
* @returns
|
|
60
63
|
*/
|
|
61
|
-
static
|
|
64
|
+
static wrapScript(isPageUx: boolean, appScriptTree: SourceFile): string;
|
|
62
65
|
static getReturnType(isPageUx: boolean): "$app_exports$['entry'] =" | "module.exports = ";
|
|
63
66
|
}
|
|
64
67
|
export default UxLoaderUtils;
|
|
@@ -36,14 +36,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
const generator_1 = require("@aiot-toolkit/generator");
|
|
39
|
-
const
|
|
39
|
+
const parser_1 = require("@aiot-toolkit/parser");
|
|
40
40
|
const UxToTypescript_1 = __importDefault(require("@aiot-toolkit/parser/lib/ux/translate/vela/UxToTypescript"));
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const parse5 = __importStar(require("parse5"));
|
|
41
|
+
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
42
|
+
const parse5 = __importStar(require("aiot-parse5"));
|
|
43
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
45
44
|
const path_1 = __importDefault(require("path"));
|
|
46
|
-
const ts_morph_1 = require("ts-morph");
|
|
47
45
|
const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
|
|
48
46
|
const { extractFunctions } = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/protobufControl');
|
|
49
47
|
/**
|
|
@@ -59,7 +57,6 @@ class UxLoaderUtils {
|
|
|
59
57
|
*/
|
|
60
58
|
static compileUxToJavascript(file, context, isAppUx, compilerOption) {
|
|
61
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
const project = new ts_morph_1.Project();
|
|
63
60
|
const logs = [];
|
|
64
61
|
const { path: filePath, content } = file;
|
|
65
62
|
const { name, ext } = path_1.default.parse(filePath);
|
|
@@ -68,44 +65,63 @@ class UxLoaderUtils {
|
|
|
68
65
|
const newFileName = `${name}.js`;
|
|
69
66
|
//判断文本,空文本则结束该文件处理
|
|
70
67
|
if (!content) {
|
|
71
|
-
|
|
68
|
+
shared_utils_1.ColorConsole.warn(`The file '${fullName}' under the path '${filePath}' has no content `);
|
|
72
69
|
return {
|
|
73
70
|
files: [],
|
|
74
71
|
logs
|
|
75
72
|
};
|
|
76
73
|
}
|
|
74
|
+
// 区分页面组件和子组件
|
|
75
|
+
const isPageUx = UxLoaderUtils.isPageUx(context, filePath);
|
|
77
76
|
// 配置转换参数
|
|
78
77
|
const options = {
|
|
79
78
|
projectPath: context.projectPath,
|
|
79
|
+
projectType: shared_utils_1.ProjectType.VELA_UX,
|
|
80
80
|
filePath,
|
|
81
|
+
fileType: isAppUx ? 'app' : isPageUx ? 'page' : '',
|
|
82
|
+
content: content.toString(),
|
|
81
83
|
onLog: (log) => {
|
|
82
84
|
logs.push(log);
|
|
83
85
|
}
|
|
84
86
|
};
|
|
87
|
+
// 收集图片资源
|
|
88
|
+
const ImageResources = [];
|
|
89
|
+
const collectImageResource = (originFilePath) => {
|
|
90
|
+
const assetDir = 'dynamicAssets';
|
|
91
|
+
const sourcePath = path_1.default.resolve(options.projectPath, compilerOption.sourceRoot);
|
|
92
|
+
const assetPath = path_1.default.resolve(sourcePath, assetDir);
|
|
93
|
+
const { name, ext } = path_1.default.parse(originFilePath);
|
|
94
|
+
const hashName = shared_utils_1.CommonUtil.calcImageDigest(originFilePath);
|
|
95
|
+
const newFilePath = path_1.default.join(assetPath, `${name}-${hashName}${ext}`);
|
|
96
|
+
const relativePath = path_1.default.posix.sep + path_1.default.relative(sourcePath, newFilePath).split(path_1.default.sep).join(path_1.default.posix.sep);
|
|
97
|
+
ImageResources.push({
|
|
98
|
+
path: newFilePath,
|
|
99
|
+
content: fs_extra_1.default.readFileSync(originFilePath)
|
|
100
|
+
});
|
|
101
|
+
return relativePath;
|
|
102
|
+
};
|
|
85
103
|
// 开始转换
|
|
86
104
|
const globalVar = ('globalVar' in context && context.globalVar) || {};
|
|
87
|
-
const parserResult = yield new
|
|
105
|
+
const parserResult = yield new parser_1.UxParser(options, compilerOption, globalVar, collectImageResource).parser();
|
|
88
106
|
// 区分app.ux和一般ux
|
|
89
107
|
// app.ux解析结果中加上manifest.json的内容
|
|
90
108
|
const manifestJson = `require('./manifest.json')`;
|
|
91
|
-
// 区分页面组件和子组件
|
|
92
|
-
const isPageUx = UxLoaderUtils.isPageUx(context, filePath);
|
|
93
109
|
const integrateFunction = (appImport, appStyleTree, appTemplateTree, appScriptTree) => {
|
|
94
110
|
// script代码放在第三个位置不能变化,影响更新source map
|
|
95
111
|
return isAppUx
|
|
96
112
|
? [
|
|
97
113
|
`${appImport.join('\n')}`,
|
|
98
|
-
`var $app_style$ = ${UxLoaderUtils.wrapStyle(
|
|
99
|
-
`var $app_script$ = ${UxLoaderUtils.
|
|
100
|
-
`$app_script$({}, $app_exports$, $app_require$)
|
|
114
|
+
`var $app_style$ = ${UxLoaderUtils.wrapStyle(JSON.stringify(appStyleTree), file, compilerOption)}`,
|
|
115
|
+
`var $app_script$ = ${UxLoaderUtils.wrapScript(false, appScriptTree)}`,
|
|
116
|
+
`$app_script$({}, $app_exports$, $app_require$);`,
|
|
101
117
|
`$app_exports$.default.style = $app_style$;`,
|
|
102
118
|
`$app_exports$.default.manifest = ${manifestJson}`
|
|
103
119
|
]
|
|
104
120
|
: [
|
|
105
121
|
`${appImport.join('\n')}`,
|
|
106
|
-
`var $app_style$ = ${UxLoaderUtils.wrapStyle(
|
|
107
|
-
`var $app_script$ = ${UxLoaderUtils.
|
|
108
|
-
`var $app_template$ = ${UxLoaderUtils.wrapTempalte(appTemplateTree, file, compilerOption)}
|
|
122
|
+
`var $app_style$ = ${UxLoaderUtils.wrapStyle(JSON.stringify(appStyleTree), file, compilerOption)}`,
|
|
123
|
+
`var $app_script$ = ${UxLoaderUtils.wrapScript(isPageUx, appScriptTree)}`,
|
|
124
|
+
`var $app_template$ = ${UxLoaderUtils.wrapTempalte(appTemplateTree, file, compilerOption)}`,
|
|
109
125
|
`${UxLoaderUtils.getReturnType(isPageUx)} function ($app_exports$) {`,
|
|
110
126
|
`$app_script$({}, $app_exports$, $app_require$);`,
|
|
111
127
|
`$app_exports$.default.template = $app_template$;`,
|
|
@@ -113,7 +129,7 @@ class UxLoaderUtils {
|
|
|
113
129
|
`}`
|
|
114
130
|
];
|
|
115
131
|
};
|
|
116
|
-
const { targetTree, mapList, sourceMap } = yield new UxToTypescript_1.default(options,
|
|
132
|
+
const { targetTree, mapList, sourceMap } = yield new UxToTypescript_1.default(options, integrateFunction, compilerOption, context).translate(parserResult.ast, []);
|
|
117
133
|
const { code } = new generator_1.TypescriptGenerator().generate({
|
|
118
134
|
sourceFilePath: fullName,
|
|
119
135
|
targetFilePath: newFileName,
|
|
@@ -124,13 +140,14 @@ class UxLoaderUtils {
|
|
|
124
140
|
return {
|
|
125
141
|
files: [
|
|
126
142
|
{
|
|
127
|
-
path:
|
|
143
|
+
path: filePath,
|
|
128
144
|
content: code
|
|
129
145
|
},
|
|
130
146
|
{
|
|
131
|
-
path:
|
|
147
|
+
path: shared_utils_1.FileUtil.updateFileName(filePath, `${name}${ext}.map`),
|
|
132
148
|
content: sourceMap.toString()
|
|
133
|
-
}
|
|
149
|
+
},
|
|
150
|
+
...ImageResources
|
|
134
151
|
],
|
|
135
152
|
logs
|
|
136
153
|
};
|
|
@@ -142,7 +159,7 @@ class UxLoaderUtils {
|
|
|
142
159
|
* @param resultFiles
|
|
143
160
|
* @param context
|
|
144
161
|
*/
|
|
145
|
-
static compileAppUxToJavascript(file,
|
|
162
|
+
static compileAppUxToJavascript(file, context, compileOption) {
|
|
146
163
|
return __awaiter(this, void 0, void 0, function* () {
|
|
147
164
|
const { path: filePath, content } = file;
|
|
148
165
|
let appContent = content;
|
|
@@ -153,7 +170,7 @@ class UxLoaderUtils {
|
|
|
153
170
|
}
|
|
154
171
|
// 解析script和style两部分
|
|
155
172
|
const compileResult = yield UxLoaderUtils.compileUxToJavascript({ path: filePath, content: appContent }, context, isAppUx, compileOption);
|
|
156
|
-
|
|
173
|
+
return compileResult;
|
|
157
174
|
});
|
|
158
175
|
}
|
|
159
176
|
/**
|
|
@@ -173,7 +190,8 @@ class UxLoaderUtils {
|
|
|
173
190
|
* @returns
|
|
174
191
|
*/
|
|
175
192
|
static isPageUx(context, filePath) {
|
|
176
|
-
|
|
193
|
+
var _a;
|
|
194
|
+
return Boolean((_a = context.entries) === null || _a === void 0 ? void 0 : _a.includes(filePath));
|
|
177
195
|
}
|
|
178
196
|
/**
|
|
179
197
|
* 获取app.ux的内容,且只返回script和style内容
|
|
@@ -289,7 +307,7 @@ class UxLoaderUtils {
|
|
|
289
307
|
* @param appScriptTree
|
|
290
308
|
* @returns
|
|
291
309
|
*/
|
|
292
|
-
static
|
|
310
|
+
static wrapScript(isPageUx, appScriptTree) {
|
|
293
311
|
if (isPageUx) {
|
|
294
312
|
// 页面组件添加ViewModel处理代码
|
|
295
313
|
appScriptTree.addStatements(UxLoaderUtils.contenAccess);
|