@aiot-toolkit/aiotpack 2.0.5-beta.15 → 2.0.5-beta.17

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.
@@ -29,9 +29,10 @@ class UxAfterCompile {
29
29
  static compileJavascript = async params => {
30
30
  const {
31
31
  context,
32
- compilerOption
32
+ compilerOption,
33
+ onLog
33
34
  } = params;
34
- return new _JavascriptCompiler.default().compile({
35
+ return new _JavascriptCompiler.default(context, onLog).compile({
35
36
  projectPath: _path.default.join(context.projectPath, context.output),
36
37
  mode: _CompileMode.default.DEVELOPMENT,
37
38
  devtool: false,
@@ -9,7 +9,7 @@ var _fileLane = require("file-lane");
9
9
  class UxAfterWorks {
10
10
  static async cleanOutput(context) {
11
11
  const outputPath = _fileLane.FileLaneUtil.getOutputPath(context);
12
- _sharedUtils.FileUtil.del(outputPath);
12
+ await _sharedUtils.FileUtil.del(outputPath);
13
13
  }
14
14
  }
15
15
  var _default = exports.default = UxAfterWorks;
@@ -1,9 +1,23 @@
1
+ import { ILog } from '@aiot-toolkit/shared-utils';
2
+ import { IFileLaneContext } from 'file-lane';
1
3
  import ICompileParam from '../interface/ICompileParam';
2
4
  import ICompiler from '../interface/ICompiler';
3
5
  import IJavascriptCompileOption from './interface/IJavascriptCompileOption';
4
6
  declare class JavascriptCompiler implements ICompiler {
7
+ private readonly context;
8
+ private readonly onLog?;
5
9
  readonly QUICKAPP_CONFIG = "quickapp.config.js";
10
+ constructor(context: IFileLaneContext, onLog?: ((log: ILog[]) => void) | undefined);
6
11
  compile(param: IJavascriptCompileOption): Promise<void>;
12
+ /**
13
+ * 压缩插件
14
+ *
15
+ * dev模式,只处理console,其它禁用
16
+ * prod模式,其它使用默认值
17
+ * @param mode
18
+ * @returns
19
+ */
20
+ private createMinimizerRspackPlugin;
7
21
  private createWebpackConfig;
8
22
  private getConfigurator;
9
23
  clean(param: ICompileParam & IJavascriptCompileOption): Promise<void>;
@@ -8,12 +8,17 @@ var _sharedUtils = require("@aiot-toolkit/shared-utils");
8
8
  var _core = require("@rspack/core");
9
9
  var _lodash = _interopRequireDefault(require("lodash"));
10
10
  var _path = _interopRequireDefault(require("path"));
11
+ var _CompileMode = _interopRequireDefault(require("../enum/CompileMode"));
11
12
  var _AndroidWebpackConfigurator = _interopRequireDefault(require("./android/AndroidWebpackConfigurator"));
12
13
  var _VelaWebpackConfigurator = _interopRequireDefault(require("./vela/VelaWebpackConfigurator"));
13
14
  var _UxCompileUtil = _interopRequireDefault(require("./vela/utils/UxCompileUtil"));
14
15
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
16
  class JavascriptCompiler {
16
17
  QUICKAPP_CONFIG = 'quickapp.config.js';
18
+ constructor(context, onLog) {
19
+ this.context = context;
20
+ this.onLog = onLog;
21
+ }
17
22
  async compile(param) {
18
23
  return new Promise(async (resolve, reject) => {
19
24
  try {
@@ -49,6 +54,65 @@ class JavascriptCompiler {
49
54
  }
50
55
  });
51
56
  }
57
+
58
+ /**
59
+ * 压缩插件
60
+ *
61
+ * dev模式,只处理console,其它禁用
62
+ * prod模式,其它使用默认值
63
+ * @param mode
64
+ * @returns
65
+ */
66
+ createMinimizerRspackPlugin(compileOption) {
67
+ const {
68
+ mode,
69
+ dropConsole
70
+ } = compileOption;
71
+ const translateDropConsole = () => {
72
+ let dropConsoleValue;
73
+ if (dropConsole === undefined) {
74
+ dropConsoleValue = false;
75
+ } else if (dropConsole === 'true') {
76
+ dropConsoleValue = true;
77
+ } else if (dropConsole === 'false') {
78
+ dropConsoleValue = false;
79
+ } else {
80
+ dropConsoleValue = dropConsole;
81
+ }
82
+ return dropConsoleValue;
83
+ };
84
+ const createCompressValue = dropConsoleValue => {
85
+ const result = {};
86
+ if (typeof dropConsoleValue === 'boolean') {
87
+ result.drop_console = dropConsoleValue;
88
+ } else if (typeof dropConsoleValue === 'string') {
89
+ result.pure_funcs = dropConsoleValue.split(',').map(item => item.trim()).filter(Boolean).map(item => `console.${item}`);
90
+ }
91
+ return result;
92
+ };
93
+ if (mode === _CompileMode.default.DEVELOPMENT) {
94
+ return new _core.rspack.SwcJsMinimizerRspackPlugin({
95
+ minimizerOptions: {
96
+ module: true,
97
+ minify: false,
98
+ mangle: false,
99
+ compress: {
100
+ defaults: false,
101
+ ...createCompressValue(translateDropConsole())
102
+ }
103
+ }
104
+ });
105
+ } else {
106
+ return new _core.rspack.SwcJsMinimizerRspackPlugin({
107
+ minimizerOptions: {
108
+ module: true,
109
+ compress: {
110
+ ...createCompressValue(translateDropConsole())
111
+ }
112
+ }
113
+ });
114
+ }
115
+ }
52
116
  createWebpackConfig(param) {
53
117
  const configurator = this.getConfigurator(param);
54
118
  if (!configurator) {
@@ -82,17 +146,39 @@ class JavascriptCompiler {
82
146
  rules: [{
83
147
  test: /\.ux$/,
84
148
  // 匹配以 .ux 结尾的文件
149
+ exclude: /node_modules/,
85
150
  use: [{
86
151
  loader: _path.default.join(__dirname, '../javascript/vela/utils/webpackLoader/extractMapData.js')
87
152
  }]
153
+ },
154
+ // node_modules下的ux文件
155
+ {
156
+ test: /\.ux$/,
157
+ include: /node_modules/,
158
+ use: [{
159
+ loader: _path.default.join(__dirname, '../javascript/vela/utils/webpackLoader/WebpackUxLoader'),
160
+ options: {
161
+ compileParam: param,
162
+ context: this.context,
163
+ onLog: this.onLog
164
+ }
165
+ }]
166
+ }, {
167
+ test: /\.js$/,
168
+ include: /node_modules/,
169
+ use: [{
170
+ loader: _path.default.join(__dirname, '../javascript/vela/utils/webpackLoader/WebpackJsLoader'),
171
+ options: {
172
+ compileParam: param,
173
+ context: this.context,
174
+ onLog: this.onLog
175
+ }
176
+ }]
88
177
  }]
89
178
  },
90
179
  optimization: {
91
- minimizer: [new _core.rspack.SwcJsMinimizerRspackPlugin({
92
- minimizerOptions: {
93
- module: true
94
- }
95
- })]
180
+ minimize: true,
181
+ minimizer: [this.createMinimizerRspackPlugin(param)]
96
182
  },
97
183
  resolve: {
98
184
  extensions: ['.js', '.ts', '.ux']
@@ -1,6 +1,6 @@
1
1
  import ICompileParam from '../../interface/ICompileParam';
2
2
  import BuildNameFormatType from '../vela/enum/BuildNameFormatType';
3
- export default interface IJavascriptCompileOption extends ICompileParam {
3
+ interface IJavascriptCompileOption extends ICompileParam {
4
4
  devtool?: string | false;
5
5
  /**
6
6
  * 源码路径(相对项目根目录)
@@ -60,6 +60,17 @@ export default interface IJavascriptCompileOption extends ICompileParam {
60
60
  * 是否自动补全 manifest.json 中的 features 配置
61
61
  */
62
62
  completeFeature?: boolean;
63
+ /**
64
+ * 是否删除 console
65
+ *
66
+ * true:删除全部 console
67
+ * string: 指定要去除的console,如'log'、'warn'、'error'
68
+ *
69
+ * @example true
70
+ *
71
+ * @example log,warn
72
+ */
73
+ dropConsole?: boolean | string;
63
74
  /**
64
75
  * 获取远程证书
65
76
  */
@@ -74,3 +85,4 @@ export default interface IJavascriptCompileOption extends ICompileParam {
74
85
  certificate: Buffer;
75
86
  }>;
76
87
  }
88
+ export default IJavascriptCompileOption;
@@ -1 +1,5 @@
1
- "use strict";
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -33,8 +33,7 @@ class WrapPlugin {
33
33
  const source = compilation.assets[entry];
34
34
  const isApp = entry === 'app.js';
35
35
  const createFuncnName = isApp ? 'createAppHandler' : 'createPageHandler';
36
- compilation.assets[entry] = new _webpackSources.ConcatSource(`
37
- export default function(global, globalThis, window, $app_exports$, $app_evaluate$){
36
+ compilation.assets[entry] = new _webpackSources.ConcatSource(`export default function(global, globalThis, window, $app_exports$, $app_evaluate$){
38
37
  var org_app_require = $app_require$;
39
38
 
40
39
  (function(global, globalThis, window, $app_exports$, $app_evaluate$){
@@ -0,0 +1,11 @@
1
+ import { IFileLaneContext } from 'file-lane';
2
+ import IJavascriptCompileOption from '../../../interface/IJavascriptCompileOption';
3
+ import { ILog } from '@aiot-toolkit/shared-utils';
4
+ /**
5
+ * IWebpackLoaderOption
6
+ */
7
+ export default interface IWebpackLoaderOption {
8
+ compileParam: IJavascriptCompileOption;
9
+ context: IFileLaneContext;
10
+ onLog: (log: ILog[]) => void;
11
+ }
@@ -0,0 +1,2 @@
1
+ import { LoaderContext } from '@rspack/core';
2
+ export default function (this: LoaderContext<any>, source: string): Promise<void>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = _default;
7
+ var _parser = require("@aiot-toolkit/parser");
8
+ var _sharedUtils = require("@aiot-toolkit/shared-utils");
9
+ async function _default(source) {
10
+ const callback = this.async();
11
+ const options = this.getOptions();
12
+ const {
13
+ context,
14
+ onLog,
15
+ compileParam
16
+ } = options;
17
+ const result = await new _parser.ScriptToTypescript({
18
+ filePath: this.resourcePath,
19
+ content: source,
20
+ projectPath: this.rootContext,
21
+ onLog: log => onLog?.([log]),
22
+ projectType: _sharedUtils.ProjectType.VELA_UX
23
+ }, compileParam, context).translate({
24
+ content: source
25
+ }, []);
26
+ callback(null, result.targetTree.getFullText());
27
+ }
@@ -0,0 +1,2 @@
1
+ import { LoaderContext } from '@rspack/core';
2
+ export default function (this: LoaderContext<any>, source: string): Promise<void>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = _default;
7
+ var _UxLoaderUtils = _interopRequireDefault(require("../../../../../utils/ux/UxLoaderUtils"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ async function _default(source) {
10
+ const options = this.getOptions();
11
+ const {
12
+ onLog,
13
+ compileParam,
14
+ context
15
+ } = options;
16
+ const callback = this.async();
17
+ const {
18
+ files: compiledFiles,
19
+ logs
20
+ } = await _UxLoaderUtils.default.compileUxToJavascript({
21
+ path: this.resourcePath,
22
+ content: source
23
+ }, context, false, compileParam);
24
+ onLog?.(logs);
25
+ callback(null, compiledFiles[0].content, compiledFiles[1].content);
26
+ }
@@ -9,13 +9,16 @@ const ManifestSchema = {
9
9
  required: ['package', 'name', 'icon', 'versionCode', 'config', 'router'],
10
10
  properties: {
11
11
  package: {
12
- type: 'string'
12
+ type: 'string',
13
+ minLength: 1
13
14
  },
14
15
  name: {
15
- type: 'string'
16
+ type: 'string',
17
+ minLength: 1
16
18
  },
17
19
  icon: {
18
- type: 'string'
20
+ type: 'string',
21
+ minLength: 1
19
22
  },
20
23
  banner: {
21
24
  type: 'string'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/aiotpack",
3
- "version": "2.0.5-beta.15",
3
+ "version": "2.0.5-beta.17",
4
4
  "description": "The process tool for packaging aiot projects.",
5
5
  "keywords": [
6
6
  "aiotpack"
@@ -19,14 +19,14 @@
19
19
  "test": "node ./__tests__/aiotpack.test.js"
20
20
  },
21
21
  "dependencies": {
22
- "@aiot-toolkit/generator": "2.0.5-beta.15",
23
- "@aiot-toolkit/parser": "2.0.5-beta.15",
24
- "@aiot-toolkit/shared-utils": "2.0.5-beta.15",
22
+ "@aiot-toolkit/generator": "2.0.5-beta.17",
23
+ "@aiot-toolkit/parser": "2.0.5-beta.17",
24
+ "@aiot-toolkit/shared-utils": "2.0.5-beta.17",
25
25
  "@hap-toolkit/aaptjs": "^2.0.0",
26
26
  "@rspack/core": "^1.3.9",
27
27
  "aiot-parse5": "^1.0.2",
28
28
  "babel-loader": "^9.1.3",
29
- "file-lane": "2.0.5-beta.15",
29
+ "file-lane": "2.0.5-beta.17",
30
30
  "file-loader": "^6.2.0",
31
31
  "fs-extra": "^11.2.0",
32
32
  "hap-toolkit": "^2.0.0",
@@ -43,5 +43,5 @@
43
43
  "@types/jsrsasign": "^10.5.12",
44
44
  "@types/webpack-sources": "^3.2.3"
45
45
  },
46
- "gitHead": "6e39bae7f788a36a777e08545d862b87fab26a9b"
46
+ "gitHead": "1cff047e2550e845444857b475d63a01b8705768"
47
47
  }