@aiot-toolkit/aiotpack 2.0.3-beta.7 → 2.0.3-beta.9

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.
Files changed (56) hide show
  1. package/lib/afterCompile/ux/UxAfterCompile.js +303 -266
  2. package/lib/afterCompile/xts/entryTemplate.js +111 -113
  3. package/lib/afterCompile/xts/generateRpk.js +25 -54
  4. package/lib/afterCompile/xts/ts2wasm.js +62 -63
  5. package/lib/afterWorks/ux/UxAfterWorks.js +12 -19
  6. package/lib/beforeCompile/ux/UxBeforeCompile.js +26 -25
  7. package/lib/beforeCompile/xts/preInstall.js +50 -55
  8. package/lib/beforeWorks/ux/UxBeforeWorks.js +12 -19
  9. package/lib/compiler/enum/CompileMode.js +16 -23
  10. package/lib/compiler/interface/ICompileParam.js +1 -2
  11. package/lib/compiler/interface/ICompiler.js +1 -2
  12. package/lib/compiler/interface/ISignConfig.js +1 -2
  13. package/lib/compiler/javascript/JavascriptCompiler.js +147 -154
  14. package/lib/compiler/javascript/JavascriptDefaultCompileOption.js +20 -16
  15. package/lib/compiler/javascript/android/AndroidWebpackConfigurator.js +13 -11
  16. package/lib/compiler/javascript/android/plugin/WrapPlugin.js +52 -48
  17. package/lib/compiler/javascript/interface/IJavascriptCompileOption.js +1 -2
  18. package/lib/compiler/javascript/interface/IWebpackConfigurator.js +4 -1
  19. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js +78 -75
  20. package/lib/compiler/javascript/vela/enum/BuildNameFormatType.js +30 -41
  21. package/lib/compiler/javascript/vela/enum/EntryType.js +15 -29
  22. package/lib/compiler/javascript/vela/interface/IChunk.js +4 -1
  23. package/lib/compiler/javascript/vela/interface/IManifest.js +1 -2
  24. package/lib/compiler/javascript/vela/interface/IQuickAppConfig.js +1 -2
  25. package/lib/compiler/javascript/vela/model/Package.js +80 -51
  26. package/lib/compiler/javascript/vela/plugin/WrapPlugin.js +30 -26
  27. package/lib/compiler/javascript/vela/utils/Jsc.js +30 -33
  28. package/lib/compiler/javascript/vela/utils/UxCompileUtil.js +152 -130
  29. package/lib/compiler/javascript/vela/utils/ZipUtil.js +282 -276
  30. package/lib/compiler/javascript/vela/utils/signature/Base64.js +65 -67
  31. package/lib/compiler/javascript/vela/utils/signature/CRC32.js +37 -35
  32. package/lib/compiler/javascript/vela/utils/signature/SignUtil.js +755 -731
  33. package/lib/compiler/javascript/vela/utils/signature/Signer.js +24 -22
  34. package/lib/compiler/javascript/vela/utils/webpackLoader/addColSourceMap.js +47 -52
  35. package/lib/compiler/javascript/vela/utils/webpackLoader/extractMapData.js +21 -17
  36. package/lib/config/UxConfig.js +145 -173
  37. package/lib/config/XtsConfig.js +30 -40
  38. package/lib/index.js +88 -41
  39. package/lib/interface/ICompileOptions.js +5 -2
  40. package/lib/interface/IDeviceList.js +1 -2
  41. package/lib/loader/ux/JsLoader.js +32 -30
  42. package/lib/loader/ux/PngLoader.js +47 -53
  43. package/lib/loader/ux/android/UxLoader.js +30 -31
  44. package/lib/loader/ux/vela/AppUxLoader.js +23 -24
  45. package/lib/loader/ux/vela/HmlLoader.js +59 -55
  46. package/lib/loader/ux/vela/UxLoader.js +29 -35
  47. package/lib/loader/xts/XtsLoader.js +55 -41
  48. package/lib/utils/BeforeCompileUtils.js +100 -92
  49. package/lib/utils/PngUtils.js +42 -36
  50. package/lib/utils/ux/ManifestSchema.js +198 -194
  51. package/lib/utils/ux/UxFileUtils.js +130 -116
  52. package/lib/utils/ux/UxLoaderUtils.js +292 -307
  53. package/lib/utils/ux/android/AndroidUx.js +88 -90
  54. package/lib/utils/xts/XtsFileLaneUtils.js +58 -65
  55. package/lib/utils/xts/XtsFollowWorks.js +122 -129
  56. package/package.json +6 -6
