@aiot-toolkit/aiotpack 2.0.2-dev.3 → 2.0.2-dev.4
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.
- package/lib/compiler/javascript/JavascriptCompiler.js +20 -4
- package/lib/compiler/javascript/vela/VelaWebpackConfigurator.d.ts +1 -2
- package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js +0 -3
- package/lib/compiler/javascript/vela/interface/IManifest.d.ts +2 -0
- package/lib/compiler/javascript/vela/plugin/WrapPlugin.d.ts +0 -1
- package/lib/compiler/javascript/vela/plugin/WrapPlugin.js +19 -22
- package/lib/compiler/javascript/vela/utils/webpackLoader/splitMap.d.ts +3 -0
- package/lib/compiler/javascript/vela/utils/webpackLoader/splitMap.js +20 -0
- package/lib/config/UxConfig.js +0 -5
- package/lib/utils/ux/UxFollowWorks.js +2 -1
- package/lib/utils/ux/UxLoaderUtils.js +6 -5
- package/package.json +5 -6
- package/lib/loader/ux/ImageCompressLoader.d.ts +0 -9
- package/lib/loader/ux/ImageCompressLoader.js +0 -74
|
@@ -61,20 +61,31 @@ class JavascriptCompiler {
|
|
|
61
61
|
if (configurator.create) {
|
|
62
62
|
return configurator.create();
|
|
63
63
|
}
|
|
64
|
-
const { projectPath, mode, devtool, outputPath
|
|
64
|
+
const { projectPath, mode, devtool, outputPath } = param;
|
|
65
65
|
const buildPath = path_1.default.resolve(projectPath, outputPath);
|
|
66
66
|
const quickAppConfig = CommonUtil_1.default.requireModule(path_1.default.join(param.projectPath, this.QUICKAPP_CONFIG));
|
|
67
67
|
const result = {
|
|
68
68
|
context: projectPath,
|
|
69
69
|
mode,
|
|
70
|
-
devtool,
|
|
70
|
+
devtool: 'source-map',
|
|
71
71
|
output: {
|
|
72
72
|
globalObject: 'window',
|
|
73
73
|
filename: '[name].js',
|
|
74
74
|
publicPath: './',
|
|
75
75
|
path: buildPath
|
|
76
76
|
},
|
|
77
|
-
module: {
|
|
77
|
+
module: {
|
|
78
|
+
rules: [
|
|
79
|
+
{
|
|
80
|
+
test: /\.js$/,
|
|
81
|
+
use: [
|
|
82
|
+
{
|
|
83
|
+
loader: path_1.default.join(__dirname, '../javascript/vela/utils/webpackLoader/splitMap.js')
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
},
|
|
78
89
|
stats: {
|
|
79
90
|
builtAt: false,
|
|
80
91
|
entrypoints: false,
|
|
@@ -91,7 +102,12 @@ class JavascriptCompiler {
|
|
|
91
102
|
result.entry = configurator.createEntry();
|
|
92
103
|
}
|
|
93
104
|
if (configurator.createRules && result.module) {
|
|
94
|
-
result.module.rules
|
|
105
|
+
const readyRules = result.module.rules;
|
|
106
|
+
const configuratorRules = configurator.createRules();
|
|
107
|
+
result.module.rules =
|
|
108
|
+
Array.isArray(readyRules) && readyRules.length > 0
|
|
109
|
+
? [...configuratorRules, ...readyRules]
|
|
110
|
+
: configuratorRules;
|
|
95
111
|
}
|
|
96
112
|
if (configurator.createPlugins) {
|
|
97
113
|
result.plugins = configurator.createPlugins();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EntryObject, RuleSetRule, WebpackPluginInstance } from 'webpack';
|
|
2
2
|
import ICompileParam from '../../interface/ICompileParam';
|
|
3
3
|
import IJavascriptCompileOption from '../interface/IJavascriptCompileOption';
|
|
4
4
|
import IWebpackConfigurator from '../interface/IWebpackConfigurator';
|
|
@@ -11,6 +11,5 @@ declare class VelaWebpackConfigurator implements IWebpackConfigurator {
|
|
|
11
11
|
*/
|
|
12
12
|
createEntry(): string | EntryObject | string[];
|
|
13
13
|
createRules(): RuleSetRule[];
|
|
14
|
-
hook(config: Configuration): void;
|
|
15
14
|
}
|
|
16
15
|
export default VelaWebpackConfigurator;
|
|
@@ -6,6 +6,7 @@ export default interface IManifest {
|
|
|
6
6
|
package: string;
|
|
7
7
|
name?: string;
|
|
8
8
|
versionName?: string;
|
|
9
|
+
versionCode?: number;
|
|
9
10
|
minPlatformVersion?: number;
|
|
10
11
|
deviceId?: string;
|
|
11
12
|
deviceTypeList?: string[];
|
|
@@ -22,6 +23,7 @@ export default interface IManifest {
|
|
|
22
23
|
};
|
|
23
24
|
minAPILevel?: number;
|
|
24
25
|
packageInfo?: Dictionary<string | number>;
|
|
26
|
+
icon: string;
|
|
25
27
|
}
|
|
26
28
|
export interface IFeatures {
|
|
27
29
|
name: string;
|
|
@@ -20,30 +20,27 @@ class WrapPlugin {
|
|
|
20
20
|
// 从chunk找到所有入口文件,添加包裹函数
|
|
21
21
|
entrys.forEach((entry) => {
|
|
22
22
|
if (compilation.assets[entry]) {
|
|
23
|
-
const
|
|
24
|
-
compilation.assets[entry] = new webpack_sources_1.ConcatSource(
|
|
23
|
+
const source = compilation.assets[entry];
|
|
24
|
+
compilation.assets[entry] = new webpack_sources_1.ConcatSource(`
|
|
25
|
+
export default function(global, globalThis, window, $app_exports$, $app_evaluate$){
|
|
26
|
+
var org_app_require = $app_require$;
|
|
27
|
+
|
|
28
|
+
(function(global, globalThis, window, $app_exports$, $app_evaluate$){
|
|
29
|
+
var setTimeout = global.setTimeout;
|
|
30
|
+
var setInterval = global.setInterval;
|
|
31
|
+
var clearTimeout = global.clearTimeout;
|
|
32
|
+
var clearInterval = global.clearInterval;
|
|
33
|
+
var $app_require$ = global.$app_require$ || org_app_require
|
|
34
|
+
|
|
35
|
+
var createPageHandler = function() {
|
|
36
|
+
return `, source, `
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return createPageHandler();
|
|
40
|
+
})(global, globalThis, window, $app_exports$, $app_evaluate$)
|
|
41
|
+
}`);
|
|
25
42
|
}
|
|
26
43
|
});
|
|
27
44
|
}
|
|
28
|
-
wrapFunction(code) {
|
|
29
|
-
return `
|
|
30
|
-
export default function(global, globalThis, window, $app_exports$, $app_evaluate$){
|
|
31
|
-
var org_app_require = $app_require$;
|
|
32
|
-
|
|
33
|
-
(function(global, globalThis, window, $app_exports$, $app_evaluate$){
|
|
34
|
-
var setTimeout = global.setTimeout;
|
|
35
|
-
var setInterval = global.setInterval;
|
|
36
|
-
var clearTimeout = global.clearTimeout;
|
|
37
|
-
var clearInterval = global.clearInterval;
|
|
38
|
-
var $app_require$ = global.$app_require$ || org_app_require
|
|
39
|
-
|
|
40
|
-
var createPageHandler = function() {
|
|
41
|
-
return ${code}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return createPageHandler();
|
|
45
|
-
})(global, globalThis, window, $app_exports$, $app_evaluate$)
|
|
46
|
-
}`;
|
|
47
|
-
}
|
|
48
45
|
}
|
|
49
46
|
exports.default = WrapPlugin;
|
|
@@ -0,0 +1,20 @@
|
|
|
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 fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
function splitMap(source, map) {
|
|
9
|
+
const enterFilePath = this.resourcePath;
|
|
10
|
+
// 获取当前文件夹和文件名
|
|
11
|
+
const dirName = path_1.default.dirname(enterFilePath);
|
|
12
|
+
const fileName = path_1.default.basename(enterFilePath);
|
|
13
|
+
// 取到对应的map文件内容
|
|
14
|
+
const mapFilePath = path_1.default.join(dirName, fileName + '.map');
|
|
15
|
+
if (fs_1.default.existsSync(mapFilePath)) {
|
|
16
|
+
map = fs_1.default.readFileSync(mapFilePath, { encoding: 'utf-8' });
|
|
17
|
+
}
|
|
18
|
+
this.callback(null, source, map && JSON.parse(map));
|
|
19
|
+
}
|
|
20
|
+
exports.default = splitMap;
|
package/lib/config/UxConfig.js
CHANGED
|
@@ -132,7 +132,8 @@ UxFollowWorks.copyResource = (context, config, compilerOption) => __awaiter(void
|
|
|
132
132
|
'md',
|
|
133
133
|
'ux',
|
|
134
134
|
'mix',
|
|
135
|
-
'DS_Store'
|
|
135
|
+
'DS_Store',
|
|
136
|
+
'map'
|
|
136
137
|
];
|
|
137
138
|
const excludeReg = `\.(${excludeExtList.join('|')})$`;
|
|
138
139
|
FileUtil_1.default.copyFiles(path_1.default.join(projectPath, sourceRoot), path_1.default.join(projectPath, outputPath), new RegExp(excludeReg));
|
|
@@ -90,6 +90,7 @@ class UxLoaderUtils {
|
|
|
90
90
|
// 区分页面组件和子组件
|
|
91
91
|
const isPageUx = UxLoaderUtils.isPageUx(context, filePath);
|
|
92
92
|
const integrateFunction = (appImport, appStyleTree, appTemplateTree, appScriptTree) => {
|
|
93
|
+
// script代码放在第三个位置不能变化,影响更新source map
|
|
93
94
|
return isAppUx
|
|
94
95
|
? [
|
|
95
96
|
`${appImport.join('\n')}`,
|
|
@@ -111,8 +112,8 @@ class UxLoaderUtils {
|
|
|
111
112
|
`}`
|
|
112
113
|
];
|
|
113
114
|
};
|
|
114
|
-
const { targetTree, mapList } = new UxToTypescript_1.default(options, project, integrateFunction, compilerOption).translate(parserResult.ast, []);
|
|
115
|
-
const { code
|
|
115
|
+
const { targetTree, mapList, sourceMap } = yield new UxToTypescript_1.default(options, project, integrateFunction, compilerOption).translate(parserResult.ast, []);
|
|
116
|
+
const { code } = new generator_1.TypescriptGenerator().generate({
|
|
116
117
|
sourceFilePath: fullName,
|
|
117
118
|
targetFilePath: newFileName,
|
|
118
119
|
ast: targetTree,
|
|
@@ -126,8 +127,8 @@ class UxLoaderUtils {
|
|
|
126
127
|
content: code
|
|
127
128
|
},
|
|
128
129
|
{
|
|
129
|
-
path: FileUtil_1.default.updatePath(filePath, `${name}.map
|
|
130
|
-
content:
|
|
130
|
+
path: FileUtil_1.default.updatePath(filePath, `${name}.js.map`),
|
|
131
|
+
content: sourceMap.toString()
|
|
131
132
|
}
|
|
132
133
|
],
|
|
133
134
|
logs
|
|
@@ -292,7 +293,7 @@ class UxLoaderUtils {
|
|
|
292
293
|
// 页面组件添加ViewModel处理代码
|
|
293
294
|
appScriptTree.addStatements(UxLoaderUtils.contenAccess);
|
|
294
295
|
}
|
|
295
|
-
return `function __scriptModule__(module, exports, $app_require$) {\t${appScriptTree.getFullText()}}`;
|
|
296
|
+
return `function __scriptModule__(module, exports, $app_require$) {\t${appScriptTree.getFullText()}\n}`;
|
|
296
297
|
}
|
|
297
298
|
static getReturnType(isPageUx) {
|
|
298
299
|
return isPageUx ? `$app_exports$['entry'] =` : 'module.exports = ';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiot-toolkit/aiotpack",
|
|
3
|
-
"version": "2.0.2-dev.
|
|
3
|
+
"version": "2.0.2-dev.4",
|
|
4
4
|
"description": "The process tool for packaging aiot projects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aiotpack"
|
|
@@ -19,18 +19,17 @@
|
|
|
19
19
|
"test": "node ./__tests__/aiotpack.test.js"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@aiot-toolkit/generator": "2.0.2-dev.
|
|
23
|
-
"@aiot-toolkit/parser": "2.0.2-dev.
|
|
22
|
+
"@aiot-toolkit/generator": "2.0.2-dev.4",
|
|
23
|
+
"@aiot-toolkit/parser": "2.0.2-dev.4",
|
|
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-dev.
|
|
28
|
+
"file-lane": "2.0.2-dev.4",
|
|
29
29
|
"file-loader": "^6.2.0",
|
|
30
30
|
"fs-extra": "^11.2.0",
|
|
31
31
|
"jsrsasign": "^7.2.2",
|
|
32
32
|
"jszip": "^3.10.1",
|
|
33
|
-
"sharp": "^0.33.2",
|
|
34
33
|
"url-loader": "^4.1.1",
|
|
35
34
|
"webpack": "^5.89.0",
|
|
36
35
|
"webpack-sources": "^3.2.3"
|
|
@@ -39,5 +38,5 @@
|
|
|
39
38
|
"@types/jsrsasign": "^10.5.12",
|
|
40
39
|
"@types/webpack-sources": "^3.2.3"
|
|
41
40
|
},
|
|
42
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "534fdc7c6f018623c05499bf9add8db813ef8660"
|
|
43
42
|
}
|
|
@@ -1,74 +0,0 @@
|
|
|
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;
|