-
Notifications
You must be signed in to change notification settings - Fork 554
/
Copy pathgit-cz.js
80 lines (65 loc) · 2.61 KB
/
git-cz.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import fs from 'fs';
import path from 'path';
import sh from 'shelljs';
import inquirer from 'inquirer';
import findRoot from 'find-root';
import {getParsedPackageJsonFromPath} from '../../common/util';
import {gitCz as gitCzParser, commitizen as commitizenParser} from '../parsers';
import {commit, staging, adapter} from '../../commitizen';
import {addPath} from '../../git';
import * as gitStrategy from './git';
// destructure for shorter apis
let { parse } = gitCzParser;
let { getPrompter, resolveAdapterPath } = adapter;
let { isClean } = staging;
export default gitCz;
function gitCz (rawGitArgs, environment, adapterConfig) {
// See if any override conditions exist.
// In these very specific scenarios we may want to use a different
// commit strategy than git-cz. For example, in the case of --amend
let parsedCommitizenArgs = commitizenParser.parse(rawGitArgs);
if (parsedCommitizenArgs.a) {
// console.log('override -a in place');
addPath(sh, process.cwd());
}
if (parsedCommitizenArgs.amend) {
// console.log('override --amend in place');
gitStrategy.default(rawGitArgs, environment);
return;
}
// Now, if we've made it past overrides, proceed with the git-cz strategy
let parsedGitCzArgs = parse(rawGitArgs);
// Determine if we need to process this commit as a retry instead of a
// normal commit.
let retryLastCommit = rawGitArgs && rawGitArgs[0] === '--retry';
let resolvedAdapterConfigPath = resolveAdapterPath(adapterConfig.path);
let resolvedAdapterRootPath = findRoot(resolvedAdapterConfigPath);
let prompter = getPrompter(adapterConfig.path);
isClean(process.cwd(), function (error, stagingIsClean) {
if (error) {
throw error;
}
if (stagingIsClean) {
throw new Error('No files added to staging! Did you forget to run git add?');
}
// OH GOD IM SORRY FOR THIS SECTION
let adapterPackageJson = getParsedPackageJsonFromPath(resolvedAdapterRootPath);
let cliPackageJson = getParsedPackageJsonFromPath(environment.cliPath);
console.log(`cz-cli@${cliPackageJson.version}, ${adapterPackageJson.name}@${adapterPackageJson.version}\n`);
commit(inquirer, process.cwd(), prompter, {
args: parsedGitCzArgs,
disableAppendPaths: true,
emitData: true,
quiet: false,
retryLastCommit
}).catch(function (error) {
//
// Throw in next tick to use Node.js built in error handling
//
// FIXME: This should probably be refactored so that this
// function returns a rejected promise instead...
//
process.nextTick(function () { throw error; });
});
});
}