package/lib/index.js CHANGED
@@ -1,42 +1,89 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.skipList = exports.UxFileUtils = exports.setServerPort = exports.CompileMode = exports.JavascriptDefaultCompileOption = exports.UxConfig = exports.XtsConfig = void 0;
30
- const XtsConfig_1 = __importDefault(require("./config/XtsConfig"));
31
- exports.XtsConfig = XtsConfig_1.default;
32
- const JavascriptDefaultCompileOption_1 = __importStar(require("./compiler/javascript/JavascriptDefaultCompileOption"));
33
- exports.JavascriptDefaultCompileOption = JavascriptDefaultCompileOption_1.default;
34
- Object.defineProperty(exports, "setServerPort", { enumerable: true, get: function () { return JavascriptDefaultCompileOption_1.setServerPort; } });
35
- const UxConfig_1 = __importDefault(require("./config/UxConfig"));
36
- exports.UxConfig = UxConfig_1.default;
37
- const CompileMode_1 = __importDefault(require("./compiler/enum/CompileMode"));
38
- exports.CompileMode = CompileMode_1.default;
39
- const UxFileUtils_1 = __importDefault(require("./utils/ux/UxFileUtils"));
40
- exports.UxFileUtils = UxFileUtils_1.default;
41
- const ICompileOptions_1 = require("./interface/ICompileOptions");
42
- Object.defineProperty(exports, "skipList", { enumerable: true, get: function () { return ICompileOptions_1.skipList; } });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "CompileMode", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _CompileMode.default;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "IJavascriptCompileOption", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _IJavascriptCompileOption.default;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "IManifest", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _IManifest.default;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "IQuickAppConfig", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _IQuickAppConfig.default;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "ISkipList", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _ICompileOptions.ISkipList;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "IXtsCompileOptions", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _ICompileOptions.IXtsCompileOptions;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "JavascriptDefaultCompileOption", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _JavascriptDefaultCompileOption.default;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "UxConfig", {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _UxConfig.default;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "UxFileUtils", {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _UxFileUtils.default;
58
+ }
59
+ });
60
+ Object.defineProperty(exports, "XtsConfig", {
61
+ enumerable: true,
62
+ get: function () {
63
+ return _XtsConfig.default;
64
+ }
65
+ });
66
+ Object.defineProperty(exports, "setServerPort", {
67
+ enumerable: true,
68
+ get: function () {
69
+ return _JavascriptDefaultCompileOption.setServerPort;
70
+ }
71
+ });
72
+ Object.defineProperty(exports, "skipList", {
73
+ enumerable: true,
74
+ get: function () {
75
+ return _ICompileOptions.skipList;
76
+ }
77
+ });
78
+ var _XtsConfig = _interopRequireDefault(require("./config/XtsConfig"));
79
+ var _JavascriptDefaultCompileOption = _interopRequireWildcard(require("./compiler/javascript/JavascriptDefaultCompileOption"));
80
+ var _UxConfig = _interopRequireDefault(require("./config/UxConfig"));
81
+ var _CompileMode = _interopRequireDefault(require("./compiler/enum/CompileMode"));
82
+ var _IJavascriptCompileOption = _interopRequireDefault(require("./compiler/javascript/interface/IJavascriptCompileOption"));
83
+ var _IQuickAppConfig = _interopRequireDefault(require("./compiler/javascript/vela/interface/IQuickAppConfig"));
84
+ var _UxFileUtils = _interopRequireDefault(require("./utils/ux/UxFileUtils"));
85
+ var _IManifest = _interopRequireDefault(require("./compiler/javascript/vela/interface/IManifest"));
86
+ var _ICompileOptions = require("./interface/ICompileOptions");
87
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
88
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
89
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.skipList = void 0;
4
- exports.skipList = ['xts2ts', 'install', 'ts2wasm', 'package'];
7
+ const skipList = exports.skipList = ['xts2ts', 'install', 'ts2wasm', 'package'];
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
@@ -1,36 +1,38 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const parser_1 = require("@aiot-toolkit/parser");
4
- const shared_utils_1 = require("@aiot-toolkit/shared-utils");
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _parser = require("@aiot-toolkit/parser");
8
+ var _sharedUtils = require("@aiot-toolkit/shared-utils");
5
9
  /**
6
10
  * JsLoader
7
11
  */
