-
Notifications
You must be signed in to change notification settings - Fork 2
/
doc-sync.js
44 lines (31 loc) · 1.41 KB
/
doc-sync.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* @Author : HCLonely
* @Date : 2022-01-16 15:10:54
* @LastEditTime : 2022-01-16 15:53:44
* @LastEditors : HCLonely
* @FilePath : /auto-task-new/doc-sync.js
* @Description : 文档同步
*/
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs-extra');
const chalk = require('chalk');
const currentContext = fs.readFileSync('./doc/docs/logs/README.md').toString();
const { version, change } = fs.readJSONSync('./package.json');
const bigVersion = version.replace(/\.[\d]+(-[\w]+)?$/, '');
if (currentContext.includes(`## V${version}`)) {
return console.log(chalk.yellow('No new version!'));
}
if (currentContext.includes(`## V${bigVersion}`)) {
fs.writeFileSync('./doc/docs/logs/README.md', currentContext.replace(`## V${bigVersion}`, `## V${bigVersion}
### V${version}
[Release](https://github.com/HCLonely/auto-task-v4/releases/tag/v${version})
- ${change.join('\n- ').replace(/\(#([\d]+?)\)/g, '([#$1](https://github.com/HCLonely/auto-task-v4/issues/$1))')}`));
} else {
fs.writeFileSync('./doc/docs/logs/README.md', currentContext.replace(/---[\s]+?##/, `---
## V${bigVersion}
### V${version}
[Release](https://github.com/HCLonely/auto-task-v4/releases/tag/v${version})
- ${change.join('\n- ').replace(/\(#([\d]+?)\)/g, '([#$1](https://github.com/HCLonely/auto-task-v4/issues/$1))')}
##`));
}
console.log(`Document updated ${chalk.green.bold('successfully')}!`);