node-karin 0.12.15 → 0.12.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +1 -2
- package/lib/index.js +1 -2
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +1 -0
- package/lib/utils/tools/yaml.d.ts +15 -0
- package/lib/utils/tools/yaml.js +43 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import yaml from 'yaml';
|
|
2
1
|
import axios from 'axios';
|
|
3
2
|
import moment from 'moment';
|
|
4
3
|
import lodash from 'lodash';
|
|
@@ -11,4 +10,4 @@ export * from './utils/index.js';
|
|
|
11
10
|
export * from './types/index.js';
|
|
12
11
|
export * from './adapter/index.js';
|
|
13
12
|
export { karin as default } from './core/index.js';
|
|
14
|
-
export { axios, moment, lodash, express
|
|
13
|
+
export { axios, moment, lodash, express };
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import yaml from 'yaml';
|
|
2
1
|
import axios from 'axios';
|
|
3
2
|
import moment from 'moment';
|
|
4
3
|
import lodash from 'lodash';
|
|
@@ -11,4 +10,4 @@ export * from './utils/index.js';
|
|
|
11
10
|
export * from './types/index.js';
|
|
12
11
|
export * from './adapter/index.js';
|
|
13
12
|
export { karin as default } from './core/index.js';
|
|
14
|
-
export { axios, moment, lodash, express
|
|
13
|
+
export { axios, moment, lodash, express };
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.js
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Yaml from 'yaml';
|
|
2
|
+
export declare const yaml: typeof Yaml & {
|
|
3
|
+
/**
|
|
4
|
+
* 传入yaml文件路径 自动读取并解析
|
|
5
|
+
* @param path yaml文件路径
|
|
6
|
+
*/
|
|
7
|
+
read: (path: string) => any;
|
|
8
|
+
/**
|
|
9
|
+
* 保存并写入注释
|
|
10
|
+
* @param path 保存的路径
|
|
11
|
+
* @param value 保存的数据
|
|
12
|
+
* @param commentConfig 注释配置文件路径或json
|
|
13
|
+
*/
|
|
14
|
+
save: (path: string, value: any, commentConfig?: string) => void;
|
|
15
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import Yaml from 'yaml';
|
|
3
|
+
import logger from '../core/logger.js';
|
|
4
|
+
import { YamlEditor } from '../config/yamlEditor.js';
|
|
5
|
+
const yamlNew = {
|
|
6
|
+
/**
|
|
7
|
+
* 传入yaml文件路径 自动读取并解析
|
|
8
|
+
* @param path yaml文件路径
|
|
9
|
+
*/
|
|
10
|
+
read: (path) => {
|
|
11
|
+
const data = fs.readFileSync(path, 'utf-8');
|
|
12
|
+
return Yaml.parse(data);
|
|
13
|
+
},
|
|
14
|
+
/**
|
|
15
|
+
* 保存并写入注释
|
|
16
|
+
* @param path 保存的路径
|
|
17
|
+
* @param value 保存的数据
|
|
18
|
+
* @param commentConfig 注释配置文件路径或json
|
|
19
|
+
*/
|
|
20
|
+
save: (path, value, commentConfig) => {
|
|
21
|
+
if (!commentConfig) {
|
|
22
|
+
fs.writeFileSync(path, Yaml.stringify(value));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const editor = new YamlEditor(Yaml.stringify(value));
|
|
26
|
+
const comment = JSON.parse(fs.existsSync(commentConfig) ? fs.readFileSync(commentConfig, 'utf8') : commentConfig);
|
|
27
|
+
for (const [key, value] of Object.entries(comment)) {
|
|
28
|
+
try {
|
|
29
|
+
if (typeof value === 'object') {
|
|
30
|
+
editor.comment(key, value.text, value.type === 'start');
|
|
31
|
+
}
|
|
32
|
+
else if (typeof value === 'string') {
|
|
33
|
+
editor.comment(key, value, true);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
logger.error(`[YamlEditor] 添加注释时出错,已跳过:${error.stack || error.message || error}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
fs.writeFileSync(path, editor.document.toString());
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
export const yaml = Object.assign(Yaml, yamlNew);
|