Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Domain Option #371

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bin/gh-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function main(args) {
'--before-add <file>',
'Execute the function exported by <file> before "git add"'
)
.option('--domain <domain>', 'Custom Domain to publish page')
.parse(args);

let user;
Expand Down Expand Up @@ -122,7 +123,8 @@ function main(args) {
push: !!program.push,
history: !!program.history,
user: user,
beforeAdd: beforeAdd
beforeAdd: beforeAdd,
domain: program.domain
};

return publish(config);
Expand Down
8 changes: 8 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ exports.publish = function publish(basePath, config, callback) {
);
})
.then(git => {
if (options.domain) {
log('Adding CNAME');
fs.writeFileSync(
path.join(git.cwd, options.dest, 'CNAME'),
options.domain
);
}

return Promise.resolve(
options.beforeAdd && options.beforeAdd(git)
).then(() => git);
Expand Down
39 changes: 39 additions & 0 deletions test/integration/domain.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const helper = require('../helper');
const ghPages = require('../../lib');
const path = require('path');

const fixtures = path.join(__dirname, 'fixtures');
const fixtureName = 'domain';

beforeEach(() => {
ghPages.clean();
});

describe('the domain option', () => {
it('adds CNAME file', 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'
},
domain: 'customdomain.github.io'
};

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/domain/expected/CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
customdomain.github.io
1 change: 1 addition & 0 deletions test/integration/fixtures/domain/expected/hello-world.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World!
1 change: 1 addition & 0 deletions test/integration/fixtures/domain/local/hello-world.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World!
Empty file.