@aiot-toolkit/aiotpack 2.0.3-beta.7 → 2.0.3-beta.8

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.
Files changed (56) hide show
  1. package/lib/afterCompile/ux/UxAfterCompile.js +301 -266
  2. package/lib/afterCompile/xts/entryTemplate.js +111 -113
  3. package/lib/afterCompile/xts/generateRpk.js +25 -54
  4. package/lib/afterCompile/xts/ts2wasm.js +62 -63
  5. package/lib/afterWorks/ux/UxAfterWorks.js +12 -19
  6. package/lib/beforeCompile/ux/UxBeforeCompile.js +26 -25
  7. package/lib/beforeCompile/xts/preInstall.js +50 -55
  8. package/lib/beforeWorks/ux/UxBeforeWorks.js +12 -19
  9. package/lib/compiler/enum/CompileMode.js +16 -23
  10. package/lib/compiler/interface/ICompileParam.js +1 -2
  11. package/lib/compiler/interface/ICompiler.js +1 -2
  12. package/lib/compiler/interface/ISignConfig.js +1 -2
  13. package/lib/compiler/javascript/JavascriptCompiler.js +147 -154
  14. package/lib/compiler/javascript/JavascriptDefaultCompileOption.js +20 -16
  15. package/lib/compiler/javascript/android/AndroidWebpackConfigurator.js +13 -11
  16. package/lib/compiler/javascript/android/plugin/WrapPlugin.js +52 -48
  17. package/lib/compiler/javascript/interface/IJavascriptCompileOption.js +1 -2
  18. package/lib/compiler/javascript/interface/IWebpackConfigurator.js +4 -1
  19. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js +78 -75
  20. package/lib/compiler/javascript/vela/enum/BuildNameFormatType.js +30 -41
  21. package/lib/compiler/javascript/vela/enum/EntryType.js +15 -29
  22. package/lib/compiler/javascript/vela/interface/IChunk.js +4 -1
  23. package/lib/compiler/javascript/vela/interface/IManifest.js +1 -2
  24. package/lib/compiler/javascript/vela/interface/IQuickAppConfig.js +1 -2
  25. package/lib/compiler/javascript/vela/model/Package.js +80 -51
  26. package/lib/compiler/javascript/vela/plugin/WrapPlugin.js +30 -26
  27. package/lib/compiler/javascript/vela/utils/Jsc.js +30 -33
  28. package/lib/compiler/javascript/vela/utils/UxCompileUtil.js +152 -130
  29. package/lib/compiler/javascript/vela/utils/ZipUtil.js +282 -276
  30. package/lib/compiler/javascript/vela/utils/signature/Base64.js +65 -67
  31. package/lib/compiler/javascript/vela/utils/signature/CRC32.js +37 -35
  32. package/lib/compiler/javascript/vela/utils/signature/SignUtil.js +755 -731
  33. package/lib/compiler/javascript/vela/utils/signature/Signer.js +24 -22
  34. package/lib/compiler/javascript/vela/utils/webpackLoader/addColSourceMap.js +47 -52
  35. package/lib/compiler/javascript/vela/utils/webpackLoader/extractMapData.js +21 -17
  36. package/lib/config/UxConfig.js +145 -173
  37. package/lib/config/XtsConfig.js +30 -40
  38. package/lib/index.js +88 -41
  39. package/lib/interface/ICompileOptions.js +5 -2
  40. package/lib/interface/IDeviceList.js +1 -2
  41. package/lib/loader/ux/JsLoader.js +32 -30
  42. package/lib/loader/ux/PngLoader.js +47 -53
  43. package/lib/loader/ux/android/UxLoader.js +30 -31
  44. package/lib/loader/ux/vela/AppUxLoader.js +23 -24
  45. package/lib/loader/ux/vela/HmlLoader.js +59 -55
  46. package/lib/loader/ux/vela/UxLoader.js +29 -35
  47. package/lib/loader/xts/XtsLoader.js +55 -41
  48. package/lib/utils/BeforeCompileUtils.js +100 -92
  49. package/lib/utils/PngUtils.js +42 -36
  50. package/lib/utils/ux/ManifestSchema.js +198 -194
  51. package/lib/utils/ux/UxFileUtils.js +130 -116
  52. package/lib/utils/ux/UxLoaderUtils.js +292 -307
  53. package/lib/utils/ux/android/AndroidUx.js +88 -90
  54. package/lib/utils/xts/XtsFileLaneUtils.js +58 -65
  55. package/lib/utils/xts/XtsFollowWorks.js +122 -129
  56. package/package.json +6 -6
