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

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.
@@ -36,9 +36,17 @@ export default interface IJavascriptCompileOption extends ICompileParam {
36
36
  /**
37
37
  * 禁用 jsc
38
38
  */
39
- disabledJSC?: boolean;
39
+ disabledJsc?: boolean;
40
40
  /**
41
41
  * 启用 protobuf
42
42
  */
43
43
  enableProtobuf?: boolean;
44
+ /**
45
+ * 启用应用自动化测试
46
+ */
47
+ enableE2e?: boolean;
48
+ /**
49
+ * 启用代码体积分析,会生成 report.html 文件,可查看打包后各模块占用体积
50
+ */
51
+ enableStats?: boolean;
44
52
  }
@@ -10,10 +10,20 @@ const WrapPlugin_1 = __importDefault(require("./plugin/WrapPlugin"));
10
10
  const UxCompileUtil_1 = __importDefault(require("./utils/UxCompileUtil"));
11
11
  class VelaWebpackConfigurator {
12
12
  createPlugins() {
13
- return [
13
+ const result = [
14
14
  // 给 入口js 添加包裹
15
15
  new WrapPlugin_1.default()
16
16
  ];
17
+ // 如果开启 stats 参数,则添加 webpack-bundle-analyzer 插件
18
+ if (this.param.enableStats) {
19
+ const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
20
+ result.push(new BundleAnalyzerPlugin({
21
+ analyzerMode: 'static',
22
+ openAnalyzer: false,
23
+ excludeAssets: /^@(system|service)\./
24
+ }));
25
+ }
26
+ return result;
17
27
  }
18
28
  /**
19
29
  * 通过读取 manifest.json 生成 entry
@@ -40,7 +50,6 @@ class VelaWebpackConfigurator {
40
50
  {
41
51
  loader: require.resolve('babel-loader'),
42
52
  options: {
43
- // configFile: getBabelConfigJsPath(cwd),
44
53
  cwd: this.param.projectPath,
45
54
  cacheDirectory: true
46
55
  }
@@ -2,6 +2,7 @@ import { IFileLaneConfig } from 'file-lane';
2
2
  import IJavascriptCompileOption from '../compiler/javascript/interface/IJavascriptCompileOption';
3
3
  import AppUxLoader from '../loader/ux/AppUxLoader';
4
4
  import JsLoader from '../loader/ux/JsLoader';
5
+ import PngLoader from '../loader/ux/PngLoader';
5
6
  import UxLoader from '../loader/ux/UxLoader';
6
7
  declare class UxConfig implements IFileLaneConfig<IJavascriptCompileOption> {
7
8
  readonly projectPath: string;
@@ -21,6 +22,10 @@ declare class UxConfig implements IFileLaneConfig<IJavascriptCompileOption> {
21
22
  test: RegExp[];
22
23
  loader: (typeof JsLoader)[];
23
24
  exclude?: undefined;
25
+ } | {
26
+ test: RegExp[];
27
+ loader: (typeof PngLoader)[];
28
+ exclude?: undefined;
24
29
  })[];
25
30
  };
26
31
  preWorks: import("file-lane/lib/interface/IFileLaneConfig").PreWork<IJavascriptCompileOption>[];
@@ -78,7 +78,7 @@ UxFollowWorks.protobuf = (context, config, compilerOption) => __awaiter(void 0,
78
78
  }
79
79
  });
80
80
  UxFollowWorks.jsc = (context, config, compilerOption) => __awaiter(void 0, void 0, void 0, function* () {
81
- if (compilerOption && compilerOption.disabledJSC === false) {
81
+ if (compilerOption && compilerOption.disabledJsc === false) {
82
82
  return new Jsc_1.default(context.projectPath, path_1.default.join(context.projectPath, context.output, compilerOption.outputPath)).jsc();
83
83
  }
84
84
  });
@@ -1,9 +1,11 @@
1
1
  import { IFileLaneContext, IFileParam, ILoader } from 'file-lane';
2
+ import IJavascriptCompileOption from '../../compiler/javascript/interface/IJavascriptCompileOption';
2
3
  /**
3
4
  * JsLoader
4
5
  */
5
6
  declare class JsLoader implements ILoader {
6
7
  context: IFileLaneContext;
8
+ compilerOption: IJavascriptCompileOption;
7
9
  parser(files: IFileParam<any>[]): IFileParam<any>[] | Promise<IFileParam<any>[]>;
8
10
  }
9
11
  export default JsLoader;
@@ -27,7 +27,7 @@ class JsLoader {
27
27
  };
28
28
  return {
29
29
  path: item.path,
30
- content: new ScriptToTypescript_1.default(project, options)
30
+ content: new ScriptToTypescript_1.default(project, options, this.compilerOption)
31
31
  .translate({
32
32
  content: new ScriptParser_1.default(options).parser(item.content.toString()).ast.content
33
33
  }, [])
@@ -40,10 +40,11 @@ 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 StringUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/StringUtil"));
44
43
  const parse5 = __importStar(require("parse5"));
45
44
  const path_1 = __importDefault(require("path"));
45
+ const fs_extra_1 = __importDefault(require("fs-extra"));
46
46
  const ts_morph_1 = require("ts-morph");
47
+ const CommonUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/CommonUtil"));
47
48
  const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
48
49
  const { extractFunctions } = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/protobufControl');
49
50
  /**
@@ -74,28 +75,45 @@ class UxLoaderUtils {
74
75
  logs
75
76
  };
76
77
  }
78
+ // 区分页面组件和子组件
79
+ const isPageUx = UxLoaderUtils.isPageUx(context, filePath);
77
80
  // 配置转换参数
78
81
  const options = {
79
82
  projectPath: context.projectPath,
80
83
  filePath,
84
+ fileType: isAppUx ? 'app' : isPageUx ? 'page' : '',
81
85
  onLog: (log) => {
82
86
  logs.push(log);
83
87
  }
84
88
  };
89
+ // 收集图片资源
90
+ const ImageResources = [];
91
+ const collectImageResource = (originFilePath) => {
92
+ const assetDir = 'dynamicAssets';
93
+ const sourcePath = path_1.default.resolve(options.projectPath, compilerOption.sourceRoot);
94
+ const assetPath = path_1.default.resolve(sourcePath, assetDir);
95
+ const { name, ext } = path_1.default.parse(originFilePath);
96
+ const hashName = CommonUtil_1.default.calcImageDigest(originFilePath);
97
+ 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
+ ImageResources.push({
100
+ path: newFilePath,
101
+ content: fs_extra_1.default.readFileSync(originFilePath)
102
+ });
103
+ return relativePath;
104
+ };
85
105
  // 开始转换
86
106
  const globalVar = ('globalVar' in context && context.globalVar) || {};
87
- const parserResult = yield new UxParser_1.default(options, globalVar).parser(content.toString(), fullName);
107
+ const parserResult = yield new UxParser_1.default(options, compilerOption, globalVar, collectImageResource).parser(content.toString(), fullName);
88
108
  // 区分app.ux和一般ux
89
109
  // app.ux解析结果中加上manifest.json的内容
90
110
  const manifestJson = `require('./manifest.json')`;
91
- // 区分页面组件和子组件
92
- const isPageUx = UxLoaderUtils.isPageUx(context, filePath);
93
111
  const integrateFunction = (appImport, appStyleTree, appTemplateTree, appScriptTree) => {
94
112
  // script代码放在第三个位置不能变化,影响更新source map
95
113
  return isAppUx
96
114
  ? [
97
115
  `${appImport.join('\n')}`,
98
- `var $app_style$ = ${UxLoaderUtils.wrapStyle(StringUtil_1.default.arrayTostring(appStyleTree, true), file, compilerOption)}`,
116
+ `var $app_style$ = ${UxLoaderUtils.wrapStyle(JSON.stringify(appStyleTree), file, compilerOption)}`,
99
117
  `var $app_script$ = ${UxLoaderUtils.handleScriptContent(false, appScriptTree)}\n`,
100
118
  `$app_script$({}, $app_exports$, $app_require$);\n\n`,
101
119
  `$app_exports$.default.style = $app_style$;`,
@@ -103,7 +121,7 @@ class UxLoaderUtils {
103
121
  ]
104
122
  : [
105
123
  `${appImport.join('\n')}`,
106
- `var $app_style$ = ${UxLoaderUtils.wrapStyle(StringUtil_1.default.arrayTostring(appStyleTree, true), file, compilerOption)}\n`,
124
+ `var $app_style$ = ${UxLoaderUtils.wrapStyle(JSON.stringify(appStyleTree), file, compilerOption)}\n`,
107
125
  `var $app_script$ = ${UxLoaderUtils.handleScriptContent(isPageUx, appScriptTree)}`,
108
126
  `var $app_template$ = ${UxLoaderUtils.wrapTempalte(appTemplateTree, file, compilerOption)}\n`,
109
127
  `${UxLoaderUtils.getReturnType(isPageUx)} function ($app_exports$) {`,
@@ -130,7 +148,8 @@ class UxLoaderUtils {
130
148
  {
131
149
  path: FileUtil_1.default.updatePath(filePath, `${name}.js.map`),
132
150
  content: sourceMap.toString()
133
- }
151
+ },
152
+ ...ImageResources
134
153
  ],
135
154
  logs
136
155
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/aiotpack",
3
- "version": "2.0.2-beta.3",
3
+ "version": "2.0.2-beta.5",
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.3",
23
- "@aiot-toolkit/parser": "2.0.2-beta.3",
22
+ "@aiot-toolkit/generator": "2.0.2-beta.5",
23
+ "@aiot-toolkit/parser": "2.0.2-beta.5",
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.3",
28
+ "file-lane": "2.0.2-beta.5",
29
29
  "file-loader": "^6.2.0",
30
30
  "fs-extra": "^11.2.0",
31
31
  "jsrsasign": "^7.2.2",
@@ -33,11 +33,13 @@
33
33
  "source-map": "^0.7.4",
34
34
  "url-loader": "^4.1.1",
35
35
  "webpack": "^5.89.0",
36
+ "webpack-bundle-analyzer": "^4.10.1",
36
37
  "webpack-sources": "^3.2.3"
37
38
  },
38
39
  "devDependencies": {
40
+ "@types/fs-extra": "^11.0.4",
39
41
  "@types/jsrsasign": "^10.5.12",
40
42
  "@types/webpack-sources": "^3.2.3"
41
43
  },
42
- "gitHead": "8bfdd8895ffd8fc4aa1465779def5ab4392a7a4b"
44
+ "gitHead": "8c18753992c453c6569a3125378e75fbf4760a1f"
43
45
  }