@aiot-toolkit/aiotpack 2.0.1-alpha.9 → 2.0.2-dev.2

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 (108) 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 +23 -17
  7. package/lib/compiler/javascript/JavascriptDefaultCompileOption.d.ts +1 -0
  8. package/lib/compiler/javascript/JavascriptDefaultCompileOption.js +5 -2
  9. package/lib/compiler/javascript/interface/IJavascriptCompileOption.d.ts +8 -4
  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.js +0 -2
  13. package/lib/compiler/javascript/vela/enum/BuildNameFormatType.js +0 -2
  14. package/lib/compiler/javascript/vela/enum/EntryType.js +0 -2
  15. package/lib/compiler/javascript/vela/interface/IChunk.js +0 -2
  16. package/lib/compiler/javascript/vela/interface/IManifest.d.ts +1 -0
  17. package/lib/compiler/javascript/vela/interface/IManifest.js +0 -2
  18. package/lib/compiler/javascript/vela/interface/IQuickAppConfig.js +0 -2
  19. package/lib/compiler/javascript/vela/model/Package.js +2 -4
  20. package/lib/compiler/javascript/vela/plugin/WrapPlugin.js +0 -2
  21. package/lib/compiler/javascript/vela/utils/Jsc.d.ts +1 -1
  22. package/lib/compiler/javascript/vela/utils/Jsc.js +4 -7
  23. package/lib/compiler/javascript/vela/utils/UxCompileUtil.js +2 -4
  24. package/lib/compiler/javascript/vela/utils/ZipUtil.js +5 -7
  25. package/lib/compiler/javascript/vela/utils/signature/Base64.js +0 -2
  26. package/lib/compiler/javascript/vela/utils/signature/CRC32.js +0 -2
  27. package/lib/compiler/javascript/vela/utils/signature/SignUtil.d.ts +1 -1
  28. package/lib/compiler/javascript/vela/utils/signature/SignUtil.js +14 -12
  29. package/lib/compiler/javascript/vela/utils/signature/Signer.js +0 -2
  30. package/lib/config/UxConfig.d.ts +8 -3
  31. package/lib/config/UxConfig.js +23 -6
  32. package/lib/config/XtsConfig.js +0 -2
  33. package/lib/followWorks/xts/entryTemplate.d.ts +2 -2
  34. package/lib/followWorks/xts/entryTemplate.js +61 -44
  35. package/lib/followWorks/xts/generateRpk.js +1 -3
  36. package/lib/followWorks/xts/ts2wasm.js +3 -14
  37. package/lib/index.js +0 -2
  38. package/lib/interface/ICompileOptions.d.ts +1 -1
  39. package/lib/interface/ICompileOptions.js +1 -3
  40. package/lib/interface/IDeviceList.js +0 -2
  41. package/lib/loader/ux/AppUxLoader.d.ts +2 -0
  42. package/lib/loader/ux/AppUxLoader.js +1 -3
  43. package/lib/loader/ux/ImageCompressLoader.d.ts +9 -0
  44. package/lib/loader/ux/ImageCompressLoader.js +74 -0
  45. package/lib/loader/ux/JsLoader.d.ts +9 -0
  46. package/lib/loader/ux/JsLoader.js +39 -0
  47. package/lib/loader/ux/PngLoader.js +4 -9
  48. package/lib/loader/ux/UxLoader.d.ts +2 -0
  49. package/lib/loader/ux/UxLoader.js +15 -4
  50. package/lib/loader/xts/XtsLoader.js +3 -9
  51. package/lib/preWorks/xts/preInstall.js +4 -12
  52. package/lib/utils/PngUtils.js +0 -2
  53. package/lib/utils/PreWorkUtils.d.ts +5 -0
  54. package/lib/utils/PreWorkUtils.js +39 -9
  55. package/lib/utils/ux/ManifestSchema.d.ts +3 -0
  56. package/lib/utils/ux/ManifestSchema.js +207 -0
  57. package/lib/utils/ux/UxFileUtils.d.ts +21 -4
  58. package/lib/utils/ux/UxFileUtils.js +74 -5
  59. package/lib/utils/ux/UxFollowWorks.d.ts +1 -0
  60. package/lib/utils/ux/UxFollowWorks.js +57 -5
  61. package/lib/utils/ux/UxLoaderUtils.d.ts +11 -7
  62. package/lib/utils/ux/UxLoaderUtils.js +115 -31
  63. package/lib/utils/ux/UxPreWorks.d.ts +10 -0
  64. package/lib/utils/ux/UxPreWorks.js +31 -0
  65. package/lib/utils/xts/XtsFollowWorks.js +3 -12
  66. package/package.json +6 -5
  67. package/lib/compiler/enum/CompileMode.js.map +0 -1
  68. package/lib/compiler/interface/ICompileParam.js.map +0 -1
  69. package/lib/compiler/interface/ICompiler.js.map +0 -1
  70. package/lib/compiler/interface/ISignConfig.js.map +0 -1
  71. package/lib/compiler/javascript/JavascriptCompiler.js.map +0 -1
  72. package/lib/compiler/javascript/JavascriptDefaultCompileOption.js.map +0 -1
  73. package/lib/compiler/javascript/interface/IJavascriptCompileOption.js.map +0 -1
  74. package/lib/compiler/javascript/interface/IWebpackConfigurator.js.map +0 -1
  75. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js.map +0 -1
  76. package/lib/compiler/javascript/vela/enum/BuildNameFormatType.js.map +0 -1
  77. package/lib/compiler/javascript/vela/enum/EntryType.js.map +0 -1
  78. package/lib/compiler/javascript/vela/interface/IChunk.js.map +0 -1
  79. package/lib/compiler/javascript/vela/interface/IManifest.js.map +0 -1
  80. package/lib/compiler/javascript/vela/interface/IQuickAppConfig.js.map +0 -1
  81. package/lib/compiler/javascript/vela/model/Package.js.map +0 -1
  82. package/lib/compiler/javascript/vela/plugin/WrapPlugin.js.map +0 -1
  83. package/lib/compiler/javascript/vela/utils/Jsc.js.map +0 -1
  84. package/lib/compiler/javascript/vela/utils/UxCompileUtil.js.map +0 -1
  85. package/lib/compiler/javascript/vela/utils/ZipUtil.js.map +0 -1
  86. package/lib/compiler/javascript/vela/utils/signature/Base64.js.map +0 -1
  87. package/lib/compiler/javascript/vela/utils/signature/CRC32.js.map +0 -1
  88. package/lib/compiler/javascript/vela/utils/signature/SignUtil.js.map +0 -1
  89. package/lib/compiler/javascript/vela/utils/signature/Signer.js.map +0 -1
  90. package/lib/config/UxConfig.js.map +0 -1
  91. package/lib/config/XtsConfig.js.map +0 -1
  92. package/lib/followWorks/xts/entryTemplate.js.map +0 -1
  93. package/lib/followWorks/xts/generateRpk.js.map +0 -1
  94. package/lib/followWorks/xts/ts2wasm.js.map +0 -1
  95. package/lib/index.js.map +0 -1
  96. package/lib/interface/ICompileOptions.js.map +0 -1
  97. package/lib/interface/IDeviceList.js.map +0 -1
  98. package/lib/loader/ux/AppUxLoader.js.map +0 -1
  99. package/lib/loader/ux/PngLoader.js.map +0 -1
  100. package/lib/loader/ux/UxLoader.js.map +0 -1
  101. package/lib/loader/xts/XtsLoader.js.map +0 -1
  102. package/lib/preWorks/xts/preInstall.js.map +0 -1
  103. package/lib/utils/PngUtils.js.map +0 -1
  104. package/lib/utils/PreWorkUtils.js.map +0 -1
  105. package/lib/utils/ux/UxFileUtils.js.map +0 -1
  106. package/lib/utils/ux/UxFollowWorks.js.map +0 -1
  107. package/lib/utils/ux/UxLoaderUtils.js.map +0 -1
  108. 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;