@@ -1,267 +1,274 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
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
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
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 { extractFunctions } = require('@aiot-toolkit/parser/lib/ux/translate/vela/protobuf/protobufControl');
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
- * 转换单个ux文件为js文件
53
- * @param file ux文件内容
54
- * @param context 文件所在项目上下文
55
- * @param project
56
- * @returns
57
- */
58
- static compileUxToJavascript(file, context, isAppUx, compilerOption) {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- const logs = [];
61
- const { path: filePath, content } = file;
62
- const { name, ext } = path_1.default.parse(filePath);
63
- const fullName = `${name}${ext}`;
64
- // 转换后新的文件名
65
- const newFileName = `${name}.js`;
66
- //判断文本,空文本则结束该文件处理
67
- if (!content) {
68
- shared_utils_1.ColorConsole.warn(`The file '${fullName}' under the path '${filePath}' has no content `);
69
- return {
70
- files: [],
71
- logs
72
- };
73
- }
74
- // 区分页面组件和子组件
75
- const isPageUx = UxLoaderUtils.isPageUx(context, filePath);
76
- // 配置转换参数
77
- const options = {
78
- projectPath: context.projectPath,
79
- projectType: shared_utils_1.ProjectType.VELA_UX,
80
- filePath,
81
- fileType: isAppUx ? 'app' : isPageUx ? 'page' : '',
82
- content: content.toString(),
83
- onLog: (log) => {
84
- logs.push(log);
85
- }
86
- };
87
- // 收集图片资源
88
- const ImageResources = [];
89
- const collectImageResource = (originFilePath) => {
90
- const assetDir = 'dynamicAssets';
91
- const sourcePath = path_1.default.resolve(options.projectPath, compilerOption.sourceRoot);
92
- const assetPath = path_1.default.resolve(sourcePath, assetDir);
93
- const { name, ext } = path_1.default.parse(originFilePath);
94
- const hashName = shared_utils_1.CommonUtil.calcImageDigest(originFilePath);
95
- const newFilePath = path_1.default.join(assetPath, `${name}-${hashName}${ext}`);
96
- const relativePath = path_1.default.posix.sep + path_1.default.relative(sourcePath, newFilePath).split(path_1.default.sep).join(path_1.default.posix.sep);
97
- ImageResources.push({
98
- path: newFilePath,
99
- content: fs_extra_1.default.readFileSync(originFilePath)
100
- });
101
- return relativePath;
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
- * @param context
189
- * @param filePath
190
- * @returns
191
- */
192
- static isPageUx(context, filePath) {
193
- var _a;
194
- return Boolean((_a = context.entries) === null || _a === void 0 ? void 0 : _a.includes(filePath));
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
- * 获取app.ux的内容,且只返回script和style内容
198
- * @param fileContent
199
- * @returns
200
- */
201
- static getAppUxContent(fileContent) {
202
- const appUxAst = parse5.parseFragment(fileContent, {
203
- scriptingEnabled: false,
204
- sourceCodeLocationInfo: true
205
- });
206
- // 创建一个临时父节点对象
207
- const parentNode = parse5.defaultTreeAdapter.createElement('div', parse5.html.NS.HTML, []);
208
- for (const childNode of appUxAst.childNodes) {
209
- const { nodeName } = childNode;
210
- if (nodeName !== 'template') {
211
- parse5.defaultTreeAdapter.appendChild(parentNode, childNode);
212
- }
213
- }
214
- return parse5.serialize(parentNode);
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
- static addTemplateProtobuf(file, code) {
217
- const funToString = (fun) => {
218
- const { aiotfor, aiotcb } = fun;
219
- // 如果aiotfor存在,需要把函数体替换为aiotfor.funcArr
220
- if (aiotfor) {
221
- const { funcArr = [], key, value } = aiotfor;
222
- const forFun = `function(${key || '$idx'}, ${value || '$item'}) {
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((item) => funToString(item)).join(',\r\n')}
225
+ ${funcArr.map(item => funToString(item)).join(',\r\n')}
225
226
  ]
226
227
  }`;
227
- return forFun;
228
- }
229
- if (aiotcb) {
230
- const { funcArr = [] } = aiotcb;
231
- const cbFun = `function($data){
228
+ return forFun;
229
+ }
230
+ if (aiotcb) {
231
+ const {
232
+ funcArr = []
233
+ } = aiotcb;
234
+ const cbFun = `function($data){
232
235
  return [
233
- ${funcArr.map((item) => funToString(item)).join(',\r\n')}
236
+ ${funcArr.map(item => funToString(item)).join(',\r\n')}
234
237
  ]
235
238
  }`;
236
- return cbFun;
237
- }
238
- return fun.toString();
239
- };
240
- const stringifyObjectWithFunctions = (obj) => {
241
- const processValue = (value) => {
242
- if (typeof value === 'function') {
243
- return value.toString();
244
- }
245
- else if (typeof value === 'object' && value !== null) {
246
- return stringifyObjectWithFunctions(value);
247
- }
248
- else {
249
- return JSON.stringify(value, undefined, 2);
250
- }
251
- };
252
- const entries = Object.entries(obj).map(([key, value]) => {
253
- return `"${key}": ${processValue(value)}`;
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
- const { path } = file;
260
- const aiot = extractFunctions(code);
261
- const { funcArr = [], optArr } = aiot;
262
- const templateResult = BinaryPlugin.addTemplate(path, path, code);
263
- BinaryPlugin.addTagName(path, path);
264
- const result = `function (vm) {
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((item) => funToString(item)).join(',\r\n')}
279
+ ${funcArr.map(item => funToString(item)).join(',\r\n')}
273
280
  ],
274
281
  __optsArr__:[
275
- ${optArr.map((item) => stringifyObjectWithFunctions(item))},
282
+ ${optArr.map(item => stringifyObjectWithFunctions(item))},
276
283
  ]
277
284
  }
278
285
  )
279
286
  }`;
280
- return result;
281
- }
282
- /**
283
- * 给template增加外层包裹内容
284
- * @param templateTree
285
- * @returns
286
- */
287
- static wrapTempalte(templateTree, file, compilerOption) {
288
- const result = `function (vm) {
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
- if (compilerOption.enableProtobuf) {
293
- return this.addTemplateProtobuf(file, result);
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
- * 给script增加外层包裹内容
306
- * @param isPageUx
307
- * @param appScriptTree
308
- * @returns
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
- // 页面组件需要添加ViewModel数据校验和处理代码
322
- UxLoaderUtils.contenAccess = `\n
323
- const moduleOwn = exports.default || module.exports
324
- const accessors = ['public', 'protected', 'private']
310
+ return code;
311
+ }
325
312
 
326
- if (moduleOwn.data && accessors.some(function (acc) { return moduleOwn[acc] })) {
327
- throw new Error('页面VM对象中的属性data不可与"' + accessors.join(',') + '"同时存在,请使用private替换data名称')
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
- else if (!moduleOwn.data) {
330
- moduleOwn.data = {}
331
- moduleOwn._descriptor = {}
332
- accessors.forEach(function (acc) {
333
- const accType = typeof moduleOwn[acc]
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;