g6/packages/site/scripts/clear-doc.ts
Aaron 45750f7790
docs: add documentation (#5695)
* refactor(site): adjust script

* feat(site): add script that can sort docs in specific folder

* docs: remove apis folder

* docs: add getting-started for chinese version

* docs: add core-concept for chinese version

* docs: add upgrade for chinese version

* docs: remove quick-start

* refactor(site): add createGraph global utils

* docs: add extension in core concept
2024-05-06 10:52:18 +08:00

42 lines
975 B
TypeScript

import fs from 'fs';
import path from 'path';
/**
* <zh/> 清理自动生成的文档
*
* <en/> Clear the auto-generated documents
*/
function clear() {
const baseDir = path.resolve(__dirname, '../docs/api');
// read gitignore
const gitignore = fs.readFileSync(path.resolve(baseDir, '.gitignore'), 'utf-8');
// clear all files list in .gitignore
const lines = gitignore.split('\n');
lines.forEach((line) => {
if (line.startsWith('#')) return;
const file = line.trim();
if (file) {
const filepath = path.resolve(baseDir, file);
if (fs.existsSync(filepath)) {
if (fs.lstatSync(filepath).isDirectory()) {
console.log('Clearing folder: ', filepath);
fs.rmdirSync(filepath, { recursive: true });
} else {
console.log('Clearing file: ', filepath);
fs.unlinkSync(filepath);
}
}
}
});
// remove .gitignore
fs.unlinkSync('docs/api/.gitignore');
}
clear();