Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' into feat/no-emoji
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed May 16, 2020
2 parents 52a43d9 + 38f3b04 commit 8debcfe
Show file tree
Hide file tree
Showing 6 changed files with 291 additions and 136 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## [4.3.1](https://github.com/streamich/git-cz/compare/v4.3.0...v4.3.1) (2020-02-03)


### Bug Fixes

* 🐛 fix git commit error ([b116ba0](https://github.com/streamich/git-cz/commit/b116ba0ed4206a173dfb63206ddf7c058e2046ba))

# [4.3.0](https://github.com/streamich/git-cz/compare/v4.2.0...v4.3.0) (2020-02-02)


### Features

* 🎸 add help & version flags ([799fff2](https://github.com/streamich/git-cz/commit/799fff2d9da4ec04ad7ee85b01172a038020ae89))
* 🎸 improve help screen ([1838c1c](https://github.com/streamich/git-cz/commit/1838c1c5cb96d37b116234bb1ebe06721035ca46))

# [4.2.0](https://github.com/streamich/git-cz/compare/v4.1.0...v4.2.0) (2020-01-20)


Expand Down
52 changes: 15 additions & 37 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const {spawn} = require('child_process');
const fs = require('fs');
const {join} = require('path');
const shellescape = require('any-shell-escape');
const minimist = require('minimist');
const signale = require('signale');
const parseArgs = require('./parseArgs');
const createState = require('./createState');
const runInteractiveQuestions = require('./runInteractiveQuestions');
const runNonInteractiveMode = require('./runNonInteractiveMode');
Expand All @@ -27,45 +27,18 @@ const executeCommand = (command, args = [], env = process.env) => {

const main = async () => {
try {
const {_: args, ...params} = minimist(process.argv.slice(2));
const state = createState();

for (const arg of args) {
params[arg] = true;
}
const {cliAnswers, cliOptions, passThroughParams} = parseArgs();

const {
'dry-run': isDryRun,
'non-interactive': isNonInteractiveMode,
'disable-emoji': disableEmoji,
hook: isHook,
body,
breaking,
issues,
lerna,
scope,
subject,
type,
...passThroughParams
} = params;

const cliAnswers = {
body,
breaking,
issues,
lerna,
scope,
subject,
type
};

if (isDryRun) {
if (cliOptions.dryRun) {
// eslint-disable-next-line no-console
console.log('Running in dry mode.');
}

const state = createState({disableEmoji});
const state = createState({disableEmoji: cliOptions['disable-emoji']});

if (isNonInteractiveMode) {
if (cliOptions.nonInteractive) {
await runNonInteractiveMode(state, cliAnswers);
} else {
await runInteractiveQuestions(state, cliAnswers);
Expand All @@ -77,7 +50,7 @@ const main = async () => {
* @author https://github.com/oxyii
* @see https://github.com/streamich/git-cz/issues/79
*/
if (isHook) {
if (cliOptions.hook) {
const commitMsgFile = join(getGitRootDir(), '.git', 'COMMIT_EDITMSG');

fs.writeFileSync(commitMsgFile, message);
Expand All @@ -89,7 +62,7 @@ const main = async () => {

// eslint-disable-next-line guard-for-in
for (const key in passThroughParams) {
const value = params[key];
const value = passThroughParams[key];

if (key.length === 1) {
appendedArgs.push('-' + key);
Expand All @@ -102,9 +75,14 @@ const main = async () => {
}
}

const executeCommandArgs = ['commit', '--message', message, ...appendedArgs];
const executeCommandArgs = [
'commit',
'--message',
message,
...appendedArgs
];

if (isDryRun) {
if (cliOptions.dryRun) {
const command = shellescape(['git', ...executeCommandArgs]);

// eslint-disable-next-line no-console
Expand Down
90 changes: 90 additions & 0 deletions lib/parseArgs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* eslint-disable no-process-exit */
/* eslint-disable no-console */
/* eslint-disable id-length */
const minimist = require('minimist');
const pkg = require('../package.json');

const helpScreen = `
${pkg.description}
Usage: git-cz [options]
options:
-h, --help show usage information
-v, --version print version info and exit
--non-interactive run git-cz in non-interactive mode
non-interactive mode options:
--type type of the commit, defaults to "chore"
--subject message of the commit, defaults to "automated commit"
--scope semantic commit scope
--body extended description of the commit
--breaking description of breaking changes, if any
--issues GitHub issues this commit closed, e.g "#123"
--lerna Lerna mono-repo packages this commit affects
`;

const parseArgs = () => {
const {
// eslint-disable-next-line no-unused-vars
_: inputs,
'dry-run': dryRun,
hook,
'non-interactive': nonInteractive,
body,
breaking,
issues,
lerna,
scope,
subject,
type,
help,
h,
version,
v,
...passThroughParams
} = minimist(process.argv.slice(2), {
alias: {
h: 'help',
v: 'version'
},
boolean: ['version', 'help', 'non-interactive', 'hook', 'dry-run'],
string: ['type', 'subject', 'scope', 'body', 'breaking', 'issues', 'learna']
});

if (help || h) {
console.log(helpScreen);
process.exit();
}

if (version || v) {
console.log(pkg.version);
process.exit();
}

const cliOptions = {
dryRun,
help,
hook,
nonInteractive,
version
};

const cliAnswers = {
body,
breaking,
issues,
lerna,
scope,
subject,
type
};

return {
cliAnswers,
cliOptions,
passThroughParams
};
};

module.exports = parseArgs;
2 changes: 1 addition & 1 deletion lib/util/getGitRootDir.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {execSync} = require('child_process');

const getGitRootDir = () => {
const devNull = process.platform === 'win32' ? ' nul' : '/dev/null'
const devNull = process.platform === 'win32' ? ' nul' : '/dev/null';
const dir = execSync('git rev-parse --show-toplevel 2>' + devNull)
.toString()
.trim();
Expand Down
21 changes: 9 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@
"eslint": "eslint lib/*.js"
},
"devDependencies": {
"semantic-release": "15.14.0",
"@semantic-release/changelog": "3.0.6",
"@semantic-release/git": "8.0.0",
"any-shell-escape": "0.1.1",
"browserify": "16.5.0",
"browserify": "16.5.1",
"chai": "4.2.0",
"chalk": "2.4.2",
"commitizen": "2.10.1",
"eslint": "4.19.1",
"eslint-config-mailonline": "9.0.0",
"eslint-config-mailonline": "9.0.1",
"fuzzy": "0.1.3",
"husky": "4.2.0",
"global": "4.4.0",
"husky": "4.2.5",
"inquirer": "6.5.2",
"inquirer-list-search-prompt": "1.0.2",
"minimist": "1.2.0",
"mocha": "6.2.2",
"pkg": "4.4.2",
"rimraf": "3.0.0",
"semantic-release": "16.0.3",
"minimist": "1.2.5",
"mocha": "6.2.3",
"pkg": "4.4.8",
"rimraf": "3.0.2",
"semantic-release": "16.0.4",
"signale": "1.4.0",
"word-wrap": "1.2.3"
},
Expand All @@ -65,9 +65,6 @@
"scripts": "./build/readme.js",
"backup": false
},
"dependencies": {
"global": "^4.3.2"
},
"release": {
"verifyConditions": [
"@semantic-release/changelog",
Expand Down
Loading

0 comments on commit 8debcfe

Please sign in to comment.