@aiot-toolkit/aiotpack 2.0.1-alpha.9 → 2.0.2-beta.10

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 (115) hide show
  1. package/lib/compiler/enum/CompileMode.js +0 -2
  2. package/lib/compiler/interface/ICompileParam.js +0 -2
  3. package/lib/compiler/interface/ICompiler.js +0 -2
  4. package/lib/compiler/interface/ISignConfig.js +0 -2
  5. package/lib/compiler/javascript/JavascriptCompiler.d.ts +1 -1
  6. package/lib/compiler/javascript/JavascriptCompiler.js +51 -18
  7. package/lib/compiler/javascript/JavascriptDefaultCompileOption.d.ts +1 -0
  8. package/lib/compiler/javascript/JavascriptDefaultCompileOption.js +5 -3
  9. package/lib/compiler/javascript/interface/IJavascriptCompileOption.d.ts +17 -5
  10. package/lib/compiler/javascript/interface/IJavascriptCompileOption.js +0 -2
  11. package/lib/compiler/javascript/interface/IWebpackConfigurator.js +0 -2
  12. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.d.ts +1 -2
  13. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js +11 -7
  14. package/lib/compiler/javascript/vela/enum/BuildNameFormatType.js +0 -2
  15. package/lib/compiler/javascript/vela/enum/EntryType.js +0 -2
  16. package/lib/compiler/javascript/vela/interface/IChunk.js +0 -2
  17. package/lib/compiler/javascript/vela/interface/IManifest.d.ts +3 -0
  18. package/lib/compiler/javascript/vela/interface/IManifest.js +0 -2
  19. package/lib/compiler/javascript/vela/interface/IQuickAppConfig.js +0 -2
  20. package/lib/compiler/javascript/vela/model/Package.js +2 -4
  21. package/lib/compiler/javascript/vela/plugin/WrapPlugin.d.ts +0 -1
  22. package/lib/compiler/javascript/vela/plugin/WrapPlugin.js +19 -24
  23. package/lib/compiler/javascript/vela/utils/Jsc.d.ts +1 -1
  24. package/lib/compiler/javascript/vela/utils/Jsc.js +4 -7
  25. package/lib/compiler/javascript/vela/utils/UxCompileUtil.js +3 -5
  26. package/lib/compiler/javascript/vela/utils/ZipUtil.js +6 -8
  27. package/lib/compiler/javascript/vela/utils/signature/Base64.js +0 -2
  28. package/lib/compiler/javascript/vela/utils/signature/CRC32.js +0 -2
  29. package/lib/compiler/javascript/vela/utils/signature/SignUtil.d.ts +1 -1
  30. package/lib/compiler/javascript/vela/utils/signature/SignUtil.js +14 -12
  31. package/lib/compiler/javascript/vela/utils/signature/Signer.js +0 -2
  32. package/lib/compiler/javascript/vela/utils/webpackLoader/addColSourceMap.d.ts +3 -0
  33. package/lib/compiler/javascript/vela/utils/webpackLoader/addColSourceMap.js +59 -0
  34. package/lib/compiler/javascript/vela/utils/webpackLoader/extractMapData.d.ts +3 -0
  35. package/lib/compiler/javascript/vela/utils/webpackLoader/extractMapData.js +20 -0
  36. package/lib/config/UxConfig.d.ts +8 -19
  37. package/lib/config/UxConfig.js +69 -13
  38. package/lib/config/XtsConfig.d.ts +5 -2
  39. package/lib/config/XtsConfig.js +12 -5
  40. package/lib/{utils → followWorks}/ux/UxFollowWorks.d.ts +1 -0
  41. package/lib/{utils → followWorks}/ux/UxFollowWorks.js +72 -14
  42. package/lib/followWorks/xts/entryTemplate.d.ts +2 -2
  43. package/lib/followWorks/xts/entryTemplate.js +61 -44
  44. package/lib/followWorks/xts/generateRpk.js +1 -3
  45. package/lib/followWorks/xts/ts2wasm.js +3 -14
  46. package/lib/index.js +0 -2
  47. package/lib/interface/ICompileOptions.d.ts +1 -1
  48. package/lib/interface/ICompileOptions.js +1 -3
  49. package/lib/interface/IDeviceList.js +0 -2
  50. package/lib/loader/ux/AppUxLoader.d.ts +2 -0
  51. package/lib/loader/ux/AppUxLoader.js +14 -4
  52. package/lib/loader/ux/HmlLoader.d.ts +24 -0
  53. package/lib/loader/ux/HmlLoader.js +63 -0
  54. package/lib/loader/ux/JsLoader.d.ts +11 -0
  55. package/lib/loader/ux/JsLoader.js +40 -0
  56. package/lib/loader/ux/PngLoader.js +4 -9
  57. package/lib/loader/ux/UxLoader.d.ts +2 -0
  58. package/lib/loader/ux/UxLoader.js +15 -4
  59. package/lib/loader/xts/XtsLoader.js +3 -9
  60. package/lib/preWorks/ux/UxPreWorks.d.ts +10 -0
  61. package/lib/preWorks/ux/UxPreWorks.js +31 -0
  62. package/lib/preWorks/xts/preInstall.js +4 -12
  63. package/lib/utils/PngUtils.js +0 -2
  64. package/lib/utils/PreWorkUtils.d.ts +5 -0
  65. package/lib/utils/PreWorkUtils.js +45 -12
  66. package/lib/utils/ux/ManifestSchema.d.ts +3 -0
  67. package/lib/utils/ux/ManifestSchema.js +207 -0
  68. package/lib/utils/ux/UxFileUtils.d.ts +21 -4
  69. package/lib/utils/ux/UxFileUtils.js +74 -5
  70. package/lib/utils/ux/UxLoaderUtils.d.ts +14 -7
  71. package/lib/utils/ux/UxLoaderUtils.js +144 -38
  72. package/lib/utils/xts/XtsFollowWorks.js +3 -12
  73. package/package.json +8 -10
  74. package/lib/compiler/enum/CompileMode.js.map +0 -1
  75. package/lib/compiler/interface/ICompileParam.js.map +0 -1
  76. package/lib/compiler/interface/ICompiler.js.map +0 -1
  77. package/lib/compiler/interface/ISignConfig.js.map +0 -1
  78. package/lib/compiler/javascript/JavascriptCompiler.js.map +0 -1
  79. package/lib/compiler/javascript/JavascriptDefaultCompileOption.js.map +0 -1
  80. package/lib/compiler/javascript/interface/IJavascriptCompileOption.js.map +0 -1
  81. package/lib/compiler/javascript/interface/IWebpackConfigurator.js.map +0 -1
  82. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js.map +0 -1
  83. package/lib/compiler/javascript/vela/enum/BuildNameFormatType.js.map +0 -1
  84. package/lib/compiler/javascript/vela/enum/EntryType.js.map +0 -1
  85. package/lib/compiler/javascript/vela/interface/IChunk.js.map +0 -1
  86. package/lib/compiler/javascript/vela/interface/IManifest.js.map +0 -1
  87. package/lib/compiler/javascript/vela/interface/IQuickAppConfig.js.map +0 -1
  88. package/lib/compiler/javascript/vela/model/Package.js.map +0 -1
  89. package/lib/compiler/javascript/vela/plugin/WrapPlugin.js.map +0 -1
  90. package/lib/compiler/javascript/vela/utils/Jsc.js.map +0 -1
  91. package/lib/compiler/javascript/vela/utils/UxCompileUtil.js.map +0 -1
  92. package/lib/compiler/javascript/vela/utils/ZipUtil.js.map +0 -1
  93. package/lib/compiler/javascript/vela/utils/signature/Base64.js.map +0 -1
  94. package/lib/compiler/javascript/vela/utils/signature/CRC32.js.map +0 -1
  95. package/lib/compiler/javascript/vela/utils/signature/SignUtil.js.map +0 -1
  96. package/lib/compiler/javascript/vela/utils/signature/Signer.js.map +0 -1
  97. package/lib/config/UxConfig.js.map +0 -1
  98. package/lib/config/XtsConfig.js.map +0 -1
  99. package/lib/followWorks/xts/entryTemplate.js.map +0 -1
  100. package/lib/followWorks/xts/generateRpk.js.map +0 -1
  101. package/lib/followWorks/xts/ts2wasm.js.map +0 -1
  102. package/lib/index.js.map +0 -1
  103. package/lib/interface/ICompileOptions.js.map +0 -1
  104. package/lib/interface/IDeviceList.js.map +0 -1
  105. package/lib/loader/ux/AppUxLoader.js.map +0 -1
  106. package/lib/loader/ux/PngLoader.js.map +0 -1
  107. package/lib/loader/ux/UxLoader.js.map +0 -1
  108. package/lib/loader/xts/XtsLoader.js.map +0 -1
  109. package/lib/preWorks/xts/preInstall.js.map +0 -1
  110. package/lib/utils/PngUtils.js.map +0 -1
  111. package/lib/utils/PreWorkUtils.js.map +0 -1
  112. package/lib/utils/ux/UxFileUtils.js.map +0 -1
  113. package/lib/utils/ux/UxFollowWorks.js.map +0 -1
  114. package/lib/utils/ux/UxLoaderUtils.js.map +0 -1
  115. package/lib/utils/xts/XtsFollowWorks.js.map +0 -1