8
12
  class JsLoader {
9
- parser(files) {
10
- const onLog = () => { };
11
- return files.map((item) => {
12
- if (!item.content) {
13
- return {
14
- path: item.path,
15
- content: item.content
16
- };
17
- }
18
- const options = {
19
- filePath: item.path,
20
- projectPath: this.context.projectPath,
21
- content: item.content.toString(),
22
- projectType: shared_utils_1.ProjectType.getProjectType(this.context.projectPath),
23
- onLog
24
- };
25
- return {
26
- path: item.path,
27
- content: new parser_1.ScriptToTypescript(options, this.compilerOption, this.context)
28
- .translate({
29
- content: new parser_1.ScriptParser(options).parser(item.content.toString()).ast.content
30
- }, [])
31
- .targetTree.getFullText()
32
- };
33
- });
34
- }
13
+ parser(files) {
14
+ const onLog = () => {};
15
+ return files.map(item => {
16
+ if (!item.content) {
17
+ return {
18
+ path: item.path,
19
+ content: item.content
20
+ };
21
+ }
22
+ const options = {
23
+ filePath: item.path,
24
+ projectPath: this.context.projectPath,
25
+ content: item.content.toString(),
26
+ projectType: _sharedUtils.ProjectType.getProjectType(this.context.projectPath),
27
+ onLog
28
+ };
29
+ return {
30
+ path: item.path,
31
+ content: new _parser.ScriptToTypescript(options, this.compilerOption, this.context).translate({
32
+ content: new _parser.ScriptParser(options).parser(item.content.toString()).ast.content
33
+ }, []).targetTree.getFullText()
34
+ };
35
+ });
36
+ }
35
37
  }
36
- exports.default = JsLoader;
38
+ var _default = exports.default = JsLoader;
@@ -1,64 +1,58 @@
1
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 PngUtils_1 = __importDefault(require("../../utils/PngUtils"));
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _sharedUtils = require("@aiot-toolkit/shared-utils");
8
+ var _path = _interopRequireDefault(require("path"));
9
+ var _PngUtils = _interopRequireDefault(require("../../utils/PngUtils"));
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
18
11
  const aaptjs = require('@hap-toolkit/aaptjs');
12
+
19
13
  /**
20
14
  * PngLoader
21
15
  */
