@aiot-toolkit/shared-utils 1.0.20-importfile-dev.1 → 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 (50) hide show
  1. package/README.md +10 -2
  2. package/lib/ColorConsole.d.ts +13 -0
  3. package/lib/ColorConsole.js +45 -0
  4. package/lib/ColorConsole.js.map +1 -0
  5. package/lib/ColorConsole2.d.ts +41 -0
  6. package/lib/ColorConsole2.js +107 -0
  7. package/lib/ColorConsole2.js.map +1 -0
  8. package/lib/data/MapData.d.ts +8 -0
  9. package/lib/data/MapData.js +12 -0
  10. package/lib/data/MapData.js.map +1 -0
  11. package/lib/data/PositionError.d.ts +9 -0
  12. package/lib/data/PositionError.js +14 -0
  13. package/lib/data/PositionError.js.map +1 -0
  14. package/lib/index.d.ts +7 -0
  15. package/lib/index.js +24 -1
  16. package/lib/index.js.map +1 -0
  17. package/lib/interface/ILog.d.ts +19 -0
  18. package/lib/interface/ILog.js +15 -0
  19. package/lib/interface/ILog.js.map +1 -0
  20. package/lib/interface/IPosition.d.ts +30 -0
  21. package/lib/interface/IPosition.js +4 -0
  22. package/lib/interface/IPosition.js.map +1 -0
  23. package/lib/type/Type.d.ts +4 -0
  24. package/lib/type/Type.js +4 -0
  25. package/lib/type/Type.js.map +1 -0
  26. package/lib/utils/CommonUtil.d.ts +21 -0
  27. package/lib/utils/CommonUtil.js +54 -0
  28. package/lib/utils/CommonUtil.js.map +1 -0
  29. package/lib/utils/FileUtil.d.ts +73 -0
  30. package/lib/utils/FileUtil.js +157 -0
  31. package/lib/utils/FileUtil.js.map +1 -0
  32. package/lib/utils/NetworkUtil.d.ts +14 -0
  33. package/lib/utils/NetworkUtil.js +54 -0
  34. package/lib/utils/NetworkUtil.js.map +1 -0
  35. package/lib/utils/StringUtil.d.ts +16 -0
  36. package/lib/utils/StringUtil.js +26 -0
  37. package/lib/utils/StringUtil.js.map +1 -0
  38. package/lib/utils/WrapCallback.d.ts +13 -0
  39. package/lib/utils/WrapCallback.js +34 -0
  40. package/lib/utils/WrapCallback.js.map +1 -0
  41. package/package.json +17 -20
  42. package/compilation-config.js +0 -141
  43. package/config.js +0 -14
  44. package/event-bus.js +0 -13
  45. package/lib/buildMode/BuildModeManager.js +0 -2
  46. package/lib/buildMode/util.js +0 -2
  47. package/lib/protobuf/protobuf.js +0 -2
  48. package/lib/protobuf/protobufControl.js +0 -2
  49. package/lib/protobuf/vdom_pb.js +0 -2
  50. package/lib/record-client.js +0 -2
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const fs_extra_1 = __importDefault(require("fs-extra"));
7
+ const path_1 = __importDefault(require("path"));
8
+ /**
9
+ * FileUtil
10
+ */
11
+ class FileUtil {
12
+ /**
13
+ * 判断字符串是否符合包含、不包含的条件
14
+ *
15
+ * 规则为:
16
+ * 1. 如果设置了不包含且匹配,则不包含
17
+ * 2. 否则,如果设置了包含且不匹配,则不包含
18
+ * 3. 否则,包含
19
+ * @param value
20
+ * @param include
21
+ * @param exclude
22
+ */
23
+ static include(path, include, exclude) {
24
+ if (exclude && this.match(path, exclude)) {
25
+ return false;
26
+ }
27
+ if (include && !this.match(path, include)) {
28
+ return false;
29
+ }
30
+ return true;
31
+ }
32
+ /**
33
+ * 判断字符串是否匹配指定规则
34
+ * @param value
35
+ * @param matchType
36
+ * @returns
37
+ */
38
+ static match(value, matchType) {
39
+ switch (typeof matchType) {
40
+ case 'function':
41
+ return matchType(value);
42
+ case 'string':
43
+ return matchType === value;
44
+ case 'object':
45
+ if (matchType instanceof RegExp) {
46
+ return matchType.test(value);
47
+ }
48
+ else if (matchType instanceof Array) {
49
+ // 递归检查每一项
50
+ let result = matchType.find((item) => this.match(value, item));
51
+ if (result) {
52
+ return true;
53
+ }
54
+ }
55
+ return false;
56
+ default:
57
+ return false;
58
+ }
59
+ }
60
+ /**
61
+ * 获取指定目录所有层级的文件
62
+ * @param dir
63
+ * @returns
64
+ */
65
+ static readAlldirSync(dir, includes, excludes) {
66
+ const files = fs_extra_1.default.readdirSync(dir, { withFileTypes: true });
67
+ const result = [];
68
+ files.forEach((item) => {
69
+ const itemPath = path_1.default.join(dir, item.name);
70
+ if (item.isDirectory() && item) {
71
+ const children = this.readAlldirSync(itemPath, includes, excludes);
72
+ result.push(...children);
73
+ }
74
+ else {
75
+ if (this.include(itemPath, includes, excludes)) {
76
+ result.push(itemPath);
77
+ }
78
+ }
79
+ });
80
+ return result;
81
+ }
82
+ /**
83
+ * 替换文件内容
84
+ *
85
+ * @see replaceKeywords
86
+ * @param filePath
87
+ * @param keywordDic
88
+ */
89
+ static replaceFileContent(filePath, keywordDic) {
90
+ let content = fs_extra_1.default.readFileSync(filePath, 'utf-8');
91
+ content = this.replaceKeywords(content, keywordDic);
92
+ fs_extra_1.default.writeFileSync(filePath, content);
93
+ }
94
+ /**
95
+ * 替换字符串内容
96
+ *
97
+ * @example
98
+ * // 替换 abc{{value}} 为 abc123
99
+ * replaceKeywords(`abc{{value}}`, {value: '123'})
100
+ *
101
+ * @param content
102
+ * @param keywordDic
103
+ * @returns
104
+ */
105
+ static replaceKeywords(content, keywordDic) {
106
+ return content.replace(/{{(.*?)}}/gm, (_, key) => {
107
+ key = key.trim();
108
+ return keywordDic[key] !== undefined ? keywordDic[key] : key;
109
+ });
110
+ }
111
+ /**
112
+ * 更新文件路径
113
+ * @param path
114
+ * @param fullName
115
+ * @returns
116
+ */
117
+ static updatePath(path, fullName) {
118
+ if (fs_extra_1.default.statSync(path).isFile()) {
119
+ return path_1.default.join(path_1.default.dirname(path), fullName);
120
+ }
121
+ return path;
122
+ }
123
+ /**
124
+ * 复制文件
125
+ * @param sourceDir 源目录
126
+ * @param targetDir 目标目录
127
+ * @param excludes 不包含的文件
128
+ * @param includes 包含的文件
129
+ */
130
+ static copyFiles(sourceDir, targetDir, excludes, includes) {
131
+ const files = this.readAlldirSync(sourceDir, includes, excludes);
132
+ for (let file of files) {
133
+ const targetPath = path_1.default.join(targetDir, path_1.default.relative(sourceDir, file));
134
+ fs_extra_1.default.copySync(file, targetPath, { overwrite: true });
135
+ }
136
+ }
137
+ /**
138
+ * 校验文件
139
+ * @param fileList
140
+ */
141
+ static checkFilePath(fileList) {
142
+ let checkPass = true;
143
+ fileList.forEach((filePath) => {
144
+ if (!fs_extra_1.default.existsSync(filePath)) {
145
+ const fileName = path_1.default.basename(filePath);
146
+ const dirPath = path_1.default.dirname(filePath);
147
+ // 此处需要报错,但是不需要结束程序
148
+ console.error(`Error: File ${fileName} does not exist in the path:${dirPath}`);
149
+ checkPass = false;
150
+ }
151
+ });
152
+ return checkPass;
153
+ }
154
+ }
155
+ exports.default = FileUtil;
156
+
157
+ //# sourceMappingURL=FileUtil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["utils/FileUtil.ts"],"names":[],"mappings":"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","file":"FileUtil.js","sourcesContent":["import Fs from 'fs-extra'\nimport Path from 'path'\ntype OneMatchType = string | RegExp | ((path: string) => boolean)\n\nexport type MatchType = OneMatchType | OneMatchType[]\n/**\n * FileUtil\n */\nclass FileUtil {\n /**\n * 判断字符串是否符合包含、不包含的条件\n *\n * 规则为:\n * 1. 如果设置了不包含且匹配,则不包含\n * 2. 否则,如果设置了包含且不匹配,则不包含\n * 3. 否则,包含\n * @param value\n * @param include\n * @param exclude\n */\n static include(path: string, include?: MatchType, exclude?: MatchType) {\n if (exclude && this.match(path, exclude)) {\n return false\n }\n\n if (include && !this.match(path, include)) {\n return false\n }\n\n return true\n }\n /**\n * 判断字符串是否匹配指定规则\n * @param value\n * @param matchType\n * @returns\n */\n static match(value: string, matchType: MatchType) {\n switch (typeof matchType) {\n case 'function':\n return matchType(value)\n case 'string':\n return matchType === value\n case 'object':\n if (matchType instanceof RegExp) {\n return matchType.test(value)\n } else if (matchType instanceof Array) {\n // 递归检查每一项\n let result = matchType.find((item) => this.match(value, item))\n if (result) {\n return true\n }\n }\n return false\n default:\n return false\n }\n }\n /**\n * 获取指定目录所有层级的文件\n * @param dir\n * @returns\n */\n\n static readAlldirSync(dir: string, includes?: MatchType, excludes?: MatchType) {\n const files = Fs.readdirSync(dir, { withFileTypes: true })\n const result: string[] = []\n files.forEach((item) => {\n const itemPath = Path.join(dir, item.name)\n if (item.isDirectory() && item) {\n const children = this.readAlldirSync(itemPath, includes, excludes)\n result.push(...children)\n } else {\n if (this.include(itemPath, includes, excludes)) {\n result.push(itemPath)\n }\n }\n })\n return result\n }\n\n /**\n * 替换文件内容\n *\n * @see replaceKeywords\n * @param filePath\n * @param keywordDic\n */\n static replaceFileContent(filePath: string, keywordDic: Record<string, string>) {\n let content = Fs.readFileSync(filePath, 'utf-8')\n content = this.replaceKeywords(content, keywordDic)\n Fs.writeFileSync(filePath, content)\n }\n\n /**\n * 替换字符串内容\n *\n * @example\n * // 替换 abc{{value}} 为 abc123\n * replaceKeywords(`abc{{value}}`, {value: '123'})\n *\n * @param content\n * @param keywordDic\n * @returns\n */\n static replaceKeywords(content: string, keywordDic: Record<string, string>) {\n return content.replace(/{{(.*?)}}/gm, (_, key) => {\n key = key.trim()\n return keywordDic[key] !== undefined ? keywordDic[key] : key\n })\n }\n /**\n * 更新文件路径\n * @param path\n * @param fullName\n * @returns\n */\n static updatePath(path: string, fullName: string) {\n if (Fs.statSync(path).isFile()) {\n return Path.join(Path.dirname(path), fullName)\n }\n return path\n }\n\n /**\n * 复制文件\n * @param sourceDir 源目录\n * @param targetDir 目标目录\n * @param excludes 不包含的文件\n * @param includes 包含的文件\n */\n static copyFiles(\n sourceDir: string,\n targetDir: string,\n excludes?: MatchType,\n includes?: MatchType\n ) {\n const files = this.readAlldirSync(sourceDir, includes, excludes)\n for (let file of files) {\n const targetPath = Path.join(targetDir, Path.relative(sourceDir, file))\n Fs.copySync(file, targetPath, { overwrite: true })\n }\n }\n /**\n * 校验文件\n * @param fileList\n */\n static checkFilePath(fileList: string[]): boolean {\n let checkPass = true\n fileList.forEach((filePath) => {\n if (!Fs.existsSync(filePath)) {\n const fileName = Path.basename(filePath)\n const dirPath = Path.dirname(filePath)\n // 此处需要报错,但是不需要结束程序\n console.error(`Error: File ${fileName} does not exist in the path:${dirPath}`)\n checkPass = false\n }\n })\n return checkPass\n }\n}\nexport default FileUtil\n"],"sourceRoot":"../../src"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * NetworkUtil
3
+ */
4
+ declare class NetworkUtil {
5
+ /**
6
+ * clone git 项目
7
+ * @param url
8
+ * @param localPath
9
+ * @param showProgress 是否显示进度条,默认为 true,会在命令行工具中显示绿色进度条
10
+ * @returns
11
+ */
12
+ static gitClone(url: string, localPath: string, showProgress?: boolean): Promise<void>;
13
+ }
14
+ export default NetworkUtil;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const ansi_colors_1 = __importDefault(require("ansi-colors"));
7
+ const cli_progress_1 = __importDefault(require("cli-progress"));
8
+ const simple_git_1 = __importDefault(require("simple-git"));
9
+ /**
10
+ * NetworkUtil
11
+ */
12
+ class NetworkUtil {
13
+ /**
14
+ * clone git 项目
15
+ * @param url
16
+ * @param localPath
17
+ * @param showProgress 是否显示进度条,默认为 true,会在命令行工具中显示绿色进度条
18
+ * @returns
19
+ */
20
+ static gitClone(url, localPath, showProgress = true) {
21
+ return new Promise((resolve, reject) => {
22
+ let bar;
23
+ if (showProgress) {
24
+ bar = new cli_progress_1.default.SingleBar({
25
+ format: `progress: {percentage}% ${ansi_colors_1.default.green(`{bar}`)} {value}/{total}`
26
+ }, cli_progress_1.default.Presets.shades_classic);
27
+ bar.start(100, 0);
28
+ }
29
+ (0, simple_git_1.default)({
30
+ progress: (data) => {
31
+ if (bar) {
32
+ bar.setTotal(data.total);
33
+ bar.update(data.processed);
34
+ }
35
+ }
36
+ })
37
+ .clone(url, localPath)
38
+ .then(() => {
39
+ resolve();
40
+ })
41
+ .catch((error) => {
42
+ reject(error);
43
+ })
44
+ .finally(() => {
45
+ if (bar) {
46
+ bar.stop();
47
+ }
48
+ });
49
+ });
50
+ }
51
+ }
52
+ exports.default = NetworkUtil;
53
+
54
+ //# sourceMappingURL=NetworkUtil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["utils/NetworkUtil.ts"],"names":[],"mappings":";;;;;AAAA,8DAAgC;AAChC,gEAAsC;AACtC,4DAAkC;AAElC;;GAEG;AACH,MAAM,WAAW;IACf;;;;;;OAMG;IACH,MAAM,CAAC,QAAQ,CAAC,GAAW,EAAE,SAAiB,EAAE,YAAY,GAAG,IAAI;QACjE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,GAA0B,CAAA;YAC9B,IAAI,YAAY,EAAE;gBAChB,GAAG,GAAG,IAAI,sBAAW,CAAC,SAAS,CAC7B;oBACE,MAAM,EAAE,2BAA2B,qBAAM,CAAC,KAAK,CAAC,OAAO,CAAC,mBAAmB;iBAC5E,EACD,sBAAW,CAAC,OAAO,CAAC,cAAc,CACnC,CAAA;gBACD,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;aAClB;YAED,IAAA,oBAAS,EAAC;gBACR,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE;oBACjB,IAAI,GAAG,EAAE;wBACP,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;wBACxB,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;qBAC3B;gBACH,CAAC;aACF,CAAC;iBACC,KAAK,CAAC,GAAG,EAAE,SAAS,CAAC;iBACrB,IAAI,CAAC,GAAG,EAAE;gBACT,OAAO,EAAE,CAAA;YACX,CAAC,CAAC;iBACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;gBACf,MAAM,CAAC,KAAK,CAAC,CAAA;YACf,CAAC,CAAC;iBACD,OAAO,CAAC,GAAG,EAAE;gBACZ,IAAI,GAAG,EAAE;oBACP,GAAG,CAAC,IAAI,EAAE,CAAA;iBACX;YACH,CAAC,CAAC,CAAA;QACN,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AACD,kBAAe,WAAW,CAAA","file":"NetworkUtil.js","sourcesContent":["import Colors from 'ansi-colors'\nimport CliProgress from 'cli-progress'\nimport SimpleGit from 'simple-git'\n\n/**\n * NetworkUtil\n */\nclass NetworkUtil {\n /**\n * clone git 项目\n * @param url\n * @param localPath\n * @param showProgress 是否显示进度条,默认为 true,会在命令行工具中显示绿色进度条\n * @returns\n */\n static gitClone(url: string, localPath: string, showProgress = true): Promise<void> {\n return new Promise((resolve, reject) => {\n let bar: CliProgress.SingleBar\n if (showProgress) {\n bar = new CliProgress.SingleBar(\n {\n format: `progress: {percentage}% ${Colors.green(`{bar}`)} {value}/{total}`\n },\n CliProgress.Presets.shades_classic\n )\n bar.start(100, 0)\n }\n\n SimpleGit({\n progress: (data) => {\n if (bar) {\n bar.setTotal(data.total)\n bar.update(data.processed)\n }\n }\n })\n .clone(url, localPath)\n .then(() => {\n resolve()\n })\n .catch((error) => {\n reject(error)\n })\n .finally(() => {\n if (bar) {\n bar.stop()\n }\n })\n })\n }\n}\nexport default NetworkUtil\n"],"sourceRoot":"../../src"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * StringUtil
3
+ */
4
+ declare class StringUtil {
5
+ /** 使用正则表达式去除开头和结尾的 ' " ` */
6
+ static removeQuotes(str: string): string;
7
+ /**
8
+ * 中划线文本转为驼峰
9
+ * @param value
10
+ * @returns
11
+ */
12
+ static middleLinetoCame(value: string): string;
13
+ /** 首字母大写 */
14
+ static capitalizeFirstLetter([first, ...rest]: string): string;
15
+ }
16
+ export default StringUtil;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * StringUtil
5
+ */
6
+ class StringUtil {
7
+ /** 使用正则表达式去除开头和结尾的 ' " ` */
8
+ static removeQuotes(str) {
9
+ return str.replace(/^['"`]+|['"`]+$/g, '');
10
+ }
11
+ /**
12
+ * 中划线文本转为驼峰
13
+ * @param value
14
+ * @returns
15
+ */
16
+ static middleLinetoCame(value) {
17
+ return value === null || value === void 0 ? void 0 : value.replace(/-([a-z])/g, (_, match) => match.toUpperCase());
18
+ }
19
+ /** 首字母大写 */
20
+ static capitalizeFirstLetter([first, ...rest]) {
21
+ return [first.toUpperCase(), ...rest].join('');
22
+ }
23
+ }
24
+ exports.default = StringUtil;
25
+
26
+ //# sourceMappingURL=StringUtil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["utils/StringUtil.ts"],"names":[],"mappings":";;AAAA;;GAEG;AACH,MAAM,UAAU;IACd,6BAA6B;IAC7B,MAAM,CAAC,YAAY,CAAC,GAAW;QAC7B,OAAO,GAAG,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAA;IAC5C,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,gBAAgB,CAAC,KAAa;QACnC,OAAO,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAA;IAC/E,CAAC;IAED,YAAY;IACZ,MAAM,CAAC,qBAAqB,CAAC,CAAC,KAAK,EAAE,GAAG,IAAI,CAAS;QACnD,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAChD,CAAC;CACF;AACD,kBAAe,UAAU,CAAA","file":"StringUtil.js","sourcesContent":["/**\n * StringUtil\n */\nclass StringUtil {\n /** 使用正则表达式去除开头和结尾的 ' \" ` */\n static removeQuotes(str: string) {\n return str.replace(/^['\"`]+|['\"`]+$/g, '')\n }\n\n /**\n * 中划线文本转为驼峰\n * @param value\n * @returns\n */\n static middleLinetoCame(value: string) {\n return value?.replace(/-([a-z])/g, (_, match: string) => match.toUpperCase())\n }\n\n /** 首字母大写 */\n static capitalizeFirstLetter([first, ...rest]: string) {\n return [first.toUpperCase(), ...rest].join('')\n }\n}\nexport default StringUtil\n"],"sourceRoot":"../../src"}
@@ -0,0 +1,13 @@
1
+ import { Logger } from '../interface/ILog';
2
+ /**
3
+ * 包装回调函数
4
+ */
5
+ declare class WrapCallback {
6
+ /**
7
+ * 包装日志回调函数
8
+ * @param onLog
9
+ * @returns
10
+ */
11
+ static wrapOnLog(onLog: Logger): Logger;
12
+ }
13
+ export default WrapCallback;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const PositionError_1 = __importDefault(require("../data/PositionError"));
7
+ const ILog_1 = require("../interface/ILog");
8
+ /**
9
+ * 包装回调函数
10
+ */
11
+ class WrapCallback {
12
+ /**
13
+ * 包装日志回调函数
14
+ * @param onLog
15
+ * @returns
16
+ */
17
+ static wrapOnLog(onLog) {
18
+ return (log) => {
19
+ // 1. 传递给外部log
20
+ onLog(log);
21
+ // 2. 对throw和error进行错误抛出
22
+ const { level, message, position } = log;
23
+ if (level === ILog_1.LOG_LEVEL.Error || level === ILog_1.LOG_LEVEL.Throw) {
24
+ if (position) {
25
+ throw new PositionError_1.default(position, message);
26
+ }
27
+ throw new Error(message);
28
+ }
29
+ };
30
+ }
31
+ }
32
+ exports.default = WrapCallback;
33
+
34
+ //# sourceMappingURL=WrapCallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["utils/WrapCallback.ts"],"names":[],"mappings":";;;;;AAAA,0EAAiD;AACjD,4CAA2D;AAE3D;;GAEG;AACH,MAAM,YAAY;IAChB;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,KAAa;QAC5B,OAAO,CAAC,GAAS,EAAE,EAAE;YACnB,cAAc;YACd,KAAK,CAAC,GAAG,CAAC,CAAA;YACV,wBAAwB;YACxB,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAA;YACxC,IAAI,KAAK,KAAK,gBAAS,CAAC,KAAK,IAAI,KAAK,KAAK,gBAAS,CAAC,KAAK,EAAE;gBAC1D,IAAI,QAAQ,EAAE;oBACZ,MAAM,IAAI,uBAAa,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;iBAC3C;gBACD,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;aACzB;QACH,CAAC,CAAA;IACH,CAAC;CACF;AACD,kBAAe,YAAY,CAAA","file":"WrapCallback.js","sourcesContent":["import PositionError from '../data/PositionError'\nimport { ILog, LOG_LEVEL, Logger } from '../interface/ILog'\n\n/**\n * 包装回调函数\n */\nclass WrapCallback {\n /**\n * 包装日志回调函数\n * @param onLog\n * @returns\n */\n static wrapOnLog(onLog: Logger): Logger {\n return (log: ILog) => {\n // 1. 传递给外部log\n onLog(log)\n // 2. 对throw和error进行错误抛出\n const { level, message, position } = log\n if (level === LOG_LEVEL.Error || level === LOG_LEVEL.Throw) {\n if (position) {\n throw new PositionError(position, message)\n }\n throw new Error(message)\n }\n }\n }\n}\nexport default WrapCallback\n"],"sourceRoot":"../../src"}
package/package.json CHANGED
@@ -1,35 +1,32 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/shared-utils",
3
- "version": "1.0.20-importfile-dev.1",
4
- "description": "aiot shared utils",
5
- "engines": {
6
- "node": ">=8.0.0"
7
- },
8
- "publishConfig": {
9
- "access": "public"
10
- },
11
- "keywords": [
12
- "hap-toolkit",
13
- "quickapp"
14
- ],
3
+ "version": "2.0.1-alpha.0",
4
+ "description": "The common method functions of the aiot-toolkit.",
5
+ "homepage": "",
6
+ "license": "ISC",
15
7
  "main": "lib/index.js",
16
8
  "directories": {
17
9
  "lib": "lib",
18
10
  "test": "__tests__"
19
11
  },
20
12
  "files": [
21
- "lib/**/*.js",
22
- "config.js",
23
- "compilation-config.js",
24
- "event-bus.js"
13
+ "lib"
25
14
  ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "ssh://xujunjie1@git.mioffice.cn:29418/vela/aiot-toolkit"
18
+ },
19
+ "scripts": {
20
+ "test": "node ./__tests__/shared-utils.test.js"
21
+ },
26
22
  "dependencies": {
27
- "chalk": "^2.4.2",
28
- "google-protobuf": "^3.21.2",
23
+ "chalk": "^4.0.0",
24
+ "crypto": "^1.0.1",
25
+ "dayjs": "^1.11.9",
29
26
  "qrcode-terminal": "^0.12.0"
30
27
  },
31
28
  "devDependencies": {
32
- "strip-ansi": "^5.2.0"
29
+ "@types/qrcode-terminal": "^0.12.0"
33
30
  },
34
- "gitHead": "68100575b45155e1dd16227b16ac0a21cf9f7f21"
31
+ "gitHead": "cde5c75fa09622188ee4f1322ff9d53faf4d8520"
35
32
  }
@@ -1,141 +0,0 @@
1
- /*
2
- * Copyright (C) 2017, hapjs.org. All rights reserved.
3
- */
4
-
5
- const compileOptionsMeta = {
6
- // 打包来源
7
- originTypeNum: {
8
- IDE: 'quickapp-ide',
9
- CMD: 'cmd'
10
- },
11
- // 签名模式的枚举
12
- signModeEnum: {
13
- BUILD: 'BUILD',
14
- RELEASE: 'RELEASE',
15
- NULL: 'NULL'
16
- },
17
- // 主包保留名
18
- MAIN_PKG_NAME: 'base',
19
- // 枚举类型
20
- splitChunksModeEnum: {
21
- // 默认:冗余到每个页面JS中
22
- REDUNDANCY: 'REDUNDANCY',
23
- // 抽取公共JS到chunk文件中
24
- SMART: 'SMART'
25
- },
26
- // 抽取公共JS的文名称
27
- splitChunksNameEnum: {
28
- APP: 'app-chunks.json',
29
- PAGE: 'page-chunks.json'
30
- },
31
-
32
- // vela抽取公共JS的文名称
33
- velaSplitChunksNameEnum: {
34
- APP: 'app-chunks.js',
35
- PAGE: 'page-chunks.js'
36
- },
37
-
38
- // 自定义包名的枚举
39
- buildNameFormat: {
40
- DEFAULT: 'DEFAULT',
41
- ORIGINAL: 'ORIGINAL'
42
- }
43
- }
44
-
45
- const compileOptionsObject = {
46
- // 打包来源,ide|cmd
47
- originType: compileOptionsMeta.originTypeNum.CMD,
48
- // 签名模式 当前默认为debug签名
49
- signMode: compileOptionsMeta.signModeEnum.BUILD,
50
- // 是否开启分析
51
- stats: false,
52
- // sourcemap配置
53
- devtool: false,
54
- // 是否禁用子包
55
- disableSubpackages: false,
56
- // 是否禁用流式编译
57
- disableStreamPack: false,
58
- // 是否禁用签名能力
59
- disableSign: false,
60
- // 是否禁用V8的6.5版本编译
61
- disableScriptV8V65: false,
62
- // 是否编译复合选择器,生成_meta信息
63
- optimizeDescMeta: false,
64
- // 是否压缩CSS属性名
65
- optimizeCssAttr: false,
66
- // 是否压缩模板属性名
67
- optimizeTemplateAttr: false,
68
- // TODO:是否支持页面级别的样式(暂不支持)
69
- optimizeStylePageLevel: false,
70
- // TODO:是否支持应用级别的样式(暂不支持)
71
- optimizeStyleAppLevel: false,
72
- // 延迟加载自定义组件
73
- enableLazyComponent: false,
74
- // 是否移除无用资源
75
- optimizeUnusedResource: false,
76
- // 是否将dsl打包到rpk
77
- includeDslFromLib: false,
78
- // 是否将html等静态资源打包到rpk
79
- includeStaticResources: false,
80
- // 解决sourcemap资源的错位问题
81
- matchSourcemap: false,
82
- // 开启css样式抽取
83
- enableExtractCss: false,
84
- removeUxStyle: false,
85
- // 是否启用e2e测试用例
86
- enableE2e: false,
87
- // 是否启用代码覆盖率检查
88
- enableIstanbul: false,
89
- // 抽取公共JS的配置
90
- splitChunksMode: compileOptionsMeta.splitChunksModeEnum.REDUNDANCY,
91
- // 是否启用日志诊断功能
92
- enableDiagnosis: false,
93
- // 是否启用性能检查
94
- enablePerformanceCheck: false,
95
- // 调试时是否启用server的watch模式
96
- enableServerWatch: false,
97
- // 是否处理.9图
98
- trimDotnine: true,
99
- // 自定义包名 默认为带版本号的包名
100
- buildNameFormat: compileOptionsMeta.buildNameFormat.DEFAULT,
101
- // IDE传入的Path,用来保存构建IDE预览包
102
- setPreviewPkgPath: null,
103
- // 是否打包模式为mirtos
104
- enableMirtos: false,
105
- // 是否打包模式为mina-h5
106
- enableMinaH5: false,
107
- // 是否打开Nuttx模拟器
108
- openNuttx: false,
109
- /**
110
- * 设置exports内容时,创建导出函数,默认直接设置
111
- */
112
- enableCustomComponent: false,
113
- /**
114
- * 设置是否将vela打包为jsc
115
- */
116
- enableJsc: false,
117
- /**
118
- * 属性使用__opts__包裹一层
119
- */
120
- enableOpsWrap: true,
121
- /**
122
- * 设置是否不打包rpk
123
- */
124
- disableBuildRpk: false,
125
-
126
- /**
127
- * 是否使用protobuf打包二进制文件
128
- */
129
- enableProtobuf: false
130
- }
131
-
132
- /**
133
- * 初始化命令行中传递的配置
134
- * @param argopts - 命令行参数对象
135
- */
136
- function initCompileOptionsObject(argopts) {
137
- // TODO release memeory, use optimize-prop only
138
- Object.assign(compileOptionsObject, argopts)
139
- }
140
-
141
- module.exports = { compileOptionsMeta, compileOptionsObject, initCompileOptionsObject }
package/config.js DELETED
@@ -1,14 +0,0 @@
1
- const path = require('path')
2
- // 用户home目录
3
- const home = require('os').homedir()
4
- const clientRecordPath = path.join(home, 'hap-toolkit-client-records.json')
5
- module.exports = {
6
- projectPath: process.cwd(),
7
- clientRecordPath,
8
- sourceRoot: './src', // 源码根目录
9
- signRoot: './sign', // 证书签名路径
10
- releasePath: './dist', // 快应用包目录
11
- outputPath: './build', // 输出目录,
12
- dataCoverage: './.nyc_output', // 项目运行的代码覆盖率数据
13
- server: { port: 8000 }
14
- }
package/event-bus.js DELETED
@@ -1,13 +0,0 @@
1
- /*
2
- * Copyright (C) 2017, hapjs.org. All rights reserved.
3
- */
4
-
5
- const EventEmitter = require('events')
6
-
7
- module.exports = new EventEmitter()
8
-
9
- module.exports.PACKAGER_BUILD_DONE = 'PACKAGER.BUILD_DONE'
10
-
11
- module.exports.PACKAGER_WATCH_START = 'PACKAGER.WATCH_START'
12
-
13
- module.exports.PACKAGER_BUILD_PROGRESS = 'PACKAGER.PACKAGER_BUILD_PROGRESS'
@@ -1,2 +0,0 @@
1
- "use strict";var _fs=_interopRequireDefault(require("fs")),_path=_interopRequireDefault(require("path")),_index=require("../index"),_util=require("./util"),_eventBus=_interopRequireDefault(require("../../event-bus"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const{PACKAGER_BUILD_DONE:PACKAGER_BUILD_DONE}=_eventBus.default;function BuildModeManager(e){(0,_util.initProjectConfig)(e),this.setRoot(e)}BuildModeManager.prototype._read=function(){let e={};try{e=(0,_index.readJson)(this._configFile)}catch(e){console.log("ENOENT"===e.code?e.message:e)}e.modeOptions||(e.modeOptions={current:-1,list:[]});const t=e.modeOptions;return t.list=t.list.filter((e=>null!==e.id&&-1!==e.id)),e},BuildModeManager.prototype._write=function(e){const t=e.modeOptions;t.list=t.list.filter((e=>null!==e.id&&-1!==e.id)).reduce(((e,t)=>(e.find((e=>e.id===t.id))||e.push(t),e)),[]),this._configFile&&_fs.default.writeFileSync(this._configFile,JSON.stringify(e,null,2))},BuildModeManager.prototype.getConfig=function(){return this._read().modeOptions},BuildModeManager.prototype.getAllPages=function(){if(!this.root)return[];const e=_path.default.join(this.root,"src/manifest.json");try{const t=(0,_index.readJson)(e).router.pages||{};return Object.keys(t)}catch(e){return console.log("ENOENT"===e.code?e.message:e),[]}},BuildModeManager.prototype._addMode=function(e,t,i){const o=e.modeOptions;let n;return n=o.list.length?Math.max.apply(null,o.list.map((e=>e.id)))+1:0,t.id=n,o.list.push(t),o.current=t.id,i||this._write(e),o},BuildModeManager.prototype.addMode=function(e){const t=this._read();return this._addMode(t,e,!1)},BuildModeManager.prototype.addModes=function(e){const t=this._read();return e.forEach((e=>{this._addMode(t,e,!0)})),this._write(t),t.modeOptions},BuildModeManager.prototype.delete=function(e){const t=this._read(),i=t.modeOptions,o=i.list.findIndex((t=>t.id===e));return i.current=-1,-1!==o&&(i.list.splice(o,1),this._write(t)),i},BuildModeManager.prototype.update=function(e){const t=this._read(),i=t.modeOptions,o=i.list.findIndex((t=>t.id===e.id));return-1!==o&&(i.list[o]=e),this._write(t),i},BuildModeManager.prototype.select=function(e){const t=this._read(),i=t.modeOptions;return-1!==i.list.findIndex((t=>t.id===e))&&(i.current=e,this._write(t),_eventBus.default.emit(PACKAGER_BUILD_DONE)),i},BuildModeManager.prototype.setToNormal=function(){const e=this._read(),t=e.modeOptions;return t.current=-1,this._write(e),_eventBus.default.emit(PACKAGER_BUILD_DONE),t},BuildModeManager.prototype.setRoot=function(e){if("string"==typeof e){this.root=e,this._configFile=_path.default.resolve(e,_util.CONFIG_FILE);return this._read().modeOptions}return null},module.exports=BuildModeManager;
2
- //# sourceMappingURL=BuildModeManager.js.map
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.readJson=readJson,exports.initProjectConfig=initProjectConfig,exports.getLaunchPage=getLaunchPage,exports.CONFIG_FILE=void 0;var _fs=_interopRequireDefault(require("fs")),_path=_interopRequireDefault(require("path")),_config=_interopRequireDefault(require("../../config"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const CONFIG_FILE=".quickapp.preview.json";function readJson(e){try{return JSON.parse(_fs.default.readFileSync(e).toString())}catch(t){throw t instanceof SyntaxError?new SyntaxError(`Failed to parse ${e}, format error`):t.message.startsWith("ENOENT:")?(t.message=`Failed to read ${e}, the file cannot be found`,t):(console.error("Failed to read %s",e),t)}}function initProjectConfig(e){const t=_path.default.join(e,CONFIG_FILE);_fs.default.existsSync(t)||_fs.default.writeFileSync(t,JSON.stringify({},null,2))}function getLaunchPage(){let e="";const t=_path.default.join(_config.default.projectPath,CONFIG_FILE);if(_fs.default.existsSync(t))try{const{modeOptions:r}=readJson(t);if(r&&"number"==typeof r.current&&r.list){const t=r.list.find((e=>e.id===r.current));t&&(e=`${t.pathName}?${t.query}`)}}catch(e){console.log("ENOENT"===e.code?e.message:e)}return e}exports.CONFIG_FILE=CONFIG_FILE;
2
- //# sourceMappingURL=util.js.map
@@ -1,2 +0,0 @@
1
- "use strict";const vdom_pb=require("./vdom_pb");class AIOT{constructor(e){this.funcArr=[],this.chld=[],this.idCount=-1,this.expCell=new vdom_pb.ExportCell,this.aiotf=e,this.optArr=[]}init(e){this.expCell.setTagname(e)}parseObj(e){let t=new vdom_pb.StyleValueArr;for(let r in e){let s=new vdom_pb.StyleKey,i=new vdom_pb.OneStyleValue;s.setValue(r),i.setKey(s);let l=Object.prototype.toString.call(e[r]);if("[object Number]"===l)i.setDoublevl(e[r]);else if("[object String]"===l)i.setStringvl(e[r]);else if("[object Function]"===l)null==this.aiotf?(this.funcArr.push(e[r]),i.setFuncid(this.funcArr.length-1)):(this.aiotf.funcArr.push(e[r]),i.setFuncid(this.aiotf.funcArr.length-1));else if("[object Object]"===l){let t=new vdom_pb.StyleValueArr;t=this.parseObj(e[r]),i.setStylevlarr(t)}else if("[object Array]"===l){let t=new vdom_pb.StringArr;t.setStringvlarrList(e[r]),i.setStringarr(t)}else"[object Boolean]"===l&&i.setBoolvl(e[r]);t.addVlarr(i)}return t}__cdc__(e,t,r){return this.__ce__(e,t,r,"__cdc__")}__ce__(e,t,r,s="__ce__"){let i=new vdom_pb.TemplateOne,l=new vdom_pb.TemplateUnit;if(l.setType(s),l.setTag(e),Array.isArray(r)&&r.length>0){let e=[];for(let t in r)e.push(r[t].id_);i.setChldsidList(e)}i.setId(++this.idCount);let n=this.parseObj(t.__opts__);return l.setOptsarrList(n.getVlarrList()),i.setCv(l),this.expCell.addTemplatearr(i),{id_:this.idCount,aiot_:this}}__ci__(e,t){let r=new vdom_pb.TemplateOne,s=new vdom_pb.TemplateUnit;s.setType("__ci__"),r.setId(++this.idCount);let i=this.parseObj(e.__opts__);s.setOptsarrList(i.getVlarrList());let l=new AIOT(this);l.funcArr=this.funcArr,l.optArr=this.optArr;let n=t(l),_=Object.prototype.toString.call(n);if("[object Object]"===_)s.setTemplaterenderList(n.aiot_.expCell.getTemplatearrList());else if("[object Array]"===_)for(let e in n){s.setTemplaterenderList(n[e].aiot_.expCell.getTemplatearrList());break}return this.funcArr=l.aiotf.funcArr,r.setCv(s),this.expCell.addTemplatearr(r),{id_:this.idCount,aiot_:this}}__cf__(e,t){let r=new vdom_pb.TemplateOne,s=new vdom_pb.TemplateUnit;s.setType("__cf__"),r.setId(++this.idCount);let i=this.parseObj(e.__opts__);s.setOptsarrList(i.getVlarrList());let l=new AIOT;l.optArr=this.optArr;let n=t(undefined,undefined,l),_=Object.prototype.toString.call(n);if("[object Object]"===_)s.setTemplaterenderList(n.aiot_.expCell.getTemplatearrList());else if("[object Array]"===_)for(let e in n){s.setTemplaterenderList(n[e].aiot_.expCell.getTemplatearrList());break}if(l.funcArr.length>0){const t=function(e,t){return l.aiotf.funcArr};t.aiotfor=l,t.aiotfor.key=e.__opts__.key,t.aiotfor.value=e.__opts__.value,this.funcArr.push(t),s.setFuncrender(this.funcArr.length-1)}else s.setFuncrender(-1);return r.setCv(s),this.expCell.addTemplatearr(r),{id_:this.idCount,aiot_:this}}__cc__(e,t){let r=new vdom_pb.TemplateOne,s=new vdom_pb.TemplateUnit;s.setType("__cc__"),s.setTag(e),r.setId(++this.idCount);let i=this.parseObj(t.__opts__);return s.setOptsarrList(i.getVlarrList()),r.setCv(s),this.expCell.addTemplatearr(r),{id_:this.idCount,aiot_:this}}__cb__(e,t){let r=new vdom_pb.TemplateOne,s=new vdom_pb.TemplateUnit;s.setType("__cb__"),r.setId(++this.idCount);let i=this.parseObj(e.__opts__);s.setOptsarrList(i.getVlarrList());let l=new AIOT;l.optArr=this.optArr;let n=t(undefined,l),_=Object.prototype.toString.call(n);if("[object Object]"===_)s.setTemplaterenderList(n.aiot_.expCell.getTemplatearrList());else if("[object Array]"===_)for(let e in n){s.setTemplaterenderList(n[e].aiot_.expCell.getTemplatearrList());break}if(l.funcArr.length>0){const e=function(e){return l.aiotf.funcArr};e.aiotcb=l,this.funcArr.push(e),s.setFuncrender(this.funcArr.length-1)}else s.setFuncrender(-1);return r.setCv(s),this.expCell.addTemplatearr(r),{id_:this.idCount,aiot_:this}}}module.exports=AIOT;
2
- //# sourceMappingURL=protobuf.js.map
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.extractFunctions=extractFunctions,exports.createBin=createBin;var _lib=require("../../lib");const vdom_pb=require("./vdom_pb"),Path=require("path"),fs=require("fs"),AIOT=require("./protobuf");function translateStyle(e,t){const r=t.expCell;return e.forEach((e=>{const a=3===e.length;let s,n=e[0],l=e[1];a&&(s=e[0],n=e[1],l=e[2]);const c=r.addCssarr();a&&s&&Object.keys(s).forEach((e=>{const t=s[e],r=c.addPropertyarr(),a=new vdom_pb.StyleKey;switch(a.setValue(e),r.setKey(a),typeof t){case"string":r.setStringvl(t);break;case"number":Number.isInteger(t)?r.setInt32vl(t):r.setDoublevl(t)}})),n.forEach((e=>{const t=c.addSelectorarr();t.setId(e[0]),t.setName(e[1])})),Object.keys(l).forEach((e=>{const r=l[e],a=c.addStylearr(),s=new vdom_pb.StyleKey;s.setValue(e),a.setKey(s);const n=typeof r;switch(n){case"string":a.setStringvl(r);break;case"number":Number.isInteger(r)?a.setInt32vl(r):a.setDoublevl(r);break;case"object":a.setStylevlarr(t.parseObj(r));break;default:_lib.colorconsole.warn(`CssValue Of ${n} NotProcessed`)}}))})),r}function translateTemplate(template,aiot){const vm={};template&&eval(`(${template})`)(vm)}function createItem(e,t,r){let a=new AIOT;return a.init(e||"entry"),translateTemplate(r,a),translateStyle(t,a),a}function extractFunctions(e){let t=new AIOT;return t.init("temp"),translateTemplate(e,t),t}function createBin(e,t,r,a){const s=r.map(((e,r)=>createItem(t[r],JSON.parse(e),a[r])));let n=new vdom_pb.ExportArr;n.clearValuearrList(),s.forEach((e=>{n.addValuearr(e.expCell)}));const l=Path.dirname(e);fs.existsSync(l)||fs.mkdirSync(l,{recursive:!0});let c=n.serializeBinary();fs.writeFileSync(e,c)}
2
- //# sourceMappingURL=protobufControl.js.map