@@ -14,9 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.generateEntryFile = exports.XtsEntryFileName = exports.entryTemplate = void 0;
16
16
  const Framework_1 = require("@aiot-toolkit/parser/lib/xts/enum/Framework");
17
- const shared_utils_1 = require("@aiot-toolkit/shared-utils");
18
17
  const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
19
- const fast_glob_1 = __importDefault(require("fast-glob"));
20
18
  const fs_extra_1 = __importDefault(require("fs-extra"));
21
19
  const path_1 = __importDefault(require("path"));
22
20
  const entryTemplate = (options) => {
@@ -41,20 +39,24 @@ const entryTemplate = (options) => {
41
39
  for (let i = 0; i < aspects.length; i++) {
42
40
  const aspect = aspects[i];
43
41
  const { routes = [] } = aspect;
42
+ res += `
43
+ const aspectName_${i + 1} = '${aspect.name}'
44
+ const pathPages_${i + 1} = new Map()`;
44
45
  for (let r = 0; r < routes.length; r++) {
45
46
  const route = routes[r];
46
47
  res += `
47
- const pathPages${i + 1}_${r + 1} = new Map()
48
- pathPages${i + 1}_${r + 1}.set('${route.route}', function (params?: ${Framework_1.HomeState.interface}${i + 1}_${r + 1}_): Page {
48
+ pathPages_${i + 1}.set('${route.route}', function (params?: ${Framework_1.HomeState.interface}${i + 1}_${r + 1}_): Page {
49
49
  return new Page${i + 1}_${r + 1}(params)
50
50
  })
51
- const aspectName_${i + 1} = '${aspect.name}'
51
+ `;
52
+ }
53
+ res += `
52
54
  const aspectDef_${i + 1}: AspectDefinition = {
53
55
  newFn: (): ViewAspect => new AspectClass${i + 1}(),
54
- pathPages: pathPages${i + 1}_${r + 1}
56
+ pathPages: pathPages_${i + 1}
55
57
  }
56
- aspectDefs.set(aspectName_${i + 1}, aspectDef_${i + 1})`;
57
- }
58
+ aspectDefs.set(aspectName_${i + 1}, aspectDef_${i + 1})
59
+ `;
58
60
  }
59
61
  return res;
60
62
  }
@@ -110,57 +112,72 @@ export { entry, on }
110
112
  `;
111
113
  };
112
114
  exports.entryTemplate = entryTemplate;
115
+ function getManifest(manifestPath) {
116
+ const content = fs_extra_1.default.readFileSync(manifestPath, 'utf-8');
117
+ const data = JSON.parse(content);
118
+ return data;
119
+ }
113
120
  exports.XtsEntryFileName = '__entry__.ts';
114
121
  /**
115
122
  * 生成 __entry__.ts 文件
116
123
  * @param context
117
124
  */
118
- function generateEntryFile(context) {
119
- var _a, _b, _c;
125
+ const generateEntryFile = function generateEntryFile(context, _, compilerOptions) {
126
+ var _a, _b;
120
127
  return __awaiter(this, void 0, void 0, function* () {
121
128
  const { projectPath, output } = context;
122
- ColorConsole_1.default.log({
123
- level: shared_utils_1.LOG_LEVEL.Info,
124
- message: `Generating entry file`
125
- });
126
- const dist = path_1.default.resolve(projectPath, output);
127
- const manifests = yield (0, fast_glob_1.default)(`${fast_glob_1.default.convertPathToPattern(dist)}/**/manifest.json`);
128
- function relativeDist(tar) {
129
- return path_1.default.join('.', path_1.default.relative(dist, tar)).replace(path_1.default.sep, '/');
129
+ if ((_a = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.skip) === null || _a === void 0 ? void 0 : _a.includes('xts2ts')) {
130
+ ColorConsole_1.default.info(`### skip generate entry file due to --skip xts2ts}`);
131
+ return;
132
+ }
133
+ ColorConsole_1.default.info(`Generating entry file`);
134
+ const buildDir = path_1.default.resolve(projectPath, output);
135
+ const appManifestPath = path_1.default.join(buildDir, 'app', 'manifest.json');
136
+ const appManifest = getManifest(appManifestPath);
137
+ if (!appManifest) {
138
+ ColorConsole_1.default.throw('not find app/manifest.json file !');
130
139
  }
131
- const appTs = yield (0, fast_glob_1.default)(`${fast_glob_1.default.convertPathToPattern(dist)}/**/app.ts`);
132
- if (appTs.length !== 1) {
133
- ColorConsole_1.default.log({ level: shared_utils_1.LOG_LEVEL.Error, message: 'app.ts can only have one!' });
140
+ const appTs = path_1.default.join(buildDir, 'app', 'app.ts');
141
+ if (!fs_extra_1.default.existsSync(appTs)) {
142
+ ColorConsole_1.default.throw('not find app/app.ts file !');
143
+ }
144
+ function relativeDist(tar) {
145
+ return path_1.default.join('.', path_1.default.relative(buildDir, tar)).replace(path_1.default.sep, '/');
134
146
  }
135
147
  let opt = {
136
- appPath: relativeDist(appTs[0].replace('.ts', '')),
148
+ appPath: relativeDist(appTs.replace('.ts', '')),
137
149
  aspects: []
138
150
  };
139
- for (const manifest of manifests) {
140
- const content = fs_extra_1.default.readFileSync(manifest, 'utf-8');
141
- const data = JSON.parse(content);
142
- if ((_a = data === null || data === void 0 ? void 0 : data.router) === null || _a === void 0 ? void 0 : _a.pages) {
143
- (_b = opt.aspects) === null || _b === void 0 ? void 0 : _b.push({
144
- name: data.name,
145
- path: relativeDist(path_1.default.resolve(path_1.default.dirname(manifest), 'aspect')),
146
- routes: Object.entries((_c = data === null || data === void 0 ? void 0 : data.router) === null || _c === void 0 ? void 0 : _c.pages).map(([k, v]) => {
147
- return {
148
- importPath: relativeDist(path_1.default.resolve(path_1.default.dirname(manifest), v.path)),
149
- name: k,
150
- route: v.path
151
- };
152
- })
151
+ function getAspectRoutes(aspectPath) {
152
+ var _a;
153
+ const aspectManifestPath = path_1.default.join(aspectPath, 'src', 'manifest.json');
154
+ const aspectManifest = getManifest(aspectManifestPath);
155
+ if (!((_a = aspectManifest === null || aspectManifest === void 0 ? void 0 : aspectManifest.router) === null || _a === void 0 ? void 0 : _a.pages))
156
+ return [];
157
+ return Object.entries(aspectManifest.router.pages).map(([k, v]) => {
158
+ return {
159
+ importPath: relativeDist(path_1.default.resolve(path_1.default.dirname(aspectManifestPath), v.path)),
160
+ name: k,
161
+ route: v.path
162
+ };
163
+ });
164
+ }
165
+ if ((_b = appManifest === null || appManifest === void 0 ? void 0 : appManifest.router) === null || _b === void 0 ? void 0 : _b.aspects) {
166
+ Object.entries(appManifest.router.aspects).forEach(([name, aspects]) => {
167
+ aspects.forEach((aspect) => {
168
+ var _a;
169
+ const aspectPath = path_1.default.join(buildDir, aspect.path);
170
+ (_a = opt.aspects) === null || _a === void 0 ? void 0 : _a.push({
171
+ name: name,
172
+ path: relativeDist(path_1.default.resolve(buildDir, aspect.path, 'src', 'aspect')),
173
+ routes: getAspectRoutes(aspectPath)
174
+ });
153
175
  });
154
- }
176
+ });
155
177
  }
156
178
  const template = (0, exports.entryTemplate)(opt);
157
179
  fs_extra_1.default.writeFileSync(path_1.default.join(projectPath, output, exports.XtsEntryFileName), template);
158
- ColorConsole_1.default.log({
159
- level: shared_utils_1.LOG_LEVEL.Info,
160
- message: `Entry file built`
161
- });
180
+ ColorConsole_1.default.info(`entry file built`);
162
181
  });
163
- }
182
+ };
164
183
  exports.generateEntryFile = generateEntryFile;
165
-
166
- //# sourceMappingURL=entryTemplate.js.map
@@ -43,7 +43,7 @@ const ts2wasm_1 = require("./ts2wasm");
43
43
  const generateRpk = (context, _, compilerOptions) => __awaiter(void 0, void 0, void 0, function* () {
44
44
  var _a;
45
45
  if ((_a = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.skip) === null || _a === void 0 ? void 0 : _a.includes('package')) {
46
- ColorConsole_1.default.log({ message: `skip package due to --skip ${compilerOptions.skip.join(',')}` });
46
+ ColorConsole_1.default.info(`### skip package due to --skip ${compilerOptions.skip.join(',')}`);
47
47
  return;
48
48
  }
49
49
  const manifestPath = path_1.default.resolve(context.projectPath, 'app', 'manifest.json');
@@ -54,5 +54,3 @@ const generateRpk = (context, _, compilerOptions) => __awaiter(void 0, void 0, v
54
54
  });
55
55
  });
56
56
  exports.generateRpk = generateRpk;
57
-
58
- //# sourceMappingURL=generateRpk.js.map
@@ -13,7 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.ts2wasm = exports.wasmPackageName = void 0;
16
- const shared_utils_1 = require("@aiot-toolkit/shared-utils");
17
16
  const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
18
17
  const child_process_1 = require("child_process");
19
18
  const fast_glob_1 = __importDefault(require("fast-glob"));
@@ -38,22 +37,14 @@ const ts2wasm = (context, _, compilerOptions) => __awaiter(void 0, void 0, void
38
37
  function compile() {
39
38
  // TODO: 后续修改为 @mi
40
39
  const ts2wasmpath = path_1.default.resolve(projectPath, 'node_modules', 'mi/wasmnizer-ts');
41
- ColorConsole_1.default.log({
42
- level: shared_utils_1.LOG_LEVEL.Info,
43
- message: 'Waiting for generating app.wasm file.'
44
- });
40
+ ColorConsole_1.default.info('### Waiting for generating app.wasm file.');
45
41
  const res = (0, child_process_1.execSync)(`node ${ts2wasmpath}/build/cli/ts2wasm.js ${entryFile} -o ${wasmDir}/app.wasm`, {
46
42
  encoding: 'utf-8'
47
43
  });
48
- ColorConsole_1.default.log({
49
- level: shared_utils_1.LOG_LEVEL.Info,
50
- message: res
51
- });
44
+ ColorConsole_1.default.info(`### ts2wasm ### ${res.toString()}`);
52
45
  }
53
46
  if ((_a = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.skip) === null || _a === void 0 ? void 0 : _a.includes('ts2wasm')) {
54
- ColorConsole_1.default.log({
55
- message: `skip compile ts to wasm due to --skip ${compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.skip.join(',')}`
56
- });
47
+ ColorConsole_1.default.info(`### skip compile ts to wasm due to --skip ${compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.skip.join(',')}`);
57
48
  }
58
49
  else {
59
50
  compile();
@@ -76,5 +67,3 @@ const ts2wasm = (context, _, compilerOptions) => __awaiter(void 0, void 0, void
76
67
  fs_1.default.copyFileSync(path_1.default.resolve(fast_glob_1.default.convertPathToPattern(projectPath), output, 'app', 'manifest.json'), path_1.default.resolve(fast_glob_1.default.convertPathToPattern(projectPath), exports.wasmPackageName, 'manifest.json'));
77
68
  });
78
69
  exports.ts2wasm = ts2wasm;
79
-
80
- //# sourceMappingURL=ts2wasm.js.map
package/lib/index.js CHANGED
@@ -6,5 +6,3 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.XtsConfig = void 0;
7
7
  const XtsConfig_1 = __importDefault(require("./config/XtsConfig"));
8
8
  exports.XtsConfig = XtsConfig_1.default;
9
-
10
- //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- export declare const skipList: readonly ["install", "ts2wasm", "package"];
1
+ export declare const skipList: readonly ["xts2ts", "install", "ts2wasm", "package"];
2
2
  export type ISkipList = typeof skipList;
3
3
  export interface IXtsCompileOptions {
4
4
  watch?: boolean;
@@ -1,6 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.skipList = void 0;
4
- exports.skipList = ['install', 'ts2wasm', 'package'];
5
-
6
- //# sourceMappingURL=ICompileOptions.js.map
4
+ exports.skipList = ['xts2ts', 'install', 'ts2wasm', 'package'];
@@ -1,4 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
-
4
- //# sourceMappingURL=IDeviceList.js.map
@@ -1,10 +1,12 @@
1
1
  import { IFileLaneContext, IFileParam, ILoader } from 'file-lane';
2
+ import IJavascriptCompileOption from '../../compiler/javascript/interface/IJavascriptCompileOption';
2
3
  /**
3
4
  * 处理app.ux的Loader
4
5
  * AppUxLoader
5
6
  */
6
7
  declare class AppUxLoader implements ILoader {
7
8
  context: IFileLaneContext;
9
+ compilerOption: IJavascriptCompileOption;
8
10
  parser(files: IFileParam<any>[]): Promise<IFileParam<any>[]>;
9
11
  }
10
12
  export default AppUxLoader;
@@ -13,6 +13,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
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
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
16
19
  /**
17
20
  * 处理app.ux的Loader
18
21
  * AppUxLoader
@@ -20,12 +23,19 @@ const UxLoaderUtils_1 = __importDefault(require("../../utils/ux/UxLoaderUtils"))
20
23
  class AppUxLoader {
21
24
  parser(files) {
22
25
  return __awaiter(this, void 0, void 0, function* () {
23
- const resultFiles = [];
24
- yield UxLoaderUtils_1.default.compileAppUxToJavascript(files[0], resultFiles, this.context);
26
+ const { projectPath } = this.context;
27
+ const { files: resultFiles, logs } = yield UxLoaderUtils_1.default.compileAppUxToJavascript(files[0], this.context, this.compilerOption);
28
+ if (logs) {
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
+ }
25
37
  return resultFiles;
26
38
  });
27
39
  }
28
40
  }
29
41
  exports.default = AppUxLoader;
30
-
31
- //# sourceMappingURL=AppUxLoader.js.map
@@ -0,0 +1,24 @@
1
+ import { IFileLaneContext, IFileParam, ILoader } from 'file-lane';
2
+ /**
3
+ * HmlLoader
4
+ */
5
+ declare class HmlLoader implements ILoader {
6
+ context?: IFileLaneContext | undefined;
7
+ compilerOption?: any;
8
+ parser(files: IFileParam<any>[]): IFileParam<any>[] | Promise<IFileParam<any>[]>;
9
+ /**
10
+ * 包裹 hml 文件
11
+ *
12
+ * # 路径
13
+ * 如果存在同路径的 ux 后缀,报错;否则转换为同路径的 ux 后缀
14
+ *
15
+ * # 内容
16
+ * 1. 给hml的内容加上<template></template>
17
+ * 2. 如果存在同路径同名的 script文件,则加到<script></script>中
18
+ * 3. 如果存在同路径同名的 style文件,则加到<style></style>中
19
+ *
20
+ * @param file
21
+ */
22
+ private wrapHml;
23
+ }
24
+ export default HmlLoader;
@@ -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;
@@ -0,0 +1,11 @@
1
+ import { IFileLaneContext, IFileParam, ILoader } from 'file-lane';
2
+ import IJavascriptCompileOption from '../../compiler/javascript/interface/IJavascriptCompileOption';
3
+ /**
4
+ * JsLoader
5
+ */
6
+ declare class JsLoader implements ILoader {
7
+ context: IFileLaneContext;
8
+ compilerOption: IJavascriptCompileOption;
9
+ parser(files: IFileParam<any>[]): IFileParam<any>[] | Promise<IFileParam<any>[]>;
10
+ }
11
+ export default JsLoader;
@@ -0,0 +1,40 @@
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 ParserUtil_1 = __importDefault(require("@aiot-toolkit/parser/lib/utils/ParserUtil"));
7
+ const ScriptParser_1 = __importDefault(require("@aiot-toolkit/parser/lib/ux/parser/ScriptParser"));
8
+ const ScriptToTypescript_1 = __importDefault(require("@aiot-toolkit/parser/lib/ux/translate/vela/ScriptToTypescript"));
9
+ /**
10
+ * JsLoader
11
+ */
12
+ class JsLoader {
13
+ parser(files) {
14
+ const project = ParserUtil_1.default.createProject();
15
+ const onLog = () => { };
16
+ return files.map((item) => {
17
+ if (!item.content) {
18
+ return {
19
+ path: item.path,
20
+ content: item.content
21
+ };
22
+ }
23
+ const options = {
24
+ filePath: item.path,
25
+ projectPath: this.context.projectPath,
26
+ content: item.content.toString(),
27
+ onLog
28
+ };
29
+ return {
30
+ path: item.path,
31
+ content: new ScriptToTypescript_1.default(project, options, this.compilerOption)
32
+ .translate({
33
+ content: new ScriptParser_1.default(options).parser(item.content.toString()).ast.content
34
+ }, [])
35
+ .targetTree.getFullText()
36
+ };
37
+ });
38
+ }
39
+ }
40
+ exports.default = JsLoader;
@@ -12,7 +12,6 @@ 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
15
  const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
17
16
  const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
18
17
  const path_1 = __importDefault(require("path"));
@@ -31,10 +30,7 @@ class PngLoader {
31
30
  const fullName = `${name}${ext}`;
32
31
  //判断文本,空文本则结束该文件处理
33
32
  if (!content) {
34
- ColorConsole_1.default.log({
35
- level: shared_utils_1.LOG_LEVEL.Warn,
36
- message: `【XtsLoader】the file '${fullName}' under the path '${filePath}' has no content `
37
- });
33
+ ColorConsole_1.default.warn(`The file '${fullName}' under the path '${filePath}' has no content `);
38
34
  return [];
39
35
  }
40
36
  // 判断传入的.png资源是不是.9.png资源
@@ -58,13 +54,12 @@ class PngLoader {
58
54
  yield aaptjs.singleCrunch(filePath, outputFile);
59
55
  }
60
56
  catch (error) {
61
- // 报错
62
- console.error('.9.png资源文件优化失败', error);
57
+ ColorConsole_1.default.throw(`.9.png resource file processing failed`);
63
58
  }
64
59
  }
65
60
  });
66
61
  }
67
62
  }
63
+ ;
64
+ PngLoader.raw = true;
68
65
  exports.default = PngLoader;
69
-
70
- //# sourceMappingURL=PngLoader.js.map
@@ -1,6 +1,8 @@
1
1
  import { IFileLaneContext, IFileParam, ILoader } from 'file-lane';
2
+ import IJavascriptCompileOption from '../../compiler/javascript/interface/IJavascriptCompileOption';
2
3
  declare class UxLoader implements ILoader {
3
4
  context: IFileLaneContext;
5
+ compilerOption: IJavascriptCompileOption;
4
6
  parser(files: IFileParam<any>[]): Promise<IFileParam<any>[]>;
5
7
  }
6
8
  export default UxLoader;
@@ -12,20 +12,31 @@ 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
+ const path_1 = __importDefault(require("path"));
15
18
  const UxLoaderUtils_1 = __importDefault(require("../../utils/ux/UxLoaderUtils"));
16
19
  class UxLoader {
17
20
  parser(files) {
18
21
  return __awaiter(this, void 0, void 0, function* () {
19
22
  const resultFiles = [];
23
+ const { projectPath } = this.context;
20
24
  for (const file of files) {
21
25
  // 转换每个文件
22
- const compileFiles = yield UxLoaderUtils_1.default.compileUxToJavascript(file, this.context, false);
23
- resultFiles.push(...compileFiles);
26
+ const { files: compiledFiles, logs } = yield UxLoaderUtils_1.default.compileUxToJavascript(file, this.context, false, this.compilerOption);
27
+ if (logs) {
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
+ }
36
+ resultFiles.push(...compiledFiles);
24
37
  }
25
38
  return resultFiles;
26
39
  });
27
40
  }
28
41
  }
29
42
  exports.default = UxLoader;
30
-
31
- //# sourceMappingURL=UxLoader.js.map
@@ -5,7 +5,6 @@ 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 shared_utils_1 = require("@aiot-toolkit/shared-utils");
9
8
  const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
10
9
  const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
11
10
  const path_1 = __importDefault(require("path"));
@@ -24,14 +23,11 @@ class XtsLoader {
24
23
  const newFileName = `${name}.ts`;
25
24
  //判断文本,空文本则结束该文件处理
26
25
  if (!content) {
27
- ColorConsole_1.default.log({
28
- level: shared_utils_1.LOG_LEVEL.Warn,
29
- message: `【XtsLoader】the file '${fullName}' under the path '${path}' has no content `
30
- });
26
+ ColorConsole_1.default.warn(`The file '${fullName}' under the path '${path}' has no content `);
31
27
  return [];
32
28
  }
33
- const parserResult = new parser_1.XtsParser(project, ColorConsole_1.default.log).parser(content, fullName);
34
- const { ast, mapList } = new parser_1.XtsToTypescript(project, ColorConsole_1.default.log, this.context, path).translate(parserResult.ast, parserResult.offsetList);
29
+ const parserResult = new parser_1.XtsParser(project, ColorConsole_1.default.logger).parser(content.toString(), fullName);
30
+ const { ast, mapList } = new parser_1.XtsToTypescript(project, ColorConsole_1.default.logger, this.context, path).translate(parserResult.ast, parserResult.offsetList);
35
31
  const { code, sourcemap } = new generator_1.TypescriptGenerator().generate({
36
32
  sourceFilePath: fullName,
37
33
  targetFilePath: newFileName,
@@ -51,5 +47,3 @@ class XtsLoader {
51
47
  }
52
48
  }
53
49
  exports.default = XtsLoader;
54
-
55
- //# sourceMappingURL=XtsLoader.js.map
@@ -0,0 +1,10 @@
1
+ import { PreWork } from 'file-lane/lib/interface/IFileLaneConfig';
2
+ import IJavascriptCompileOption from '../../compiler/javascript/interface/IJavascriptCompileOption';
3
+ /**
4
+ * UxPreWorks
5
+ */
6
+ declare class UxPreWorks {
7
+ static validateManifest: PreWork<IJavascriptCompileOption>;
8
+ static validateSitemap: PreWork<IJavascriptCompileOption>;
9
+ }
10
+ export default UxPreWorks;
@@ -0,0 +1,31 @@
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 UxFileUtils_1 = __importDefault(require("../../utils/ux/UxFileUtils"));
17
+ /**
18
+ * UxPreWorks
19
+ */
20
+ class UxPreWorks {
21
+ }
22
+ _a = UxPreWorks;
23
+ UxPreWorks.validateManifest = (context) => __awaiter(void 0, void 0, void 0, function* () {
24
+ const { projectPath } = context;
25
+ return UxFileUtils_1.default.validateManifest(projectPath);
26
+ });
27
+ UxPreWorks.validateSitemap = (context) => __awaiter(void 0, void 0, void 0, function* () {
28
+ const { projectPath } = context;
29
+ UxFileUtils_1.default.validateSitemap(projectPath);
30
+ });
31
+ exports.default = UxPreWorks;
@@ -20,16 +20,14 @@ 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
- ColorConsole_1.default.log({
24
- message: `skip install pre-dependencies due to --skip ${compilerOption === null || compilerOption === void 0 ? void 0 : compilerOption.skip.join(',')}`
25
- });
23
+ ColorConsole_1.default.info(`### skip install pre-dependencies due to --skip ${compilerOption === null || compilerOption === void 0 ? void 0 : compilerOption.skip.join(',')}`);
26
24
  return;
27
25
  }
28
26
  const { projectPath } = context;
29
27
  const packagePath = path_1.default.resolve(projectPath, 'package.json');
30
28
  const preContent = {
31
29
  dependencies: {
32
- '@mi/ts-framework': 'https://pkgs.d.xiaomi.net:443/artifactory/api/npm/mi-npm/@mi/ts-framework/-/@mi/ts-framework-1.0.7.tgz',
30
+ '@mi/ts-framework': 'https://pkgs.d.xiaomi.net:443/artifactory/api/npm/mi-npm/@mi/ts-framework/-/@mi/ts-framework-1.0.9.tgz',
33
31
  '@mi/wasmnizer-ts': 'https://pkgs.d.xiaomi.net:443/artifactory/api/npm/mi-npm/@mi/wasmnizer-ts/-/@mi/wasmnizer-ts-0.0.12.tgz'
34
32
  }
35
33
  };
@@ -49,18 +47,12 @@ const preInstall = (context, _, __, compilerOption) => __awaiter(void 0, void 0,
49
47
  });
50
48
  }
51
49
  }
52
- ColorConsole_1.default.log({
53
- message: 'Installing pre-dependencies. The initial build may take some time, please be patient...'
54
- });
50
+ ColorConsole_1.default.info('### Installing pre-dependencies. The initial build may take some time, please be patient...');
55
51
  (0, child_process_1.execSync)('npm install', {
56
52
  cwd: projectPath
57
53
  });
58
54
  // 目前ts2wasm不支持@符号
59
55
  fs_1.default.renameSync(path_1.default.resolve(projectPath, 'node_modules/@mi'), path_1.default.resolve(projectPath, 'node_modules/mi'));
60
- ColorConsole_1.default.log({
61
- message: 'Dependencies installation complete.'
62
- });
56
+ ColorConsole_1.default.info('### Dependencies installation complete.');
63
57
  });
64
58
  exports.preInstall = preInstall;
65
-
66
- //# sourceMappingURL=preInstall.js.map
@@ -41,5 +41,3 @@ class PngUtils {
41
41
  }
42
42
  }
43
43
  exports.default = PngUtils;
44
-
45
- //# sourceMappingURL=PngUtils.js.map
@@ -13,5 +13,10 @@ declare class PreWorkUtils {
13
13
  */
14
14
  static getEntries(context: IFileLaneContext): Promise<void>;
15
15
  static clean: PreWork<IJavascriptCompileOption>;
16
+ /**
17
+ * 获取项目的全局样式变量配置
18
+ * @param context
19
+ */
20
+ static getGlobalVar(context: IFileLaneContext): Promise<void>;
16
21
  }
17
22
  export default PreWorkUtils;