Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit

Permalink
feat(cli): use cac for cli (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
2nthony authored and clarkdo committed Jun 27, 2019
1 parent 1760f6a commit b80fa2d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
32 changes: 22 additions & 10 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
#!/usr/bin/env node
const path = require('path')
const sao = require('sao')
const cac = require('cac')
const chalk = require('chalk')
const { version } = require('./package.json')

const generator = path.resolve(__dirname, './')
// In a custom directory or current directory
const outDir = path.resolve(process.argv[2] || '.')

console.log(chalk`{cyan create-nuxt-app v${version}}`)
console.log(chalk`✨ Generating Nuxt.js project in {cyan ${outDir}}`)
const cli = cac('create-nuxt-app')

// See https://sao.js.org/#/advanced/standalone-cli
sao({ generator, outDir, logLevel: 2 })
.run()
.catch((err) => {
console.trace(err)
process.exit(1)
cli
.command('[out-dir]', 'Generate in a custom directory or current directory')
.option('--edge', 'To install `nuxt-edge` instead of `nuxt`')
.action((outDir = '.') => {
console.log(chalk`{cyan create-nuxt-app v${version}}`)
console.log(chalk`✨ Generating Nuxt.js project in {cyan ${outDir}}`)

// See https://saojs.org/api.html#standalone-cli
sao({ generator, outDir, logLevel: 2 })
.run()
.catch((err) => {
console.trace(err)
process.exit(1)
})
})

cli.help()

cli.version(version)

cli.parse()
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"release": "standard-version"
},
"dependencies": {
"cac": "^6.5.2",
"chalk": "^2.4.2",
"cross-spawn": "^6.0.5",
"glob": "^7.1.3",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,11 @@ cac@^6.3.8:
resolved "https://registry.yarnpkg.com/cac/-/cac-6.4.2.tgz#6b2a2ab12619b778b3acc19f97e5298761d9c3de"
integrity sha512-HM7kl/Izk6pb2HD7z66LVNU52j0xWpBXg8J2MLnOdRMUo2wsrcxu3yRnubnDe/cT0btDzSOl3FPhze09uaT1Vw==

cac@^6.5.2:
version "6.5.2"
resolved "https://registry.npmjs.org/cac/-/cac-6.5.2.tgz#92ef1490b9ffde5f0be7eeadec5ea926f0e78ef6"
integrity sha512-8JdiD9/ZLsG418j/chyZQ3VWuhFELSGlH4EUxzNKgIH8wK8dO0j5Pqu6Pk7B/RP3kX9aasyQhPrrUjYO5e0w7w==

cache-base@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/cache-base/-/cache-base-1.0.1.tgz#0a7f46416831c8b662ee36fe4e7c59d76f666ab2"
Expand Down

0 comments on commit b80fa2d

Please sign in to comment.