@aiot-toolkit/aiotpack 2.0.2-beta.10 → 2.0.2-beta.12
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/compiler/interface/ICompileParam.d.ts +1 -1
- package/lib/compiler/javascript/JavascriptCompiler.js +19 -6
- 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 +78 -0
- package/lib/compiler/javascript/interface/IJavascriptCompileOption.d.ts +7 -0
- package/lib/compiler/javascript/vela/VelaWebpackConfigurator.d.ts +2 -0
- package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js +14 -10
- package/lib/compiler/javascript/vela/interface/IManifest.d.ts +1 -1
- package/lib/compiler/javascript/vela/model/Package.d.ts +1 -1
- package/lib/compiler/javascript/vela/model/Package.js +2 -5
- package/lib/compiler/javascript/vela/utils/Jsc.js +3 -4
- package/lib/compiler/javascript/vela/utils/UxCompileUtil.d.ts +1 -1
- package/lib/compiler/javascript/vela/utils/UxCompileUtil.js +3 -3
- package/lib/compiler/javascript/vela/utils/ZipUtil.d.ts +1 -1
- package/lib/compiler/javascript/vela/utils/ZipUtil.js +7 -9
- package/lib/compiler/javascript/vela/utils/signature/SignUtil.d.ts +3 -5
- package/lib/compiler/javascript/vela/utils/signature/SignUtil.js +53 -28
- package/lib/compiler/javascript/vela/utils/webpackLoader/addColSourceMap.js +2 -5
- package/lib/config/UxConfig.d.ts +40 -7
- package/lib/config/UxConfig.js +67 -35
- package/lib/config/XtsConfig.d.ts +2 -3
- package/lib/followWorks/ux/UxFollowWorks.d.ts +1 -1
- package/lib/followWorks/ux/UxFollowWorks.js +19 -24
- package/lib/followWorks/xts/entryTemplate.d.ts +1 -1
- package/lib/followWorks/xts/entryTemplate.js +10 -10
- package/lib/followWorks/xts/generateRpk.d.ts +1 -1
- package/lib/followWorks/xts/generateRpk.js +2 -2
- package/lib/followWorks/xts/ts2wasm.d.ts +1 -1
- package/lib/followWorks/xts/ts2wasm.js +4 -4
- package/lib/index.d.ts +9 -1
- package/lib/index.js +35 -1
- package/lib/loader/ux/JsLoader.js +5 -9
- package/lib/loader/ux/PngLoader.js +4 -5
- package/lib/loader/ux/android/UxLoader.d.ts +11 -0
- package/lib/loader/ux/android/UxLoader.js +39 -0
- package/lib/loader/ux/{AppUxLoader.d.ts → vela/AppUxLoader.d.ts} +1 -1
- package/lib/loader/ux/{AppUxLoader.js → vela/AppUxLoader.js} +3 -12
- package/lib/loader/ux/{UxLoader.d.ts → vela/UxLoader.d.ts} +1 -1
- package/lib/loader/ux/{UxLoader.js → vela/UxLoader.js} +2 -11
- package/lib/loader/xts/XtsLoader.js +6 -7
- package/lib/preWorks/ux/UxPreWorks.d.ts +1 -1
- package/lib/preWorks/xts/preInstall.d.ts +1 -1
- package/lib/preWorks/xts/preInstall.js +4 -4
- package/lib/utils/PreWorkUtils.d.ts +1 -2
- package/lib/utils/PreWorkUtils.js +27 -32
- package/lib/utils/ux/ManifestSchema.d.ts +1 -1
- package/lib/utils/ux/UxFileUtils.js +11 -13
- package/lib/utils/ux/UxLoaderUtils.d.ts +3 -3
- package/lib/utils/ux/UxLoaderUtils.js +14 -14
- 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 +7 -7
- package/package.json +6 -5
- /package/lib/loader/ux/{HmlLoader.d.ts → vela/HmlLoader.d.ts} +0 -0
- /package/lib/loader/ux/{HmlLoader.js → vela/HmlLoader.js} +0 -0
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const AndroidUx_1 = __importDefault(require("../../../utils/ux/android/AndroidUx"));
|
|
18
|
+
/**
|
|
19
|
+
* UxLoader
|
|
20
|
+
*/
|
|
21
|
+
class UxLoader {
|
|
22
|
+
parser(files) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const result = [];
|
|
25
|
+
const { projectPath } = this.context;
|
|
26
|
+
for (let item of files) {
|
|
27
|
+
const { files, logs } = yield new AndroidUx_1.default().compileUx({
|
|
28
|
+
context: this.context,
|
|
29
|
+
file: item,
|
|
30
|
+
compilerOption: this.compilerOption
|
|
31
|
+
});
|
|
32
|
+
shared_utils_1.CommonUtil.processingLogsInTerminal(logs.map((item) => (Object.assign(Object.assign({}, item), { filePath: item.filePath ? path_1.default.relative(projectPath, item.filePath) : '' }))));
|
|
33
|
+
result.push(...files);
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.default = UxLoader;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IFileLaneContext, IFileParam, ILoader } from 'file-lane';
|
|
2
|
-
import IJavascriptCompileOption from '
|
|
2
|
+
import IJavascriptCompileOption from '../../../compiler/javascript/interface/IJavascriptCompileOption';
|
|
3
3
|
/**
|
|
4
4
|
* 处理app.ux的Loader
|
|
5
5
|
* AppUxLoader
|
|
@@ -12,10 +12,9 @@ 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 UxLoaderUtils_1 = __importDefault(require("../../utils/ux/UxLoaderUtils"));
|
|
16
|
-
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
17
|
-
const path_1 = __importDefault(require("path"));
|
|
18
15
|
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const UxLoaderUtils_1 = __importDefault(require("../../../utils/ux/UxLoaderUtils"));
|
|
19
18
|
/**
|
|
20
19
|
* 处理app.ux的Loader
|
|
21
20
|
* AppUxLoader
|
|
@@ -25,15 +24,7 @@ class AppUxLoader {
|
|
|
25
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
25
|
const { projectPath } = this.context;
|
|
27
26
|
const { files: resultFiles, logs } = yield UxLoaderUtils_1.default.compileAppUxToJavascript(files[0], this.context, this.compilerOption);
|
|
28
|
-
|
|
29
|
-
logs.forEach((item) => {
|
|
30
|
-
ColorConsole_1.default.logger(Object.assign(Object.assign({}, item), { filePath: item.filePath ? path_1.default.relative(projectPath, item.filePath) : '' }));
|
|
31
|
-
});
|
|
32
|
-
// 如果有 error throw,则停止
|
|
33
|
-
if (logs.some((item) => item.level && [shared_utils_1.LOG_LEVEL.Throw].includes(item.level))) {
|
|
34
|
-
throw new Error('stop!');
|
|
35
|
-
}
|
|
36
|
-
}
|
|
27
|
+
shared_utils_1.CommonUtil.processingLogsInTerminal(logs.map((item) => (Object.assign(Object.assign({}, item), { filePath: item.filePath ? path_1.default.relative(projectPath, item.filePath) : '' }))));
|
|
37
28
|
return resultFiles;
|
|
38
29
|
});
|
|
39
30
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IFileLaneContext, IFileParam, ILoader } from 'file-lane';
|
|
2
|
-
import IJavascriptCompileOption from '
|
|
2
|
+
import IJavascriptCompileOption from '../../../compiler/javascript/interface/IJavascriptCompileOption';
|
|
3
3
|
declare class UxLoader implements ILoader {
|
|
4
4
|
context: IFileLaneContext;
|
|
5
5
|
compilerOption: IJavascriptCompileOption;
|
|
@@ -13,9 +13,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
16
|
-
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
17
16
|
const path_1 = __importDefault(require("path"));
|
|
18
|
-
const UxLoaderUtils_1 = __importDefault(require("
|
|
17
|
+
const UxLoaderUtils_1 = __importDefault(require("../../../utils/ux/UxLoaderUtils"));
|
|
19
18
|
class UxLoader {
|
|
20
19
|
parser(files) {
|
|
21
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -24,15 +23,7 @@ class UxLoader {
|
|
|
24
23
|
for (const file of files) {
|
|
25
24
|
// 转换每个文件
|
|
26
25
|
const { files: compiledFiles, logs } = yield UxLoaderUtils_1.default.compileUxToJavascript(file, this.context, false, this.compilerOption);
|
|
27
|
-
|
|
28
|
-
logs.forEach((item) => {
|
|
29
|
-
ColorConsole_1.default.logger(Object.assign(Object.assign({}, item), { filePath: item.filePath ? path_1.default.relative(projectPath, item.filePath) : '' }));
|
|
30
|
-
});
|
|
31
|
-
// 如果有 error throw,则停止
|
|
32
|
-
if (logs.some((item) => item.level && [shared_utils_1.LOG_LEVEL.Throw].includes(item.level))) {
|
|
33
|
-
throw new Error('stop!');
|
|
34
|
-
}
|
|
35
|
-
}
|
|
26
|
+
shared_utils_1.CommonUtil.processingLogsInTerminal(logs.map((item) => (Object.assign(Object.assign({}, item), { filePath: item.filePath ? path_1.default.relative(projectPath, item.filePath) : '' }))));
|
|
36
27
|
resultFiles.push(...compiledFiles);
|
|
37
28
|
}
|
|
38
29
|
return resultFiles;
|
|
@@ -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
|
}
|
|
@@ -13,14 +13,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.preInstall = void 0;
|
|
16
|
-
const
|
|
16
|
+
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
17
17
|
const child_process_1 = require("child_process");
|
|
18
18
|
const fs_1 = __importDefault(require("fs"));
|
|
19
19
|
const path_1 = __importDefault(require("path"));
|
|
20
20
|
const preInstall = (context, _, __, compilerOption) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
21
|
var _a;
|
|
22
22
|
if ((_a = compilerOption === null || compilerOption === void 0 ? void 0 : compilerOption.skip) === null || _a === void 0 ? void 0 : _a.includes('install')) {
|
|
23
|
-
|
|
23
|
+
shared_utils_1.ColorConsole.info(`### skip install pre-dependencies due to --skip ${compilerOption === null || compilerOption === void 0 ? void 0 : compilerOption.skip.join(',')}`);
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
26
|
const { projectPath } = context;
|
|
@@ -47,12 +47,12 @@ const preInstall = (context, _, __, compilerOption) => __awaiter(void 0, void 0,
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
shared_utils_1.ColorConsole.info('### Installing pre-dependencies. The initial build may take some time, please be patient...');
|
|
51
51
|
(0, child_process_1.execSync)('npm install', {
|
|
52
52
|
cwd: projectPath
|
|
53
53
|
});
|
|
54
54
|
// 目前ts2wasm不支持@符号
|
|
55
55
|
fs_1.default.renameSync(path_1.default.resolve(projectPath, 'node_modules/@mi'), path_1.default.resolve(projectPath, 'node_modules/mi'));
|
|
56
|
-
|
|
56
|
+
shared_utils_1.ColorConsole.info('### Dependencies installation complete.');
|
|
57
57
|
});
|
|
58
58
|
exports.preInstall = preInstall;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { IFileLaneContext } from 'file-lane';
|
|
2
|
-
import { PreWork } from 'file-lane/lib/interface/IFileLaneConfig';
|
|
1
|
+
import { IFileLaneContext, PreWork } from 'file-lane';
|
|
3
2
|
import IJavascriptCompileOption from '../compiler/javascript/interface/IJavascriptCompileOption';
|
|
4
3
|
/**
|
|
5
4
|
* PreWorkUtils
|
|
@@ -13,13 +13,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
var _a;
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
const
|
|
16
|
+
const parser_1 = require("@aiot-toolkit/parser");
|
|
17
|
+
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
17
18
|
const del_1 = __importDefault(require("del"));
|
|
18
19
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
19
20
|
const path_1 = __importDefault(require("path"));
|
|
20
21
|
const TranslateCache_1 = __importDefault(require("../../../parser/lib/ux/translate/vela/TranslateCache"));
|
|
21
22
|
const UxFileUtils_1 = __importDefault(require("./ux/UxFileUtils"));
|
|
22
|
-
const parser_1 = require("@aiot-toolkit/parser");
|
|
23
23
|
const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
|
|
24
24
|
/**
|
|
25
25
|
* PreWorkUtils
|
|
@@ -38,38 +38,35 @@ class PreWorkUtils {
|
|
|
38
38
|
const manifestContent = UxFileUtils_1.default.getMainfestInfo(projectPath);
|
|
39
39
|
// 存储entries
|
|
40
40
|
let entryList = [];
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (!router) {
|
|
44
|
-
// 没有router配置
|
|
45
|
-
ColorConsole_1.default.throw(`### manifest ### No router configuration`);
|
|
46
|
-
}
|
|
41
|
+
const { router } = manifestContent;
|
|
42
|
+
if (router) {
|
|
47
43
|
const { pages } = router;
|
|
48
|
-
if (
|
|
44
|
+
if (pages) {
|
|
45
|
+
Object.keys(pages).map((page) => {
|
|
46
|
+
const pageContent = pages[page];
|
|
47
|
+
const entryDir = path_1.default.join(srcPath, page);
|
|
48
|
+
const entryPages = parser_1.ExtensionConfig.TEMPLATES.map((item) => `${pageContent.component}${item}`);
|
|
49
|
+
const entry = entryPages.find((item) => fs_extra_1.default.existsSync(path_1.default.join(entryDir, item)));
|
|
50
|
+
if (entry) {
|
|
51
|
+
entryList.push(path_1.default.join(entryDir, entry));
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
// 路径不存在
|
|
55
|
+
shared_utils_1.ColorConsole.throw(`### manifest ### path '${entryDir}/${entryPages.join(' | ')}' does not exist`);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
49
60
|
// 没有pages配置
|
|
50
|
-
|
|
61
|
+
shared_utils_1.ColorConsole.throw(`### manifest ### No pages configuration`);
|
|
51
62
|
}
|
|
52
|
-
Object.keys(pages).map((page) => {
|
|
53
|
-
const pageContent = pages[page];
|
|
54
|
-
const entryDir = path_1.default.join(srcPath, page);
|
|
55
|
-
const entryPages = parser_1.ExtensionConfig.TEMPLATES.map((item) => `${pageContent.component}${item}`);
|
|
56
|
-
const entry = entryPages.find((item) => fs_extra_1.default.existsSync(path_1.default.join(entryDir, item)));
|
|
57
|
-
if (entry) {
|
|
58
|
-
entryList.push(path_1.default.join(entryDir, entry));
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
// 路径不存在
|
|
62
|
-
ColorConsole_1.default.throw(`### manifest ### path '${entryPages.join(' | ')}' does not exist`);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
context['entries'] = entryList;
|
|
66
|
-
return Promise.resolve();
|
|
67
63
|
}
|
|
68
64
|
else {
|
|
69
|
-
//
|
|
70
|
-
|
|
71
|
-
return Promise.reject();
|
|
65
|
+
// 没有router配置
|
|
66
|
+
shared_utils_1.ColorConsole.throw(`### manifest ### No router configuration`);
|
|
72
67
|
}
|
|
68
|
+
context['entries'] = entryList;
|
|
69
|
+
return Promise.resolve();
|
|
73
70
|
}
|
|
74
71
|
/**
|
|
75
72
|
* 获取项目的全局样式变量配置
|
|
@@ -90,14 +87,12 @@ class PreWorkUtils {
|
|
|
90
87
|
}
|
|
91
88
|
_a = PreWorkUtils;
|
|
92
89
|
PreWorkUtils.clean = (context, _, config, compileOption) => __awaiter(void 0, void 0, void 0, function* () {
|
|
93
|
-
yield (0, del_1.default)(path_1.default.join(context.projectPath, context.output));
|
|
90
|
+
yield (0, del_1.default)(path_1.default.join(context.projectPath, context.output), { force: true });
|
|
94
91
|
if (compileOption) {
|
|
95
|
-
yield (0, del_1.default)(path_1.default.join(compileOption.projectPath, compileOption.outputPath));
|
|
96
|
-
yield (0, del_1.default)(path_1.default.join(compileOption.projectPath, compileOption.releasePath));
|
|
97
92
|
yield (0, del_1.default)(path_1.default.join(context.projectPath, compileOption.outputPath));
|
|
98
93
|
yield (0, del_1.default)(path_1.default.join(context.projectPath, compileOption.releasePath));
|
|
99
94
|
}
|
|
100
|
-
TranslateCache_1.default
|
|
95
|
+
context.translateCache = new TranslateCache_1.default();
|
|
101
96
|
BinaryPlugin.reset();
|
|
102
97
|
BinaryPlugin.config = {
|
|
103
98
|
projectPath: context.projectPath,
|
|
@@ -5,8 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.UxFileUtils = void 0;
|
|
7
7
|
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
8
|
-
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
9
|
-
const CommonUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/CommonUtil"));
|
|
10
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
11
9
|
const path_1 = __importDefault(require("path"));
|
|
12
10
|
const ManifestSchema_1 = __importDefault(require("./ManifestSchema"));
|
|
@@ -43,28 +41,28 @@ class UxFileUtils {
|
|
|
43
41
|
static validateManifest(projectPath, sourceRoot = 'src') {
|
|
44
42
|
const path = UxFileUtils.getManifestFilePath(projectPath, sourceRoot);
|
|
45
43
|
if (!fs_extra_1.default.existsSync(path)) {
|
|
46
|
-
|
|
44
|
+
shared_utils_1.ColorConsole.throw(`file is missing`, {
|
|
47
45
|
word: path,
|
|
48
|
-
style:
|
|
46
|
+
style: shared_utils_1.ColorConsole.getStyle(shared_utils_1.Loglevel.THROW)
|
|
49
47
|
});
|
|
50
48
|
}
|
|
51
49
|
const jsonData = this.getMainfestInfo(projectPath, sourceRoot);
|
|
52
50
|
const schema = ManifestSchema_1.default;
|
|
53
|
-
const errors =
|
|
51
|
+
const errors = shared_utils_1.CommonUtil.validateJson(jsonData, schema);
|
|
54
52
|
if (errors) {
|
|
55
|
-
|
|
53
|
+
shared_utils_1.ColorConsole.warn(`Manefest.json error: `, ...errors.map((item, index) => {
|
|
56
54
|
return {
|
|
57
|
-
word: `\r\n${index + 1}
|
|
55
|
+
word: `\r\n${index + 1}.${item.message}`,
|
|
58
56
|
style: item instanceof TypeError
|
|
59
|
-
?
|
|
60
|
-
:
|
|
57
|
+
? shared_utils_1.ColorConsole.getStyle(shared_utils_1.Loglevel.ERROR)
|
|
58
|
+
: shared_utils_1.ColorConsole.getStyle(shared_utils_1.Loglevel.WARN)
|
|
61
59
|
};
|
|
62
60
|
}));
|
|
63
61
|
const stop = Boolean(errors.find((item) => item instanceof TypeError));
|
|
64
62
|
if (stop) {
|
|
65
|
-
|
|
63
|
+
shared_utils_1.ColorConsole.throw({
|
|
66
64
|
word: `missing required content, program stoped`,
|
|
67
|
-
style:
|
|
65
|
+
style: shared_utils_1.ColorConsole.getStyle(shared_utils_1.Loglevel.THROW)
|
|
68
66
|
});
|
|
69
67
|
}
|
|
70
68
|
}
|
|
@@ -87,13 +85,13 @@ class UxFileUtils {
|
|
|
87
85
|
rules.forEach((item, index) => {
|
|
88
86
|
const page = item.page;
|
|
89
87
|
if (page !== '*' && !pages.includes(page)) {
|
|
90
|
-
|
|
88
|
+
shared_utils_1.ColorConsole.throw(`The ${index + 1}th item of sitemap rules is configured incorrectly, the page ${page} does not exist`);
|
|
91
89
|
}
|
|
92
90
|
return page;
|
|
93
91
|
});
|
|
94
92
|
}
|
|
95
93
|
catch (error) {
|
|
96
|
-
|
|
94
|
+
shared_utils_1.ColorConsole.warn(error === null || error === void 0 ? void 0 : error.toString());
|
|
97
95
|
}
|
|
98
96
|
}
|
|
99
97
|
}
|
|
@@ -40,7 +40,7 @@ declare class UxLoaderUtils {
|
|
|
40
40
|
* @param filePath
|
|
41
41
|
* @returns
|
|
42
42
|
*/
|
|
43
|
-
static isPageUx(context: IFileLaneContext, filePath: string):
|
|
43
|
+
static isPageUx(context: IFileLaneContext, filePath: string): boolean;
|
|
44
44
|
/**
|
|
45
45
|
* 获取app.ux的内容,且只返回script和style内容
|
|
46
46
|
* @param fileContent
|
|
@@ -54,14 +54,14 @@ declare class UxLoaderUtils {
|
|
|
54
54
|
* @returns
|
|
55
55
|
*/
|
|
56
56
|
static wrapTempalte(templateTree: SourceFile, file: IFileParam, compilerOption: IJavascriptCompileOption): string;
|
|
57
|
-
|
|
57
|
+
static wrapStyle(code: string, file: IFileParam, compilerOption: IJavascriptCompileOption): string;
|
|
58
58
|
/**
|
|
59
59
|
* 给script增加外层包裹内容
|
|
60
60
|
* @param isPageUx
|
|
61
61
|
* @param appScriptTree
|
|
62
62
|
* @returns
|
|
63
63
|
*/
|
|
64
|
-
static
|
|
64
|
+
static wrapScript(isPageUx: boolean, appScriptTree: SourceFile): string;
|
|
65
65
|
static getReturnType(isPageUx: boolean): "$app_exports$['entry'] =" | "module.exports = ";
|
|
66
66
|
}
|
|
67
67
|
export default UxLoaderUtils;
|
|
@@ -36,15 +36,13 @@ 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 FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
|
|
41
|
+
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
43
42
|
const parse5 = __importStar(require("aiot-parse5"));
|
|
44
|
-
const path_1 = __importDefault(require("path"));
|
|
45
43
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
44
|
+
const path_1 = __importDefault(require("path"));
|
|
46
45
|
const ts_morph_1 = require("ts-morph");
|
|
47
|
-
const CommonUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/CommonUtil"));
|
|
48
46
|
const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
|
|
49
47
|
const { extractFunctions } = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/protobufControl');
|
|
50
48
|
/**
|
|
@@ -69,7 +67,7 @@ class UxLoaderUtils {
|
|
|
69
67
|
const newFileName = `${name}.js`;
|
|
70
68
|
//判断文本,空文本则结束该文件处理
|
|
71
69
|
if (!content) {
|
|
72
|
-
|
|
70
|
+
shared_utils_1.ColorConsole.warn(`The file '${fullName}' under the path '${filePath}' has no content `);
|
|
73
71
|
return {
|
|
74
72
|
files: [],
|
|
75
73
|
logs
|
|
@@ -80,6 +78,7 @@ class UxLoaderUtils {
|
|
|
80
78
|
// 配置转换参数
|
|
81
79
|
const options = {
|
|
82
80
|
projectPath: context.projectPath,
|
|
81
|
+
projectType: shared_utils_1.ProjectType.VELA_UX,
|
|
83
82
|
filePath,
|
|
84
83
|
fileType: isAppUx ? 'app' : isPageUx ? 'page' : '',
|
|
85
84
|
content: content.toString(),
|
|
@@ -94,7 +93,7 @@ class UxLoaderUtils {
|
|
|
94
93
|
const sourcePath = path_1.default.resolve(options.projectPath, compilerOption.sourceRoot);
|
|
95
94
|
const assetPath = path_1.default.resolve(sourcePath, assetDir);
|
|
96
95
|
const { name, ext } = path_1.default.parse(originFilePath);
|
|
97
|
-
const hashName =
|
|
96
|
+
const hashName = shared_utils_1.CommonUtil.calcImageDigest(originFilePath);
|
|
98
97
|
const newFilePath = path_1.default.join(assetPath, `${name}-${hashName}${ext}`);
|
|
99
98
|
const relativePath = path_1.default.posix.sep + path_1.default.relative(sourcePath, newFilePath).split(path_1.default.sep).join(path_1.default.posix.sep);
|
|
100
99
|
ImageResources.push({
|
|
@@ -105,7 +104,7 @@ class UxLoaderUtils {
|
|
|
105
104
|
};
|
|
106
105
|
// 开始转换
|
|
107
106
|
const globalVar = ('globalVar' in context && context.globalVar) || {};
|
|
108
|
-
const parserResult = yield new
|
|
107
|
+
const parserResult = yield new parser_1.UxParser(options, compilerOption, globalVar, collectImageResource).parser();
|
|
109
108
|
// 区分app.ux和一般ux
|
|
110
109
|
// app.ux解析结果中加上manifest.json的内容
|
|
111
110
|
const manifestJson = `require('./manifest.json')`;
|
|
@@ -115,7 +114,7 @@ class UxLoaderUtils {
|
|
|
115
114
|
? [
|
|
116
115
|
`${appImport.join('\n')}`,
|
|
117
116
|
`var $app_style$ = ${UxLoaderUtils.wrapStyle(JSON.stringify(appStyleTree), file, compilerOption)}`,
|
|
118
|
-
`var $app_script$ = ${UxLoaderUtils.
|
|
117
|
+
`var $app_script$ = ${UxLoaderUtils.wrapScript(false, appScriptTree)}`,
|
|
119
118
|
`$app_script$({}, $app_exports$, $app_require$);`,
|
|
120
119
|
`$app_exports$.default.style = $app_style$;`,
|
|
121
120
|
`$app_exports$.default.manifest = ${manifestJson}`
|
|
@@ -123,7 +122,7 @@ class UxLoaderUtils {
|
|
|
123
122
|
: [
|
|
124
123
|
`${appImport.join('\n')}`,
|
|
125
124
|
`var $app_style$ = ${UxLoaderUtils.wrapStyle(JSON.stringify(appStyleTree), file, compilerOption)}`,
|
|
126
|
-
`var $app_script$ = ${UxLoaderUtils.
|
|
125
|
+
`var $app_script$ = ${UxLoaderUtils.wrapScript(isPageUx, appScriptTree)}`,
|
|
127
126
|
`var $app_template$ = ${UxLoaderUtils.wrapTempalte(appTemplateTree, file, compilerOption)}`,
|
|
128
127
|
`${UxLoaderUtils.getReturnType(isPageUx)} function ($app_exports$) {`,
|
|
129
128
|
`$app_script$({}, $app_exports$, $app_require$);`,
|
|
@@ -132,7 +131,7 @@ class UxLoaderUtils {
|
|
|
132
131
|
`}`
|
|
133
132
|
];
|
|
134
133
|
};
|
|
135
|
-
const { targetTree, mapList, sourceMap } = yield new UxToTypescript_1.default(options, project, integrateFunction, compilerOption).translate(parserResult.ast, []);
|
|
134
|
+
const { targetTree, mapList, sourceMap } = yield new UxToTypescript_1.default(options, project, integrateFunction, compilerOption, context).translate(parserResult.ast, []);
|
|
136
135
|
const { code } = new generator_1.TypescriptGenerator().generate({
|
|
137
136
|
sourceFilePath: fullName,
|
|
138
137
|
targetFilePath: newFileName,
|
|
@@ -147,7 +146,7 @@ class UxLoaderUtils {
|
|
|
147
146
|
content: code
|
|
148
147
|
},
|
|
149
148
|
{
|
|
150
|
-
path:
|
|
149
|
+
path: shared_utils_1.FileUtil.updateFileName(filePath, `${name}${ext}.map`),
|
|
151
150
|
content: sourceMap.toString()
|
|
152
151
|
},
|
|
153
152
|
...ImageResources
|
|
@@ -193,7 +192,8 @@ class UxLoaderUtils {
|
|
|
193
192
|
* @returns
|
|
194
193
|
*/
|
|
195
194
|
static isPageUx(context, filePath) {
|
|
196
|
-
|
|
195
|
+
var _a;
|
|
196
|
+
return Boolean((_a = context.entries) === null || _a === void 0 ? void 0 : _a.includes(filePath));
|
|
197
197
|
}
|
|
198
198
|
/**
|
|
199
199
|
* 获取app.ux的内容,且只返回script和style内容
|
|
@@ -309,7 +309,7 @@ class UxLoaderUtils {
|
|
|
309
309
|
* @param appScriptTree
|
|
310
310
|
* @returns
|
|
311
311
|
*/
|
|
312
|
-
static
|
|
312
|
+
static wrapScript(isPageUx, appScriptTree) {
|
|
313
313
|
if (isPageUx) {
|
|
314
314
|
// 页面组件添加ViewModel处理代码
|
|
315
315
|
appScriptTree.addStatements(UxLoaderUtils.contenAccess);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ILog } from '@aiot-toolkit/shared-utils';
|
|
2
|
+
import { IFileLaneContext, IFileParam } from 'file-lane';
|
|
3
|
+
import IJavascriptCompileOption from '../../../compiler/javascript/interface/IJavascriptCompileOption';
|
|
4
|
+
/**
|
|
5
|
+
* AndroidUx
|
|
6
|
+
*/
|
|
7
|
+
declare class AndroidUx {
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* 编译 ux 文件
|
|
11
|
+
* 1. 获取文件类型:app page 普通ux
|
|
12
|
+
* 2. 使用`UxParse`解析
|
|
13
|
+
* 3. 使用`UxToTypeScript`转换
|
|
14
|
+
* 4. 使用`TypeScriptGenerator`生成
|
|
15
|
+
* @param params
|
|
16
|
+
*/
|
|
17
|
+
compileUx(params: {
|
|
18
|
+
context: IFileLaneContext;
|
|
19
|
+
file: IFileParam;
|
|
20
|
+
compilerOption: IJavascriptCompileOption;
|
|
21
|
+
}): Promise<{
|
|
22
|
+
files: IFileParam[];
|
|
23
|
+
logs: ILog[];
|
|
24
|
+
}>;
|
|
25
|
+
private getFileType;
|
|
26
|
+
}
|
|
27
|
+
export default AndroidUx;
|
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const parser_1 = require("@aiot-toolkit/parser");
|
|
16
|
+
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
17
|
+
const UxToTypescript_1 = __importDefault(require("@aiot-toolkit/parser/lib/ux/translate/android/UxToTypescript"));
|
|
18
|
+
const generator_1 = require("@aiot-toolkit/generator");
|
|
19
|
+
const path_1 = __importDefault(require("path"));
|
|
20
|
+
/**
|
|
21
|
+
* AndroidUx
|
|
22
|
+
*/
|
|
23
|
+
class AndroidUx {
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* 编译 ux 文件
|
|
27
|
+
* 1. 获取文件类型:app page 普通ux
|
|
28
|
+
* 2. 使用`UxParse`解析
|
|
29
|
+
* 3. 使用`UxToTypeScript`转换
|
|
30
|
+
* 4. 使用`TypeScriptGenerator`生成
|
|
31
|
+
* @param params
|
|
32
|
+
*/
|
|
33
|
+
compileUx(params) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const { context, file, compilerOption } = params;
|
|
36
|
+
const { path: filePath, content } = file;
|
|
37
|
+
const { projectPath } = context;
|
|
38
|
+
const fileType = this.getFileType(filePath, context);
|
|
39
|
+
// 无内容的文件,添加空内容警告
|
|
40
|
+
if (!content) {
|
|
41
|
+
return {
|
|
42
|
+
files: [],
|
|
43
|
+
logs: [
|
|
44
|
+
{
|
|
45
|
+
level: shared_utils_1.Loglevel.WARN,
|
|
46
|
+
message: `${filePath} is empty`,
|
|
47
|
+
filePath
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const logs = [];
|
|
53
|
+
const option = {
|
|
54
|
+
filePath,
|
|
55
|
+
projectPath,
|
|
56
|
+
projectType: shared_utils_1.ProjectType.ANDDROID_UX,
|
|
57
|
+
fileType,
|
|
58
|
+
onLog: function (log) {
|
|
59
|
+
logs.push(log);
|
|
60
|
+
},
|
|
61
|
+
content: content.toString()
|
|
62
|
+
};
|
|
63
|
+
const uxAst = yield new parser_1.UxParser(option, compilerOption, {}, (path) => path).parser();
|
|
64
|
+
const tsAst = yield new UxToTypescript_1.default(option, compilerOption, context).translate(uxAst.ast, uxAst.offsetList || []);
|
|
65
|
+
const filePathParse = path_1.default.parse(filePath);
|
|
66
|
+
const code = new generator_1.TypescriptGenerator().generate({
|
|
67
|
+
sourceFilePath: filePathParse.base,
|
|
68
|
+
targetFilePath: `${filePathParse.name}.js`,
|
|
69
|
+
ast: tsAst.targetTree,
|
|
70
|
+
mapList: tsAst.mapList
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
files: [
|
|
74
|
+
{
|
|
75
|
+
path: filePath,
|
|
76
|
+
content: code.code
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
path: `${filePathParse.dir}/${filePathParse.base}.map`,
|
|
80
|
+
content: code.sourcemap
|
|
81
|
+
}
|
|
82
|
+
// resource todo
|
|
83
|
+
],
|
|
84
|
+
logs
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
getFileType(filePath, context) {
|
|
89
|
+
const { entries } = context;
|
|
90
|
+
if (path_1.default.basename(filePath) === 'app.ux') {
|
|
91
|
+
return 'app';
|
|
92
|
+
}
|
|
93
|
+
else if (entries.includes(filePath)) {
|
|
94
|
+
return 'page';
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.default = AndroidUx;
|
|
@@ -0,0 +1,10 @@
|
|
|
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;
|