@aiot-toolkit/aiotpack 2.0.1-alpha.0

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 (123) hide show
  1. package/README.md +46 -0
  2. package/lib/compiler/c/README.md +1 -0
  3. package/lib/compiler/c++/README.md +1 -0
  4. package/lib/compiler/enum/CompileMode.d.ts +22 -0
  5. package/lib/compiler/enum/CompileMode.js +30 -0
  6. package/lib/compiler/enum/CompileMode.js.map +1 -0
  7. package/lib/compiler/interface/ICompileParam.d.ts +24 -0
  8. package/lib/compiler/interface/ICompileParam.js +4 -0
  9. package/lib/compiler/interface/ICompileParam.js.map +1 -0
  10. package/lib/compiler/interface/ICompiler.d.ts +5 -0
  11. package/lib/compiler/interface/ICompiler.js +4 -0
  12. package/lib/compiler/interface/ICompiler.js.map +1 -0
  13. package/lib/compiler/interface/ISignConfig.d.ts +8 -0
  14. package/lib/compiler/interface/ISignConfig.js +4 -0
  15. package/lib/compiler/interface/ISignConfig.js.map +1 -0
  16. package/lib/compiler/javascript/JavascriptCompiler.d.ts +11 -0
  17. package/lib/compiler/javascript/JavascriptCompiler.js +108 -0
  18. package/lib/compiler/javascript/JavascriptCompiler.js.map +1 -0
  19. package/lib/compiler/javascript/JavascriptDefaultCompileOption.d.ts +3 -0
  20. package/lib/compiler/javascript/JavascriptDefaultCompileOption.js +21 -0
  21. package/lib/compiler/javascript/JavascriptDefaultCompileOption.js.map +1 -0
  22. package/lib/compiler/javascript/interface/IJavascriptCompileOption.d.ts +40 -0
  23. package/lib/compiler/javascript/interface/IJavascriptCompileOption.js +4 -0
  24. package/lib/compiler/javascript/interface/IJavascriptCompileOption.js.map +1 -0
  25. package/lib/compiler/javascript/interface/IWebpackConfigurator.d.ts +40 -0
  26. package/lib/compiler/javascript/interface/IWebpackConfigurator.js +4 -0
  27. package/lib/compiler/javascript/interface/IWebpackConfigurator.js.map +1 -0
  28. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.d.ts +16 -0
  29. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js +74 -0
  30. package/lib/compiler/javascript/vela/VelaWebpackConfigurator.js.map +1 -0
  31. package/lib/compiler/javascript/vela/enum/BuildNameFormatType.d.ts +25 -0
  32. package/lib/compiler/javascript/vela/enum/BuildNameFormatType.js +47 -0
  33. package/lib/compiler/javascript/vela/enum/BuildNameFormatType.js.map +1 -0
  34. package/lib/compiler/javascript/vela/enum/EntryType.d.ts +30 -0
  35. package/lib/compiler/javascript/vela/enum/EntryType.js +35 -0
  36. package/lib/compiler/javascript/vela/enum/EntryType.js.map +1 -0
  37. package/lib/compiler/javascript/vela/interface/IChunk.d.ts +29 -0
  38. package/lib/compiler/javascript/vela/interface/IChunk.js +4 -0
  39. package/lib/compiler/javascript/vela/interface/IChunk.js.map +1 -0
  40. package/lib/compiler/javascript/vela/interface/IManifest.d.ts +27 -0
  41. package/lib/compiler/javascript/vela/interface/IManifest.js +4 -0
  42. package/lib/compiler/javascript/vela/interface/IManifest.js.map +1 -0
  43. package/lib/compiler/javascript/vela/interface/IQuickAppConfig.d.ts +11 -0
  44. package/lib/compiler/javascript/vela/interface/IQuickAppConfig.js +4 -0
  45. package/lib/compiler/javascript/vela/interface/IQuickAppConfig.js.map +1 -0
  46. package/lib/compiler/javascript/vela/model/Package.d.ts +75 -0
  47. package/lib/compiler/javascript/vela/model/Package.js +62 -0
  48. package/lib/compiler/javascript/vela/model/Package.js.map +1 -0
  49. package/lib/compiler/javascript/vela/plugin/WrapPlugin.d.ts +7 -0
  50. package/lib/compiler/javascript/vela/plugin/WrapPlugin.js +51 -0
  51. package/lib/compiler/javascript/vela/plugin/WrapPlugin.js.map +1 -0
  52. package/lib/compiler/javascript/vela/utils/Jsc.d.ts +10 -0
  53. package/lib/compiler/javascript/vela/utils/Jsc.js +34 -0
  54. package/lib/compiler/javascript/vela/utils/Jsc.js.map +1 -0
  55. package/lib/compiler/javascript/vela/utils/UxCompileUtil.d.ts +29 -0
  56. package/lib/compiler/javascript/vela/utils/UxCompileUtil.js +144 -0
  57. package/lib/compiler/javascript/vela/utils/UxCompileUtil.js.map +1 -0
  58. package/lib/compiler/javascript/vela/utils/ZipUtil.d.ts +75 -0
  59. package/lib/compiler/javascript/vela/utils/ZipUtil.js +278 -0
  60. package/lib/compiler/javascript/vela/utils/ZipUtil.js.map +1 -0
  61. package/lib/compiler/javascript/vela/utils/signature/Base64.d.ts +11 -0
  62. package/lib/compiler/javascript/vela/utils/signature/Base64.js +77 -0
  63. package/lib/compiler/javascript/vela/utils/signature/Base64.js.map +1 -0
  64. package/lib/compiler/javascript/vela/utils/signature/CRC32.d.ts +9 -0
  65. package/lib/compiler/javascript/vela/utils/signature/CRC32.js +45 -0
  66. package/lib/compiler/javascript/vela/utils/signature/CRC32.js.map +1 -0
  67. package/lib/compiler/javascript/vela/utils/signature/SignUtil.d.ts +94 -0
  68. package/lib/compiler/javascript/vela/utils/signature/SignUtil.js +713 -0
  69. package/lib/compiler/javascript/vela/utils/signature/SignUtil.js.map +1 -0
  70. package/lib/compiler/javascript/vela/utils/signature/Signer.d.ts +16 -0
  71. package/lib/compiler/javascript/vela/utils/signature/Signer.js +30 -0
  72. package/lib/compiler/javascript/vela/utils/signature/Signer.js.map +1 -0
  73. package/lib/compiler/javascript/vela/utils/signature/pem/certificate.pem +27 -0
  74. package/lib/compiler/javascript/vela/utils/signature/pem/private.pem +51 -0
  75. package/lib/config/UxConfig.d.ts +30 -0
  76. package/lib/config/UxConfig.js +52 -0
  77. package/lib/config/UxConfig.js.map +1 -0
  78. package/lib/config/XtsConfig.d.ts +18 -0
  79. package/lib/config/XtsConfig.js +28 -0
  80. package/lib/config/XtsConfig.js.map +1 -0
  81. package/lib/followWorks/xts/entryTemplate.d.ts +21 -0
  82. package/lib/followWorks/xts/entryTemplate.js +166 -0
  83. package/lib/followWorks/xts/entryTemplate.js.map +1 -0
  84. package/lib/followWorks/xts/ts2wasm.d.ts +6 -0
  85. package/lib/followWorks/xts/ts2wasm.js +31 -0
  86. package/lib/followWorks/xts/ts2wasm.js.map +1 -0
  87. package/lib/index.d.ts +2 -0
  88. package/lib/index.js +10 -0
  89. package/lib/index.js.map +1 -0
  90. package/lib/interface/IDeviceList.d.ts +7 -0
  91. package/lib/interface/IDeviceList.js +4 -0
  92. package/lib/interface/IDeviceList.js.map +1 -0
  93. package/lib/loader/ux/AppUxLoader.d.ts +10 -0
  94. package/lib/loader/ux/AppUxLoader.js +31 -0
  95. package/lib/loader/ux/AppUxLoader.js.map +1 -0
  96. package/lib/loader/ux/PngLoader.d.ts +10 -0
  97. package/lib/loader/ux/PngLoader.js +70 -0
  98. package/lib/loader/ux/PngLoader.js.map +1 -0
  99. package/lib/loader/ux/UxLoader.d.ts +6 -0
  100. package/lib/loader/ux/UxLoader.js +31 -0
  101. package/lib/loader/ux/UxLoader.js.map +1 -0
  102. package/lib/loader/xts/XtsLoader.d.ts +9 -0
  103. package/lib/loader/xts/XtsLoader.js +55 -0
  104. package/lib/loader/xts/XtsLoader.js.map +1 -0
  105. package/lib/utils/PngUtils.d.ts +20 -0
  106. package/lib/utils/PngUtils.js +45 -0
  107. package/lib/utils/PngUtils.js.map +1 -0
  108. package/lib/utils/PreWorkUtils.d.ts +17 -0
  109. package/lib/utils/PreWorkUtils.js +76 -0
  110. package/lib/utils/PreWorkUtils.js.map +1 -0
  111. package/lib/utils/ux/UxFileUtils.d.ts +22 -0
  112. package/lib/utils/ux/UxFileUtils.js +34 -0
  113. package/lib/utils/ux/UxFileUtils.js.map +1 -0
  114. package/lib/utils/ux/UxFollowWorks.d.ts +35 -0
  115. package/lib/utils/ux/UxFollowWorks.js +200 -0
  116. package/lib/utils/ux/UxFollowWorks.js.map +1 -0
  117. package/lib/utils/ux/UxLoaderUtils.d.ts +60 -0
  118. package/lib/utils/ux/UxLoaderUtils.js +241 -0
  119. package/lib/utils/ux/UxLoaderUtils.js.map +1 -0
  120. package/lib/utils/xts/XtsFollowWorks.d.ts +29 -0
  121. package/lib/utils/xts/XtsFollowWorks.js +149 -0
  122. package/lib/utils/xts/XtsFollowWorks.js.map +1 -0
  123. package/package.json +44 -0
