@@ -13,6 +13,7 @@ import { GithubPagesDeployOptions } from './github-pages-deploy';
1313
1414const fsReadDir = < any > denodeify ( fs . readdir ) ;
1515const fsCopy = < any > denodeify ( fse . copy ) ;
16+ const fsWriteFile = < any > denodeify ( fse . writeFile ) ;
1617
1718export default function githubPagesDeployRun ( options : GithubPagesDeployOptions , rawArgs : string [ ] ) {
1819 const ui = this . ui ;
@@ -53,11 +54,15 @@ export default function githubPagesDeployRun(options: GithubPagesDeployOptions,
5354
5455 /**
5556 * 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.
5759 * Else if --user-page is true, then keep baseHref default as declared in index.html.
5860 * Otherwise auto-replace with `/${projectName}/`.
5961 */
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+ }
6166
6267 const buildOptions = {
6368 target : options . target ,
@@ -85,6 +90,7 @@ export default function githubPagesDeployRun(options: GithubPagesDeployOptions,
8590 . then ( cleanGhPagesBranch )
8691 . then ( copyFiles )
8792 . then ( createNotFoundPage )
93+ . then ( createCustomDomainFile )
8894 . then ( addAndCommit )
8995 . then ( returnStartingBranch )
9096 . then ( pushToGitRepo )
@@ -176,6 +182,15 @@ export default function githubPagesDeployRun(options: GithubPagesDeployOptions,
176182 return fsCopy ( indexHtml , notFoundPage ) ;
177183 }
178184
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+
179194 function addAndCommit ( ) {
180195 return execPromise ( 'git add .' , execOptions )
181196 . then ( ( ) => execPromise ( `git commit -m "${ options . message } "` ) )
@@ -203,7 +218,14 @@ export default function githubPagesDeployRun(options: GithubPagesDeployOptions,
203218 function printProjectUrl ( ) {
204219 return getUsernameFromGitOrigin ( )
205220 . 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+
207229 ui . writeLine ( chalk . green ( `Deployed! Visit ${ url } ` ) ) ;
208230 ui . writeLine ( 'Github pages might take a few minutes to show the deployed site.' ) ;
209231 } ) ;
0 commit comments