@aiot-toolkit/aiotpack 2.0.1-alpha.11 → 2.0.1-alpha.13

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 (55) hide show
  1. package/lib/compiler/javascript/JavascriptCompiler.d.ts +1 -0
  2. package/lib/compiler/javascript/JavascriptCompiler.js +20 -16
  3. package/lib/compiler/javascript/JavascriptCompiler.js.map +1 -1
  4. package/lib/compiler/javascript/JavascriptDefaultCompileOption.d.ts +1 -0
  5. package/lib/compiler/javascript/JavascriptDefaultCompileOption.js +5 -0
  6. package/lib/compiler/javascript/JavascriptDefaultCompileOption.js.map +1 -1
  7. package/lib/compiler/javascript/vela/model/Package.js +2 -2
  8. package/lib/compiler/javascript/vela/model/Package.js.map +1 -1
  9. package/lib/compiler/javascript/vela/utils/Jsc.d.ts +1 -1
  10. package/lib/compiler/javascript/vela/utils/Jsc.js +4 -5
  11. package/lib/compiler/javascript/vela/utils/Jsc.js.map +1 -1
  12. package/lib/compiler/javascript/vela/utils/UxCompileUtil.js +2 -2
  13. package/lib/compiler/javascript/vela/utils/UxCompileUtil.js.map +1 -1
  14. package/lib/compiler/javascript/vela/utils/ZipUtil.js +4 -4
  15. package/lib/compiler/javascript/vela/utils/ZipUtil.js.map +1 -1
  16. package/lib/compiler/javascript/vela/utils/signature/SignUtil.js +14 -10
  17. package/lib/compiler/javascript/vela/utils/signature/SignUtil.js.map +1 -1
  18. package/lib/config/UxConfig.d.ts +3 -3
  19. package/lib/config/UxConfig.js +13 -2
  20. package/lib/config/UxConfig.js.map +1 -1
  21. package/lib/followWorks/xts/entryTemplate.d.ts +2 -2
  22. package/lib/followWorks/xts/entryTemplate.js +61 -42
  23. package/lib/followWorks/xts/entryTemplate.js.map +1 -1
  24. package/lib/followWorks/xts/generateRpk.js +1 -1
  25. package/lib/followWorks/xts/generateRpk.js.map +1 -1
  26. package/lib/followWorks/xts/ts2wasm.js +3 -12
  27. package/lib/followWorks/xts/ts2wasm.js.map +1 -1
  28. package/lib/loader/ux/JsLoader.d.ts +9 -0
  29. package/lib/loader/ux/JsLoader.js +38 -0
  30. package/lib/loader/ux/JsLoader.js.map +1 -0
  31. package/lib/loader/ux/PngLoader.js +4 -7
  32. package/lib/loader/ux/PngLoader.js.map +1 -1
  33. package/lib/loader/xts/XtsLoader.js +3 -7
  34. package/lib/loader/xts/XtsLoader.js.map +1 -1
  35. package/lib/preWorks/xts/preInstall.js +4 -10
  36. package/lib/preWorks/xts/preInstall.js.map +1 -1
  37. package/lib/utils/PreWorkUtils.js +9 -4
  38. package/lib/utils/PreWorkUtils.js.map +1 -1
  39. package/lib/utils/ux/ManifestSchema.d.ts +3 -0
  40. package/lib/utils/ux/ManifestSchema.js +209 -0
  41. package/lib/utils/ux/ManifestSchema.js.map +1 -0
  42. package/lib/utils/ux/UxFileUtils.d.ts +21 -4
  43. package/lib/utils/ux/UxFileUtils.js +74 -3
  44. package/lib/utils/ux/UxFileUtils.js.map +1 -1
  45. package/lib/utils/ux/UxFollowWorks.js +14 -2
  46. package/lib/utils/ux/UxFollowWorks.js.map +1 -1
  47. package/lib/utils/ux/UxLoaderUtils.d.ts +1 -1
  48. package/lib/utils/ux/UxLoaderUtils.js +3 -7
  49. package/lib/utils/ux/UxLoaderUtils.js.map +1 -1
  50. package/lib/utils/ux/UxPreWorks.d.ts +10 -0
  51. package/lib/utils/ux/UxPreWorks.js +33 -0
  52. package/lib/utils/ux/UxPreWorks.js.map +1 -0
  53. package/lib/utils/xts/XtsFollowWorks.js +3 -10
  54. package/lib/utils/xts/XtsFollowWorks.js.map +1 -1
  55. package/package.json +5 -5
@@ -3,11 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.UxFileUtils = void 0;
7
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
8
+ const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
9
+ const CommonUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/CommonUtil"));
6
10
  const fs_extra_1 = __importDefault(require("fs-extra"));
7
11
  const path_1 = __importDefault(require("path"));
