11#!/usr/bin/env node
22
3- var download = require ( 'download-git-repo' )
4- var program = require ( 'commander' )
5- var exists = require ( 'fs' ) . existsSync
6- var path = require ( 'path' )
7- var ora = require ( 'ora' )
8- var home = require ( 'user-home' )
9- var tildify = require ( 'tildify' )
10- var chalk = require ( 'chalk' )
11- var inquirer = require ( 'inquirer' )
12- var rm = require ( 'rimraf' ) . sync
13- var logger = require ( '../lib/logger' )
14- var generate = require ( '../lib/generate' )
15- var checkVersion = require ( '../lib/check-version' )
16- var warnings = require ( '../lib/warnings' )
17- var localPath = require ( '../lib/local-path' )
18-
19- var isLocalPath = localPath . isLocalPath
20- var getTemplatePath = localPath . getTemplatePath
3+ const download = require ( 'download-git-repo' )
4+ const program = require ( 'commander' )
5+ const exists = require ( 'fs' ) . existsSync
6+ const path = require ( 'path' )
7+ const ora = require ( 'ora' )
8+ const home = require ( 'user-home' )
9+ const tildify = require ( 'tildify' )
10+ const chalk = require ( 'chalk' )
11+ const inquirer = require ( 'inquirer' )
12+ const rm = require ( 'rimraf' ) . sync
13+ const logger = require ( '../lib/logger' )
14+ const generate = require ( '../lib/generate' )
15+ const checkVersion = require ( '../lib/check-version' )
16+ const warnings = require ( '../lib/warnings' )
17+ const localPath = require ( '../lib/local-path' )
18+
19+ const isLocalPath = localPath . isLocalPath
20+ const getTemplatePath = localPath . getTemplatePath
2121
2222/**
2323 * Usage.
@@ -32,7 +32,7 @@ program
3232 * Help.
3333 */
3434
35- program . on ( '--help' , function ( ) {
35+ program . on ( '--help' , ( ) => {
3636 console . log ( ' Examples:' )
3737 console . log ( )
3838 console . log ( chalk . gray ( ' # create a new project with an official template' ) )
@@ -57,15 +57,15 @@ help()
5757 * Settings.
5858 */
5959
60- var template = program . args [ 0 ]
61- var hasSlash = template . indexOf ( '/' ) > - 1
62- var rawName = program . args [ 1 ]
63- var inPlace = ! rawName || rawName === '.'
64- var name = inPlace ? path . relative ( '../' , process . cwd ( ) ) : rawName
65- var to = path . resolve ( rawName || '.' )
66- var clone = program . clone || false
60+ let template = program . args [ 0 ]
61+ const hasSlash = template . indexOf ( '/' ) > - 1
62+ const rawName = program . args [ 1 ]
63+ const inPlace = ! rawName || rawName === '.'
64+ const name = inPlace ? path . relative ( '../' , process . cwd ( ) ) : rawName
65+ const to = path . resolve ( rawName || '.' )
66+ const clone = program . clone || false
6767
68- var tmp = path . join ( home , '.vue-templates' , template . replace ( / \/ / g, '-' ) )
68+ const tmp = path . join ( home , '.vue-templates' , template . replace ( / \/ / g, '-' ) )
6969if ( program . offline ) {
7070 console . log ( `> Use cached template at ${ chalk . yellow ( tildify ( tmp ) ) } ` )
7171 template = tmp
@@ -76,7 +76,7 @@ if (program.offline) {
7676 */
7777
7878console . log ( )
79- process . on ( 'exit' , function ( ) {
79+ process . on ( 'exit' , ( ) => {
8080 console . log ( )
8181} )
8282
@@ -87,11 +87,11 @@ if (exists(to)) {
8787 ? 'Generate project in current directory?'
8888 : 'Target directory exists. Continue?' ,
8989 name : 'ok'
90- } ] , function ( answers ) {
90+ } ] ) . then ( answers => {
9191 if ( answers . ok ) {
9292 run ( )
9393 }
94- } )
94+ } ) . catch ( logger . fatal )
9595} else {
9696 run ( )
9797}
@@ -103,9 +103,9 @@ if (exists(to)) {
103103function run ( ) {
104104 // check if template is local
105105 if ( isLocalPath ( template ) ) {
106- var templatePath = getTemplatePath ( template )
106+ const templatePath = getTemplatePath ( template )
107107 if ( exists ( templatePath ) ) {
108- generate ( name , templatePath , to , function ( err ) {
108+ generate ( name , templatePath , to , err => {
109109 if ( err ) logger . fatal ( err )
110110 console . log ( )
111111 logger . success ( 'Generated "%s".' , name )
@@ -114,10 +114,10 @@ function run () {
114114 logger . fatal ( 'Local template "%s" not found.' , template )
115115 }
116116 } else {
117- checkVersion ( function ( ) {
117+ checkVersion ( ( ) => {
118118 if ( ! hasSlash ) {
119119 // use official templates
120- var officialTemplate = 'vuejs-templates/' + template
120+ const officialTemplate = 'vuejs-templates/' + template
121121 if ( template . indexOf ( '#' ) !== - 1 ) {
122122 downloadAndGenerate ( officialTemplate )
123123 } else {
@@ -143,14 +143,14 @@ function run () {
143143 */
144144
145145function downloadAndGenerate ( template ) {
146- var spinner = ora ( 'downloading template' )
146+ const spinner = ora ( 'downloading template' )
147147 spinner . start ( )
148148 // Remove if local template exists
149149 if ( exists ( tmp ) ) rm ( tmp )
150- download ( template , tmp , { clone : clone } , function ( err ) {
150+ download ( template , tmp , { clone } , err => {
151151 spinner . stop ( )
152152 if ( err ) logger . fatal ( 'Failed to download repo ' + template + ': ' + err . message . trim ( ) )
153- generate ( name , tmp , to , function ( err ) {
153+ generate ( name , tmp , to , err => {
154154 if ( err ) logger . fatal ( err )
155155 console . log ( )
156156 logger . success ( 'Generated "%s".' , name )
0 commit comments