perf(cli): update templates

This commit is contained in:
pengzhanbo 2024-09-07 13:20:14 +08:00
parent ee33ed946a
commit eaa0b466ac
3 changed files with 21 additions and 14 deletions

View File

@ -49,18 +49,25 @@ export async function generate(mode: Mode, data: ResolvedData): Promise<void> {
}
// rewrite git files begin ==================================
if (data.git)
fileList.push(...await readFiles(getTemplate('git')))
if (mode === Mode.init) {
const gitignorePath = path.join(cwd, '.gitignore')
const docs = data.docsDir
if (fs.existsSync(gitignorePath)) {
const content = await fs.promises.readFile(gitignorePath, 'utf-8')
fileList.push({
filepath: '.gitignore',
content: `${content}\n${docs}/.vuepress/.cache\n${docs}/.vuepress/.temp\n${docs}/.vuepress/dist\n`,
})
if (data.git) {
const gitFiles = await readFiles(getTemplate('git'))
if (mode === Mode.init) {
const gitignorePath = path.join(cwd, '.gitignore')
const docs = data.docsDir
if (fs.existsSync(gitignorePath)) {
const content = await fs.promises.readFile(gitignorePath, 'utf-8')
fileList.push({
filepath: '.gitignore',
content: `${content}\n${docs}/.vuepress/.cache\n${docs}/.vuepress/.temp\n${docs}/.vuepress/dist\n`,
})
fileList.push(...gitFiles.filter(({ filepath }) => filepath !== '.gitignore'))
}
else {
fileList.push(...gitFiles)
}
}
else {
fileList.push(...gitFiles)
}
}
// rewrite git files end ====================================

View File

@ -67,4 +67,4 @@ jobs:
build_dir: {{docsDir}}/.vuepress/dist
env:
# @see https://docs.github.com/cn/actions/reference/authentication-in-a-workflow#about-the-github_token-secret
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: $\{{ secrets.GITHUB_TOKEN }}

View File

@ -1,4 +1,4 @@
node_modules
**/node_modules
{{ docsDir }}/.vuepress/.cache
{{ docsDir }}/.vuepress/.temp