8
- /**
9
- * FileUtils
10
- */
12
+ const ManifestSchema_1 = __importDefault(require("./ManifestSchema"));
11
13
  class UxFileUtils {
12
14
  /**
13
15
  * 获取manifest.json路径
@@ -27,7 +29,76 @@ class UxFileUtils {
27
29
  static getMainfestInfo(projectPath, sourceRoot = 'src') {
28
30
  return fs_extra_1.default.readJSONSync(UxFileUtils.getManifestFilePath(projectPath, sourceRoot));
29
31
  }
32
+ /**
33
+ * 检查 manifest文件,并显示错误信息
34
+ *
35
+ * 1. TypeError,使用Error 样式
36
+ * 2. 其它错误,使用 Warn 样式
37
+ * 3. 如果存在TypeError,则终止程序
38
+ *
39
+ * @param projectPath 项目路径
40
+ * @param sourceRoot 源码路径--相对项目根目录
41
+ * @returns
42
+ */
43
+ static validateManifest(projectPath, sourceRoot = 'src') {
44
+ const path = UxFileUtils.getManifestFilePath(projectPath, sourceRoot);
45
+ if (!fs_extra_1.default.existsSync(path)) {
46
+ ColorConsole_1.default.throw(`file is missing`, {
47
+ word: path,
48
+ style: ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Throw)
49
+ });
50
+ }
51
+ const jsonData = this.getMainfestInfo(projectPath, sourceRoot);
52
+ const schema = ManifestSchema_1.default;
53
+ const errors = CommonUtil_1.default.validateJson(jsonData, schema);
54
+ if (errors) {
55
+ ColorConsole_1.default.warn(`Manefest.json error: `, ...errors.map((item, index) => {
56
+ return {
57
+ word: `\r\n${index + 1}. ${item.message}`,
58
+ style: item instanceof TypeError
59
+ ? ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Error)
60
+ : ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Warn)
61
+ };
62
+ }));
63
+ const stop = Boolean(errors.find((item) => item instanceof TypeError));
64
+ if (stop) {
65
+ ColorConsole_1.default.throw({
66
+ word: `missing required content, program stoped`,
67
+ style: ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Throw)
68
+ });
69
+ }
70
+ }
71
+ return errors;
72
+ }
73
+ /**
74
+ * 检查 sitemap.json 文件,并显示错误信息
75
+ *
76
+ * 1. 当sitemap.json的 rules 中配置的page 不存在于 manifest.json 中时,报错并终止程序
77
+ * @param projectPath
78
+ * @param sourceRoot
79
+ */
80
+ static validateSitemap(projectPath, sourceRoot = 'src') {
81
+ const sitemapPath = path_1.default.join(projectPath, sourceRoot, 'sitemap.json');
82
+ if (fs_extra_1.default.existsSync(sitemapPath)) {
83
+ try {
84
+ const rules = fs_extra_1.default.readJSONSync(sitemapPath).rules;
85
+ const manifest = this.getMainfestInfo(projectPath, sourceRoot);
86
+ const pages = Object.keys(manifest.router.pages || {});
87
+ rules.forEach((item, index) => {
88
+ const page = item.page;
89
+ if (page !== '*' && !pages.includes(page)) {
90
+ ColorConsole_1.default.throw(`The ${index + 1}th item of sitemap rules is configured incorrectly, the page ${page} does not exist`);
91
+ }
92
+ return page;
93
+ });
94
+ }
95
+ catch (error) {
96
+ ColorConsole_1.default.warn(error === null || error === void 0 ? void 0 : error.toString());
97
+ }
98
+ }
99
+ }
30
100
  }
101
+ exports.UxFileUtils = UxFileUtils;
31
102
  UxFileUtils.CONFIG_FILE_NAME = 'manifest.json';
32
103
  exports.default = UxFileUtils;
33
104
 
