-
Notifications
You must be signed in to change notification settings - Fork 554
/
Copy pathcommitizen.js
85 lines (62 loc) · 2.67 KB
/
commitizen.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
81
82
83
84
85
import { init } from '../commitizen';
import { commitizen as commitizenParser } from './parsers';
let { parse } = commitizenParser;
export {
bootstrap
};
/**
* This is the main cli entry point.
* environment may be used for debugging.
*/
function bootstrap (environment = {}, argv = process.argv) {
// Get cli args
let rawGitArgs = argv.slice(2, argv.length);
// Parse the args
let parsedArgs = parse(rawGitArgs);
let command = parsedArgs._[0];
// Do actions based on commands
if (command === "init") {
let adapterNpmName = parsedArgs._[1];
if (adapterNpmName) {
console.log(`Attempting to initialize using the npm package ${adapterNpmName}`);
try {
init(process.cwd(), adapterNpmName, parsedArgs);
} catch (e) {
console.error(`Error: ${e}`);
}
} else {
console.error('Error: You must provide an adapter name as the second argument.');
}
} else {
console.log(`
Commitizen has two command line tools:
1) commitizen -- used for installing adapters into your project
2) git-cz -- used for making commits according to convention
note: you can run 'git cz' if installed with -g
Generally if you're using someone else's repo and they've already set up an
adapter, you're going to just be running:
git-cz
However, if you create a new repo and you want to make it easier for future
contributors to follow your commit message conventions using commitizen then
you'll need to run a command like this one to add this adapter to your config:
commitizen init cz-conventional-changelog --save
You should swap out cz-conventional-changelog for the NPM package name of the
adapter you wish you install in your project's package.json.
Detailed usage:
1) commitizen <sub-command>
init <adapter-npm-name> [args]
description: Install a commitizen adapter from npm and adds it to your
config.commitizen in your package.json file.
args:
--save Install the adapter to package.json dependencies
--save-dev Install the adapter to devDependencies
--save-exact Install an exact version instead of a range
--force Force install the adapter, even if a previous one exists.
2) git-cz <any regular git commit arguments>
description: Runs the commitizen prompter, asking you questions so that you
follow the commit conventions of the repository of the current
directory.
note: git-cz may even be run as 'git cz' if installed with -g.
`);
}
}