Skip to content

Commit

Permalink
fix: fix theme templates copy
Browse files Browse the repository at this point in the history
  • Loading branch information
this-is-tobi committed Nov 24, 2024
1 parent 3e68b2a commit 4e740d0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
packages: write
with:
REGISTRY_NAMESPACE: ${{ needs.expose-vars.outputs.REGISTRY_NAMESPACE }}
PR_NUMBER: ${{ github.event.pull_request.number || github.event.number || null }}
PR_NUMBER: ${{ github.event.pull_request.number || github.event.number || '' }}
MULTI_ARCH: ${{ needs.expose-vars.outputs.MULTI_ARCH == 'true' }}
USE_QEMU: ${{ needs.expose-vars.outputs.USE_QEMU == 'true' }}

Expand Down
14 changes: 6 additions & 8 deletions src/lib/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { basename, dirname, parse, resolve } from 'node:path'
import { appendFileSync, cpSync, readdirSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs'
import YAML from 'yaml'
import type { defineConfig } from 'vitepress'
import { generateFile } from '../templates/index.js'
import { generateFile, themeTemplates } from '../templates/index.js'
import type { GlobalOpts } from '../schemas/global.js'
import type { getUserInfos } from '../utils/functions.js'
import { createDir, extractFiles, getMdFiles, prettify } from '../utils/functions.js'
import { DOCS_DIR, FORKS_FILE, INDEX_FILE, TEMPLATE_THEME, VITEPRESS_CONFIG, VITEPRESS_THEME } from '../utils/const.js'
import { DOCS_DIR, FORKS_FILE, INDEX_FILE, VITEPRESS_CONFIG } from '../utils/const.js'
import { replaceReadmePath, replaceRelativePath } from '../utils/regex.js'
import { log } from '../utils/logger.js'
import type { EnhancedRepository } from './fetch.js'
Expand Down Expand Up @@ -241,10 +241,8 @@ export function generateVitepressFiles(vitepressConfig: Partial<ReturnType<typeo
log(` Generate index file.`, 'info')
writeFileSync(INDEX_FILE, separator.concat(YAML.stringify(index), separator))
log(` Add Docpress theme files.`, 'info')
const templates = extractFiles(TEMPLATE_THEME)
for (const filePath of templates) {
const relativePath = filePath.replace(`${TEMPLATE_THEME}/`, '')
log(` Processing file '${resolve(VITEPRESS_THEME, relativePath)}'.`, 'debug')
generateFile(resolve(TEMPLATE_THEME, filePath), resolve(VITEPRESS_THEME, relativePath))
}
themeTemplates.forEach(({ path, content }) => {
log(` Processing file '${path}'.`, 'debug')
generateFile(path, content)
})
}
27 changes: 21 additions & 6 deletions src/templates/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
import { readFileSync, writeFileSync } from 'node:fs'
import { dirname } from 'node:path'
import { createDir } from '../utils/functions.js'
import { dirname, resolve } from 'node:path'
import { TEMPLATE_THEME, VITEPRESS_THEME } from '../utils/const.js'
import { createDir, extractFiles } from '../utils/functions.js'

export function generateFile(src: string, dest: string) {
const content = readFileSync(src, { encoding: 'utf8' })
createDir(dirname(dest))
writeFileSync(dest, content)
export function generateFile(path: string, content: string) {
createDir(dirname(path))
writeFileSync(path, content)
}

function getTemplates() {
console.log(extractFiles(TEMPLATE_THEME))
return extractFiles(TEMPLATE_THEME).map((path) => {
const relativePath = path.replace(`${TEMPLATE_THEME}/`, '')
return {
path: resolve(VITEPRESS_THEME, relativePath),
content: readFileSync(path, { encoding: 'utf8' }),
}
})
}

export const themeTemplates = getTemplates()

console.log({ themeTemplates })

0 comments on commit 4e740d0

Please sign in to comment.