@@ -1 +1 @@
1
- {"version":3,"sources":["utils/ux/UxFileUtils.ts"],"names":[],"mappings":";;;;;AAAA,wDAAyB;AACzB,gDAAuB;AAEvB;;GAEG;AACH,MAAM,WAAW;IAEf;;;;;OAKG;IACH,MAAM,CAAC,mBAAmB,CAAC,WAAmB,EAAE,aAAqB,KAAK;QACxE,OAAO,cAAI,CAAC,OAAO,CAAC,WAAW,EAAE,UAAU,EAAE,WAAW,CAAC,gBAAgB,CAAC,CAAA;IAC5E,CAAC;IACD;;;;;OAKG;IACH,MAAM,CAAC,eAAe,CAAC,WAAmB,EAAE,aAAqB,KAAK;QACpE,OAAO,kBAAE,CAAC,YAAY,CAAC,WAAW,CAAC,mBAAmB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC,CAAA;IAClF,CAAC;;AAlBe,4BAAgB,GAAG,eAAe,CAAA;AAoBpD,kBAAe,WAAW,CAAA","file":"UxFileUtils.js","sourcesContent":["import Fs from 'fs-extra'\nimport Path from 'path'\nimport IManifest from '../../compiler/javascript/vela/interface/IManifest'\n/**\n * FileUtils\n */\nclass UxFileUtils {\n static readonly CONFIG_FILE_NAME = 'manifest.json'\n /**\n * 获取manifest.json路径\n * @param projectPath\n * @param sourceRoot\n * @returns\n */\n static getManifestFilePath(projectPath: string, sourceRoot: string = 'src') {\n return Path.resolve(projectPath, sourceRoot, UxFileUtils.CONFIG_FILE_NAME)\n }\n /**\n * 获取manifest.json内容\n * @param projectPath\n * @param sourceRoot\n * @returns\n */\n static getMainfestInfo(projectPath: string, sourceRoot: string = 'src'): IManifest {\n return Fs.readJSONSync(UxFileUtils.getManifestFilePath(projectPath, sourceRoot))\n }\n}\nexport default UxFileUtils\n"],"sourceRoot":"../../../src"}
1
+ {"version":3,"sources":["utils/ux/UxFileUtils.ts"],"names":[],"mappings":";;;;;;AAAA,6DAAsD;AACtD,+FAAsE;AACtE,iGAAwE;AACxE,wDAAyB;AACzB,gDAAuB;AAEvB,sEAA6C;AAE7C,MAGM,WAAW;IAEf;;;;;OAKG;IACH,MAAM,CAAC,mBAAmB,CAAC,WAAmB,EAAE,aAAqB,KAAK;QACxE,OAAO,cAAI,CAAC,OAAO,CAAC,WAAW,EAAE,UAAU,EAAE,WAAW,CAAC,gBAAgB,CAAC,CAAA;IAC5E,CAAC;IACD;;;;;OAKG;IACH,MAAM,CAAC,eAAe,CAAC,WAAmB,EAAE,aAAqB,KAAK;QACpE,OAAO,kBAAE,CAAC,YAAY,CAAC,WAAW,CAAC,mBAAmB,CAAC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uGpD,kBAAe,WAAW,CAAA","file":"UxFileUtils.js","sourcesContent":["import { LOG_LEVEL } from '@aiot-toolkit/shared-utils'\nimport ColorConsole from '@aiot-toolkit/shared-utils/lib/ColorConsole'\nimport CommonUtil from '@aiot-toolkit/shared-utils/lib/utils/CommonUtil'\nimport Fs from 'fs-extra'\nimport Path from 'path'\nimport IManifest from '../../compiler/javascript/vela/interface/IManifest'\nimport ManifestSchema from './ManifestSchema'\n\nexport /**\n * FileUtils\n */\nclass UxFileUtils {\n static readonly CONFIG_FILE_NAME = 'manifest.json'\n /**\n * 获取manifest.json路径\n * @param projectPath\n * @param sourceRoot\n * @returns\n */\n static getManifestFilePath(projectPath: string, sourceRoot: string = 'src') {\n return Path.resolve(projectPath, sourceRoot, UxFileUtils.CONFIG_FILE_NAME)\n }\n /**\n * 获取manifest.json内容\n * @param projectPath\n * @param sourceRoot\n * @returns\n */\n static getMainfestInfo(projectPath: string, sourceRoot: string = 'src'): IManifest {\n return Fs.readJSONSync(UxFileUtils.getManifestFilePath(projectPath, sourceRoot))\n }\n\n /**\n * 检查 manifest文件,并显示错误信息\n *\n * 1. TypeError,使用Error 样式\n * 2. 其它错误,使用 Warn 样式\n * 3. 如果存在TypeError,则终止程序\n *\n * @param projectPath 项目路径\n * @param sourceRoot 源码路径--相对项目根目录\n * @returns\n */\n static validateManifest(projectPath: string, sourceRoot: string = 'src') {\n const path = UxFileUtils.getManifestFilePath(projectPath, sourceRoot)\n if (!Fs.existsSync(path)) {\n ColorConsole.throw(`file is missing`, {\n word: path,\n style: ColorConsole.getStyle(LOG_LEVEL.Throw)\n })\n }\n\n const jsonData = this.getMainfestInfo(projectPath, sourceRoot)\n const schema = ManifestSchema\n\n const errors = CommonUtil.validateJson(jsonData as any as JSON, schema)\n\n if (errors) {\n ColorConsole.warn(\n `Manefest.json error: `,\n ...errors.map((item, index) => {\n return {\n word: `\\r\\n${index + 1}. ${item.message}`,\n style:\n item instanceof TypeError\n ? ColorConsole.getStyle(LOG_LEVEL.Error)\n : ColorConsole.getStyle(LOG_LEVEL.Warn)\n }\n })\n )\n\n const stop = Boolean(errors.find((item) => item instanceof TypeError))\n\n if (stop) {\n ColorConsole.throw({\n word: `missing required content, program stoped`,\n style: ColorConsole.getStyle(LOG_LEVEL.Throw)\n })\n }\n }\n return errors\n }\n\n /**\n * 检查 sitemap.json 文件,并显示错误信息\n *\n * 1. 当sitemap.json的 rules 中配置的page 不存在于 manifest.json 中时,报错并终止程序\n * @param projectPath\n * @param sourceRoot\n */\n static validateSitemap(projectPath: string, sourceRoot: string = 'src') {\n const sitemapPath = Path.join(projectPath, sourceRoot, 'sitemap.json')\n\n if (Fs.existsSync(sitemapPath)) {\n try {\n const rules: any[] = Fs.readJSONSync(sitemapPath).rules\n const manifest = this.getMainfestInfo(projectPath, sourceRoot)\n const pages = Object.keys(manifest.router.pages || {})\n rules.forEach((item, index) => {\n const page = item.page\n if (page !== '*' && !pages.includes(page)) {\n ColorConsole.throw(\n `The ${\n index + 1\n }th item of sitemap rules is configured incorrectly, the page ${page} does not exist`\n )\n }\n return page\n })\n } catch (error) {\n ColorConsole.warn(error?.toString())\n }\n }\n }\n}\nexport default UxFileUtils\n"],"sourceRoot":"../../../src"}
@@ -13,6 +13,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  var _a;
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
+ const shared_utils_1 = require("@aiot-toolkit/shared-utils");
17
+ const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
16
18
  const CommonUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/CommonUtil"));
17
19
  const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
