-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #355 from Xiphe/before-add
feat(beforeAdd): allow custom script before git add
- Loading branch information
Showing
11 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function myBeforeAdd() { | ||
/* noop */ | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ const ghpages = require('../../lib/index'); | |
const sinon = require('sinon'); | ||
const cli = require('../../bin/gh-pages'); | ||
const assert = require('../helper').assert; | ||
const beforeAdd = require('./fixtures/beforeAdd'); | ||
|
||
describe('gh-pages', () => { | ||
describe('main', () => { | ||
|
@@ -71,6 +72,16 @@ describe('gh-pages', () => { | |
dist: 'lib', | ||
config: {user: {name: 'Full Name', email: '[email protected]'}} | ||
}, | ||
{ | ||
args: [ | ||
'--dist', | ||
'lib', | ||
'--before-add', | ||
require.resolve('./fixtures/beforeAdd') | ||
], | ||
dist: 'lib', | ||
config: {beforeAdd} | ||
}, | ||
{ | ||
args: ['--dist', 'lib', '-u', 'junk email'], | ||
dist: 'lib', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const helper = require('../helper'); | ||
const ghPages = require('../../lib/'); | ||
const path = require('path'); | ||
|
||
const fixtures = path.join(__dirname, 'fixtures'); | ||
const fixtureName = 'beforeAdd'; | ||
|
||
beforeEach(() => { | ||
ghPages.clean(); | ||
}); | ||
|
||
describe('the beforeAdd option', () => { | ||
it('runs a provided async function before adding files', 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, | ||
add: true, | ||
beforeAdd(git) { | ||
return Promise.resolve().then(() => { | ||
return git.rm('hello-outdated-world.txt'); | ||
}); | ||
}, | ||
user: { | ||
name: 'User Name', | ||
email: '[email protected]' | ||
} | ||
}; | ||
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
1
test/integration/fixtures/beforeAdd/expected/hello-old-world.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello Old World! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello World! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello World! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello Old World! |
1 change: 1 addition & 0 deletions
1
test/integration/fixtures/beforeAdd/remote/hello-outdated-world.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello Outdated World! |