@aiot-toolkit/aiotpack 2.0.3-beta.7 → 2.0.3-beta.9
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/afterCompile/ux/UxAfterCompile.js +303 -266
- package/lib/afterCompile/xts/entryTemplate.js +111 -113
- package/lib/afterCompile/xts/generateRpk.js +25 -54
- package/lib/afterCompile/xts/ts2wasm.js +62 -63
- package/lib/afterWorks/ux/UxAfterWorks.js +12 -19
- package/lib/beforeCompile/ux/UxBeforeCompile.js +26 -25
- package/lib/beforeCompile/xts/preInstall.js +50 -55
- package/lib/beforeWorks/ux/UxBeforeWorks.js +12 -19
- package/lib/compiler/enum/CompileMode.js +16 -23
- package/lib/compiler/interface/ICompileParam.js +1 -2
- package/lib/compiler/interface/ICompiler.js +1 -2
- package/lib/compiler/interface/ISignConfig.js +1 -2
- package/lib/compiler/javascript/JavascriptCompiler.js +147 -154
- package/lib/compiler/javascript/JavascriptDefaultCompileOption.js +20 -16
- package/lib/compiler/javascript/android/AndroidWebpackConfigurator.js +13 -11
- package/lib/compiler/javascript/android/plugin/WrapPlugin.js +52 -48
- package/lib/compiler/javascript/interface/IJavascriptCompileOption.js +1 -2
- package/lib/compiler/javascript/interface/IWebpackConfigurator.js +4 -1
- package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js +78 -75
- package/lib/compiler/javascript/vela/enum/BuildNameFormatType.js +30 -41
- package/lib/compiler/javascript/vela/enum/EntryType.js +15 -29
- package/lib/compiler/javascript/vela/interface/IChunk.js +4 -1
- package/lib/compiler/javascript/vela/interface/IManifest.js +1 -2
- package/lib/compiler/javascript/vela/interface/IQuickAppConfig.js +1 -2
- package/lib/compiler/javascript/vela/model/Package.js +80 -51
- package/lib/compiler/javascript/vela/plugin/WrapPlugin.js +30 -26
- package/lib/compiler/javascript/vela/utils/Jsc.js +30 -33
- package/lib/compiler/javascript/vela/utils/UxCompileUtil.js +152 -130
- package/lib/compiler/javascript/vela/utils/ZipUtil.js +282 -276
- package/lib/compiler/javascript/vela/utils/signature/Base64.js +65 -67
- package/lib/compiler/javascript/vela/utils/signature/CRC32.js +37 -35
- package/lib/compiler/javascript/vela/utils/signature/SignUtil.js +755 -731
- package/lib/compiler/javascript/vela/utils/signature/Signer.js +24 -22
- package/lib/compiler/javascript/vela/utils/webpackLoader/addColSourceMap.js +47 -52
- package/lib/compiler/javascript/vela/utils/webpackLoader/extractMapData.js +21 -17
- package/lib/config/UxConfig.js +145 -173
- package/lib/config/XtsConfig.js +30 -40
- package/lib/index.js +88 -41
- package/lib/interface/ICompileOptions.js +5 -2
- package/lib/interface/IDeviceList.js +1 -2
- package/lib/loader/ux/JsLoader.js +32 -30
- package/lib/loader/ux/PngLoader.js +47 -53
- package/lib/loader/ux/android/UxLoader.js +30 -31
- package/lib/loader/ux/vela/AppUxLoader.js +23 -24
- package/lib/loader/ux/vela/HmlLoader.js +59 -55
- package/lib/loader/ux/vela/UxLoader.js +29 -35
- package/lib/loader/xts/XtsLoader.js +55 -41
- package/lib/utils/BeforeCompileUtils.js +100 -92
- package/lib/utils/PngUtils.js +42 -36
- package/lib/utils/ux/ManifestSchema.js +198 -194
- package/lib/utils/ux/UxFileUtils.js +130 -116
- package/lib/utils/ux/UxLoaderUtils.js +292 -307
- package/lib/utils/ux/android/AndroidUx.js +88 -90
- package/lib/utils/xts/XtsFileLaneUtils.js +58 -65
- package/lib/utils/xts/XtsFollowWorks.js +122 -129
- package/package.json +6 -6
|
@@ -1,267 +1,274 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
17
5
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
const generator_1 = require("@aiot-toolkit/generator");
|
|
39
|
-
const parser_1 = require("@aiot-toolkit/parser");
|
|
40
|
-
const UxToTypescript_1 = __importDefault(require("@aiot-toolkit/parser/lib/ux/translate/vela/UxToTypescript"));
|
|
41
|
-
const shared_utils_1 = require("@aiot-toolkit/shared-utils");
|
|
42
|
-
const parse5 = __importStar(require("aiot-parse5"));
|
|
43
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
44
|
-
const path_1 = __importDefault(require("path"));
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _generator = require("@aiot-toolkit/generator");
|
|
8
|
+
var _parser = require("@aiot-toolkit/parser");
|
|
9
|
+
var _UxToTypescript = _interopRequireDefault(require("@aiot-toolkit/parser/lib/ux/translate/vela/UxToTypescript"));
|
|
10
|
+
var _sharedUtils = require("@aiot-toolkit/shared-utils");
|
|
11
|
+
var parse5 = _interopRequireWildcard(require("aiot-parse5"));
|
|
12
|
+
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
13
|
+
var _path = _interopRequireDefault(require("path"));
|
|
14
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
15
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
45
17
|
const BinaryPlugin = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/BinaryPlugin');
|
|
46
|
-
const {
|
|
18
|
+
const {
|
|
19
|
+
extractFunctions
|
|
20
|
+
} = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/protobufControl');
|
|
47
21
|
/**
|
|
48
22
|
* UxLoaderUtils
|
|
49
23
|
*/
|
|
50
24
|
class UxLoaderUtils {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
};
|
|
103
|
-
// 开始转换
|
|
104
|
-
const globalVar = ('globalVar' in context && context.globalVar) || {};
|
|
105
|
-
const parserResult = yield new parser_1.UxParser(options, compilerOption, globalVar, collectImageResource).parser();
|
|
106
|
-
// 区分app.ux和一般ux
|
|
107
|
-
// app.ux解析结果中加上manifest.json的内容
|
|
108
|
-
const manifestJson = `require('./manifest.json')`;
|
|
109
|
-
const integrateFunction = (appImport, appStyleTree, appTemplateTree, appScriptTree) => {
|
|
110
|
-
// script代码放在第三个位置不能变化,影响更新source map
|
|
111
|
-
return isAppUx
|
|
112
|
-
? [
|
|
113
|
-
`${appImport.join('\n')}`,
|
|
114
|
-
`var $app_style$ = ${UxLoaderUtils.wrapStyle(JSON.stringify(appStyleTree), file, compilerOption)}`,
|
|
115
|
-
`var $app_script$ = ${UxLoaderUtils.wrapScript(false, appScriptTree)}`,
|
|
116
|
-
`$app_script$({}, $app_exports$, $app_require$);`,
|
|
117
|
-
`$app_exports$.default.style = $app_style$;`,
|
|
118
|
-
`$app_exports$.default.manifest = ${manifestJson}`
|
|
119
|
-
]
|
|
120
|
-
: [
|
|
121
|
-
`${appImport.join('\n')}`,
|
|
122
|
-
`var $app_style$ = ${UxLoaderUtils.wrapStyle(JSON.stringify(appStyleTree), file, compilerOption)}`,
|
|
123
|
-
`var $app_script$ = ${UxLoaderUtils.wrapScript(isPageUx, appScriptTree)}`,
|
|
124
|
-
`var $app_template$ = ${UxLoaderUtils.wrapTempalte(appTemplateTree, file, compilerOption)}`,
|
|
125
|
-
`${UxLoaderUtils.getReturnType(isPageUx)} function ($app_exports$) {`,
|
|
126
|
-
`$app_script$({}, $app_exports$, $app_require$);`,
|
|
127
|
-
`$app_exports$.default.template = $app_template$;`,
|
|
128
|
-
`$app_exports$.default.style = $app_style$;`,
|
|
129
|
-
`}`
|
|
130
|
-
];
|
|
131
|
-
};
|
|
132
|
-
const { targetTree, mapList, sourceMap } = yield new UxToTypescript_1.default(options, integrateFunction, compilerOption, context).translate(parserResult.ast, []);
|
|
133
|
-
const { code } = new generator_1.TypescriptGenerator().generate({
|
|
134
|
-
sourceFilePath: fullName,
|
|
135
|
-
targetFilePath: newFileName,
|
|
136
|
-
ast: targetTree,
|
|
137
|
-
mapList
|
|
138
|
-
});
|
|
139
|
-
// 返回转换后的文件内容以及map内容
|
|
140
|
-
return {
|
|
141
|
-
files: [
|
|
142
|
-
{
|
|
143
|
-
path: filePath,
|
|
144
|
-
content: code
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
path: shared_utils_1.FileUtil.updateFileName(filePath, `${name}${ext}.map`),
|
|
148
|
-
content: sourceMap.toString()
|
|
149
|
-
},
|
|
150
|
-
...ImageResources
|
|
151
|
-
],
|
|
152
|
-
logs
|
|
153
|
-
};
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* 转换app.ux文件为js文件
|
|
158
|
-
* @param file
|
|
159
|
-
* @param resultFiles
|
|
160
|
-
* @param context
|
|
161
|
-
*/
|
|
162
|
-
static compileAppUxToJavascript(file, context, compileOption) {
|
|
163
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
-
const { path: filePath, content } = file;
|
|
165
|
-
let appContent = content;
|
|
166
|
-
// 校验是否为src/app.ux
|
|
167
|
-
let isAppUx = UxLoaderUtils.isAppUx(filePath);
|
|
168
|
-
if (isAppUx) {
|
|
169
|
-
appContent = UxLoaderUtils.getAppUxContent(content);
|
|
170
|
-
}
|
|
171
|
-
// 解析script和style两部分
|
|
172
|
-
const compileResult = yield UxLoaderUtils.compileUxToJavascript({ path: filePath, content: appContent }, context, isAppUx, compileOption);
|
|
173
|
-
return compileResult;
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* 判断是否为src/app.ux
|
|
178
|
-
* @param filePath
|
|
179
|
-
* @returns
|
|
180
|
-
*/
|
|
181
|
-
static isAppUx(filePath) {
|
|
182
|
-
const parentDirName = path_1.default.basename(path_1.default.dirname(filePath));
|
|
183
|
-
const fileName = path_1.default.basename(filePath);
|
|
184
|
-
return parentDirName === 'src' && fileName === 'app.ux';
|
|
25
|
+
// 页面组件需要添加ViewModel数据校验和处理代码
|
|
26
|
+
static contenAccess = `\n
|
|
27
|
+
const moduleOwn = exports.default || module.exports
|
|
28
|
+
const accessors = ['public', 'protected', 'private']
|
|
29
|
+
|
|
30
|
+
if (moduleOwn.data && accessors.some(function (acc) { return moduleOwn[acc] })) {
|
|
31
|
+
throw new Error('页面VM对象中的属性data不可与"' + accessors.join(',') + '"同时存在,请使用private替换data名称')
|
|
32
|
+
}
|
|
33
|
+
else if (!moduleOwn.data) {
|
|
34
|
+
moduleOwn.data = {}
|
|
35
|
+
moduleOwn._descriptor = {}
|
|
36
|
+
accessors.forEach(function (acc) {
|
|
37
|
+
const accType = typeof moduleOwn[acc]
|
|
38
|
+
if (accType === 'object') {
|
|
39
|
+
moduleOwn.data = Object.assign(moduleOwn.data, moduleOwn[acc])
|
|
40
|
+
for (const name in moduleOwn[acc]) {
|
|
41
|
+
moduleOwn._descriptor[name] = { access: acc }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else if (accType === 'function') {
|
|
45
|
+
console.warn('页面VM对象中的属性' + acc + '的值不能是函数,请使用对象')
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
}`;
|
|
49
|
+
/**
|
|
50
|
+
* 转换单个ux文件为js文件
|
|
51
|
+
* @param file ux文件内容
|
|
52
|
+
* @param context 文件所在项目上下文
|
|
53
|
+
* @param project
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
static async compileUxToJavascript(file, context, isAppUx, compilerOption) {
|
|
57
|
+
const logs = [];
|
|
58
|
+
const {
|
|
59
|
+
path: filePath,
|
|
60
|
+
content
|
|
61
|
+
} = file;
|
|
62
|
+
const {
|
|
63
|
+
name,
|
|
64
|
+
ext
|
|
65
|
+
} = _path.default.parse(filePath);
|
|
66
|
+
const fullName = `${name}${ext}`;
|
|
67
|
+
// 转换后新的文件名
|
|
68
|
+
const newFileName = `${name}.js`;
|
|
69
|
+
//判断文本,空文本则结束该文件处理
|
|
70
|
+
if (!content) {
|
|
71
|
+
_sharedUtils.ColorConsole.warn(`The file '${fullName}' under the path '${filePath}' has no content `);
|
|
72
|
+
return {
|
|
73
|
+
files: [],
|
|
74
|
+
logs
|
|
75
|
+
};
|
|
185
76
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
77
|
+
|
|
78
|
+
// 区分页面组件和子组件
|
|
79
|
+
const isPageUx = UxLoaderUtils.isPageUx(context, filePath);
|
|
80
|
+
// 配置转换参数
|
|
81
|
+
const options = {
|
|
82
|
+
projectPath: context.projectPath,
|
|
83
|
+
projectType: _sharedUtils.ProjectType.VELA_UX,
|
|
84
|
+
filePath,
|
|
85
|
+
fileType: isAppUx ? 'app' : isPageUx ? 'page' : '',
|
|
86
|
+
content: content.toString(),
|
|
87
|
+
onLog: log => {
|
|
88
|
+
logs.push(log);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
// 收集图片资源
|
|
92
|
+
const ImageResources = [];
|
|
93
|
+
const collectImageResource = originFilePath => {
|
|
94
|
+
const assetDir = 'dynamicAssets';
|
|
95
|
+
const sourcePath = _path.default.resolve(options.projectPath, compilerOption.sourceRoot);
|
|
96
|
+
const assetPath = _path.default.resolve(sourcePath, assetDir);
|
|
97
|
+
const {
|
|
98
|
+
name,
|
|
99
|
+
ext
|
|
100
|
+
} = _path.default.parse(originFilePath);
|
|
101
|
+
const hashName = _sharedUtils.CommonUtil.calcImageDigest(originFilePath);
|
|
102
|
+
const newFilePath = _path.default.join(assetPath, `${name}-${hashName}${ext}`);
|
|
103
|
+
const relativePath = _path.default.posix.sep + _path.default.relative(sourcePath, newFilePath).split(_path.default.sep).join(_path.default.posix.sep);
|
|
104
|
+
ImageResources.push({
|
|
105
|
+
path: newFilePath,
|
|
106
|
+
content: _fsExtra.default.readFileSync(originFilePath)
|
|
107
|
+
});
|
|
108
|
+
return relativePath;
|
|
109
|
+
};
|
|
110
|
+
// 开始转换
|
|
111
|
+
const globalVar = 'globalVar' in context && context.globalVar || {};
|
|
112
|
+
const parserResult = await new _parser.UxParser(options, compilerOption, globalVar, collectImageResource).parser();
|
|
113
|
+
// 区分app.ux和一般ux
|
|
114
|
+
// app.ux解析结果中加上manifest.json的内容
|
|
115
|
+
const manifestJson = `require('./manifest.json')`;
|
|
116
|
+
const integrateFunction = (appImport, appStyleTree, appTemplateTree, appScriptTree) => {
|
|
117
|
+
// script代码放在第三个位置不能变化,影响更新source map
|
|
118
|
+
return isAppUx ? [`${appImport.join('\n')}`, `var $app_style$ = ${UxLoaderUtils.wrapStyle(JSON.stringify(appStyleTree), file, compilerOption)}`, `var $app_script$ = ${UxLoaderUtils.wrapScript(false, appScriptTree)}`, `$app_script$({}, $app_exports$, $app_require$);`, `$app_exports$.default.style = $app_style$;`, `$app_exports$.default.manifest = ${manifestJson}`] : [`${appImport.join('\n')}`, `var $app_style$ = ${UxLoaderUtils.wrapStyle(JSON.stringify(appStyleTree), file, compilerOption)}`, `var $app_script$ = ${UxLoaderUtils.wrapScript(isPageUx, appScriptTree)}`, `var $app_template$ = ${UxLoaderUtils.wrapTempalte(appTemplateTree, file, compilerOption)}`, `${UxLoaderUtils.getReturnType(isPageUx)} function ($app_exports$) {`, `$app_script$({}, $app_exports$, $app_require$);`, `$app_exports$.default.template = $app_template$;`, `$app_exports$.default.style = $app_style$;`, `}`];
|
|
119
|
+
};
|
|
120
|
+
const {
|
|
121
|
+
targetTree,
|
|
122
|
+
mapList,
|
|
123
|
+
sourceMap
|
|
124
|
+
} = await new _UxToTypescript.default(options, integrateFunction, compilerOption, context).translate(parserResult.ast, []);
|
|
125
|
+
const {
|
|
126
|
+
code
|
|
127
|
+
} = new _generator.TypescriptGenerator().generate({
|
|
128
|
+
sourceFilePath: fullName,
|
|
129
|
+
targetFilePath: newFileName,
|
|
130
|
+
ast: targetTree,
|
|
131
|
+
mapList
|
|
132
|
+
});
|
|
133
|
+
// 返回转换后的文件内容以及map内容
|
|
134
|
+
return {
|
|
135
|
+
files: [{
|
|
136
|
+
path: filePath,
|
|
137
|
+
content: code
|
|
138
|
+
}, {
|
|
139
|
+
path: _sharedUtils.FileUtil.updateFileName(filePath, `${name}${ext}.map`),
|
|
140
|
+
content: sourceMap.toString()
|
|
141
|
+
}, ...ImageResources],
|
|
142
|
+
logs
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 转换app.ux文件为js文件
|
|
147
|
+
* @param file
|
|
148
|
+
* @param resultFiles
|
|
149
|
+
* @param context
|
|
150
|
+
*/
|
|
151
|
+
static async compileAppUxToJavascript(file, context, compileOption) {
|
|
152
|
+
const {
|
|
153
|
+
path: filePath,
|
|
154
|
+
content
|
|
155
|
+
} = file;
|
|
156
|
+
let appContent = content;
|
|
157
|
+
// 校验是否为src/app.ux
|
|
158
|
+
let isAppUx = UxLoaderUtils.isAppUx(filePath);
|
|
159
|
+
if (isAppUx) {
|
|
160
|
+
appContent = UxLoaderUtils.getAppUxContent(content);
|
|
195
161
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
162
|
+
// 解析script和style两部分
|
|
163
|
+
const compileResult = await UxLoaderUtils.compileUxToJavascript({
|
|
164
|
+
path: filePath,
|
|
165
|
+
content: appContent
|
|
166
|
+
}, context, isAppUx, compileOption);
|
|
167
|
+
return compileResult;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* 判断是否为src/app.ux
|
|
171
|
+
* @param filePath
|
|
172
|
+
* @returns
|
|
173
|
+
*/
|
|
174
|
+
static isAppUx(filePath) {
|
|
175
|
+
const parentDirName = _path.default.basename(_path.default.dirname(filePath));
|
|
176
|
+
const fileName = _path.default.basename(filePath);
|
|
177
|
+
return parentDirName === 'src' && fileName === 'app.ux';
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* 判断是否为页面组件
|
|
181
|
+
* @param context
|
|
182
|
+
* @param filePath
|
|
183
|
+
* @returns
|
|
184
|
+
*/
|
|
185
|
+
static isPageUx(context, filePath) {
|
|
186
|
+
return Boolean(context.entries?.includes(filePath));
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* 获取app.ux的内容,且只返回script和style内容
|
|
190
|
+
* @param fileContent
|
|
191
|
+
* @returns
|
|
192
|
+
*/
|
|
193
|
+
static getAppUxContent(fileContent) {
|
|
194
|
+
const appUxAst = parse5.parseFragment(fileContent, {
|
|
195
|
+
scriptingEnabled: false,
|
|
196
|
+
sourceCodeLocationInfo: true
|
|
197
|
+
});
|
|
198
|
+
// 创建一个临时父节点对象
|
|
199
|
+
const parentNode = parse5.defaultTreeAdapter.createElement('div', parse5.html.NS.HTML, []);
|
|
200
|
+
for (const childNode of appUxAst.childNodes) {
|
|
201
|
+
const {
|
|
202
|
+
nodeName
|
|
203
|
+
} = childNode;
|
|
204
|
+
if (nodeName !== 'template') {
|
|
205
|
+
parse5.defaultTreeAdapter.appendChild(parentNode, childNode);
|
|
206
|
+
}
|
|
215
207
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
208
|
+
return parse5.serialize(parentNode);
|
|
209
|
+
}
|
|
210
|
+
static addTemplateProtobuf(file, code) {
|
|
211
|
+
const funToString = fun => {
|
|
212
|
+
const {
|
|
213
|
+
aiotfor,
|
|
214
|
+
aiotcb
|
|
215
|
+
} = fun;
|
|
216
|
+
// 如果aiotfor存在,需要把函数体替换为aiotfor.funcArr
|
|
217
|
+
if (aiotfor) {
|
|
218
|
+
const {
|
|
219
|
+
funcArr = [],
|
|
220
|
+
key,
|
|
221
|
+
value
|
|
222
|
+
} = aiotfor;
|
|
223
|
+
const forFun = `function(${key || '$idx'}, ${value || '$item'}) {
|
|
223
224
|
return [
|
|
224
|
-
${funcArr.map(
|
|
225
|
+
${funcArr.map(item => funToString(item)).join(',\r\n')}
|
|
225
226
|
]
|
|
226
227
|
}`;
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
228
|
+
return forFun;
|
|
229
|
+
}
|
|
230
|
+
if (aiotcb) {
|
|
231
|
+
const {
|
|
232
|
+
funcArr = []
|
|
233
|
+
} = aiotcb;
|
|
234
|
+
const cbFun = `function($data){
|
|
232
235
|
return [
|
|
233
|
-
${funcArr.map(
|
|
236
|
+
${funcArr.map(item => funToString(item)).join(',\r\n')}
|
|
234
237
|
]
|
|
235
238
|
}`;
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
return `{
|
|
239
|
+
return cbFun;
|
|
240
|
+
}
|
|
241
|
+
return fun.toString();
|
|
242
|
+
};
|
|
243
|
+
const stringifyObjectWithFunctions = obj => {
|
|
244
|
+
const processValue = value => {
|
|
245
|
+
if (typeof value === 'function') {
|
|
246
|
+
return value.toString();
|
|
247
|
+
} else if (typeof value === 'object' && value !== null) {
|
|
248
|
+
return stringifyObjectWithFunctions(value);
|
|
249
|
+
} else {
|
|
250
|
+
return JSON.stringify(value, undefined, 2);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
const entries = Object.entries(obj).map(_ref => {
|
|
254
|
+
let [key, value] = _ref;
|
|
255
|
+
return `"${key}": ${processValue(value)}`;
|
|
256
|
+
});
|
|
257
|
+
return `{
|
|
256
258
|
${entries.join(',\r\n ')}
|
|
257
259
|
}`;
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
260
|
+
};
|
|
261
|
+
const {
|
|
262
|
+
path
|
|
263
|
+
} = file;
|
|
264
|
+
const aiot = extractFunctions(code);
|
|
265
|
+
const {
|
|
266
|
+
funcArr = [],
|
|
267
|
+
optArr
|
|
268
|
+
} = aiot;
|
|
269
|
+
const templateResult = BinaryPlugin.addTemplate(path, path, code);
|
|
270
|
+
BinaryPlugin.addTagName(path, path);
|
|
271
|
+
const result = `function (vm) {
|
|
265
272
|
const _vm_ = vm || this
|
|
266
273
|
return aiot.__cv__(
|
|
267
274
|
"${templateResult.name}",
|
|
@@ -269,77 +276,55 @@ class UxLoaderUtils {
|
|
|
269
276
|
{
|
|
270
277
|
__vm__:_vm_,
|
|
271
278
|
__func__:[
|
|
272
|
-
${funcArr.map(
|
|
279
|
+
${funcArr.map(item => funToString(item)).join(',\r\n')}
|
|
273
280
|
],
|
|
274
281
|
__optsArr__:[
|
|
275
|
-
${optArr.map(
|
|
282
|
+
${optArr.map(item => stringifyObjectWithFunctions(item))},
|
|
276
283
|
]
|
|
277
284
|
}
|
|
278
285
|
)
|
|
279
286
|
}`;
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
287
|
+
return result;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* 给template增加外层包裹内容
|
|
292
|
+
* @param templateTree
|
|
293
|
+
* @returns
|
|
294
|
+
*/
|
|
295
|
+
static wrapTempalte(templateTree, file, compilerOption) {
|
|
296
|
+
const result = `function (vm) {
|
|
289
297
|
const _vm_ = vm || this
|
|
290
298
|
return ${templateTree.getFullText()}
|
|
291
299
|
}`;
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
return result;
|
|
296
|
-
}
|
|
297
|
-
static wrapStyle(code, file, compilerOption) {
|
|
298
|
-
if (compilerOption.enableProtobuf) {
|
|
299
|
-
const result = BinaryPlugin.addStyle(file.path, file.path, code);
|
|
300
|
-
return `['${result.name}', ${result.index}]`;
|
|
301
|
-
}
|
|
302
|
-
return code;
|
|
300
|
+
if (compilerOption.enableProtobuf) {
|
|
301
|
+
return this.addTemplateProtobuf(file, result);
|
|
303
302
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
static wrapScript(isPageUx, appScriptTree) {
|
|
311
|
-
if (isPageUx) {
|
|
312
|
-
// 页面组件添加ViewModel处理代码
|
|
313
|
-
appScriptTree.addStatements(UxLoaderUtils.contenAccess);
|
|
314
|
-
}
|
|
315
|
-
return `function __scriptModule__(module, exports, $app_require$) {\t${appScriptTree.getFullText()}\n}`;
|
|
316
|
-
}
|
|
317
|
-
static getReturnType(isPageUx) {
|
|
318
|
-
return isPageUx ? `$app_exports$['entry'] =` : 'module.exports = ';
|
|
303
|
+
return result;
|
|
304
|
+
}
|
|
305
|
+
static wrapStyle(code, file, compilerOption) {
|
|
306
|
+
if (compilerOption.enableProtobuf) {
|
|
307
|
+
const result = BinaryPlugin.addStyle(file.path, file.path, code);
|
|
308
|
+
return `['${result.name}', ${result.index}]`;
|
|
319
309
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
UxLoaderUtils.contenAccess = `\n
|
|
323
|
-
const moduleOwn = exports.default || module.exports
|
|
324
|
-
const accessors = ['public', 'protected', 'private']
|
|
310
|
+
return code;
|
|
311
|
+
}
|
|
325
312
|
|
|
326
|
-
|
|
327
|
-
|
|
313
|
+
/**
|
|
314
|
+
* 给script增加外层包裹内容
|
|
315
|
+
* @param isPageUx
|
|
316
|
+
* @param appScriptTree
|
|
317
|
+
* @returns
|
|
318
|
+
*/
|
|
319
|
+
static wrapScript(isPageUx, appScriptTree) {
|
|
320
|
+
if (isPageUx) {
|
|
321
|
+
// 页面组件添加ViewModel处理代码
|
|
322
|
+
appScriptTree.addStatements(UxLoaderUtils.contenAccess);
|
|
323
|
+
}
|
|
324
|
+
return `function __scriptModule__(module, exports, $app_require$) {\t${appScriptTree.getFullText()}\n}`;
|
|
328
325
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
if (accType === 'object') {
|
|
335
|
-
moduleOwn.data = Object.assign(moduleOwn.data, moduleOwn[acc])
|
|
336
|
-
for (const name in moduleOwn[acc]) {
|
|
337
|
-
moduleOwn._descriptor[name] = { access: acc }
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
else if (accType === 'function') {
|
|
341
|
-
console.warn('页面VM对象中的属性' + acc + '的值不能是函数,请使用对象')
|
|
342
|
-
}
|
|
343
|
-
})
|
|
344
|
-
}`;
|
|
345
|
-
exports.default = UxLoaderUtils;
|
|
326
|
+
static getReturnType(isPageUx) {
|
|
327
|
+
return isPageUx ? `$app_exports$['entry'] =` : 'module.exports = ';
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
var _default = exports.default = UxLoaderUtils;
|