Skip to content

Commit fc95daa

Browse files
committed
feat(commit): enable githook output streaming
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
1 parent 2ff573e commit fc95daa

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"check-coverage": "istanbul check-coverage --statements 80 --branches 80 --functions 80 --lines 80 ",
88
"commit": "git-cz",
99
"report-coverage": "cat ./coverage/lcov.info | codecov",
10+
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
1011
"start": "npm run test:watch",
1112
"test": "istanbul cover -x ./test _mocha -- -R spec test/tests/index.js --compilers js:babel/register",
1213
"test:watch": "nodemon -q --exec \"$(npm bin)/mocha test/tests/index.js --watch --compilers js:babel/register\" --"
@@ -41,7 +42,7 @@
4142
"author": "Jim Cummins <jimthedev@gmail.com> (https://github.com/jimthedev)",
4243
"license": "MIT",
4344
"devDependencies": {
44-
"chai": "3.3.0",
45+
"chai": "3.4.0",
4546
"codecov.io": "0.1.6",
4647
"ghooks": "0.3.2",
4748
"istanbul": "0.3.22",
@@ -52,20 +53,20 @@
5253
"dependencies": {
5354
"babel": "5.8.23",
5455
"chalk": "1.1.1",
56+
"cz-conventional-changelog": "1.1.4",
5557
"dedent": "0.4.0",
5658
"find-node-modules": "1.0.1",
5759
"glob": "5.0.15",
5860
"gulp": "3.9.0",
59-
"gulp-git": "1.5.0",
61+
"gulp-git": "1.6.0",
6062
"inquirer": "0.10.1",
6163
"json": "9.0.3",
6264
"minimist": "1.2.0",
6365
"node-uuid": "1.4.3",
64-
"nodemon": "1.7.2",
66+
"nodemon": "1.7.3",
6567
"rimraf": "2.4.3",
6668
"semver": "5.0.3",
6769
"shelljs": "0.5.3",
68-
"strip-json-comments": "1.0.4",
69-
"cz-conventional-changelog": "1.1.4"
70+
"strip-json-comments": "1.0.4"
7071
}
7172
}

src/cli/strategies/git-cz.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ function gitCz(rawGitArgs, environment, adapterConfig) {
5151
if(stagingIsClean) {
5252
console.error('Error: No files added to staging! Did you forget to run git add?')
5353
} else {
54+
55+
// OH GOD IM SORRY FOR THIS SECTION
5456
let adapterPackageJson = getParsedPackageJsonFromPath(resolvedAdapterConfigPath);
5557
let cliPackageJson = getParsedPackageJsonFromPath(environment.cliPath);
5658
console.log(`cz-cli@${cliPackageJson.version}, ${adapterPackageJson.name}@${adapterPackageJson.version}\n`);
57-
commit(sh, inquirer, process.cwd(), prompter, {args: parsedGitCzArgs, disableAppendPaths:true}, function() {
59+
commit(sh, inquirer, process.cwd(), prompter, {args: parsedGitCzArgs, disableAppendPaths:true, emitData:true, quiet:false}, function() {
5860
// console.log('commit happened');
5961
});
6062

src/git/commit.js

+23-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import git from 'gulp-git';
22
import gulp from 'gulp';
33
import dedent from 'dedent';
4+
import {isString} from '../../common/util';
45

56
export { commit };
67

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

13+
var alreadyEnded = false;
14+
1215
// Get a gulp stream based off the config
1316
gulp.src(repoPath)
1417

1518
// Format then commit
1619
.pipe(git.commit(dedent(message), options))
17-
20+
21+
// Write progress to the screen
22+
.on('data',function(data) {
23+
if(!options.quiet) {
24+
if(isString(data))
25+
{
26+
process.stdout.write(data);
27+
}
28+
}
29+
})
30+
1831
// Handle commit success
1932
.on('end', function() {
20-
done();
33+
// TODO: Bug? Done is fired twice :(
34+
if(!alreadyEnded)
35+
{
36+
done();
37+
alreadyEnded=true;
38+
}
2139
})
2240

2341
// Handle commit failure
24-
.on('error', function (error) {
25-
console.error(error);
26-
done(error);
42+
.on('error', function (err) {
43+
console.error(err);
44+
done(err);
2745
});
2846

2947
}

test/tests/commit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('commit', function() {
6464

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

0 commit comments

Comments
 (0)