Skip to content

Commit

Permalink
feat(create-site): detect yarn
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Apr 15, 2019
1 parent 3414b84 commit 7e80aa5
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/create-site/cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node
const path = require('path')
const { spawnSync } = require('child_process')
const { promisify } = require('util')
const colors = require('kleur')

Expand Down Expand Up @@ -30,15 +31,26 @@ console.log(`Creating a new site...`)

const { ncp } = require('ncp')

let hasYarn = false
try {
spawnSync('yarn', ['--version'])
hasYarn = true
} catch (error) {}

promisify(ncp)(path.join(__dirname, 'template'), dir)
.then(() => {
console.log(
colors.green(`Successfully created at ${colors.underline(dir)}`)
)
console.log(colors.bold(`To start dev server, run:`))
console.log(colors.cyan(`$ cd ${path.relative(process.cwd(), dir)}`))
console.log(colors.cyan(`$ npm install`))
console.log(colors.cyan(`$ npm run dev`))
if (hasYarn) {
console.log(colors.cyan(`$ yarn`))
console.log(colors.cyan(`$ yarn dev`))
} else {
console.log(colors.cyan(`$ npm install`))
console.log(colors.cyan(`$ npm run dev`))
}
console.log(colors.dim(`For more details, please check out the README.md`))
})
.catch(console.error)

0 comments on commit 7e80aa5

Please sign in to comment.