Skip to content

Commit

Permalink
fix: create app template error (#724)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzhang1030 committed Oct 11, 2022
1 parent 1449f6c commit 6410a01
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ slides-export.md
assets/demo
packages/slidev/README.md
packages/create-app/template/slides.md
packages/create-app/template/pages
composable-vue-cn
components.d.ts
.slidev
33 changes: 33 additions & 0 deletions packages/create-app/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { copyFileSync, existsSync, mkdirSync, rmSync } from 'node:fs'
import * as url from 'node:url'
import { resolve } from 'node:path'

const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
const __templateDir = resolve(__dirname, 'template')
const __pagesDir = resolve(__templateDir, 'pages')

const shouldCreatePagesDict = () => !existsSync(__pagesDir)

// key: copy to (relative ./)
// value: origin (relative ./template)
const needCopyFiles = {
'slides.md': '../../../demo/starter/slides.md',
'pages/multiple-entries.md': '../../../demo/starter/pages/multiple-entries.md',
}

function main() {
if (shouldCreatePagesDict())
mkdirSync(__pagesDir)
Object.keys(needCopyFiles).forEach((relativeTargetPath) => {
const sourcePath = resolve(__templateDir, needCopyFiles[relativeTargetPath])
const targetPath = resolve(__templateDir, relativeTargetPath)
const exist = existsSync(targetPath)
if (exist)
rmSync(targetPath)
copyFileSync(sourcePath, targetPath)
})
// eslint-disable-next-line no-console
console.log('done...')
}

main()
2 changes: 1 addition & 1 deletion packages/create-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"node": ">=14.0.0"
},
"scripts": {
"build": "cp ../../demo/starter/slides.md template/slides.md",
"build": "node build.mjs",
"prepublishOnly": "npm run build"
},
"dependencies": {
Expand Down

0 comments on commit 6410a01

Please sign in to comment.