@@ -13,6 +13,7 @@ import { GithubPagesDeployOptions } from './github-pages-deploy';
13
13
14
14
const fsReadDir = < any > denodeify ( fs . readdir ) ;
15
15
const fsCopy = < any > denodeify ( fse . copy ) ;
16
+ const fsWriteFile = < any > denodeify ( fse . writeFile ) ;
16
17
17
18
export default function githubPagesDeployRun ( options : GithubPagesDeployOptions , rawArgs : string [ ] ) {
18
19
const ui = this . ui ;
@@ -53,11 +54,15 @@ export default function githubPagesDeployRun(options: GithubPagesDeployOptions,
53
54
54
55
/**
55
56
* BaseHref tag setting logic:
56
- * First, use --base-href flag value if provided.
57
+ * First, no value if --custom-domain is provided.
58
+ * Second, use --base-href flag value if provided.
57
59
* Else if --user-page is true, then keep baseHref default as declared in index.html.
58
60
* Otherwise auto-replace with `/${projectName}/`.
59
61
*/
60
- const baseHref = options . baseHref || ( options . userPage ? null : `/${ projectName } /` ) ;
62
+ let baseHref : String = null ;
63
+ if ( ! options . customDomain ) {
64
+ baseHref = options . baseHref || ( options . userPage ? null : `/${ projectName } /` ) ;
65
+ }
61
66
62
67
const buildOptions = {
63
68
target : options . target ,
@@ -85,6 +90,7 @@ export default function githubPagesDeployRun(options: GithubPagesDeployOptions,
85
90
. then ( cleanGhPagesBranch )
86
91
. then ( copyFiles )
87
92
. then ( createNotFoundPage )
93
+ . then ( createCustomDomainFile )
88
94
. then ( addAndCommit )
89
95
. then ( returnStartingBranch )
90
96
. then ( pushToGitRepo )
@@ -176,6 +182,15 @@ export default function githubPagesDeployRun(options: GithubPagesDeployOptions,
176
182
return fsCopy ( indexHtml , notFoundPage ) ;
177
183
}
178
184
185
+ function createCustomDomainFile ( ) {
186
+ if ( ! options . customDomain ) {
187
+ return ;
188
+ }
189
+
190
+ const cnameFile = path . join ( root , 'CNAME' ) ;
191
+ return fsWriteFile ( cnameFile , options . customDomain ) ;
192
+ }
193
+
179
194
function addAndCommit ( ) {
180
195
return execPromise ( 'git add .' , execOptions )
181
196
. then ( ( ) => execPromise ( `git commit -m "${ options . message } "` ) )
@@ -203,7 +218,14 @@ export default function githubPagesDeployRun(options: GithubPagesDeployOptions,
203
218
function printProjectUrl ( ) {
204
219
return getUsernameFromGitOrigin ( )
205
220
. then ( ( userName ) => {
206
- let url = `https://${ userName } .github.io/${ options . userPage ? '' : ( baseHref + '/' ) } ` ;
221
+ let url = '' ;
222
+
223
+ if ( options . customDomain ) {
224
+ url = `http://${ options . customDomain } /` ;
225
+ } else {
226
+ url = `https://${ userName } .github.io/${ options . userPage ? '' : ( baseHref + '/' ) } ` ;
227
+ }
228
+
207
229
ui . writeLine ( chalk . green ( `Deployed! Visit ${ url } ` ) ) ;
208
230
ui . writeLine ( 'Github pages might take a few minutes to show the deployed site.' ) ;
209
231
} ) ;
0 commit comments