Skip to content

Commit

Permalink
feat: improve create app
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Apr 25, 2021
1 parent 5aef371 commit 83b3ef9
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 24 deletions.
1 change: 0 additions & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"private": true,
"version": "0.0.0-beta.1",
"scripts": {
"dev": "nodemon -w '../packages/slidev/dist/*.js' --exec 'slidev --open=false'",
"starter": "nodemon -w '../packages/slidev/dist/*.js' --exec 'slidev starter.md --open=false'",
Expand Down
32 changes: 26 additions & 6 deletions packages/create-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ const fs = require('fs')
const path = require('path')
const argv = require('minimist')(process.argv.slice(2))
const { prompt } = require('enquirer')
const execa = require('execa')

const cwd = process.cwd()

const renameFiles = {
_gitignore: '.gitignore',
_npmrc: '.npmrc',
}

async function init() {
Expand Down Expand Up @@ -83,13 +85,31 @@ async function init() {
? 'pnpm'
: /yarn/.test(process.env.npm_execpath) ? 'yarn' : 'npm'

console.log('\nDone. Now run:\n')
if (root !== cwd)
console.log(` cd ${path.relative(cwd, root)}`)
const related = path.relative(cwd, root)

/**
* @type {{ yes: boolean }}
*/
const { yes } = await prompt({
type: 'confirm',
name: 'yes',
initial: 'Y',
message: 'Done. Do you want to install the dependency and start the server now?',
})

if (yes) {
await execa(pkgManager, ['-C', related, 'install'], { stdio: 'inherit' })
await execa(pkgManager, ['-C', related, 'run', 'dev'], { stdio: 'inherit' })
}
else {
console.log('\nNow run:\n')
if (root !== cwd)
console.log(` cd ${related}`)

console.log(` ${pkgManager === 'yarn' ? 'yarn' : `${pkgManager} install`}`)
console.log(` ${pkgManager === 'yarn' ? 'yarn dev' : `${pkgManager} run dev`}`)
console.log()
console.log(` ${pkgManager === 'yarn' ? 'yarn' : `${pkgManager} install`}`)
console.log(` ${pkgManager === 'yarn' ? 'yarn dev' : `${pkgManager} run dev`}`)
console.log()
}
}

function copy(src, dest) {
Expand Down
2 changes: 2 additions & 0 deletions packages/create-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"bugs": "https://github.com/slidevjs/slidev/issues",
"dependencies": {
"enquirer": "^2.3.6",
"execa": "^5.0.0",
"kolorist": "^1.4.1",
"minimist": "^1.2.5"
}
}
2 changes: 2 additions & 0 deletions packages/create-app/template/_npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# for pnpm
shamefully-hoist=true
1 change: 1 addition & 0 deletions packages/slidev/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ cli.command(
const { create } = await prompt<{create: boolean}>({
name: 'create',
type: 'confirm',
initial: 'Y',
message: `Entry file ${entry} does not exist, do you want to create it?`,
})
if (create)
Expand Down
2 changes: 1 addition & 1 deletion packages/slidev/node/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export function parse(
const config: SlidevConfig = Object.assign({}, headmatter.config || {})

config.theme ||= headmatter.theme || '@slidev/theme-default'
config.title ||= headmatter.title || (markdown.match(/^# (.*)$/m)?.[1] || '').trim()
config.title ||= headmatter.title || (slides[0].content.match(/^# (.*)$/m)?.[1] || '').trim()
config.remoteAssets ??= headmatter.remoteAssets ?? true

return {
Expand Down
20 changes: 4 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 83b3ef9

Please sign in to comment.