22
16
  class PngLoader {
23
- parser(files) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- const resultFiles = [];
26
- for (const file of files) {
27
- const { path: filePath, content } = file;
28
- const { name, ext } = path_1.default.parse(filePath);
29
- const fullName = `${name}${ext}`;
30
- //判断文本,空文本则结束该文件处理
31
- if (!content) {
32
- shared_utils_1.ColorConsole.warn(`The file '${fullName}' under the path '${filePath}' has no content `);
33
- return [];
34
- }
35
- // 判断传入的.png资源是不是.9.png资源
36
- if (shared_utils_1.FileUtil.match(filePath, /.+\.9\.png$/)) {
37
- yield this.compile9Png(filePath);
38
- }
39
- else {
40
- resultFiles.push(file);
41
- }
42
- }
43
- return resultFiles;
44
- });
17
+ async parser(files) {
18
+ const resultFiles = [];
19
+ for (const file of files) {
20
+ const {
21
+ path: filePath,
22
+ content
23
+ } = file;
24
+ const {
25
+ name,
26
+ ext
27
+ } = _path.default.parse(filePath);
28
+ const fullName = `${name}${ext}`;
29
+ //判断文本,空文本则结束该文件处理
30
+ if (!content) {
31
+ _sharedUtils.ColorConsole.warn(`The file '${fullName}' under the path '${filePath}' has no content `);
32
+ return [];
33
+ }
34
+ // 判断传入的.png资源是不是.9.png资源
35
+ if (_sharedUtils.FileUtil.match(filePath, /.+\.9\.png$/)) {
36
+ await this.compile9Png(filePath);
37
+ } else {
38
+ resultFiles.push(file);
39
+ }
45
40
  }
46
- compile9Png(filePath) {
47
- return __awaiter(this, void 0, void 0, function* () {
48
- // 判断.9.png是否经过编码处理
49
- if (!PngUtils_1.default.isEncode9Png(filePath)) {
50
- // 将.9.png资源使用@hap-toolkit/aaptjs处理
51
- const outputFile = PngUtils_1.default.convertOutputPath(filePath, this.context);
52
- try {
53
- yield aaptjs.singleCrunch(filePath, outputFile);
54
- }
55
- catch (error) {
56
- shared_utils_1.ColorConsole.throw(`.9.png resource file processing failed`);
57
- }
58
- }
59
- });
41
+ return resultFiles;
42
+ }
43
+ async compile9Png(filePath) {
44
+ // 判断.9.png是否经过编码处理
45
+ if (!_PngUtils.default.isEncode9Png(filePath)) {
46
+ // 将.9.png资源使用@hap-toolkit/aaptjs处理
47
+ const outputFile = _PngUtils.default.convertOutputPath(filePath, this.context);
48
+ try {
49
+ await aaptjs.singleCrunch(filePath, outputFile);
50
+ } catch (error) {
51
+ _sharedUtils.ColorConsole.throw(`.9.png resource file processing failed`);
52
+ }
60
53
  }
54
+ }
61
55
  }
62
56
  ;
63
57
  PngLoader.raw = true;
64
- exports.default = PngLoader;
58
+ var _default = exports.default = PngLoader;
@@ -1,38 +1,37 @@
1
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 path_1 = __importDefault(require("path"));
16
- const AndroidUx_1 = __importDefault(require("../../../utils/ux/android/AndroidUx"));
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _path = _interopRequireDefault(require("path"));
8
+ var _AndroidUx = _interopRequireDefault(require("../../../utils/ux/android/AndroidUx"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
10
  /**
18
11
  * UxLoader
19
12
  */
20
13
  class UxLoader {
21
- parser(files) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- const result = [];
24
- const { projectPath } = this.context;
25
- for (let item of files) {
26
- const { files, logs } = yield new AndroidUx_1.default().compileUx({
27
- context: this.context,
28
- file: item,
29
- compilerOption: this.compilerOption
30
- });
31
- this.logs = logs.map((item) => (Object.assign(Object.assign({}, item), { filePath: item.filePath ? path_1.default.relative(projectPath, item.filePath) : '' })));
32
- result.push(...files);
33
- }
34
- return result;
35
- });
14
+ async parser(files) {
15
+ const result = [];
16
+ const {
17
+ projectPath
18
+ } = this.context;
19
+ for (let item of files) {
20
+ const {
21
+ files,
22
+ logs
23
+ } = await new _AndroidUx.default().compileUx({
24
+ context: this.context,
25
+ file: item,
26
+ compilerOption: this.compilerOption
27
+ });
28
+ this.logs = logs.map(item => ({
29
+ ...item,
30
+ filePath: item.filePath ? _path.default.relative(projectPath, item.filePath) : ''
31
+ }));
32
+ result.push(...files);
36
33
  }
34
+ return result;
35
+ }
37
36
  }
