From 763c770c2d0c8b1147c8be48a86b19638092f92e Mon Sep 17 00:00:00 2001 From: alexzhang1030 <1642114555@qq.com> Date: Mon, 10 Oct 2022 18:40:43 +0800 Subject: [PATCH 1/3] fix: fix create app template error --- .gitignore | 1 + packages/create-app/build.mjs | 31 +++++++++++++++++++++++++++++++ packages/create-app/package.json | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 packages/create-app/build.mjs diff --git a/.gitignore b/.gitignore index 6eed2f02e4..342f9b0299 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/packages/create-app/build.mjs b/packages/create-app/build.mjs new file mode 100644 index 0000000000..a3a5606a11 --- /dev/null +++ b/packages/create-app/build.mjs @@ -0,0 +1,31 @@ +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) + +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() diff --git a/packages/create-app/package.json b/packages/create-app/package.json index 2eb222d1e5..dd5454d73d 100644 --- a/packages/create-app/package.json +++ b/packages/create-app/package.json @@ -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": { From b4aa8bd08401f992ec95dfa5fd91928c8b48ed13 Mon Sep 17 00:00:00 2001 From: alexzhang1030 <1642114555@qq.com> Date: Mon, 10 Oct 2022 18:43:17 +0800 Subject: [PATCH 2/3] fix: fix typo --- packages/create-app/build.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/create-app/build.mjs b/packages/create-app/build.mjs index a3a5606a11..0266a5ee1a 100644 --- a/packages/create-app/build.mjs +++ b/packages/create-app/build.mjs @@ -6,7 +6,7 @@ const __dirname = url.fileURLToPath(new URL('.', import.meta.url)) const __templateDir = resolve(__dirname, 'template') const __pagesDir = resolve(__templateDir, 'pages') -const shouldCreatePagesDict = () => existsSync(__pagesDir) +const shouldCreatePagesDict = () => !existsSync(__pagesDir) const needCopyFiles = { 'slides.md': '../../../demo/starter/slides.md', @@ -14,7 +14,7 @@ const needCopyFiles = { } function main() { - if (!shouldCreatePagesDict()) + if (shouldCreatePagesDict()) mkdirSync(__pagesDir) Object.keys(needCopyFiles).forEach((relativeTargetPath) => { const sourcePath = resolve(__templateDir, needCopyFiles[relativeTargetPath]) From 17d6dc8cbad140f61894ed4baf1e86396b7a8965 Mon Sep 17 00:00:00 2001 From: alexzhang1030 <1642114555@qq.com> Date: Mon, 10 Oct 2022 19:58:10 +0800 Subject: [PATCH 3/3] chore: add comments --- packages/create-app/build.mjs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/create-app/build.mjs b/packages/create-app/build.mjs index 0266a5ee1a..a9e7402432 100644 --- a/packages/create-app/build.mjs +++ b/packages/create-app/build.mjs @@ -8,6 +8,8 @@ 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',