Skip to content

Commit

Permalink
feat(commit): enable githook output streaming
Browse files Browse the repository at this point in the history
We needed a way to provide incremental progress to the cli as the commit exec command runs. We
needed to land a PR in gulp-git first. This has now landed. This implements an incremental feedback
using the emitData option and does a few dependency updates.

Closes #8 Closes #28 Closes #31 Closes #32 Closes #33
  • Loading branch information
jimthedev committed Oct 21, 2015
1 parent 2ff573e commit fc95daa
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"check-coverage": "istanbul check-coverage --statements 80 --branches 80 --functions 80 --lines 80 ",
"commit": "git-cz",
"report-coverage": "cat ./coverage/lcov.info | codecov",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"start": "npm run test:watch",
"test": "istanbul cover -x ./test _mocha -- -R spec test/tests/index.js --compilers js:babel/register",
"test:watch": "nodemon -q --exec \"$(npm bin)/mocha test/tests/index.js --watch --compilers js:babel/register\" --"
Expand Down Expand Up @@ -41,7 +42,7 @@
"author": "Jim Cummins <jimthedev@gmail.com> (https://github.com/jimthedev)",
"license": "MIT",
"devDependencies": {
"chai": "3.3.0",
"chai": "3.4.0",
"codecov.io": "0.1.6",
"ghooks": "0.3.2",
"istanbul": "0.3.22",
Expand All @@ -52,20 +53,20 @@
"dependencies": {
"babel": "5.8.23",
"chalk": "1.1.1",
"cz-conventional-changelog": "1.1.4",
"dedent": "0.4.0",
"find-node-modules": "1.0.1",
"glob": "5.0.15",
"gulp": "3.9.0",
"gulp-git": "1.5.0",
"gulp-git": "1.6.0",
"inquirer": "0.10.1",
"json": "9.0.3",
"minimist": "1.2.0",
"node-uuid": "1.4.3",
"nodemon": "1.7.2",
"nodemon": "1.7.3",
"rimraf": "2.4.3",
"semver": "5.0.3",
"shelljs": "0.5.3",
"strip-json-comments": "1.0.4",
"cz-conventional-changelog": "1.1.4"
"strip-json-comments": "1.0.4"
}
}
4 changes: 3 additions & 1 deletion src/cli/strategies/git-cz.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ function gitCz(rawGitArgs, environment, adapterConfig) {
if(stagingIsClean) {
console.error('Error: No files added to staging! Did you forget to run git add?')
} else {

// OH GOD IM SORRY FOR THIS SECTION
let adapterPackageJson = getParsedPackageJsonFromPath(resolvedAdapterConfigPath);
let cliPackageJson = getParsedPackageJsonFromPath(environment.cliPath);
console.log(`cz-cli@${cliPackageJson.version}, ${adapterPackageJson.name}@${adapterPackageJson.version}\n`);
commit(sh, inquirer, process.cwd(), prompter, {args: parsedGitCzArgs, disableAppendPaths:true}, function() {
commit(sh, inquirer, process.cwd(), prompter, {args: parsedGitCzArgs, disableAppendPaths:true, emitData:true, quiet:false}, function() {
// console.log('commit happened');
});

Expand Down
28 changes: 23 additions & 5 deletions src/git/commit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import git from 'gulp-git';
import gulp from 'gulp';
import dedent from 'dedent';
import {isString} from '../../common/util';

export { commit };

Expand All @@ -9,21 +10,38 @@ export { commit };
*/
function commit(sh, repoPath, message, options, done) {

var alreadyEnded = false;

// Get a gulp stream based off the config
gulp.src(repoPath)

// Format then commit
.pipe(git.commit(dedent(message), options))


// Write progress to the screen
.on('data',function(data) {
if(!options.quiet) {
if(isString(data))
{
process.stdout.write(data);
}
}
})

// Handle commit success
.on('end', function() {
done();
// TODO: Bug? Done is fired twice :(
if(!alreadyEnded)
{
done();
alreadyEnded=true;
}
})

// Handle commit failure
.on('error', function (error) {
console.error(error);
done(error);
.on('error', function (err) {
console.error(err);
done(err);
});

}
2 changes: 1 addition & 1 deletion test/tests/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('commit', function() {

// Pass in inquirer but it never gets used since we've mocked out a different
// version of prompter.
commitizenCommit(sh, inquirer, repoConfig.path, prompter, {disableAppendPaths:true, quiet:true}, function() {
commitizenCommit(sh, inquirer, repoConfig.path, prompter, {disableAppendPaths:true, quiet:true, emitData:true}, function() {
log(repoConfig.path, function(logOutput) {
expect(logOutput).to.have.string(dummyCommitMessage);
done();
Expand Down

0 comments on commit fc95daa

Please sign in to comment.