@@ -9,6 +9,7 @@ import * as path from 'path';
9
9
import * as WebpackBuild from '../tasks/build-webpack' ;
10
10
import * as CreateGithubRepo from '../tasks/create-github-repo' ;
11
11
import { CliConfig } from '../models/config' ;
12
+ import { oneLine } from 'common-tags' ;
12
13
13
14
const fsReadFile = Promise . denodeify ( fs . readFile ) ;
14
15
const fsWriteFile = Promise . denodeify ( fs . writeFile ) ;
@@ -18,7 +19,10 @@ const fsCopy = Promise.denodeify(fse.copy);
18
19
module . exports = Command . extend ( {
19
20
name : 'github-pages:deploy' ,
20
21
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
+ ` ,
22
26
works : 'insideProject' ,
23
27
24
28
availableOptions : [
@@ -60,13 +64,13 @@ module.exports = Command.extend({
60
64
} ] ,
61
65
62
66
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 = {
66
70
cwd : root
67
71
} ;
68
72
69
- if ( options . environment === '' ) {
73
+ if ( options . environment === '' ) {
70
74
if ( options . target === 'development' ) {
71
75
options . environment = 'dev' ;
72
76
}
@@ -75,7 +79,7 @@ module.exports = Command.extend({
75
79
}
76
80
}
77
81
78
- var projectName = this . project . pkg . name ;
82
+ const projectName = this . project . pkg . name ;
79
83
80
84
const outDir = CliConfig . fromProject ( ) . config . apps [ 0 ] . outDir ;
81
85
@@ -86,7 +90,7 @@ module.exports = Command.extend({
86
90
// declared here so that tests can stub exec
87
91
const execPromise = Promise . denodeify ( exec ) ;
88
92
89
- var buildTask = new WebpackBuild ( {
93
+ const buildTask = new WebpackBuild ( {
90
94
ui : this . ui ,
91
95
analytics : this . analytics ,
92
96
cliProject : this . project ,
@@ -95,19 +99,19 @@ module.exports = Command.extend({
95
99
outputPath : outDir
96
100
} ) ;
97
101
98
- var buildOptions = {
102
+ const buildOptions = {
99
103
target : options . target ,
100
104
environment : options . environment ,
101
105
outputPath : outDir
102
106
} ;
103
107
104
- var createGithubRepoTask = new CreateGithubRepo ( {
108
+ const createGithubRepoTask = new CreateGithubRepo ( {
105
109
ui : this . ui ,
106
110
analytics : this . analytics ,
107
111
project : this . project
108
112
} ) ;
109
113
110
- var createGithubRepoOptions = {
114
+ const createGithubRepoOptions = {
111
115
projectName,
112
116
ghUsername : options . ghUsername ,
113
117
ghToken : options . ghToken
@@ -137,7 +141,7 @@ module.exports = Command.extend({
137
141
}
138
142
139
143
function build ( ) {
140
- if ( options . skipBuild ) return Promise . resolve ( ) ;
144
+ if ( options . skipBuild ) { return Promise . resolve ( ) ; }
141
145
return buildTask . run ( buildOptions ) ;
142
146
}
143
147
@@ -165,7 +169,7 @@ module.exports = Command.extend({
165
169
166
170
function checkoutGhPages ( ) {
167
171
return execPromise ( `git checkout ${ ghPagesBranch } ` )
168
- . catch ( createGhPagesBranch )
172
+ . catch ( createGhPagesBranch ) ;
169
173
}
170
174
171
175
function createGhPagesBranch ( ) {
@@ -179,16 +183,16 @@ module.exports = Command.extend({
179
183
function copyFiles ( ) {
180
184
return fsReadDir ( outDir )
181
185
. then ( ( files ) => Promise . all ( files . map ( ( file ) => {
182
- if ( file === '.gitignore' ) {
186
+ if ( file === '.gitignore' ) {
183
187
// don't overwrite the .gitignore file
184
188
return Promise . resolve ( ) ;
185
189
}
186
- return fsCopy ( path . join ( outDir , file ) , path . join ( '.' , file ) )
190
+ return fsCopy ( path . join ( outDir , file ) , path . join ( '.' , file ) ) ;
187
191
} ) ) ) ;
188
192
}
189
193
190
194
function updateBaseHref ( ) {
191
- if ( options . userPage ) return Promise . resolve ( ) ;
195
+ if ( options . userPage ) { return Promise . resolve ( ) ; }
192
196
let indexHtml = path . join ( root , 'index.html' ) ;
193
197
return fsReadFile ( indexHtml , 'utf8' )
194
198
. then ( ( data ) => data . replace ( / < b a s e h r e f = " \/ " > / g, `<base href="/${ projectName } /">` ) )
@@ -215,7 +219,8 @@ module.exports = Command.extend({
215
219
function printProjectUrl ( ) {
216
220
return execPromise ( 'git remote -v' )
217
221
. 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 ( ) ;
219
224
let url = `https://${ userName } .github.io/${ options . userPage ? '' : ( projectName + '/' ) } ` ;
220
225
ui . writeLine ( chalk . green ( `Deployed! Visit ${ url } ` ) ) ;
221
226
ui . writeLine ( 'Github pages might take a few minutes to show the deployed site.' ) ;
@@ -225,7 +230,8 @@ module.exports = Command.extend({
225
230
function failGracefully ( error ) {
226
231
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 ) ) ) {
227
232
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.' ;
229
235
msg += `\nYou might also need to return to the ${ initialBranch } branch manually.` ;
230
236
return Promise . reject ( new SilentError ( msg ) ) ;
231
237
} else {
0 commit comments