@@ -21,11 +21,9 @@ class AppUxLoader {
21
21
  parser(files) {
22
22
  return __awaiter(this, void 0, void 0, function* () {
23
23
  const resultFiles = [];
24
- yield UxLoaderUtils_1.default.compileAppUxToJavascript(files[0], resultFiles, this.context);
24
+ yield UxLoaderUtils_1.default.compileAppUxToJavascript(files[0], resultFiles, this.context, this.compilerOption);
25
25
  return resultFiles;
26
26
  });
27
27
  }
28
28
  }
29
29
  exports.default = AppUxLoader;
30
-
31
- //# sourceMappingURL=AppUxLoader.js.map
@@ -0,0 +1,9 @@
1
+ import { IFileParam, ILoader } from 'file-lane';
2
+ /**
3
+ * 图片压缩
4
+ */
5
+ declare class ImageCompressLoader implements ILoader {
6
+ parser(files: IFileParam<any>[]): Promise<IFileParam<any>[]>;
7
+ private compressImages;
8
+ }
9
+ export default ImageCompressLoader;
@@ -0,0 +1,74 @@
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 sharp_1 = __importDefault(require("sharp"));
17
+ /**
18
+ * 图片压缩
19
+ */
20
+ class ImageCompressLoader {
21
+ parser(files) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ const result = [];
24
+ for (const file of files) {
25
+ const { path, content } = file;
26
+ if (content instanceof Buffer) {
27
+ const newContent = yield this.compressImages(path, content);
28
+ result.push({
29
+ path,
30
+ content: newContent
31
+ });
32
+ }
33
+ }
34
+ return result;
35
+ });
36
+ }
37
+ compressImages(path, content, minSize = 1024 * 10) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ if (content.length < minSize) {
40
+ return content;
41
+ }
42
+ let result = null;
43
+ const quality = 80;
44
+ const ext = path_1.default.parse(path).ext;
45
+ switch (ext) {
46
+ case '.png':
47
+ result = yield (0, sharp_1.default)(content).png({ quality }).toBuffer();
48
+ break;
49
+ case '.jpg':
50
+ case '.jpeg':
51
+ result = yield (0, sharp_1.default)(content).jpeg({ quality }).toBuffer();
52
+ break;
53
+ case '.gif':
54
+ result = yield (0, sharp_1.default)(content, { animated: true }).gif({ interFrameMaxError: 8 }).toBuffer();
55
+ break;
56
+ case '.webp':
57
+ const metadata = yield (0, sharp_1.default)(content).metadata();
58
+ result = yield (0, sharp_1.default)(content, metadata.pages ? { animated: true } : undefined)
59
+ .webp({ quality })
60
+ .toBuffer();
61
+ break;
62
+ default:
63
+ return content;
64
+ }
65
+ if (result && result.length < content.length) {
66
+ return result;
67
+ }
68
+ return content;
69
+ });
70
+ }
71
+ }
72
+ ;
73
+ ImageCompressLoader.raw = true;
74
+ exports.default = ImageCompressLoader;
@@ -0,0 +1,9 @@
1
+ import { IFileLaneContext, IFileParam, ILoader } from 'file-lane';
2
+ /**
3
+ * JsLoader
4
+ */
5
+ declare class JsLoader implements ILoader {
6
+ context: IFileLaneContext;
7
+ parser(files: IFileParam<any>[]): IFileParam<any>[] | Promise<IFileParam<any>[]>;
8
+ }
9
+ export default JsLoader;
@@ -0,0 +1,39 @@
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
+ onLog
27
+ };
28
+ return {
29
+ path: item.path,
30
+ content: new ScriptToTypescript_1.default(project, options)
31
+ .translate({
32
+ content: new ScriptParser_1.default(options).parser(item.content.toString()).ast.content
33
+ }, [])
34
+ .targetTree.getFullText()
35
+ };
36
+ });
37
+ }
38
+ }
39
+ 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, 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(...files);
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
@@ -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;