g6/packages/site/scripts/doc-template.js
Aaron ea9cc6b4c0
docs: adjust docs structure, create docs template (#5670)
* docs: remove old docs

* docs: adjust example dir name

* feat: add script to create doc template

* docs: create site docs template

* docs: adjust api/element structure

* docs: adjust graph docs

* docs: adjust category naming
2024-04-23 15:56:29 +08:00

34 lines
1.1 KiB
JavaScript

/**
* @description 在当前目录下创建中英文文档模板
* @param {string} path - 文件路径,指定为 $PWD
* @param {string} title - 文件标题
* @param {string} order - 文件排序[可选]
* @example npm run add-doc $PWD overview
*/
import chalk from 'chalk';
import { existsSync, writeFileSync } from 'fs';
const [path, title, order] = process.argv.slice(2);
if (!path || !title) {
console.log(chalk.bold(chalk.green('Example:')), chalk.greenBright('npm run add-doc $PWD overview'));
} else {
const zhPath = `${path}/${title}.zh.md`;
const enPath = `${path}/${title}.en.md`;
const content =
'---\n' +
Object.entries({ title, order })
.filter(([, v]) => !!v)
.map(([k, v]) => `${k}: ${v}`)
.join('\n') +
'\n---';
if (!existsSync(zhPath) && !existsSync(enPath)) {
writeFileSync(zhPath, content);
writeFileSync(enPath, content);
} else console.log(chalk.bold(chalk.red('Error:')), chalk.redBright('File already exists!'));
console.log(chalk.bold(chalk.green('Success:')), chalk.greenBright('Create doc file successfully!'));
}