@@ -9,6 +9,7 @@ import * as path from 'path';
99import * as WebpackBuild from '../tasks/build-webpack' ;
1010import * as CreateGithubRepo from '../tasks/create-github-repo' ;
1111import { CliConfig } from '../models/config' ;
12+ import { oneLine } from 'common-tags' ;
1213
1314const fsReadFile = Promise . denodeify ( fs . readFile ) ;
1415const fsWriteFile = Promise . denodeify ( fs . writeFile ) ;
@@ -18,7 +19,10 @@ const fsCopy = Promise.denodeify(fse.copy);
1819module . exports = Command . extend ( {
1920 name : 'github-pages:deploy' ,
2021 aliases : [ 'gh-pages:deploy' ] ,
21- description : 'Build the test app for production, commit it into a git branch, setup GitHub repo and push to it' ,
22+ description : oneLine `
23+ Build the test app for production, commit it into a git branch,
24+ setup GitHub repo and push to it
25+ ` ,
2226 works : 'insideProject' ,
2327
2428 availableOptions : [
@@ -60,13 +64,13 @@ module.exports = Command.extend({
6064 } ] ,
6165
6266 run : function ( options , rawArgs ) {
63- var ui = this . ui ;
64- var root = this . project . root ;
65- var execOptions = {
67+ const ui = this . ui ;
68+ const root = this . project . root ;
69+ const execOptions = {
6670 cwd : root
6771 } ;
6872
69- if ( options . environment === '' ) {
73+ if ( options . environment === '' ) {
7074 if ( options . target === 'development' ) {
7175 options . environment = 'dev' ;
7276 }
@@ -75,7 +79,7 @@ module.exports = Command.extend({
7579 }
7680 }
7781
78- var projectName = this . project . pkg . name ;
82+ const projectName = this . project . pkg . name ;
7983
8084 const outDir = CliConfig . fromProject ( ) . config . apps [ 0 ] . outDir ;
8185
@@ -86,7 +90,7 @@ module.exports = Command.extend({
8690 // declared here so that tests can stub exec
8791 const execPromise = Promise . denodeify ( exec ) ;
8892
89- var buildTask = new WebpackBuild ( {
93+ const buildTask = new WebpackBuild ( {
9094 ui : this . ui ,
9195 analytics : this . analytics ,
9296 cliProject : this . project ,
@@ -95,19 +99,19 @@ module.exports = Command.extend({
9599 outputPath : outDir
96100 } ) ;
97101
98- var buildOptions = {
102+ const buildOptions = {
99103 target : options . target ,
100104 environment : options . environment ,
101105 outputPath : outDir
102106 } ;
103107
104- var createGithubRepoTask = new CreateGithubRepo ( {
108+ const createGithubRepoTask = new CreateGithubRepo ( {
105109 ui : this . ui ,
106110 analytics : this . analytics ,
107111 project : this . project
108112 } ) ;
109113
110- var createGithubRepoOptions = {
114+ const createGithubRepoOptions = {
111115 projectName,
112116 ghUsername : options . ghUsername ,
113117 ghToken : options . ghToken
@@ -137,7 +141,7 @@ module.exports = Command.extend({
137141 }
138142
139143 function build ( ) {
140- if ( options . skipBuild ) return Promise . resolve ( ) ;
144+ if ( options . skipBuild ) { return Promise . resolve ( ) ; }
141145 return buildTask . run ( buildOptions ) ;
142146 }
143147
@@ -165,7 +169,7 @@ module.exports = Command.extend({
165169
166170 function checkoutGhPages ( ) {
167171 return execPromise ( `git checkout ${ ghPagesBranch } ` )
168- . catch ( createGhPagesBranch )
172+ . catch ( createGhPagesBranch ) ;
169173 }
170174
171175 function createGhPagesBranch ( ) {
@@ -179,16 +183,16 @@ module.exports = Command.extend({
179183 function copyFiles ( ) {
180184 return fsReadDir ( outDir )
181185 . then ( ( files ) => Promise . all ( files . map ( ( file ) => {
182- if ( file === '.gitignore' ) {
186+ if ( file === '.gitignore' ) {
183187 // don't overwrite the .gitignore file
184188 return Promise . resolve ( ) ;
185189 }
186- return fsCopy ( path . join ( outDir , file ) , path . join ( '.' , file ) )
190+ return fsCopy ( path . join ( outDir , file ) , path . join ( '.' , file ) ) ;
187191 } ) ) ) ;
188192 }
189193
190194 function updateBaseHref ( ) {
191- if ( options . userPage ) return Promise . resolve ( ) ;
195+ if ( options . userPage ) { return Promise . resolve ( ) ; }
192196 let indexHtml = path . join ( root , 'index.html' ) ;
193197 return fsReadFile ( indexHtml , 'utf8' )
194198 . then ( ( data ) => data . replace ( / < b a s e h r e f = " \/ " > / g, `<base href="/${ projectName } /">` ) )
@@ -215,7 +219,8 @@ module.exports = Command.extend({
215219 function printProjectUrl ( ) {
216220 return execPromise ( 'git remote -v' )
217221 . then ( ( stdout ) => {
218- let userName = stdout . match ( / o r i g i n \s + (?: h t t p s : \/ \/ | g i t @ ) g i t h u b \. c o m (?: \: | \/ ) ( [ ^ \/ ] + ) / m) [ 1 ] . toLowerCase ( ) ;
222+ let match = stdout . match ( / o r i g i n \s + (?: h t t p s : \/ \/ | g i t @ ) g i t h u b \. c o m (?: \: | \/ ) ( [ ^ \/ ] + ) / m) ;
223+ let userName = match [ 1 ] . toLowerCase ( ) ;
219224 let url = `https://${ userName } .github.io/${ options . userPage ? '' : ( projectName + '/' ) } ` ;
220225 ui . writeLine ( chalk . green ( `Deployed! Visit ${ url } ` ) ) ;
221226 ui . writeLine ( 'Github pages might take a few minutes to show the deployed site.' ) ;
@@ -225,7 +230,8 @@ module.exports = Command.extend({
225230 function failGracefully ( error ) {
226231 if ( error && ( / g i t c l e a n / . test ( error . message ) || / P e r m i s s i o n d e n i e d / . test ( error . message ) ) ) {
227232 ui . writeLine ( error . message ) ;
228- let msg = 'There was a permissions error during git file operations, please close any open project files/folders and try again.' ;
233+ let msg = 'There was a permissions error during git file operations, ' +
234+ 'please close any open project files/folders and try again.' ;
229235 msg += `\nYou might also need to return to the ${ initialBranch } branch manually.` ;
230236 return Promise . reject ( new SilentError ( msg ) ) ;
231237 } else {
0 commit comments