@@ -0,0 +1,200 @@
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
+ var _a;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ const CommonUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/CommonUtil"));
17
+ const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
18
+ const fs_extra_1 = __importDefault(require("fs-extra"));
19
+ const lodash_1 = __importDefault(require("lodash"));
20
+ const path_1 = __importDefault(require("path"));
21
+ const CompileMode_1 = __importDefault(require("../../compiler/enum/CompileMode"));
22
+ const JavascriptCompiler_1 = __importDefault(require("../../compiler/javascript/JavascriptCompiler"));
23
+ const JavascriptDefaultCompileOption_1 = __importDefault(require("../../compiler/javascript/JavascriptDefaultCompileOption"));
24
+ const Jsc_1 = __importDefault(require("../../compiler/javascript/vela/utils/Jsc"));
25
+ const ZipUtil_1 = __importDefault(require("../../compiler/javascript/vela/utils/ZipUtil"));
26
+ const UxFileUtils_1 = __importDefault(require("./UxFileUtils"));
27
+ /**
28
+ * UxFollowWorks
29
+ */
30
+ class UxFollowWorks {
31
+ }
32
+ _a = UxFollowWorks;
33
+ UxFollowWorks.webpack = (context, config, compilerOption) => __awaiter(void 0, void 0, void 0, function* () {
34
+ yield new JavascriptCompiler_1.default().compile(Object.assign(Object.assign({ projectPath: path_1.default.join(context.projectPath, context.output), mode: CompileMode_1.default.DEVELOPMENT, devtool: false, platform: 'vela' }, JavascriptDefaultCompileOption_1.default), compilerOption));
35
+ });
36
+ UxFollowWorks.jsc = (context, config, compilerOption) => __awaiter(void 0, void 0, void 0, function* () {
37
+ if (compilerOption && !compilerOption.disabledJSC) {
38
+ return new Jsc_1.default(context.projectPath, path_1.default.join(context.projectPath, context.output, compilerOption.outputPath)).jsc();
39
+ }
40
+ });
41
+ UxFollowWorks.toRpk = (context, config, compilerOption) => __awaiter(void 0, void 0, void 0, function* () {
42
+ if (compilerOption) {
43
+ return ZipUtil_1.default.createRpk(path_1.default.join(compilerOption.projectPath, compilerOption.outputPath), compilerOption);
44
+ }
45
+ });
46
+ /**
47
+ * 复制各类资源文件,例如图片、视频等
48
+ * @param context
49
+ * @param config
50
+ * @param compilerOption
51
+ */
52
+ UxFollowWorks.copyResource = (context, config, compilerOption) => __awaiter(void 0, void 0, void 0, function* () {
53
+ const genDeviceManifests = (compilerOption) => {
54
+ const { projectPath, sourceRoot, outputPath } = compilerOption;
55
+ const manifest = fs_extra_1.default.readJSONSync(path_1.default.join(projectPath, sourceRoot, 'manifest.json'));
56
+ const { deviceTypeList } = manifest;
57
+ if (deviceTypeList) {
58
+ deviceTypeList.forEach((deviceType) => {
59
+ let data = Object.assign({}, manifest);
60
+ const deviceConfigPath = path_1.default.join(projectPath, sourceRoot, `config-${deviceType}.json`);
61
+ if (fs_extra_1.default.existsSync(deviceConfigPath)) {
62
+ const deviceJson = fs_extra_1.default.readJSONSync(deviceConfigPath);
63
+ data = lodash_1.default.merge({}, data, deviceJson);
64
+ }
65
+ const buildPath = path_1.default.join(projectPath, outputPath, `manifest-${deviceType}.json`);
66
+ fs_extra_1.default.writeFileSync(buildPath, JSON.stringify(data, undefined, 2));
67
+ });
68
+ }
69
+ };
70
+ const copyResourceFiles = (compilerOption) => {
71
+ // 复制除 js/jsx/ts/tsx/json 外,但是包含manifest.json、sitemap.json的文件
72
+ const { projectPath, sourceRoot, outputPath } = compilerOption;
73
+ const includeList = ['sitemap.json', /i18n(.+)\.json/];
74
+ const excludeExtList = [
75
+ 'js',
76
+ 'jsx',
77
+ 'coffee',
78
+ 'ts',
79
+ 'tsx',
80
+ 'vue',
81
+ 'css',
82
+ 'less',
83
+ 'sass',
84
+ 'styl',
85
+ 'html',
86
+ 'json',
87
+ 'md',
88
+ 'ux',
89
+ 'mix',
90
+ 'DS_Store'
91
+ ];
92
+ const excludeReg = `\.(${excludeExtList.join('|')})$`;
93
+ FileUtil_1.default.copyFiles(path_1.default.join(projectPath, sourceRoot), path_1.default.join(projectPath, outputPath), new RegExp(excludeReg));
94
+ FileUtil_1.default.copyFiles(path_1.default.join(projectPath, sourceRoot), path_1.default.join(projectPath, outputPath), undefined, includeList);
95
+ };
96
+ /**
97
+ * 写入 manifest.json 文件
98
+ *
99
+ * 需要在源码manifest.json基础加一些额外的内容
100
+ * @param compilerOption
101
+ */
102
+ const updateManifest = (compilerOption) => {
103
+ const { projectPath, sourceRoot, outputPath } = compilerOption;
104
+ const content = UxFileUtils_1.default.getMainfestInfo(projectPath, sourceRoot);
105
+ if (!content.minAPILevel) {
106
+ content.minAPILevel = 1;
107
+ }
108
+ if (!content.packageInfo) {
109
+ content.packageInfo = ZipUtil_1.default.createComment(compilerOption);
110
+ }
111
+ fs_extra_1.default.writeJSONSync(path_1.default.join(projectPath, outputPath, UxFileUtils_1.default.CONFIG_FILE_NAME), content, {
112
+ spaces: 2
113
+ });
114
+ };
115
+ const genMetaFiles = (compilerOption) => __awaiter(void 0, void 0, void 0, function* () {
116
+ const { projectPath, outputPath, sourceRoot } = compilerOption;
117
+ const outputAbsPath = path_1.default.join(projectPath, outputPath);
118
+ const comment = ZipUtil_1.default.createComment(compilerOption);
119
+ // build.txt
120
+ const content = Object.keys(comment)
121
+ .map((key) => `${key}=${comment[key]}`)
122
+ .join('\n');
123
+ fs_extra_1.default.outputFileSync(path_1.default.join(outputAbsPath, ZipUtil_1.default.BUILD_FILE_PATH), content);
124
+ // cert
125
+ const files = ZipUtil_1.default.getSortedFiles(outputAbsPath, compilerOption, UxFileUtils_1.default.getMainfestInfo(projectPath, sourceRoot));
126
+ const digestDic = Object.fromEntries(files.map((item) => [
127
+ item,
128
+ CommonUtil_1.default.calcDataDigest(fs_extra_1.default.readFileSync(path_1.default.join(outputAbsPath, item))).toString('hex')
129
+ ]));
130
+ const hashJson = [
131
+ {
132
+ path: ZipUtil_1.default.DIGEST_HASH_JSON,
133
+ content: JSON.stringify({
134
+ algorithm: 'SHA-256',
135
+ digests: digestDic
136
+ })
137
+ }
138
+ ];
139
+ const buffer = yield ZipUtil_1.default.createZipBufferFromFileList(hashJson, JSON.stringify(comment));
140
+ fs_extra_1.default.outputFileSync(path_1.default.join(outputAbsPath, ZipUtil_1.default.CERT_PATH), buffer);
141
+ });
142
+ if (compilerOption) {
143
+ copyResourceFiles(compilerOption);
144
+ genDeviceManifests(compilerOption);
145
+ updateManifest(compilerOption);
146
+ yield genMetaFiles(compilerOption);
147
+ }
148
+ });
149
+ /**
150
+ * 打包结果移回源码项目,并删除中间项目
151
+ *
152
+ * 1. 把 build和rpk 目录从**中间项目**移回**源码项目**
153
+ * 2. 删除中间项目
154
+ * @param context
155
+ * @param config
156
+ * @param compilerOption
157
+ */
158
+ UxFollowWorks.moveBackResult = (context, config, compilerOption) => __awaiter(void 0, void 0, void 0, function* () {
159
+ if (!compilerOption) {
160
+ return;
161
+ }
162
+ const { outputPath, releasePath, projectPath } = compilerOption;
163
+ const { projectPath: orgProjectPath } = context;
164
+ const targetList = [
165
+ {
166
+ from: path_1.default.join(projectPath, outputPath),
167
+ to: path_1.default.join(orgProjectPath, outputPath)
168
+ },
169
+ {
170
+ from: path_1.default.join(projectPath, releasePath),
171
+ to: path_1.default.join(orgProjectPath, releasePath)
172
+ }
173
+ ];
174
+ targetList.forEach((item) => {
175
+ fs_extra_1.default.moveSync(item.from, item.to, { overwrite: true });
176
+ fs_extra_1.default.removeSync(item.from);
177
+ });
178
+ fs_extra_1.default.removeSync(projectPath);
179
+ });
180
+ /**
181
+ * 创建 node_module 软链
182
+ * @param context
183
+ * @param config
184
+ * @param compilerOption
185
+ */
186
+ UxFollowWorks.symlinkNodeModule = (context, config, compilerOption) => __awaiter(void 0, void 0, void 0, function* () {
187
+ if (!compilerOption) {
188
+ return;
189
+ }
190
+ const foldList = ['node_modules'];
191
+ foldList.forEach((item) => {
192
+ const sourcePath = path_1.default.join(context.projectPath, item);
193
+ if (fs_extra_1.default.existsSync(sourcePath)) {
194
+ fs_extra_1.default.symlinkSync(sourcePath, path_1.default.join(compilerOption.projectPath, item));
195
+ }
196
+ });
197
+ });
198
+ exports.default = UxFollowWorks;
199
+
200
+ //# sourceMappingURL=UxFollowWorks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["utils/ux/UxFollowWorks.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,iGAAwE;AACxE,6FAAoE;AAEpE,wDAAyB;AACzB,oDAA2B;AAC3B,gDAAuB;AACvB,kFAAyD;AACzD,sGAA6E;AAC7E,8HAAqG;AAGrG,mFAA0D;AAC1D,2FAAkE;AAClE,gEAAuC;AACvC;;GAEG;AACH,MAAM,aAAa;;;AACV,qBAAO,GAAyC,CACrD,OAAO,EACP,MAAM,EACN,cAAc,EACd,EAAE;IACF,MAAM,IAAI,4BAAkB,EAAE,CAAC,OAAO,CAAC,8BACrC,WAAW,EAAE,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,EAC3D,IAAI,EAAE,qBAAW,CAAC,WAAW,EAC7B,OAAO,EAAE,KAAK,EACd,QAAQ,EAAE,MAAM,IACb,wCAA8B,GAC9B,cAAc,CACU,CAAC,CAAA;AAChC,CAAC,CAba,AAab,CAAA;AAEM,iBAAG,GAAyC,C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7B,kBAAE,CAAC,WAAW,CAAC,UAAU,EAAE,cAAI,CAAC,IAAI,CAAC,cAAc,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,CAAA;SACxE;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAhBuB,AAgBvB,CAAA;AAEH,kBAAe,aAAa,CAAA","file":"UxFollowWorks.js","sourcesContent":["import { Dictionary } from '@aiot-toolkit/shared-utils/lib/type/Type'\nimport CommonUtil from '@aiot-toolkit/shared-utils/lib/utils/CommonUtil'\nimport FileUtil from '@aiot-toolkit/shared-utils/lib/utils/FileUtil'\nimport { FollowWork } from 'file-lane/lib/interface/IFileLaneConfig'\nimport Fs from 'fs-extra'\nimport Lodash from 'lodash'\nimport Path from 'path'\nimport CompileMode from '../../compiler/enum/CompileMode'\nimport JavascriptCompiler from '../../compiler/javascript/JavascriptCompiler'\nimport JavascriptDefaultCompileOption from '../../compiler/javascript/JavascriptDefaultCompileOption'\nimport IJavascriptCompileOption from '../../compiler/javascript/interface/IJavascriptCompileOption'\nimport IManifest from '../../compiler/javascript/vela/interface/IManifest'\nimport Jsc from '../../compiler/javascript/vela/utils/Jsc'\nimport ZipUtil from '../../compiler/javascript/vela/utils/ZipUtil'\nimport UxFileUtils from './UxFileUtils'\n/**\n * UxFollowWorks\n */\nclass UxFollowWorks {\n static webpack: FollowWork<IJavascriptCompileOption> = async (\n context,\n config,\n compilerOption\n ) => {\n await new JavascriptCompiler().compile({\n projectPath: Path.join(context.projectPath, context.output),\n mode: CompileMode.DEVELOPMENT,\n devtool: false,\n platform: 'vela',\n ...JavascriptDefaultCompileOption,\n ...compilerOption\n } as IJavascriptCompileOption)\n }\n\n static jsc: FollowWork<IJavascriptCompileOption> = async (context, config, compilerOption) => {\n if (compilerOption && !compilerOption.disabledJSC) {\n return new Jsc(\n context.projectPath,\n Path.join(context.projectPath, context.output, compilerOption.outputPath)\n ).jsc()\n }\n }\n\n static toRpk: FollowWork<IJavascriptCompileOption> = async (context, config, compilerOption) => {\n if (compilerOption) {\n return ZipUtil.createRpk(\n Path.join(compilerOption.projectPath, compilerOption.outputPath),\n compilerOption\n )\n }\n }\n\n /**\n * 复制各类资源文件,例如图片、视频等\n * @param context\n * @param config\n * @param compilerOption\n */\n static copyResource: FollowWork<IJavascriptCompileOption> = async (\n context,\n config,\n compilerOption\n ) => {\n const genDeviceManifests = (compilerOption: IJavascriptCompileOption) => {\n const { projectPath, sourceRoot, outputPath } = compilerOption\n const manifest: IManifest = Fs.readJSONSync(\n Path.join(projectPath, sourceRoot, 'manifest.json')\n )\n const { deviceTypeList } = manifest\n if (deviceTypeList) {\n deviceTypeList.forEach((deviceType) => {\n let data = { ...manifest }\n const deviceConfigPath = Path.join(projectPath, sourceRoot, `config-${deviceType}.json`)\n if (Fs.existsSync(deviceConfigPath)) {\n const deviceJson = Fs.readJSONSync(deviceConfigPath)\n data = Lodash.merge({}, data, deviceJson)\n }\n const buildPath = Path.join(projectPath, outputPath, `manifest-${deviceType}.json`)\n Fs.writeFileSync(buildPath, JSON.stringify(data, undefined, 2))\n })\n }\n }\n\n const copyResourceFiles = (compilerOption: IJavascriptCompileOption) => {\n // 复制除 js/jsx/ts/tsx/json 外,但是包含manifest.json、sitemap.json的文件\n const { projectPath, sourceRoot, outputPath } = compilerOption\n const includeList = ['sitemap.json', /i18n(.+)\\.json/]\n const excludeExtList = [\n 'js',\n 'jsx',\n 'coffee',\n 'ts',\n 'tsx',\n 'vue',\n 'css',\n 'less',\n 'sass',\n 'styl',\n 'html',\n 'json',\n 'md',\n 'ux',\n 'mix',\n 'DS_Store'\n ]\n const excludeReg = `\\.(${excludeExtList.join('|')})$`\n\n FileUtil.copyFiles(\n Path.join(projectPath, sourceRoot),\n Path.join(projectPath, outputPath),\n new RegExp(excludeReg)\n )\n\n FileUtil.copyFiles(\n Path.join(projectPath, sourceRoot),\n Path.join(projectPath, outputPath),\n undefined,\n includeList\n )\n }\n\n /**\n * 写入 manifest.json 文件\n *\n * 需要在源码manifest.json基础加一些额外的内容\n * @param compilerOption\n */\n const updateManifest = (compilerOption: IJavascriptCompileOption) => {\n const { projectPath, sourceRoot, outputPath } = compilerOption\n const content: Dictionary<any> = UxFileUtils.getMainfestInfo(projectPath, sourceRoot)\n\n if (!content.minAPILevel) {\n content.minAPILevel = 1\n }\n if (!content.packageInfo) {\n content.packageInfo = ZipUtil.createComment(compilerOption)\n }\n Fs.writeJSONSync(Path.join(projectPath, outputPath, UxFileUtils.CONFIG_FILE_NAME), content, {\n spaces: 2\n })\n }\n\n const genMetaFiles = async (compilerOption: IJavascriptCompileOption) => {\n const { projectPath, outputPath, sourceRoot } = compilerOption\n const outputAbsPath = Path.join(projectPath, outputPath)\n const comment = ZipUtil.createComment(compilerOption)\n\n // build.txt\n const content = Object.keys(comment)\n .map((key) => `${key}=${comment[key]}`)\n .join('\\n')\n Fs.outputFileSync(Path.join(outputAbsPath, ZipUtil.BUILD_FILE_PATH), content)\n // cert\n const files = ZipUtil.getSortedFiles(\n outputAbsPath,\n compilerOption,\n UxFileUtils.getMainfestInfo(projectPath, sourceRoot)\n )\n const digestDic = Object.fromEntries(\n files.map((item) => [\n item,\n CommonUtil.calcDataDigest(Fs.readFileSync(Path.join(outputAbsPath, item))).toString('hex')\n ])\n )\n\n const hashJson = [\n {\n path: ZipUtil.DIGEST_HASH_JSON,\n content: JSON.stringify({\n algorithm: 'SHA-256',\n digests: digestDic\n })\n }\n ]\n\n const buffer = await ZipUtil.createZipBufferFromFileList(hashJson, JSON.stringify(comment))\n Fs.outputFileSync(Path.join(outputAbsPath, ZipUtil.CERT_PATH), buffer)\n }\n\n if (compilerOption) {\n copyResourceFiles(compilerOption)\n genDeviceManifests(compilerOption)\n updateManifest(compilerOption)\n await genMetaFiles(compilerOption)\n }\n }\n\n /**\n * 打包结果移回源码项目,并删除中间项目\n *\n * 1. 把 build和rpk 目录从**中间项目**移回**源码项目**\n * 2. 删除中间项目\n * @param context\n * @param config\n * @param compilerOption\n */\n static moveBackResult: FollowWork<IJavascriptCompileOption> = async (\n context,\n config,\n compilerOption\n ) => {\n if (!compilerOption) {\n return\n }\n const { outputPath, releasePath, projectPath } = compilerOption\n const { projectPath: orgProjectPath } = context\n\n const targetList = [\n {\n from: Path.join(projectPath, outputPath),\n to: Path.join(orgProjectPath, outputPath)\n },\n {\n from: Path.join(projectPath, releasePath),\n to: Path.join(orgProjectPath, releasePath)\n }\n ]\n\n targetList.forEach((item) => {\n Fs.moveSync(item.from, item.to, { overwrite: true })\n Fs.removeSync(item.from)\n })\n\n Fs.removeSync(projectPath)\n }\n\n /**\n * 创建 node_module 软链\n * @param context\n * @param config\n * @param compilerOption\n */\n static symlinkNodeModule: FollowWork<IJavascriptCompileOption> = async (\n context,\n config,\n compilerOption\n ) => {\n if (!compilerOption) {\n return\n }\n\n const foldList = ['node_modules']\n foldList.forEach((item) => {\n const sourcePath = Path.join(context.projectPath, item)\n if (Fs.existsSync(sourcePath)) {\n Fs.symlinkSync(sourcePath, Path.join(compilerOption.projectPath, item))\n }\n })\n }\n}\nexport default UxFollowWorks\n"],"sourceRoot":"../../../src"}
@@ -0,0 +1,60 @@
1
+ import { IFileLaneContext, IFileParam } from 'file-lane';
2
+ import { SourceFile } from 'ts-morph';
3
+ /**
4
+ * UxLoaderUtils
5
+ */
6
+ declare class UxLoaderUtils {
7
+ static contenAccess: string;
8
+ /**
9
+ * 转换单个ux文件为js文件
10
+ * @param file ux文件内容
11
+ * @param context 文件所在项目上下文
12
+ * @param project
13
+ * @returns
14
+ */
15
+ static compileUxToJavascript(file: IFileParam, context: IFileLaneContext, isAppUx: boolean): Promise<{
16
+ path: string;
17
+ content: string;
18
+ }[]>;
19
+ /**
20
+ * 转换app.ux文件为js文件
21
+ * @param file
22
+ * @param resultFiles
23
+ * @param context
24
+ */
25
+ static compileAppUxToJavascript(file: IFileParam, resultFiles: IFileParam[], context: IFileLaneContext): Promise<void>;
26
+ /**
27
+ * 判断是否为src/app.ux
28
+ * @param filePath
29
+ * @returns
30
+ */
31
+ static isAppUx(filePath: string): boolean;
32
+ /**
33
+ * 判断是否为页面组件
34
+ * @param context
35
+ * @param filePath
36
+ * @returns
37
+ */
38
+ static isPageUx(context: IFileLaneContext, filePath: string): any;
39
+ /**
40
+ * 获取app.ux的内容,且只返回script和style内容
41
+ * @param fileContent
42
+ * @returns
43
+ */
44
+ static getAppUxContent(fileContent: string): string;
45
+ /**
46
+ * 给template增加外层包裹内容
47
+ * @param templateTree
48
+ * @returns
49
+ */
50
+ static wrapTempalte(templateTree: SourceFile): string;
51
+ /**
52
+ * 给script增加外层包裹内容
53
+ * @param isPageUx
54
+ * @param appScriptTree
55
+ * @returns
56
+ */
57
+ static handleScriptContent(isPageUx: boolean, appScriptTree: SourceFile): string;
58
+ static getReturnType(isPageUx: boolean): "$app_exports$['entry'] =" | "return";
59
+ }
60
+ export default UxLoaderUtils;
@@ -0,0 +1,241 @@
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;
17
+ });
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 UxParser_1 = __importDefault(require("@aiot-toolkit/parser/lib/ux/parser/UxParser"));
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 ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
43
+ const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
44
+ const parse5 = __importStar(require("parse5"));
45
+ const path_1 = __importDefault(require("path"));
46
+ const ts_morph_1 = require("ts-morph");
47
+ /**
48
+ * UxLoaderUtils
49
+ */
50
+ 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) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ const project = new ts_morph_1.Project();
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
+ ColorConsole_1.default.log({
69
+ level: shared_utils_1.LOG_LEVEL.Warn,
70
+ message: `【compileUxToJavascript】the file '${fullName}' under the path '${filePath}' has no content `
71
+ });
72
+ return [];
73
+ }
74
+ // 配置转换参数
75
+ const options = {
76
+ projectPath: context.projectPath,
77
+ filePath
78
+ };
79
+ // 开始转换
80
+ const parserResult = yield new UxParser_1.default(options).parser(content, fullName);
81
+ // 区分app.ux和一般ux
82
+ // app.ux解析结果中加上manifest.json的内容
83
+ const manifestJson = `require('./manifest.json')`;
84
+ // 区分页面组件和子组件
85
+ const isPageUx = UxLoaderUtils.isPageUx(context, filePath);
86
+ const integrateFunction = (appImport, appStyleTree, appTemplateTree, appScriptTree) => {
87
+ return isAppUx
88
+ ? [
89
+ `${appImport.join('\n')}`,
90
+ `var $app_style$ = ${JSON.stringify(appStyleTree)}`,
91
+ `var $app_script$ = ${UxLoaderUtils.handleScriptContent(false, appScriptTree)}\n`,
92
+ `$app_script$({}, $app_exports$, $app_require$);\n\n`,
93
+ `$app_exports$.default.style = $app_style$;`,
94
+ `$app_exports$.default.manifest = ${manifestJson}`
95
+ ]
96
+ : [
97
+ `${appImport.join('\n')}`,
98
+ `var $app_style$ = ${JSON.stringify(appStyleTree)}\n`,
99
+ `var $app_script$ = ${UxLoaderUtils.handleScriptContent(isPageUx, appScriptTree)}`,
100
+ `var $app_template$ = ${UxLoaderUtils.wrapTempalte(appTemplateTree)}\n`,
101
+ `${UxLoaderUtils.getReturnType(isPageUx)} function ($app_exports$) {`,
102
+ `$app_script$({}, $app_exports$, $app_require$);`,
103
+ `$app_exports$.default.template = $app_template$;`,
104
+ `$app_exports$.default.style = $app_style$;`,
105
+ `}`
106
+ ];
107
+ };
108
+ const { targetTree, mapList } = new UxToTypescript_1.default(options, project, integrateFunction).translate(parserResult.ast, []);
109
+ const { code, sourcemap } = new generator_1.TypescriptGenerator().generate({
110
+ sourceFilePath: fullName,
111
+ targetFilePath: newFileName,
112
+ ast: targetTree,
113
+ mapList
114
+ });
115
+ // 返回转换后的文件内容以及map内容
116
+ return [
117
+ {
118
+ path: FileUtil_1.default.updatePath(filePath, newFileName),
119
+ content: code
120
+ },
121
+ {
122
+ path: FileUtil_1.default.updatePath(filePath, `${name}.map.js`),
123
+ content: sourcemap
124
+ }
125
+ ];
126
+ });
127
+ }
128
+ /**
129
+ * 转换app.ux文件为js文件
130
+ * @param file
131
+ * @param resultFiles
132
+ * @param context
133
+ */
134
+ static compileAppUxToJavascript(file, resultFiles, context) {
135
+ return __awaiter(this, void 0, void 0, function* () {
136
+ const { path: filePath, content } = file;
137
+ let appContent = content;
138
+ // 校验是否为src/app.ux
139
+ let isAppUx = UxLoaderUtils.isAppUx(filePath);
140
+ if (isAppUx) {
141
+ appContent = UxLoaderUtils.getAppUxContent(content);
142
+ }
143
+ // 解析script和style两部分
144
+ const compileFiles = yield UxLoaderUtils.compileUxToJavascript({ path: filePath, content: appContent }, context, isAppUx);
145
+ resultFiles.push(...compileFiles);
146
+ });
147
+ }
148
+ /**
149
+ * 判断是否为src/app.ux
150
+ * @param filePath
151
+ * @returns
152
+ */
153
+ static isAppUx(filePath) {
154
+ const parentDirName = path_1.default.basename(path_1.default.dirname(filePath));
155
+ const fileName = path_1.default.basename(filePath);
156
+ return parentDirName === 'src' && fileName === 'app.ux';
157
+ }
158
+ /**
159
+ * 判断是否为页面组件
160
+ * @param context
161
+ * @param filePath
162
+ * @returns
163
+ */
164
+ static isPageUx(context, filePath) {
165
+ return ('entries' in context && context.entries.find((entryItem) => entryItem === filePath));
166
+ }
167
+ /**
168
+ * 获取app.ux的内容,且只返回script和style内容
169
+ * @param fileContent
170
+ * @returns
171
+ */
172
+ static getAppUxContent(fileContent) {
173
+ const appUxAst = parse5.parseFragment(fileContent, {
174
+ scriptingEnabled: false,
175
+ sourceCodeLocationInfo: true
176
+ });
177
+ // 创建一个临时父节点对象
178
+ const parentNode = parse5.defaultTreeAdapter.createElement('div', parse5.html.NS.HTML, []);
179
+ for (const childNode of appUxAst.childNodes) {
180
+ const { nodeName } = childNode;
181
+ if (nodeName !== 'template') {
182
+ parse5.defaultTreeAdapter.appendChild(parentNode, childNode);
183
+ }
184
+ }
185
+ return parse5.serialize(parentNode);
186
+ }
187
+ /**
188
+ * 给template增加外层包裹内容
189
+ * @param templateTree
190
+ * @returns
191
+ */
192
+ static wrapTempalte(templateTree) {
193
+ return `function (vm) {
194
+ const _vm_ = vm || this
195
+ return ${templateTree.getFullText()}
196
+ }`;
197
+ }
198
+ /**
199
+ * 给script增加外层包裹内容
200
+ * @param isPageUx
201
+ * @param appScriptTree
202
+ * @returns
203
+ */
204
+ static handleScriptContent(isPageUx, appScriptTree) {
205
+ if (isPageUx) {
206
+ // 页面组件添加ViewModel处理代码
207
+ appScriptTree.addStatements(UxLoaderUtils.contenAccess);
208
+ }
209
+ return `function __scriptModule__(module, exports, $app_require$) {\t${appScriptTree.getFullText()}}`;
210
+ }
211
+ static getReturnType(isPageUx) {
212
+ return isPageUx ? `$app_exports$['entry'] =` : 'return';
213
+ }
214
+ }
215
+ // 页面组件需要添加ViewModel数据校验和处理代码
216
+ UxLoaderUtils.contenAccess = `\n
217
+ const moduleOwn = exports.default || module.exports
218
+ const accessors = ['public', 'protected', 'private']
219
+
220
+ if (moduleOwn.data && accessors.some(function (acc) { return moduleOwn[acc] })) {
221
+ throw new Error('页面VM对象中的属性data不可与"' + accessors.join(',') + '"同时存在,请使用private替换data名称')
222
+ }
223
+ else if (!moduleOwn.data) {
224
+ moduleOwn.data = {}
225
+ moduleOwn._descriptor = {}
226
+ accessors.forEach(function (acc) {
227
+ const accType = typeof moduleOwn[acc]
228
+ if (accType === 'object') {
229
+ moduleOwn.data = Object.assign(moduleOwn.data, moduleOwn[acc])
230
+ for (const name in moduleOwn[acc]) {
231
+ moduleOwn._descriptor[name] = { access: acc }
232
+ }
233
+ }
234
+ else if (accType === 'function') {
235
+ console.warn('页面VM对象中的属性' + acc + '的值不能是函数,请使用对象')
236
+ }
237
+ })
238
+ }`;
239
+ exports.default = U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,CAAC,QAAiB;QACpC,OAAO,QAAQ,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,QAAQ,CAAA;IACzD,CAAC;;AAjND,6BAA6B;AACtB,0BAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;IAsBpB,CAAA;AA4LJ,kBAAe,aAAa,CAAA","file":"UxLoaderUtils.js","sourcesContent":["import { TypescriptGenerator } from '@aiot-toolkit/generator'\nimport { IStyleNode } from '@aiot-toolkit/parser/lib/ux/interface/IStyleAst'\nimport UxParser from '@aiot-toolkit/parser/lib/ux/parser/UxParser'\nimport UxToTypescript from '@aiot-toolkit/parser/lib/ux/translate/vela/UxToTypescript'\nimport { LOG_LEVEL } from '@aiot-toolkit/shared-utils'\nimport ColorConsole from '@aiot-toolkit/shared-utils/lib/ColorConsole'\nimport FileUtil from '@aiot-toolkit/shared-utils/lib/utils/FileUtil'\nimport { IFileLaneContext, IFileParam } from 'file-lane'\nimport * as parse5 from 'parse5'\nimport Path from 'path'\nimport { Project, SourceFile } from 'ts-morph'\n/**\n * UxLoaderUtils\n */\nclass UxLoaderUtils {\n // 页面组件需要添加ViewModel数据校验和处理代码\n static contenAccess = `\\n\n const moduleOwn = exports.default || module.exports\n const accessors = ['public', 'protected', 'private']\n\n if (moduleOwn.data && accessors.some(function (acc) { return moduleOwn[acc] })) {\n throw new Error('页面VM对象中的属性data不可与\"' + accessors.join(',') + '\"同时存在,请使用private替换data名称')\n }\n else if (!moduleOwn.data) {\n moduleOwn.data = {}\n moduleOwn._descriptor = {}\n accessors.forEach(function (acc) {\n const accType = typeof moduleOwn[acc]\n if (accType === 'object') {\n moduleOwn.data = Object.assign(moduleOwn.data, moduleOwn[acc])\n for (const name in moduleOwn[acc]) {\n moduleOwn._descriptor[name] = { access: acc }\n }\n }\n else if (accType === 'function') {\n console.warn('页面VM对象中的属性' + acc + '的值不能是函数,请使用对象')\n }\n })\n }`\n /**\n * 转换单个ux文件为js文件\n * @param file ux文件内容\n * @param context 文件所在项目上下文\n * @param project\n * @returns\n */\n static async compileUxToJavascript(\n file: IFileParam,\n context: IFileLaneContext,\n isAppUx: boolean\n ) {\n const project = new Project()\n const { path: filePath, content } = file\n const { name, ext } = Path.parse(filePath)\n const fullName = `${name}${ext}`\n // 转换后新的文件名\n const newFileName = `${name}.js`\n //判断文本,空文本则结束该文件处理\n if (!content) {\n ColorConsole.log({\n level: LOG_LEVEL.Warn,\n message: `【compileUxToJavascript】the file '${fullName}' under the path '${filePath}' has no content `\n })\n return []\n }\n // 配置转换参数\n const options = {\n projectPath: context.projectPath,\n filePath\n }\n // 开始转换\n const parserResult = await new UxParser(options).parser(content, fullName)\n // 区分app.ux和一般ux\n // app.ux解析结果中加上manifest.json的内容\n const manifestJson = `require('./manifest.json')`\n\n // 区分页面组件和子组件\n const isPageUx = UxLoaderUtils.isPageUx(context, filePath)\n\n const integrateFunction = (\n appImport: string[],\n appStyleTree: IStyleNode[],\n appTemplateTree: SourceFile,\n appScriptTree: SourceFile\n ) => {\n return isAppUx\n ? [\n `${appImport.join('\\n')}`,\n `var $app_style$ = ${JSON.stringify(appStyleTree)}`,\n `var $app_script$ = ${UxLoaderUtils.handleScriptContent(false, appScriptTree)}\\n`,\n `$app_script$({}, $app_exports$, $app_require$);\\n\\n`,\n `$app_exports$.default.style = $app_style$;`,\n `$app_exports$.default.manifest = ${manifestJson}`\n ]\n : [\n `${appImport.join('\\n')}`,\n `var $app_style$ = ${JSON.stringify(appStyleTree)}\\n`,\n `var $app_script$ = ${UxLoaderUtils.handleScriptContent(isPageUx, appScriptTree)}`,\n `var $app_template$ = ${UxLoaderUtils.wrapTempalte(appTemplateTree)}\\n`,\n `${UxLoaderUtils.getReturnType(isPageUx)} function ($app_exports$) {`,\n `$app_script$({}, $app_exports$, $app_require$);`,\n `$app_exports$.default.template = $app_template$;`,\n `$app_exports$.default.style = $app_style$;`,\n `}`\n ]\n }\n const { targetTree, mapList } = new UxToTypescript(\n options,\n project,\n integrateFunction\n ).translate(parserResult.ast, [])\n const { code, sourcemap } = new TypescriptGenerator().generate({\n sourceFilePath: fullName,\n targetFilePath: newFileName,\n ast: targetTree,\n mapList\n })\n // 返回转换后的文件内容以及map内容\n return [\n {\n path: FileUtil.updatePath(filePath, newFileName),\n content: code\n },\n {\n path: FileUtil.updatePath(filePath, `${name}.map.js`),\n content: sourcemap\n }\n ]\n }\n /**\n * 转换app.ux文件为js文件\n * @param file\n * @param resultFiles\n * @param context\n */\n static async compileAppUxToJavascript(\n file: IFileParam,\n resultFiles: IFileParam[],\n context: IFileLaneContext\n ) {\n const { path: filePath, content } = file\n let appContent = content\n // 校验是否为src/app.ux\n let isAppUx = UxLoaderUtils.isAppUx(filePath)\n if (isAppUx) {\n appContent = UxLoaderUtils.getAppUxContent(content as string)\n }\n // 解析script和style两部分\n const compileFiles = await UxLoaderUtils.compileUxToJavascript(\n { path: filePath, content: appContent },\n context,\n isAppUx\n )\n resultFiles.push(...compileFiles)\n }\n /**\n * 判断是否为src/app.ux\n * @param filePath\n * @returns\n */\n static isAppUx(filePath: string) {\n const parentDirName = Path.basename(Path.dirname(filePath))\n const fileName = Path.basename(filePath)\n\n return parentDirName === 'src' && fileName === 'app.ux'\n }\n /**\n * 判断是否为页面组件\n * @param context\n * @param filePath\n * @returns\n */\n static isPageUx(context: IFileLaneContext, filePath: string) {\n return (\n 'entries' in context && context.entries.find((entryItem: string) => entryItem === filePath)\n )\n }\n /**\n * 获取app.ux的内容,且只返回script和style内容\n * @param fileContent\n * @returns\n */\n static getAppUxContent(fileContent: string): string {\n const appUxAst = parse5.parseFragment(fileContent, {\n scriptingEnabled: false,\n sourceCodeLocationInfo: true\n })\n // 创建一个临时父节点对象\n const parentNode = parse5.defaultTreeAdapter.createElement('div', parse5.html.NS.HTML, [])\n for (const childNode of appUxAst.childNodes) {\n const { nodeName } = childNode\n if (nodeName !== 'template') {\n parse5.defaultTreeAdapter.appendChild(parentNode, childNode)\n }\n }\n return parse5.serialize(parentNode)\n }\n /**\n * 给template增加外层包裹内容\n * @param templateTree\n * @returns\n */\n static wrapTempalte(templateTree: SourceFile) {\n return `function (vm) {\n const _vm_ = vm || this\n return ${templateTree.getFullText()}\n }`\n }\n /**\n * 给script增加外层包裹内容\n * @param isPageUx\n * @param appScriptTree\n * @returns\n */\n static handleScriptContent(isPageUx: boolean, appScriptTree: SourceFile) {\n if (isPageUx) {\n // 页面组件添加ViewModel处理代码\n appScriptTree.addStatements(UxLoaderUtils.contenAccess)\n }\n\n return `function __scriptModule__(module, exports, $app_require$) {\\t${appScriptTree.getFullText()}}`\n }\n static getReturnType(isPageUx: boolean) {\n return isPageUx ? `$app_exports$['entry'] =` : 'return'\n }\n}\nexport default UxLoaderUtils\n"],"sourceRoot":"../../../src"}
@@ -0,0 +1,29 @@
1
+ import { IFileLaneContext } from 'file-lane';
2
+ /**
3
+ * XtsFollowWorks
4
+ */
5
+ declare class XtsFollowWorks {
6
+ /**
7
+ * 将项目中build文件夹的内容压缩成zip包,并将压缩产物放到dist文件夹下
8
+ * @param context
9
+ */
10
+ static defaultZipProject(context: IFileLaneContext): Promise<void>;
11
+ /**
12
+ * 将分布式项目按照manifest.json中的配置打包,思路如下:
13
+ * 1. 获取manifest中aspect的路由配置
14
+ * 2. 对aspects中的所有路由信息进行遍历
15
+ * 3. 按照设备(设备+rule)对aspect分类
16
+ * 4. 按照设备列表分别进行打包
17
+ * @param context
18
+ */
19
+ static zipDistributedQuickApp(context: IFileLaneContext): Promise<void>;
20
+ /**
21
+ * 根据项目路径,打包文件夹名和传入的压缩包名,生成压缩文件zip路径
22
+ * @param projectPath
23
+ * @param outputDir
24
+ * @param zipName
25
+ * @returns
26
+ */
27
+ static getFilePath(projectPath: string, outputDir?: string, zipName?: string): string;
28
+ }
29
+ export default XtsFollowWorks;