Skip to content

Commit

Permalink
Merge pull request #535 from WillBAnders/fix/missing-cname-option
Browse files Browse the repository at this point in the history
fix: Add missing cname option not passed to the config
  • Loading branch information
tschaub authored Dec 23, 2023
2 parents 727d714 + b6b8454 commit 3312dc4
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions bin/gh-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions test/bin/gh-pages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
38 changes: 38 additions & 0 deletions test/integration/cnameExists.spec.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
});
1 change: 1 addition & 0 deletions test/integration/fixtures/cname-exists/expected/CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
custom-domain.com
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World!
1 change: 1 addition & 0 deletions test/integration/fixtures/cname-exists/remote/CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
existing-domain.com
Empty file.

0 comments on commit 3312dc4

Please sign in to comment.