@@ -11,11 +11,20 @@ import * as CreateGithubRepo from '../tasks/create-github-repo';
11
11
import { CliConfig } from '../models/config' ;
12
12
import { oneLine } from 'common-tags' ;
13
13
14
- const fsReadFile = Promise . denodeify ( fs . readFile ) ;
15
- const fsWriteFile = Promise . denodeify ( fs . writeFile ) ;
16
14
const fsReadDir = Promise . denodeify ( fs . readdir ) ;
17
15
const fsCopy = Promise . denodeify ( fse . copy ) ;
18
16
17
+ interface GithubPagesDeployOptions {
18
+ message ?: string ;
19
+ target ?: string ;
20
+ environment ?: string ;
21
+ userPage ?: boolean ;
22
+ skipBuild ?: boolean ;
23
+ ghToken ?: string ;
24
+ ghUsername ?: string ;
25
+ baseHref ?: string ;
26
+ }
27
+
19
28
module . exports = Command . extend ( {
20
29
name : 'github-pages:deploy' ,
21
30
aliases : [ 'gh-pages:deploy' ] ,
@@ -61,9 +70,14 @@ module.exports = Command.extend({
61
70
type : String ,
62
71
default : '' ,
63
72
description : 'Github username'
73
+ } , {
74
+ name : 'base-href' ,
75
+ type : String ,
76
+ default : null ,
77
+ aliases : [ 'bh' ]
64
78
} ] ,
65
79
66
- run : function ( options , rawArgs ) {
80
+ run : function ( options : GithubPagesDeployOptions , rawArgs ) {
67
81
const ui = this . ui ;
68
82
const root = this . project . root ;
69
83
const execOptions = {
@@ -99,10 +113,19 @@ module.exports = Command.extend({
99
113
outputPath : outDir
100
114
} ) ;
101
115
116
+ /**
117
+ * BaseHref tag setting logic:
118
+ * First, use --base-href flag value if provided.
119
+ * Else if --user-page is true, then keep baseHref default as declared in index.html.
120
+ * Otherwise auto-replace with `/${projectName}/`.
121
+ */
122
+ const baseHref = options . baseHref || ( options . userPage ? null : `/${ projectName } /` ) ;
123
+
102
124
const buildOptions = {
103
125
target : options . target ,
104
126
environment : options . environment ,
105
- outputPath : outDir
127
+ outputPath : outDir ,
128
+ baseHref : baseHref ,
106
129
} ;
107
130
108
131
const createGithubRepoTask = new CreateGithubRepo ( {
@@ -123,7 +146,7 @@ module.exports = Command.extend({
123
146
. then ( createGitHubRepoIfNeeded )
124
147
. then ( checkoutGhPages )
125
148
. then ( copyFiles )
126
- . then ( updateBaseHref )
149
+ . then ( createNotFoundPage )
127
150
. then ( addAndCommit )
128
151
. then ( returnStartingBranch )
129
152
. then ( pushToGitRepo )
@@ -191,15 +214,10 @@ module.exports = Command.extend({
191
214
} ) ) ) ;
192
215
}
193
216
194
- function updateBaseHref ( ) {
195
- if ( options . userPage ) { return Promise . resolve ( ) ; }
196
- let indexHtml = path . join ( root , 'index.html' ) ;
197
- return fsReadFile ( indexHtml , 'utf8' )
198
- . then ( ( data ) => data . replace ( / < b a s e h r e f = " \/ " > / g, `<base href="/${ projectName } /">` ) )
199
- . then ( ( data ) => {
200
- fsWriteFile ( indexHtml , data , 'utf8' ) ;
201
- fsWriteFile ( path . join ( root , '404.html' ) , data , 'utf8' ) ;
202
- } ) ;
217
+ function createNotFoundPage ( ) {
218
+ const indexHtml = path . join ( root , 'index.html' ) ;
219
+ const notFoundPage = path . join ( root , '404.html' ) ;
220
+ return fsCopy ( indexHtml , notFoundPage ) ;
203
221
}
204
222
205
223
function addAndCommit ( ) {
0 commit comments