18
20
  const fs_extra_1 = __importDefault(require("fs-extra"));
@@ -31,10 +33,20 @@ class UxFollowWorks {
31
33
  }
32
34
  _a = UxFollowWorks;
33
35
  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));
36
+ return new JavascriptCompiler_1.default()
37
+ .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))
38
+ .then(() => {
39
+ ColorConsole_1.default.info(`webpack complete`);
40
+ })
41
+ .catch((errors) => {
42
+ ColorConsole_1.default.throw(`webpack error: \r\n`, {
43
+ word: errors.map((item, index) => `${index + 1}. ${item.message}`).join('\r\n'),
44
+ style: ColorConsole_1.default.getStyle(shared_utils_1.LOG_LEVEL.Throw)
45
+ });
46
+ });
35
47
  });
36
48
  UxFollowWorks.jsc = (context, config, compilerOption) => __awaiter(void 0, void 0, void 0, function* () {
37
- if (compilerOption && !compilerOption.disabledJSC) {
49
+ if (compilerOption && compilerOption.disabledJSC === false) {
38
50
  return new Jsc_1.default(context.projectPath, path_1.default.join(context.projectPath, context.output, compilerOption.outputPath)).jsc();
39
51
  }
40
52
  });
@@ -1 +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,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CAAC,CAAA;IACjC,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACxB,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;QACvD,IAAI,kBAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE;YAC7B,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"}
1
+ {"version":3,"sources":["utils/ux/UxFollowWorks.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6DAAsD;AACtD,+FAAsE;AAEtE,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,cA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C;YACzC,EAAE,EAAE,cAAI,CAAC,IAAI,CAAC,cAAc,EAAE,WAAW,CAAC;SAC3C;KACF,CAAA;IAED,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC1B,kBAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QACpD,kBAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC1B,CAAC,CAAC,CAAA;IAEF,kBAAE,CAAC,UAAU,CAAC,WAAW,CAAC,CAAA;AAC5B,CAAC,CA5BoB,AA4BpB,CAAA;AAED;;;;;GAKG;AACI,+BAAiB,GAAyC,CAC/D,OAAO,EACP,MAAM,EACN,cAAc,EACd,EAAE;IACF,IAAI,CAAC,cAAc,EAAE;QACnB,OAAM;KACP;IAED,MAAM,QAAQ,GAAG,CAAC,cAAc,CAAC,CAAA;IACjC,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACxB,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;QACvD,IAAI,kBAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE;YAC7B,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 { LOG_LEVEL } from '@aiot-toolkit/shared-utils'\nimport ColorConsole from '@aiot-toolkit/shared-utils/lib/ColorConsole'\nimport { 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 return new JavascriptCompiler()\n .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 .then(() => {\n ColorConsole.info(`webpack complete`)\n })\n .catch((errors: Error[]) => {\n ColorConsole.throw(`webpack error: \\r\\n`, {\n word: errors.map((item, index) => `${index + 1}. ${item.message}`).join('\\r\\n'),\n style: ColorConsole.getStyle(LOG_LEVEL.Throw)\n })\n })\n }\n\n static jsc: FollowWork<IJavascriptCompileOption> = async (context, config, compilerOption) => {\n if (compilerOption && compilerOption.disabledJSC === false) {\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"}
@@ -55,6 +55,6 @@ declare class UxLoaderUtils {
55
55
  * @returns
56
56
  */
57
57
  static handleScriptContent(isPageUx: boolean, appScriptTree: SourceFile): string;
58
- static getReturnType(isPageUx: boolean): "$app_exports$['entry'] =" | "return";
58
+ static getReturnType(isPageUx: boolean): "$app_exports$['entry'] =" | "module.exports = ";
59
59
  }
60
60
  export default UxLoaderUtils;
@@ -38,7 +38,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
38
38
  const generator_1 = require("@aiot-toolkit/generator");
39
39
  const UxParser_1 = __importDefault(require("@aiot-toolkit/parser/lib/ux/parser/UxParser"));
40
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
41
  const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
43
42
  const FileUtil_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/utils/FileUtil"));
44
43
  const parse5 = __importStar(require("parse5"));
@@ -65,10 +64,7 @@ class UxLoaderUtils {
65
64
  const newFileName = `${name}.js`;
66
65
  //判断文本,空文本则结束该文件处理
67
66
  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
- });
67
+ ColorConsole_1.default.warn(`The file '${fullName}' under the path '${filePath}' has no content `);
72
68
  return [];
73
69
  }
74
70
  // 配置转换参数
@@ -77,7 +73,7 @@ class UxLoaderUtils {
77
73
  filePath
78
74
  };
79
75
  // 开始转换
80
- const parserResult = yield new UxParser_1.default(options).parser(content, fullName);
76
+ const parserResult = yield new UxParser_1.default(options).parser(content.toString(), fullName);
81
77
  // 区分app.ux和一般ux
82
78
  // app.ux解析结果中加上manifest.json的内容
83
79
  const manifestJson = `require('./manifest.json')`;
@@ -209,7 +205,7 @@ class UxLoaderUtils {
209
205
  return `function __scriptModule__(module, exports, $app_require$) {\t${appScriptTree.getFullText()}}`;
210
206
  }
211
207
  static getReturnType(isPageUx) {
212
- return isPageUx ? `$app_exports$['entry'] =` : 'return';
208
+ return isPageUx ? `$app_exports$['entry'] =` : 'module.exports = ';
213
209
  }