38
- exports.default = UxLoader;
37
+ var _default = exports.default = UxLoader;
@@ -1,31 +1,30 @@
1
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 path_1 = __importDefault(require("path"));
16
- const UxLoaderUtils_1 = __importDefault(require("../../../utils/ux/UxLoaderUtils"));
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _path = _interopRequireDefault(require("path"));
8
+ var _UxLoaderUtils = _interopRequireDefault(require("../../../utils/ux/UxLoaderUtils"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
10
  /**
18
11
  * 处理app.ux的Loader
19
12
  * AppUxLoader
20
13
  */
21
14
  class AppUxLoader {
22
- parser(files) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- const { projectPath } = this.context;
25
- const { files: resultFiles, logs } = yield UxLoaderUtils_1.default.compileAppUxToJavascript(files[0], this.context, this.compilerOption);
26
- this.logs = logs.map((item) => (Object.assign(Object.assign({}, item), { filePath: item.filePath ? path_1.default.relative(projectPath, item.filePath) : '' })));
27
- return resultFiles;
28
- });
29
- }
15
+ async parser(files) {
16
+ const {
17
+ projectPath
18
+ } = this.context;
19
+ const {
20
+ files: resultFiles,
21
+ logs
22
+ } = await _UxLoaderUtils.default.compileAppUxToJavascript(files[0], this.context, this.compilerOption);
23
+ this.logs = logs.map(item => ({
24
+ ...item,
25
+ filePath: item.filePath ? _path.default.relative(projectPath, item.filePath) : ''
26
+ }));
27
+ return resultFiles;
28
+ }
30
29
  }
31
- exports.default = AppUxLoader;
30
+ var _default = exports.default = AppUxLoader;
@@ -1,63 +1,67 @@
1
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");
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _path = _interopRequireDefault(require("path"));
8
+ var _fs = _interopRequireDefault(require("fs"));
9
+ var _parser = require("@aiot-toolkit/parser");
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
11
  /**
10
12
  * HmlLoader
11
13
  */
12
14
  class HmlLoader {
13
- parser(files) {
14
- return files.map((file) => {
15
- return this.wrapHml(file);
16
- });
15
+ parser(files) {
16
+ return files.map(file => {
17
+ return this.wrapHml(file);
18
+ });
19
+ }
20
+
21
+ /**
22
+ * 包裹 hml 文件
23
+ *
24
+ * # 路径
25
+ * 如果存在同路径的 ux 后缀,报错;否则转换为同路径的 ux 后缀
26
+ *
27
+ * # 内容
28
+ * 1. 给hml的内容加上<template></template>
29
+ * 2. 如果存在同路径同名的 script文件,则加到<script></script>中
30
+ * 3. 如果存在同路径同名的 style文件,则加到<style></style>中
31
+ *
32
+ * @param file
33
+ */
34
+ wrapHml(file) {
35
+ const {
36
+ path,
37
+ content
38
+ } = file;
39
+ const uxExt = _parser.ExtensionConfig.UX;
40
+ const getFilePath = ext => {
41
+ const pathParsed = _path.default.parse(path);
42
+ pathParsed.ext = ext;
43
+ pathParsed.base = pathParsed.name + ext;
44
+ return _path.default.format(pathParsed);
45
+ };
46
+ const uxPath = getFilePath(uxExt);
47
+ if (_fs.default.existsSync(uxPath)) {
48
+ throw new Error(`${uxPath} already exists`);
17
49
  }
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
- };
50
+ const scriptExts = _parser.ExtensionConfig.SCRIPTS;
51
+ const styleExts = _parser.ExtensionConfig.STYLES;
52
+ const scriptPath = scriptExts.map(item => getFilePath(item)).find(item => _fs.default.existsSync(item));
53
+ const stylePath = styleExts.map(item => getFilePath(item)).find(item => _fs.default.existsSync(item));
54
+ let uxContent = ['<template>', content, '</template>'].join('\n');
55
+ if (scriptPath) {
56
+ uxContent += ['<script>', _fs.default.readFileSync(scriptPath, 'utf-8'), '</script>'].join('\n');
61
57
  }
58
+ if (stylePath) {
59
+ uxContent += ['<style>', _fs.default.readFileSync(stylePath, 'utf-8'), '</style>'].join('\n');
60
+ }
61
+ return {
62
+ path,
63
+ content: uxContent
64
+ };
65
+ }
62
66
  }
63
- exports.default = HmlLoader;
67
+ var _default = exports.default = HmlLoader;