From 81ac71947d2cfad9c4746b51253da2e69bf50e98 Mon Sep 17 00:00:00 2001 From: WillBAnders Date: Tue, 21 Nov 2023 19:38:16 -0500 Subject: [PATCH 1/3] Add missing cname option not passed to the config --- bin/gh-pages.js | 1 + test/bin/gh-pages.spec.js | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/bin/gh-pages.js b/bin/gh-pages.js index bf51f2c..9b3b5ad 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/test/bin/gh-pages.spec.js b/test/bin/gh-pages.spec.js index e0353fc..61563fc 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', From 1c60556b34b99ebece5b22911e6f049feb37d746 Mon Sep 17 00:00:00 2001 From: WillBAnders Date: Wed, 20 Dec 2023 22:06:02 -0500 Subject: [PATCH 2/3] Add debug logs for nojekyll/cname creation as recommended by @paymand --- lib/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index f74e6fd..eef52a2 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; From b6b84541cb7918ce1b99ea9688808f63af0c356a Mon Sep 17 00:00:00 2001 From: WillBAnders Date: Wed, 20 Dec 2023 22:25:57 -0500 Subject: [PATCH 3/3] Add test for cnameExists, asserting it replaces the existing CNAME --- test/integration/cnameExists.spec.js | 38 +++++++++++++++++++ .../fixtures/cname-exists/expected/CNAME | 1 + .../cname-exists/expected/hello-world.txt | 1 + .../cname-exists/local/hello-world.txt | 1 + .../fixtures/cname-exists/remote/CNAME | 1 + .../fixtures/cname-exists/remote/initial | 0 6 files changed, 42 insertions(+) create mode 100644 test/integration/cnameExists.spec.js create mode 100644 test/integration/fixtures/cname-exists/expected/CNAME create mode 100644 test/integration/fixtures/cname-exists/expected/hello-world.txt create mode 100644 test/integration/fixtures/cname-exists/local/hello-world.txt create mode 100644 test/integration/fixtures/cname-exists/remote/CNAME create mode 100644 test/integration/fixtures/cname-exists/remote/initial diff --git a/test/integration/cnameExists.spec.js b/test/integration/cnameExists.spec.js new file mode 100644 index 0000000..33e5749 --- /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 0000000..5e5c92e --- /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 0000000..980a0d5 --- /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 0000000..980a0d5 --- /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 0000000..50c94db --- /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 0000000..e69de29