Skip to content

Commit e33a13d

Browse files
committed
feat: elog flow
1 parent 1689d30 commit e33a13d

File tree

5 files changed

+102
-19
lines changed

5 files changed

+102
-19
lines changed

packages/elog/src/Graph.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export default class Graph {
1414
private readonly cachedDocList: DocDetail[] = [];
1515
constructor(options: ElogConfig) {
1616
this.elogConfig = options;
17-
this.elogConfig.cacheFilePath = this.elogConfig.cacheFilePath || 'elog.cache.json';
1817
this.cachedDocList = this.initCache(options);
1918
this.pluginDriver = new PluginDriver(options, this.cachedDocList);
2019
}
@@ -47,14 +46,6 @@ export default class Graph {
4746
writeCache<T>(sortedDocList: SortedDoc<T>[] = []) {
4847
try {
4948
const { cacheFilePath } = this.elogConfig;
50-
// // 判断cachedDocList列表中对象是否有 body 属性
51-
// const hasBody = this.cachedDocList?.some((doc) => !!doc.body);
52-
// if (hasBody) {
53-
// out.debug(
54-
// '警告',
55-
// '缓存信息存在 body(文档内容)信息,可能会导致缓存文件过大,如无必要用途建议删除 body 属性',
56-
// );
57-
// }
5849
// 写入缓存
5950
const cacheJson = {
6051
cachedDocList: this.cachedDocList.map((item) => ({ ...item, body: undefined })),
@@ -63,6 +54,7 @@ export default class Graph {
6354
fs.writeFileSync(cacheFilePath!, JSON.stringify(cacheJson, null, 2), {
6455
encoding: 'utf8',
6556
});
57+
out.success('任务结束', `同步成功,已生成缓存文件:${cacheFilePath}`);
6658
} catch (e) {
6759
out.warn('缓存失败', `写入缓存信息失败,请检查,${e.message}`);
6860
}
@@ -74,9 +66,7 @@ export default class Graph {
7466
* @param docStatusMap
7567
*/
7668
updateCache(docList: DocDetail[], docStatusMap: any) {
77-
console.log('docStatusMap', docStatusMap);
7869
for (const doc of docList) {
79-
console.log('doc.id', doc.id);
8070
const { _updateIndex, _status } = docStatusMap[doc.id];
8171
if (_status === DocStatus.NEW) {
8272
// 新增文档

packages/elog/src/utils/load.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import path from 'path';
22
import JoyCon from 'joycon';
33
import { bundleRequire } from 'bundle-require';
44
import { defineConfig } from './elog';
5+
import { ElogConfig } from '../types/common';
56

67
export async function loadConfigFromFile(
78
cwd: string,
@@ -21,9 +22,33 @@ export async function loadConfigFromFile(
2122
const config = await bundleRequire({
2223
filepath: configPath,
2324
});
25+
26+
let data: ElogConfig | ElogConfig[] = config.mod.default || config.mod;
27+
if (Array.isArray(data)) {
28+
if (data.length > 1) {
29+
data = data.map((item, index) => {
30+
return {
31+
...item,
32+
cacheFilePath: item.cacheFilePath || `elog.cache${index + 1}.json`,
33+
};
34+
});
35+
} else {
36+
data = data.map((item) => {
37+
return {
38+
...item,
39+
cacheFilePath: item.cacheFilePath || 'elog.cache.json',
40+
};
41+
});
42+
}
43+
} else {
44+
data = {
45+
...data,
46+
cacheFilePath: data.cacheFilePath || 'elog.cache.json',
47+
};
48+
}
2449
return {
2550
path: configPath,
26-
data: config.mod.default || config.mod,
51+
data,
2752
};
2853
}
2954

tests/test-elog/elog.config-muti.ts

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default defineConfig([
99
from: fromYuqueToken({
1010
token: process.env.YUQUE_TOKEN,
1111
login: process.env.YUQUE_LOGIN,
12-
repo: process.env.YUQUE_REPO,
12+
repo: process.env.YUQUE_REPO1,
1313
onlyPublic: false,
1414
}),
1515
to: [
@@ -28,27 +28,95 @@ export default defineConfig([
2828
}),
2929
],
3030
},
31+
{
32+
from: fromYuqueToken({
33+
token: process.env.YUQUE_TOKEN,
34+
login: process.env.YUQUE_LOGIN,
35+
repo: process.env.YUQUE_REPO1,
36+
onlyPublic: false,
37+
}),
38+
to: [
39+
toLocal({
40+
outputDir: './docs2',
41+
deployByStructure: true,
42+
filename: 'title',
43+
frontMatter: { enable: true },
44+
}),
45+
],
46+
plugins: [
47+
imageLocal({
48+
outputDir: './images2',
49+
// prefixKey: '../../images',
50+
pathFollowDoc: { enable: true, docOutputDir: './docs1' },
51+
}),
52+
],
53+
},
54+
{
55+
from: fromYuqueToken({
56+
token: process.env.YUQUE_TOKEN,
57+
login: process.env.YUQUE_LOGIN,
58+
repo: process.env.YUQUE_REPO1,
59+
onlyPublic: false,
60+
}),
61+
to: [
62+
toLocal({
63+
outputDir: './docs3',
64+
deployByStructure: true,
65+
filename: 'title',
66+
frontMatter: { enable: true },
67+
}),
68+
],
69+
plugins: [
70+
imageLocal({
71+
outputDir: './images3',
72+
// prefixKey: '../../images',
73+
pathFollowDoc: { enable: true, docOutputDir: './docs1' },
74+
}),
75+
],
76+
},
77+
{
78+
from: fromYuqueToken({
79+
token: process.env.YUQUE_TOKEN,
80+
login: process.env.YUQUE_LOGIN,
81+
repo: process.env.YUQUE_REPO1,
82+
onlyPublic: false,
83+
}),
84+
to: [
85+
toLocal({
86+
outputDir: './docs4',
87+
deployByStructure: true,
88+
filename: 'title',
89+
frontMatter: { enable: true },
90+
}),
91+
],
92+
plugins: [
93+
imageLocal({
94+
outputDir: './images4',
95+
// prefixKey: '../../images',
96+
pathFollowDoc: { enable: true, docOutputDir: './docs1' },
97+
}),
98+
],
99+
},
31100
{
32101
from: fromYuque({
33102
username: process.env.YUQUE_USERNAME,
34103
password: process.env.YUQUE_PWD,
35104
login: process.env.YUQUE_LOGIN,
36-
repo: process.env.YUQUE_REPO,
105+
repo: process.env.YUQUE_REPO2,
37106
onlyPublic: false,
38107
linebreak: false,
39-
cacheFilePath: 'elog.cache2.json',
40108
}),
41109
to: [
42110
toLocal({
43-
outputDir: './docs2',
111+
outputDir: './docs5',
44112
deployByStructure: true,
45113
filename: 'title',
46114
frontMatter: { enable: true },
47115
}),
48116
],
49117
plugins: [
50118
imageLocal({
51-
outputDir: './images2',
119+
outputDir: './images5',
52120
// prefixKey: '../../images',
53121
pathFollowDoc: { enable: true, docOutputDir: './docs2' },
54122
}),

tests/test-elog/elog.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default defineConfig({
77
from: fromYuque({
88
token: process.env.YUQUE_TOKEN,
99
login: process.env.YUQUE_LOGIN,
10-
repo: process.env.YUQUE_REPO,
10+
repo: process.env.YUQUE_REPO1,
1111
onlyPublic: false,
1212
}),
1313
to: [

tests/test-elog/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"elog:init-templ": "elog init --template yuque-local",
99
"elog:init": "elog init",
1010
"elog:sync": "elog sync --env .elog.env",
11-
"elog:sync-muti": "elog sync --env .elog.env --config elog.config-muti.ts --cache elog.cache-muti.json ",
11+
"elog:sync-muti": "elog sync --env .elog.env --config elog.config-muti.ts",
1212
"elog:version": "elog --version",
1313
"elog": "elog"
1414
},

0 commit comments

Comments
 (0)