@aiot-toolkit/aiotpack 2.0.2-beta.5 → 2.0.2-beta.7

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.
@@ -130,7 +130,7 @@ class UxCompileUtil {
130
130
  * @returns
131
131
  */
132
132
  static getExtensionList(withDot = true) {
133
- const result = ['js'];
133
+ const result = ['ux'];
134
134
  if (withDot) {
135
135
  return result.map((item) => `.${item}`);
136
136
  }
@@ -1,32 +1,13 @@
1
1
  import { IFileLaneConfig } from 'file-lane';
2
2
  import IJavascriptCompileOption from '../compiler/javascript/interface/IJavascriptCompileOption';
3
- import AppUxLoader from '../loader/ux/AppUxLoader';
4
- import JsLoader from '../loader/ux/JsLoader';
5
- import PngLoader from '../loader/ux/PngLoader';
6
- import UxLoader from '../loader/ux/UxLoader';
3
+ import { IRule } from 'file-lane/lib/interface/IFileLaneConfig';
7
4
  declare class UxConfig implements IFileLaneConfig<IJavascriptCompileOption> {
8
5
  readonly projectPath: string;
9
6
  constructor(projectPath: string);
10
- exclude: RegExp[];
7
+ exclude: (RegExp | ((filePath: string) => boolean))[];
11
8
  get output(): string;
12
9
  module: {
13
- rules: ({
14
- test: string[];
15
- loader: (typeof AppUxLoader)[];
16
- exclude?: undefined;
17
- } | {
18
- test: RegExp[];
19
- exclude: RegExp[];
20
- loader: (typeof UxLoader)[];
21
- } | {
22
- test: RegExp[];
23
- loader: (typeof JsLoader)[];
24
- exclude?: undefined;
25
- } | {
26
- test: RegExp[];
27
- loader: (typeof PngLoader)[];
28
- exclude?: undefined;
29
- })[];
10
+ rules: IRule[];
30
11
  };
31
12
  preWorks: import("file-lane/lib/interface/IFileLaneConfig").PreWork<IJavascriptCompileOption>[];
32
13
  followWorks: {
@@ -11,10 +11,30 @@ const UxLoader_1 = __importDefault(require("../loader/ux/UxLoader"));
11
11
  const PreWorkUtils_1 = __importDefault(require("../utils/PreWorkUtils"));
12
12
  const UxFollowWorks_1 = __importDefault(require("../followWorks/ux/UxFollowWorks"));
13
13
  const UxPreWorks_1 = __importDefault(require("../preWorks/ux/UxPreWorks"));
14
+ const HmlLoader_1 = __importDefault(require("../loader/ux/HmlLoader"));
15
+ const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
16
+ const fs_1 = __importDefault(require("fs"));
17
+ const parser_1 = require("@aiot-toolkit/parser");
14
18
  class UxConfig {
15
19
  constructor(projectPath) {
16
20
  this.projectPath = projectPath;
17
- this.exclude = [/node_modules/, /dist/, /build/];
21
+ this.exclude = [
22
+ /node_modules/,
23
+ /dist/,
24
+ /build/,
25
+ (filePath) => {
26
+ // 如果 是 script, style文件,且同路径下存在同名 hml,则忽略
27
+ const { ext, name } = path_1.default.parse(filePath);
28
+ if (![...parser_1.ExtensionConfig.SCRIPTS, ...parser_1.ExtensionConfig.STYLES].includes(ext)) {
29
+ return false;
30
+ }
31
+ const hmlPath = FileUtil_1.default.updatePath(filePath, `${name}${parser_1.ExtensionConfig.HML}`);
32
+ if (fs_1.default.existsSync(hmlPath)) {
33
+ return true;
34
+ }
35
+ return false;
36
+ }
37
+ ];
18
38
  this.module = {
19
39
  rules: [
20
40
  {
@@ -26,6 +46,10 @@ class UxConfig {
26
46
  exclude: [/app\.ux/],
27
47
  loader: [UxLoader_1.default]
28
48
  },
49
+ {
50
+ test: [/.+\.hml$/],
51
+ loader: [HmlLoader_1.default, UxLoader_1.default]
52
+ },
29
53
  {
30
54
  test: [/.+\.js$/],
31
55
  loader: [JsLoader_1.default]
@@ -1,5 +1,6 @@
1
1
  import { IFileLaneConfig } from 'file-lane';
2
2
  import XtsLoader from '../loader/xts/XtsLoader';
3
+ import { PreWork } from 'file-lane/lib/interface/IFileLaneConfig';
3
4
  /**
4
5
  * XtsConfig
5
6
  */
@@ -12,7 +13,7 @@ declare class XtsConfig implements IFileLaneConfig {
12
13
  loader: (typeof XtsLoader)[];
13
14
  }[];
14
15
  };
15
- preWorks: import("file-lane/lib/interface/IFileLaneConfig").PreWork<import("../interface/ICompileOptions").IXtsCompileOptions>[];
16
+ preWorks: PreWork[];
16
17
  followWorks: {
17
18
  worker: import("file-lane/lib/interface/IFileLaneConfig").FollowWork<import("../interface/ICompileOptions").IXtsCompileOptions>;
18
19
  }[];
@@ -7,7 +7,6 @@ const entryTemplate_1 = require("../followWorks/xts/entryTemplate");
7
7
  const generateRpk_1 = require("../followWorks/xts/generateRpk");
8
8
  const ts2wasm_1 = require("../followWorks/xts/ts2wasm");
9
9
  const XtsLoader_1 = __importDefault(require("../loader/xts/XtsLoader"));
10
- const preInstall_1 = require("../preWorks/xts/preInstall");
11
10
  /**
12
11
  * XtsConfig
13
12
  */
@@ -23,7 +22,7 @@ class XtsConfig {
23
22
  }
24
23
  ]
25
24
  };
26
- this.preWorks = [preInstall_1.preInstall];
25
+ this.preWorks = [];
27
26
  this.followWorks = [
28
27
  {
29
28
  worker: entryTemplate_1.generateEntryFile
@@ -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,8 +23,17 @@ 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, this.compilerOption);
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
  }
@@ -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;
@@ -23,6 +23,7 @@ class JsLoader {
23
23
  const options = {
24
24
  filePath: item.path,
25
25
  projectPath: this.context.projectPath,
26
+ content: item.content.toString(),
26
27
  onLog
27
28
  };
28
29
  return {
@@ -23,7 +23,7 @@ class UxLoader {
23
23
  const { projectPath } = this.context;
24
24
  for (const file of files) {
25
25
  // 转换每个文件
26
- const { files, logs } = yield UxLoaderUtils_1.default.compileUxToJavascript(file, this.context, false, this.compilerOption);
26
+ const { files: compiledFiles, logs } = yield UxLoaderUtils_1.default.compileUxToJavascript(file, this.context, false, this.compilerOption);
27
27
  if (logs) {
28
28
  logs.forEach((item) => {
29
29
  ColorConsole_1.default.logger(Object.assign(Object.assign({}, item), { filePath: item.filePath ? path_1.default.relative(projectPath, item.filePath) : '' }));
@@ -33,7 +33,7 @@ class UxLoader {
33
33
  throw new Error('stop!');
34
34
  }
35
35
  }
36
- resultFiles.push(...files);
36
+ resultFiles.push(...compiledFiles);
37
37
  }
38
38
  return resultFiles;
39
39
  });
@@ -19,6 +19,7 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
19
19
  const path_1 = __importDefault(require("path"));
20
20
  const TranslateCache_1 = __importDefault(require("../../../parser/lib/ux/translate/vela/TranslateCache"));
21
21
  const UxFileUtils_1 = __importDefault(require("./ux/UxFileUtils"));
22
+ const parser_1 = require("@aiot-toolkit/parser");
22
23
  const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
23
24
  /**
24
25
  * PreWorkUtils
@@ -51,13 +52,14 @@ class PreWorkUtils {
51
52
  Object.keys(pages).map((page) => {
52
53
  const pageContent = pages[page];
53
54
  const entryDir = path_1.default.join(srcPath, page);
54
- const entryPage = path_1.default.join(entryDir, `${pageContent.component}.ux`);
55
- if (fs_extra_1.default.existsSync(entryPage)) {
56
- entryList.push(entryPage);
55
+ const entryPages = parser_1.ExtensionConfig.TEMPLATES.map((item) => `${pageContent.component}${item}`);
56
+ const entry = entryPages.find((item) => fs_extra_1.default.existsSync(path_1.default.join(entryDir, item)));
57
+ if (entry) {
58
+ entryList.push(path_1.default.join(entryDir, entry));
57
59
  }
58
60
  else {
59
61
  // 路径不存在
60
- ColorConsole_1.default.throw(`### manifest ### path '${entryPage}' does not exist`);
62
+ ColorConsole_1.default.throw(`### manifest ### path '${entryPages.join(' | ')}' does not exist`);
61
63
  }
62
64
  });
63
65
  context['entries'] = entryList;
@@ -24,7 +24,10 @@ declare class UxLoaderUtils {
24
24
  * @param resultFiles
25
25
  * @param context
26
26
  */
27
- static compileAppUxToJavascript(file: IFileParam, resultFiles: IFileParam[], context: IFileLaneContext, compileOption: IJavascriptCompileOption): Promise<void>;
27
+ static compileAppUxToJavascript(file: IFileParam, context: IFileLaneContext, compileOption: IJavascriptCompileOption): Promise<{
28
+ files: IFileParam<any>[];
29
+ logs: ILog[];
30
+ }>;
28
31
  /**
29
32
  * 判断是否为src/app.ux
30
33
  * @param filePath
@@ -40,7 +40,7 @@ const UxParser_1 = __importDefault(require("@aiot-toolkit/parser/lib/ux/parser/U
40
40
  const UxToTypescript_1 = __importDefault(require("@aiot-toolkit/parser/lib/ux/translate/vela/UxToTypescript"));
41
41
  const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
42
42
  const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
43
- const parse5 = __importStar(require("parse5"));
43
+ const parse5 = __importStar(require("aiot-parse5"));
44
44
  const path_1 = __importDefault(require("path"));
45
45
  const fs_extra_1 = __importDefault(require("fs-extra"));
46
46
  const ts_morph_1 = require("ts-morph");
@@ -82,6 +82,7 @@ class UxLoaderUtils {
82
82
  projectPath: context.projectPath,
83
83
  filePath,
84
84
  fileType: isAppUx ? 'app' : isPageUx ? 'page' : '',
85
+ content: content.toString(),
85
86
  onLog: (log) => {
86
87
  logs.push(log);
87
88
  }
@@ -95,7 +96,7 @@ class UxLoaderUtils {
95
96
  const { name, ext } = path_1.default.parse(originFilePath);
96
97
  const hashName = CommonUtil_1.default.calcImageDigest(originFilePath);
97
98
  const newFilePath = path_1.default.join(assetPath, `${name}-${hashName}${ext}`);
98
- const relativePath = path_1.default.posix.sep + path_1.default.relative(sourcePath, newFilePath);
99
+ const relativePath = path_1.default.posix.sep + path_1.default.relative(sourcePath, newFilePath).split(path_1.default.sep).join(path_1.default.posix.sep);
99
100
  ImageResources.push({
100
101
  path: newFilePath,
101
102
  content: fs_extra_1.default.readFileSync(originFilePath)
@@ -104,7 +105,7 @@ class UxLoaderUtils {
104
105
  };
105
106
  // 开始转换
106
107
  const globalVar = ('globalVar' in context && context.globalVar) || {};
107
- const parserResult = yield new UxParser_1.default(options, compilerOption, globalVar, collectImageResource).parser(content.toString(), fullName);
108
+ const parserResult = yield new UxParser_1.default(options, compilerOption, globalVar, collectImageResource).parser();
108
109
  // 区分app.ux和一般ux
109
110
  // app.ux解析结果中加上manifest.json的内容
110
111
  const manifestJson = `require('./manifest.json')`;
@@ -142,7 +143,7 @@ class UxLoaderUtils {
142
143
  return {
143
144
  files: [
144
145
  {
145
- path: FileUtil_1.default.updatePath(filePath, newFileName),
146
+ path: filePath,
146
147
  content: code
147
148
  },
148
149
  {
@@ -161,7 +162,7 @@ class UxLoaderUtils {
161
162
  * @param resultFiles
162
163
  * @param context
163
164
  */
164
- static compileAppUxToJavascript(file, resultFiles, context, compileOption) {
165
+ static compileAppUxToJavascript(file, context, compileOption) {
165
166
  return __awaiter(this, void 0, void 0, function* () {
166
167
  const { path: filePath, content } = file;
167
168
  let appContent = content;
@@ -172,7 +173,7 @@ class UxLoaderUtils {
172
173
  }
173
174
  // 解析script和style两部分
174
175
  const compileResult = yield UxLoaderUtils.compileUxToJavascript({ path: filePath, content: appContent }, context, isAppUx, compileOption);
175
- resultFiles.push(...compileResult.files);
176
+ return compileResult;
176
177
  });
177
178
  }
178
179
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/aiotpack",
3
- "version": "2.0.2-beta.5",
3
+ "version": "2.0.2-beta.7",
4
4
  "description": "The process tool for packaging aiot projects.",
5
5
  "keywords": [
6
6
  "aiotpack"
@@ -19,13 +19,13 @@
19
19
  "test": "node ./__tests__/aiotpack.test.js"
20
20
  },
21
21
  "dependencies": {
22
- "@aiot-toolkit/generator": "2.0.2-beta.5",
23
- "@aiot-toolkit/parser": "2.0.2-beta.5",
22
+ "@aiot-toolkit/generator": "2.0.2-beta.7",
23
+ "@aiot-toolkit/parser": "2.0.2-beta.7",
24
24
  "@hap-toolkit/aaptjs": "^2.0.0",
25
25
  "babel-loader": "^9.1.3",
26
26
  "del": "^4.1.0",
27
27
  "fast-glob": "^3.3.2",
28
- "file-lane": "2.0.2-beta.5",
28
+ "file-lane": "2.0.2-beta.7",
29
29
  "file-loader": "^6.2.0",
30
30
  "fs-extra": "^11.2.0",
31
31
  "jsrsasign": "^7.2.2",
@@ -41,5 +41,5 @@
41
41
  "@types/jsrsasign": "^10.5.12",
42
42
  "@types/webpack-sources": "^3.2.3"
43
43
  },
44
- "gitHead": "8c18753992c453c6569a3125378e75fbf4760a1f"
44
+ "gitHead": "dc37f9f6fbef3895d17b54ad41274c66f154f670"
45
45
  }