Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: create app template error #724

Merged
merged 3 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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