diff --git a/bin/gh-pages.js b/bin/gh-pages.js index bf51f2c4..9b3b5ada 100755 --- a/bin/gh-pages.js +++ b/bin/gh-pages.js @@ -127,6 +127,7 @@ function main(args) { depth: options.depth, dotfiles: !!options.dotfiles, nojekyll: !!options.nojekyll, + cname: options.cname, add: !!options.add, remove: options.remove, remote: options.remote, diff --git a/lib/index.js b/lib/index.js index f74e6fd0..eef52a2d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -183,13 +183,15 @@ exports.publish = function publish(basePath, config, callback) { } }) .then((git) => { - log('Copying files'); if (options.nojekyll) { + log('Creating .nojekyll'); fs.createFileSync(path.join(git.cwd, '.nojekyll')); } if (options.cname) { + log('Creating CNAME for %s', options.cname); fs.writeFileSync(path.join(git.cwd, 'CNAME'), options.cname); } + log('Copying files'); return copy(files, basePath, path.join(git.cwd, options.dest)).then( function () { return git; diff --git a/test/bin/gh-pages.spec.js b/test/bin/gh-pages.spec.js index e0353fca..61563fc0 100644 --- a/test/bin/gh-pages.spec.js +++ b/test/bin/gh-pages.spec.js @@ -47,6 +47,11 @@ describe('gh-pages', () => { dist: 'lib', config: {nojekyll: true}, }, + { + args: ['--dist', 'lib', '--cname', 'CNAME'], + dist: 'lib', + config: {cname: 'CNAME'}, + }, { args: ['--dist', 'lib', '--dest', 'target'], dist: 'lib', diff --git a/test/integration/cnameExists.spec.js b/test/integration/cnameExists.spec.js new file mode 100644 index 00000000..33e57490 --- /dev/null +++ b/test/integration/cnameExists.spec.js @@ -0,0 +1,38 @@ +const helper = require('../helper.js'); +const ghPages = require('../../lib/index.js'); +const path = require('path'); + +const fixtures = path.join(__dirname, 'fixtures'); +const fixtureName = 'cname-exists'; + +beforeEach(() => { + ghPages.clean(); +}); + +describe('the --cname option', () => { + it('works even if the CNAME file already exists AND replaces any existing value', (done) => { + const local = path.join(fixtures, fixtureName, 'local'); + const expected = path.join(fixtures, fixtureName, 'expected'); + const branch = 'gh-pages'; + + helper.setupRemote(fixtureName, {branch}).then((url) => { + const options = { + repo: url, + user: { + name: 'User Name', + email: 'user@email.com', + }, + cname: 'custom-domain.com', + }; + ghPages.publish(local, options, (err) => { + if (err) { + return done(err); + } + helper + .assertContentsMatch(expected, url, branch) + .then(() => done()) + .catch(done); + }); + }); + }); +}); diff --git a/test/integration/fixtures/cname-exists/expected/CNAME b/test/integration/fixtures/cname-exists/expected/CNAME new file mode 100644 index 00000000..5e5c92eb --- /dev/null +++ b/test/integration/fixtures/cname-exists/expected/CNAME @@ -0,0 +1 @@ +custom-domain.com diff --git a/test/integration/fixtures/cname-exists/expected/hello-world.txt b/test/integration/fixtures/cname-exists/expected/hello-world.txt new file mode 100644 index 00000000..980a0d5f --- /dev/null +++ b/test/integration/fixtures/cname-exists/expected/hello-world.txt @@ -0,0 +1 @@ +Hello World! diff --git a/test/integration/fixtures/cname-exists/local/hello-world.txt b/test/integration/fixtures/cname-exists/local/hello-world.txt new file mode 100644 index 00000000..980a0d5f --- /dev/null +++ b/test/integration/fixtures/cname-exists/local/hello-world.txt @@ -0,0 +1 @@ +Hello World! diff --git a/test/integration/fixtures/cname-exists/remote/CNAME b/test/integration/fixtures/cname-exists/remote/CNAME new file mode 100644 index 00000000..50c94db5 --- /dev/null +++ b/test/integration/fixtures/cname-exists/remote/CNAME @@ -0,0 +1 @@ +existing-domain.com diff --git a/test/integration/fixtures/cname-exists/remote/initial b/test/integration/fixtures/cname-exists/remote/initial new file mode 100644 index 00000000..e69de29b