214
210
  }
215
211
  // 页面组件需要添加ViewModel数据校验和处理代码
@@ -1 +1 @@
1
- {"version":3,"sources":["utils/ux/UxLoaderUtils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAA6D;AAE7D,2FAAkE;AAClE,+GAAsF;AACtF,6DAAsD;AACtD,+FAAsE;AACtE,6FAAoE;AAEpE,+CAAgC;AAChC,gDAAuB;AACvB,uCAA8C;AAC9C;;GAEG;AACH,MAAM,aAAa;IAyBjB;;;;;;OAMG;IACH,MAAM,CAAO,qBAAqB,CAChC,IAAgB,EAChB,OAAyB,EACzB,OAAgB;;YAEhB,MAAM,OAAO,GAAG,IAAI,kBAAO,EAAE,CAAA;YAC7B,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;YACxC,MAAM,EAAE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AAK,MAAM,SAAS,IAAI,QAAQ,CAAC,UAAU,EAAE;YAC3C,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAA;YAC9B,IAAI,QAAQ,KAAK,UAAU,EAAE;gBAC3B,MAAM,CAAC,kBAAkB,CAAC,WAAW,CAAC,UAAU,EAAE,SAAS,CAAC,CAAA;aAC7D;SACF;QACD,OAAO,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,CAAA;IACrC,CAAC;IACD;;;;OAIG;IACH,MAAM,CAAC,YAAY,CAAC,YAAwB;QAC1C,OAAO;;eAEI,YAAY,CAAC,WAAW,EAAE;MACnC,CAAA;IACJ,CAAC;IACD;;;;;OAKG;IACH,MAAM,CAAC,mBAAmB,CAAC,QAAiB,EAAE,aAAyB;QACrE,IAAI,QAAQ,EAAE;YACZ,sBAAsB;YACtB,aAAa,CAAC,aAAa,CAAC,aAAa,CAAC,YAAY,CAAC,CAAA;SACxD;QAED,OAAO,gEAAgE,aAAa,CAAC,WAAW,EAAE,GAAG,CAAA;IACvG,CAAC;IACD,MAAM,CAAC,aAAa,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"}
1
+ {"version":3,"sources":["utils/ux/UxLoaderUtils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,u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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 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.warn(`The file '${fullName}' under the path '${filePath}' has no content `)\n return []\n }\n // 配置转换参数\n const options = {\n projectPath: context.projectPath,\n filePath\n }\n // 开始转换\n const parserResult = await new UxParser(options).parser(content.toString(), 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'] =` : 'module.exports = '\n }\n}\nexport default UxLoaderUtils\n"],"sourceRoot":"../../../src"}
@@ -0,0 +1,10 @@
1
+ import { PreWork } from 'file-lane/lib/interface/IFileLaneConfig';
2
+ import IJavascriptCompileOption from '../../compiler/javascript/interface/IJavascriptCompileOption';
3
+ /**
4
+ * UxPreWorks
5
+ */
6
+ declare class UxPreWorks {
7
+ static validateManifest: PreWork<IJavascriptCompileOption>;
8
+ static validateSitemap: PreWork<IJavascriptCompileOption>;
9
+ }
10
+ export default UxPreWorks;
@@ -0,0 +1,33 @@
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 UxFileUtils_1 = __importDefault(require("./UxFileUtils"));
17
+ /**
18
+ * UxPreWorks
19
+ */
20
+ class UxPreWorks {
21
+ }
22
+ _a = UxPreWorks;
23
+ UxPreWorks.validateManifest = (context) => __awaiter(void 0, void 0, void 0, function* () {
24
+ const { projectPath } = context;
25
+ return UxFileUtils_1.default.validateManifest(projectPath);
26
+ });
27
+ UxPreWorks.validateSitemap = (context) => __awaiter(void 0, void 0, void 0, function* () {
28
+ const { projectPath } = context;
29
+ UxFileUtils_1.default.validateSitemap(projectPath);
30
+ });
31
+ exports.default = UxPreWorks;
32
+
33
+ //# sourceMappingURL=UxPreWorks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["utils/ux/UxPreWorks.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,gEAAuC;AAEvC;;GAEG;AACH,MAAM,UAAU;;;AACP,2BAAgB,GAAsC,CAAO,OAAO,EAAE,EAAE;IAC7E,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAA;IAC/B,OAAO,qBAAW,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAA;AAClD,CAAC,CAHsB,AAGtB,CAAA;AAEM,0BAAe,GAAsC,CAAO,OAAO,EAAE,EAAE;IAC5E,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAA;IAC/B,qBAAW,CAAC,eAAe,CAAC,WAAW,CAAC,CAAA;AAC1C,CAAC,CAHqB,AAGrB,CAAA;AAEH,kBAAe,UAAU,CAAA","file":"UxPreWorks.js","sourcesContent":["import { PreWork } from 'file-lane/lib/interface/IFileLaneConfig'\nimport IJavascriptCompileOption from '../../compiler/javascript/interface/IJavascriptCompileOption'\nimport UxFileUtils from './UxFileUtils'\n\n/**\n * UxPreWorks\n */\nclass UxPreWorks {\n static validateManifest: PreWork<IJavascriptCompileOption> = async (context) => {\n const { projectPath } = context\n return UxFileUtils.validateManifest(projectPath)\n }\n\n static validateSitemap: PreWork<IJavascriptCompileOption> = async (context) => {\n const { projectPath } = context\n UxFileUtils.validateSitemap(projectPath)\n }\n}\nexport default UxPreWorks\n"],"sourceRoot":"../../../src"}
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const shared_utils_1 = require("@aiot-toolkit/shared-utils");
16
15
  const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
17
16
  const FileLaneUtil_1 = __importDefault(require("file-lane/lib/utils/FileLaneUtil"));
18
17
  const fs_extra_1 = __importDefault(require("fs-extra"));
@@ -34,10 +33,7 @@ class XtsFollowWorks {
34
33
  const zipPath = path_1.default.join(projectPath, 'dist');
35
34
  // buildPath必须是真实文件夹路径
36
35
  if (!fs_extra_1.default.existsSync(buildPath)) {
37
- ColorConsole_1.default.log({
38
- level: shared_utils_1.LOG_LEVEL.Error,
39
- message: `XtsConfig follwWorkers zip build error, buildPath not exist`
40
- });
36
+ ColorConsole_1.default.throw(`buildPath: '${buildPath}' not exist`);
41
37
  }
42
38
  try {
43
39
  // 确认文件夹是否存在,不存在则创建
@@ -48,7 +44,7 @@ class XtsFollowWorks {
48
44
  yield FileLaneUtil_1.default.zipProject([buildPath], filePath, [options.packageName]);
49
45
  }
50
46
  catch (err) {
51
- ColorConsole_1.default.log({ level: shared_utils_1.LOG_LEVEL.Error, message: err.message });
47
+ ColorConsole_1.default.throw(`${err.message}`);
52
48
  }
53
49
  });
54
50
  }
