1#!/usr/bin/env node2 3Const DOWNLOAD = require (' Download-git-repo ')4Const PROGRAM = require (' Commander ')5Const EXISTS = require (' FS '). Existssync6Const PATH = require (' path ')7Const ORA = require (' ora ')8Const HOME = require (' User-home ')9Const TILDIFY = require (' tildify ')TenConst CHALK = require (' Chalk ') OneConst Inquirer = require (' Inquirer ') AConst RM = require (' Rimraf '). Sync -Const LOGGER = require ('.. /lib/logger ') -Const Generate = require ('.. /lib/generate ') theConst Checkversion = require ('.. /lib/check-version ') -Const WARNINGS = require ('.. /lib/warnings ') -Const LOCALPATH = require ('.. /lib/local-path ') - +Const ISLOCALPATH =Localpath.islocalpath -Const GETTEMPLATEPATH =Localpath.gettemplatepath + A /** at * Usage. - */ - - Program -. Usage (' <template-name> [Project-name] ') -. option ('-C,--clone ', ' Use Git clone ') in. Option ('--offline ', ' Use cached template ') - to /** + * Help. - */ the *Program.on ('--help ', () = { $Console.log (' Examples: ')Panax Notoginseng Console.log () -Console.log (Chalk.gray (' # Create a new project with an official template '))) theConsole.log (' $ vue init webpack my-project ') + Console.log () AConsole.log (Chalk.gray (' # Create a new project straight from a github template ')) theConsole.log (' $ vue init username/repo my-project ') + Console.log () - }) $ $ /** - * Help. - */ the - functionHelp () {Wuyi program.parse (PROCESS.ARGV) the if(Program.args.length < 1)returnprogram.help () - } Wu Help () - About /** $ * Settings. - */ - -Let template = Program.args[0] AConst Hasslash = template.indexof ('/') >-1 +Const RAWNAME = program.args[1] theConst INPLACE =!rawname | | Rawname = = = '. ' -Const NAME = InPlace? Path.relative ('.. /‘, PROCESS.CWD ()): Rawname $Const TO = path.resolve (Rawname | | ‘.‘) theConst Clone = Program.clone | |false the theCONST TMP = Path.join (Home, '. Vue-templates ', Template.replace (/[\/:]/g, '-'))) the if(program.offline) { -Console.log (' >Use cached template at ${chalk.yellow (tildify (TMP))} ') inTemplate =tmp the } the About /** the * Padding. the */ the + Console.log () -Process.on (' exit ', () = { the Console.log ()Bayi }) the the if(InPlace | |exists (to)) { - inquirer.prompt ([{ -Type: ' Confirm ', the Message:inplace the? ' Generate project in current directory? ' the: ' Target directory exists. Continue? ', theName: ' OK ' -}]). Then (answers = { the if(Answers.ok) { the Run () the }94}).Catch(logger.fatal) the}Else { the Run () the }98 About /** - * Check, download and generate the project.101 */102 103 functionrun () {104 //Check if template is local the if(Islocalpath (template)) {106Const TEMPLATEPATH =Gettemplatepath (template)107 if(Exists (TemplatePath)) {108Generate (name, TemplatePath, to, err = {109 if(Err) logger.fatal (err) the Console.log ()111Logger.success (' Generated '%s '). ', name) the })113}Else { theLogger.fatal (' Local template '%s ' not found. '), template) the } the}Else {117Checkversion (() = {118 if(!Hasslash) {119 //Use official Templates -Const Officialtemplate = ' vuejs-templates/' +Template121 if(Template.indexof (' # ')!==-1) {122 downloadandgenerate (officialtemplate)123}Else {124 if(Template.indexof ('-2.0 ')!==-1) { thewarnings.v2suffixtemplatesdeprecated (template, InPlace?) ‘‘: Name)126 return127 } - 129 //warnings.v2branchisnowdefault (template, InPlace?) ": Name) the downloadandgenerate (officialtemplate)131 } the}Else {133 downloadandgenerate (template)134 }135 })136 }137 }138 139 /** $ * Download a generate from a template repo.141 *142 * @param {String} template143 */144 145 functiondownloadandgenerate (template) {146Const spinner = ora (' Downloading template ')147 Spinner.start ()148 //Remove if local template exists149 if(EXISTS (TMP)) RM (TMP) MaxDownload (template, tmp, {clone}, Err = {151 spinner.stop () the if(err) logger.fatal (' Failed to download repo ' + template + ': ' +Err.message.trim ())153Generate (name, TMP, to, err = = {154 if(Err) logger.fatal (err)155 Console.log ()156Logger.success (' Generated '%s '). ', name)157 })158 })159}
Https://github.com/vuejs-templates VUE-CLI's template address
HTTPS://GITHUB.COM/VUEJS/VUE-CLI VUE-CLI Source
The main use is bin/vue-init
NPM Package Download-git-repo Commander
Main code
Downloadandgenerate () inside the
About similar VUE-CLI scaffolding