@@ -11,11 +11,20 @@ import * as CreateGithubRepo from '../tasks/create-github-repo';
1111import { CliConfig } from '../models/config' ;
1212import { oneLine } from 'common-tags' ;
1313
14- const fsReadFile = Promise . denodeify ( fs . readFile ) ;
15- const fsWriteFile = Promise . denodeify ( fs . writeFile ) ;
1614const fsReadDir = Promise . denodeify ( fs . readdir ) ;
1715const fsCopy = Promise . denodeify ( fse . copy ) ;
1816
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+
1928module . exports = Command . extend ( {
2029 name : 'github-pages:deploy' ,
2130 aliases : [ 'gh-pages:deploy' ] ,
@@ -61,9 +70,14 @@ module.exports = Command.extend({
6170 type : String ,
6271 default : '' ,
6372 description : 'Github username'
73+ } , {
74+ name : 'base-href' ,
75+ type : String ,
76+ default : null ,
77+ aliases : [ 'bh' ]
6478 } ] ,
6579
66- run : function ( options , rawArgs ) {
80+ run : function ( options : GithubPagesDeployOptions , rawArgs ) {
6781 const ui = this . ui ;
6882 const root = this . project . root ;
6983 const execOptions = {
@@ -99,10 +113,19 @@ module.exports = Command.extend({
99113 outputPath : outDir
100114 } ) ;
101115
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+
102124 const buildOptions = {
103125 target : options . target ,
104126 environment : options . environment ,
105- outputPath : outDir
127+ outputPath : outDir ,
128+ baseHref : baseHref ,
106129 } ;
107130
108131 const createGithubRepoTask = new CreateGithubRepo ( {
@@ -123,7 +146,7 @@ module.exports = Command.extend({
123146 . then ( createGitHubRepoIfNeeded )
124147 . then ( checkoutGhPages )
125148 . then ( copyFiles )
126- . then ( updateBaseHref )
149+ . then ( createNotFoundPage )
127150 . then ( addAndCommit )
128151 . then ( returnStartingBranch )
129152 . then ( pushToGitRepo )
@@ -191,15 +214,10 @@ module.exports = Command.extend({
191214 } ) ) ) ;
192215 }
193216
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 ) ;
203221 }
204222
205223 function addAndCommit ( ) {
0 commit comments