@@ -125,10 +121,7 @@ class XtsFollowWorks {
125
121
  }
126
122
  }
127
123
  else {
128
- ColorConsole_1.default.log({
129
- level: shared_utils_1.LOG_LEVEL.Error,
130
- message: 'zip DistributedQuickApp not find manifest.json'
131
- });
124
+ ColorConsole_1.default.throw('not find manifest.json');
132
125
  }
133
126
  });
134
127
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["utils/xts/XtsFollowWorks.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,6DAAsD;AACtD,+FAAsE;AAEtE,oFAA2D;AAC3D,wDAAyB;AACzB,gDAAuB;AAEvB,sEAA6C;AAQ7C;;GAEG;AACH,MAAM,cAAc;IAClB;;;OAGG;IACH,MAAM,CAAO,iBAAiB,CAAC,OAAyB,EAAE,OAAiC;;YACzF,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAA;YAC/B,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,M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,GAAG,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,CAAA;QACjD,OAAO,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IACpC,CAAC;CACF;AACD,kBAAe,cAAc,CAAA","file":"XtsFollowWorks.js","sourcesContent":["import { LOG_LEVEL } from '@aiot-toolkit/shared-utils'\nimport ColorConsole from '@aiot-toolkit/shared-utils/lib/ColorConsole'\nimport { IFileLaneContext } from 'file-lane'\nimport FileLaneUtil from 'file-lane/lib/utils/FileLaneUtil'\nimport Fs from 'fs-extra'\nimport Path from 'path'\nimport IDeviceList from '../../interface/IDeviceList'\nimport UxFileUtils from './../ux/UxFileUtils'\n\nexport interface DefaultZipProjectOptions {\n tarDir?: string\n ext?: string\n packageName: string\n}\n\n/**\n * XtsFollowWorks\n */\nclass XtsFollowWorks {\n /**\n * 将项目中build文件夹的内容压缩成zip包,并将压缩产物放到dist文件夹下\n * @param context\n */\n static async defaultZipProject(context: IFileLaneContext, options: DefaultZipProjectOptions) {\n const { projectPath } = context\n const output = options.tarDir || context.output\n const buildPath = Path.join(projectPath, output)\n const zipPath = Path.join(projectPath, 'dist')\n // buildPath必须是真实文件夹路径\n if (!Fs.existsSync(buildPath)) {\n ColorConsole.log({\n level: LOG_LEVEL.Error,\n message: `XtsConfig follwWorkers zip build error, buildPath not exist`\n })\n }\n try {\n // 确认文件夹是否存在,不存在则创建\n Fs.ensureDirSync(zipPath)\n // 清空dist文件夹\n Fs.emptyDirSync(zipPath)\n const filePath = XtsFollowWorks.getFilePath(projectPath, 'dist', options.packageName, 'rpk')\n await FileLaneUtil.zipProject([buildPath], filePath, [options.packageName])\n } catch (err) {\n ColorConsole.log({ level: LOG_LEVEL.Error, message: (err as Error).message })\n }\n }\n /**\n * 将分布式项目按照manifest.json中的配置打包,思路如下:\n * 1. 获取manifest中aspect的路由配置\n * 2. 对aspects中的所有路由信息进行遍历\n * 3. 按照设备(设备+rule)对aspect分类\n * 4. 按照设备列表分别进行打包\n * @param context\n */\n static async zipDistributedQuickApp(context: IFileLaneContext) {\n const deviceList: IDeviceList[] = [\n {\n device: 'phone',\n aspectList: []\n }\n ]\n const { projectPath, output } = context\n const manifestPath = UxFileUtils.getManifestFilePath(projectPath, 'app')\n if (Fs.existsSync(manifestPath)) {\n //获取manifest.json内容\n const aspectsRule = Fs.readJSONSync(manifestPath)?.router?.aspects\n if (aspectsRule) {\n Object.keys(aspectsRule).forEach((aspectRule) => {\n // 分别处理每个aspectRule数组\n for (let item of aspectsRule[aspectRule]) {\n const { devices, rule, path } = item\n // 如果存在设备列表\n if (devices && Array.isArray(devices) && devices.length > 0) {\n for (let device of devices) {\n // 设备名与rule组合为一个设备\n if (rule) {\n device = `${device}.${rule}`\n }\n // 查找设备是否已存在于设备列表中\n const index =\n device === 'phone' ? 0 : deviceList.findIndex((item) => item.device === device)\n if (index === -1) {\n // 新设备\n deviceList.push({\n device,\n aspectList: [path]\n })\n } else {\n // 已存在的设备信息时,仅需添加aspect路由\n deviceList[index].aspectList.push(path)\n }\n }\n } else {\n // 设备值默认值为phone\n deviceList[0].aspectList.push(path)\n }\n }\n })\n }\n const zipPath = Path.join(projectPath, 'dist')\n\n Fs.ensureDirSync(zipPath)\n Fs.emptyDirSync(zipPath)\n // 根据deviceList进行打包\n for (const item of deviceList) {\n // 所有zip包都需要app信息\n item.aspectList.push('app')\n // 将路由转为真实路径\n const buildPaths = item.aspectList.map((name) => Path.join(projectPath, output, name))\n const filePath = XtsFollowWorks.getFilePath(projectPath, 'dist', item.device)\n try {\n await FileLaneUtil.zipProject(buildPaths, filePath)\n } catch (error) {}\n }\n } else {\n ColorConsole.log({\n level: LOG_LEVEL.Error,\n message: 'zip DistributedQuickApp not find manifest.json'\n })\n }\n }\n /**\n * 根据项目路径,打包文件夹名和传入的压缩包名,生成压缩文件zip路径\n * @param projectPath\n * @param outputDir\n * @param zipName\n * @returns\n */\n static getFilePath(\n projectPath: string,\n outputDir: string = 'dist',\n zipName?: string,\n ext = 'zip'\n ) {\n zipName = zipName ? `${zipName}.${ext}` : `${Path.basename(projectPath)}.${ext}`\n const zipPath = Path.join(projectPath, outputDir)\n return Path.join(zipPath, zipName)\n }\n}\nexport default XtsFollowWorks\n"],"sourceRoot":"../../../src"}
1
+ {"version":3,"sources":["utils/xts/XtsFollowWorks.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+FAAsE;AAEtE,oFAA2D;AAC3D,wDAAyB;AACzB,gDAAuB;AAEvB,sEAA6C;AAQ7C;;GAEG;AACH,MAAM,cAAc;IAClB;;;OAGG;IACH,MAAM,CAAO,iBAAiB,CAAC,OAAyB,EAAE,OAAiC;;YACzF,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAA;YAC/B,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAA;YAC/C,MAAM,SAAS,GAAG,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA;YAChD,MAAM,OAAO,GAAG,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA;YAC9C,sBAAsB;YACtB,IAAI,CAAC,kBAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;gBAC7B,sBAAY,CAAC,KAAK,CAAC,eAAe,SAAS,aAAa,CAAC,CAAA;aAC1D;YACD,IAAI;gBACF,mBAAmB;gBACnB,kBAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;gBACzB,YAAY;gBACZ,kBAAE,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;gBACxB,MAAM,QAAQ,GAAG,cAAc,CAAC,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,CAAA;gBAC5F,MAAM,sBAAY,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAA;aAC5E;YA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nB;aACF;iBAAM;gBACL,sBAAY,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAA;aAC7C;;KACF;IACD;;;;;;OAMG;IACH,MAAM,CAAC,WAAW,CAChB,WAAmB,EACnB,YAAoB,MAAM,EAC1B,OAAgB,EAChB,GAAG,GAAG,KAAK;QAEX,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,cAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,GAAG,EAAE,CAAA;QAChF,MAAM,OAAO,GAAG,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,CAAA;QACjD,OAAO,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IACpC,CAAC;CACF;AACD,kBAAe,cAAc,CAAA","file":"XtsFollowWorks.js","sourcesContent":["import ColorConsole from '@aiot-toolkit/shared-utils/lib/ColorConsole'\nimport { IFileLaneContext } from 'file-lane'\nimport FileLaneUtil from 'file-lane/lib/utils/FileLaneUtil'\nimport Fs from 'fs-extra'\nimport Path from 'path'\nimport IDeviceList from '../../interface/IDeviceList'\nimport UxFileUtils from './../ux/UxFileUtils'\n\nexport interface DefaultZipProjectOptions {\n tarDir?: string\n ext?: string\n packageName: string\n}\n\n/**\n * XtsFollowWorks\n */\nclass XtsFollowWorks {\n /**\n * 将项目中build文件夹的内容压缩成zip包,并将压缩产物放到dist文件夹下\n * @param context\n */\n static async defaultZipProject(context: IFileLaneContext, options: DefaultZipProjectOptions) {\n const { projectPath } = context\n const output = options.tarDir || context.output\n const buildPath = Path.join(projectPath, output)\n const zipPath = Path.join(projectPath, 'dist')\n // buildPath必须是真实文件夹路径\n if (!Fs.existsSync(buildPath)) {\n ColorConsole.throw(`buildPath: '${buildPath}' not exist`)\n }\n try {\n // 确认文件夹是否存在,不存在则创建\n Fs.ensureDirSync(zipPath)\n // 清空dist文件夹\n Fs.emptyDirSync(zipPath)\n const filePath = XtsFollowWorks.getFilePath(projectPath, 'dist', options.packageName, 'rpk')\n await FileLaneUtil.zipProject([buildPath], filePath, [options.packageName])\n } catch (err) {\n ColorConsole.throw(`${(err as Error).message}`)\n }\n }\n /**\n * 将分布式项目按照manifest.json中的配置打包,思路如下:\n * 1. 获取manifest中aspect的路由配置\n * 2. 对aspects中的所有路由信息进行遍历\n * 3. 按照设备(设备+rule)对aspect分类\n * 4. 按照设备列表分别进行打包\n * @param context\n */\n static async zipDistributedQuickApp(context: IFileLaneContext) {\n const deviceList: IDeviceList[] = [\n {\n device: 'phone',\n aspectList: []\n }\n ]\n const { projectPath, output } = context\n const manifestPath = UxFileUtils.getManifestFilePath(projectPath, 'app')\n if (Fs.existsSync(manifestPath)) {\n //获取manifest.json内容\n const aspectsRule = Fs.readJSONSync(manifestPath)?.router?.aspects\n if (aspectsRule) {\n Object.keys(aspectsRule).forEach((aspectRule) => {\n // 分别处理每个aspectRule数组\n for (let item of aspectsRule[aspectRule]) {\n const { devices, rule, path } = item\n // 如果存在设备列表\n if (devices && Array.isArray(devices) && devices.length > 0) {\n for (let device of devices) {\n // 设备名与rule组合为一个设备\n if (rule) {\n device = `${device}.${rule}`\n }\n // 查找设备是否已存在于设备列表中\n const index =\n device === 'phone' ? 0 : deviceList.findIndex((item) => item.device === device)\n if (index === -1) {\n // 新设备\n deviceList.push({\n device,\n aspectList: [path]\n })\n } else {\n // 已存在的设备信息时,仅需添加aspect路由\n deviceList[index].aspectList.push(path)\n }\n }\n } else {\n // 设备值默认值为phone\n deviceList[0].aspectList.push(path)\n }\n }\n })\n }\n const zipPath = Path.join(projectPath, 'dist')\n\n Fs.ensureDirSync(zipPath)\n Fs.emptyDirSync(zipPath)\n // 根据deviceList进行打包\n for (const item of deviceList) {\n // 所有zip包都需要app信息\n item.aspectList.push('app')\n // 将路由转为真实路径\n const buildPaths = item.aspectList.map((name) => Path.join(projectPath, output, name))\n const filePath = XtsFollowWorks.getFilePath(projectPath, 'dist', item.device)\n try {\n await FileLaneUtil.zipProject(buildPaths, filePath)\n } catch (error) {}\n }\n } else {\n ColorConsole.throw('not find manifest.json')\n }\n }\n /**\n * 根据项目路径,打包文件夹名和传入的压缩包名,生成压缩文件zip路径\n * @param projectPath\n * @param outputDir\n * @param zipName\n * @returns\n */\n static getFilePath(\n projectPath: string,\n outputDir: string = 'dist',\n zipName?: string,\n ext = 'zip'\n ) {\n zipName = zipName ? `${zipName}.${ext}` : `${Path.basename(projectPath)}.${ext}`\n const zipPath = Path.join(projectPath, outputDir)\n return Path.join(zipPath, zipName)\n }\n}\nexport default XtsFollowWorks\n"],"sourceRoot":"../../../src"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/aiotpack",
3
- "version": "2.0.1-alpha.11",
3
+ "version": "2.0.1-alpha.13",
4
4
  "description": "The process tool for packaging aiot projects.",
5
5
  "keywords": [
6
6
  "aiotpack"
@@ -24,13 +24,13 @@
24
24
  "test": "node ./__tests__/aiotpack.test.js"
25
25
  },
26
26
  "dependencies": {
27
- "@aiot-toolkit/generator": "2.0.1-alpha.11",
28
- "@aiot-toolkit/parser": "2.0.1-alpha.11",
27
+ "@aiot-toolkit/generator": "2.0.1-alpha.13",
28
+ "@aiot-toolkit/parser": "2.0.1-alpha.13",
29
29
  "@hap-toolkit/aaptjs": "^2.0.0",
30
30
  "babel-loader": "^9.1.3",
31
31
  "del": "^4.1.0",
32
32
  "fast-glob": "^3.3.2",
33
- "file-lane": "2.0.1-alpha.11",
33
+ "file-lane": "2.0.1-alpha.13",
34
34
  "file-loader": "^6.2.0",
35
35
  "fs-extra": "^11.2.0",
36
36
  "jsrsasign": "^7.2.2",
@@ -43,5 +43,5 @@
43
43
  "@types/jsrsasign": "^10.5.12",
44
44
  "@types/webpack-sources": "^3.2.3"
45
45
  },
46
- "gitHead": "efd50ce0ed4755bc2cd12aebc5114319e75d9927"
46
+ "gitHead": "49040b26a267943df4d0b202b200d4df5bcbc1ef"
47
47
  }