Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
{
"extends": "standard",
"rules": {
"brace-style": 0,
"comma-dangle": 0,
"indent": 0,
"operator-linebreak": 0,
"padded-blocks": 0,
"quotes": 0,
"semi": 0
}
"extends": "standard"
}
2 changes: 1 addition & 1 deletion bin/commitizen.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

require('../dist/cli/commitizen.js').bootstrap();
require('../dist/cli/commitizen.js').bootstrap()
8 changes: 4 additions & 4 deletions bin/git-cz.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var path = require('path');
var path = require('path')

process.on('uncaughtException', function (err) {
console.error(err.message || err);
process.exit(1);
console.error(err.message || err)
process.exit(1)
})

require('../dist/cli/git-cz.js').bootstrap({
cliPath: path.join(__dirname, '../')
});
})
32 changes: 15 additions & 17 deletions src/cli/commitizen.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
import { init } from '../commitizen';
import { commitizen as commitizenParser } from './parsers';
import * as sh from 'shelljs';
import { init } from '../commitizen'
import { commitizen as commitizenParser } from './parsers'
import * as sh from 'shelljs'

let { parse } = commitizenParser;
let { parse } = commitizenParser

export {
bootstrap
};
}

/**
* This is the main cli entry point.
* environment may be used for debugging.
*/
function bootstrap (environment = {}) {

// Get cli args
let rawGitArgs = process.argv.slice(2, process.argv.length);
let rawGitArgs = process.argv.slice(2, process.argv.length)

// Parse the args
let parsedArgs = parse(rawGitArgs);
let command = parsedArgs._[0];
let parsedArgs = parse(rawGitArgs)
let command = parsedArgs._[0]

// Do actions based on commands
if (command === "init") {
let adapterNpmName = parsedArgs._[1];
if (command === 'init') {
let adapterNpmName = parsedArgs._[1]
if (adapterNpmName) {
console.log(`Attempting to initialize using the npm package ${adapterNpmName}`);
console.log(`Attempting to initialize using the npm package ${adapterNpmName}`)
try {
init(sh, process.cwd(), adapterNpmName, parsedArgs);
init(sh, process.cwd(), adapterNpmName, parsedArgs)
} catch (e) {
console.error(`Error: ${e}`);
console.error(`Error: ${e}`)
}
} else {
console.error('Error: You must provide an adapter name as the second argument.');
console.error('Error: You must provide an adapter name as the second argument.')
}
} else {
console.log(`
Expand Down Expand Up @@ -80,7 +79,6 @@ function bootstrap (environment = {}) {

note: git-cz may even be run as 'git cz' if installed with -g.

`);
`)
}

}
15 changes: 7 additions & 8 deletions src/cli/git-cz.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import { configLoader } from '../commitizen';
import { git as useGitStrategy, gitCz as useGitCzStrategy } from './strategies';
import { configLoader } from '../commitizen'
import { git as useGitStrategy, gitCz as useGitCzStrategy } from './strategies'

export {
bootstrap
};
}

/**
* This is the main cli entry point.
* environment may be used for debugging.
*/
function bootstrap (environment = {}) {

// Get cli args
let rawGitArgs = process.argv.slice(2, process.argv.length);
let rawGitArgs = process.argv.slice(2, process.argv.length)

let adapterConfig = environment.config || configLoader.load();
let adapterConfig = environment.config || configLoader.load()

// Choose a strategy based on the existance the adapter config
if (typeof adapterConfig !== 'undefined') {
// This tells commitizen we're in business
useGitCzStrategy(rawGitArgs, environment, adapterConfig);
useGitCzStrategy(rawGitArgs, environment, adapterConfig)
} else {
// This tells commitizen that it is not needed, just use git
useGitStrategy(rawGitArgs, environment);
useGitStrategy(rawGitArgs, environment)
}
}
6 changes: 3 additions & 3 deletions src/cli/parsers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as commitizen from './parsers/commitizen';
import * as gitCz from './parsers/git-cz';
import * as commitizen from './parsers/commitizen'
import * as gitCz from './parsers/git-cz'

export {
commitizen,
gitCz
};
}
13 changes: 6 additions & 7 deletions src/cli/parsers/commitizen.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import minimist from 'minimist';
import minimist from 'minimist'

export {
parse
};
}

/**
* Takes args, parses with minimist and some ugly vudoo, returns output
*
* TODO: Aww shit this is ugly. Rewrite with mega leet tests plz, kthnx.
*/
function parse (rawGitArgs) {
var args = minimist(rawGitArgs, {
boolean: true
})

var args = minimist(rawGitArgs, {
boolean: true
});

return args;
return args
}
34 changes: 17 additions & 17 deletions src/cli/parsers/git-cz.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
export {
parse
};
}

const reShortMessage = /^-([a-zA-Z]*)m(.*)$/;
const reLongMessage = /^--message(=.*)?$/;
const reShortMessage = /^-([a-zA-Z]*)m(.*)$/
const reLongMessage = /^--message(=.*)?$/

/**
* Strip message declaration from git arguments
*/
function parse (rawGitArgs) {
let result = [];
let skipNext = false;
let result = []
let skipNext = false

for (const arg of rawGitArgs) {
let match;
let match

if (skipNext) {
skipNext = false;
continue;
skipNext = false
continue
}

match = reShortMessage.exec(arg);
match = reShortMessage.exec(arg)

if (match) {
if (match[1]) {
result.push(`-${match[1]}`);
result.push(`-${match[1]}`)
}

if (!match[2]) {
skipNext = true;
skipNext = true
}

continue;
continue
}

match = reLongMessage.exec(arg);
match = reLongMessage.exec(arg)

if (match) {
if (!match[1]) {
skipNext = true;
skipNext = true
}

continue;
continue
}

result.push(arg);
result.push(arg)
}

return result;
return result
}
6 changes: 3 additions & 3 deletions src/cli/strategies.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import git from './strategies/git';
import gitCz from './strategies/git-cz';
import git from './strategies/git'
import gitCz from './strategies/git-cz'

export {
git,
gitCz
};
}
56 changes: 27 additions & 29 deletions src/cli/strategies/git-cz.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,56 @@
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 * as gitStrategy from './git';
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 * as gitStrategy from './git'

// destructure for shorter apis
let { parse } = gitCzParser;
let { parse } = gitCzParser

let { getPrompter, resolveAdapterPath } = adapter;
let { isClean } = staging;
let { getPrompter, resolveAdapterPath } = adapter
let { isClean } = staging

export default gitCz;
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);
let parsedCommitizenArgs = commitizenParser.parse(rawGitArgs)

if (parsedCommitizenArgs.amend) {
// console.log('override --amend in place');
gitStrategy.default(rawGitArgs, environment);
return;
gitStrategy.default(rawGitArgs, environment)
return
}

// Now, if we've made it past overrides, proceed with the git-cz strategy
let parsedGitCzArgs = parse(rawGitArgs);
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 retryLastCommit = rawGitArgs && rawGitArgs[0] === '--retry'

let resolvedAdapterConfigPath = resolveAdapterPath(adapterConfig.path);
let resolvedAdapterRootPath = findRoot(resolvedAdapterConfigPath);
let prompter = getPrompter(adapterConfig.path);
let resolvedAdapterConfigPath = resolveAdapterPath(adapterConfig.path)
let resolvedAdapterRootPath = findRoot(resolvedAdapterConfigPath)
let prompter = getPrompter(adapterConfig.path)

isClean(process.cwd(), function (error, stagingIsClean) {
if (error) {
throw error;
throw error
}

if (stagingIsClean && !parsedGitCzArgs.includes('--allow-empty')) {
throw new Error('No files added to staging! Did you forget to run git add?');
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`);
let adapterPackageJson = getParsedPackageJsonFromPath(resolvedAdapterRootPath)
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,
Expand All @@ -60,9 +59,8 @@ function gitCz (rawGitArgs, environment, adapterConfig) {
retryLastCommit
}, function (error) {
if (error) {
throw error;
throw error
}
});
});

})
})
}
16 changes: 8 additions & 8 deletions src/cli/strategies/git.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import childProcess from 'child_process';
import childProcess from 'child_process'

export default git;
export default git

// We don't have a config, so either we use raw args to try to commit
// or if debug is enabled then we do a strict check for a config file.
function git (rawGitArgs, environment) {
if (environment.debug === true) {
console.error('COMMITIZEN DEBUG: No git-cz friendly config was detected. I looked for .czrc, .cz.json, or czConfig in package.json.');
console.error('COMMITIZEN DEBUG: No git-cz friendly config was detected. I looked for .czrc, .cz.json, or czConfig in package.json.')
} else {
var vanillaGitArgs = ["commit"].concat(rawGitArgs);
var vanillaGitArgs = ['commit'].concat(rawGitArgs)

var child = childProcess.spawn('git', vanillaGitArgs, {
stdio: 'inherit'
});
})

child.on('error', function (e, code) {
console.error(e);
throw e;
});
console.error(e)
throw e
})
}
}
14 changes: 7 additions & 7 deletions src/commitizen.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as adapter from './commitizen/adapter';
import * as cache from './commitizen/cache';
import commit from './commitizen/commit';
import * as configLoader from './commitizen/configLoader';
import init from './commitizen/init';
import * as staging from './commitizen/staging';
import * as adapter from './commitizen/adapter'
import * as cache from './commitizen/cache'
import commit from './commitizen/commit'
import * as configLoader from './commitizen/configLoader'
import init from './commitizen/init'
import * as staging from './commitizen/staging'

export {
adapter,
Expand All @@ -12,4 +12,4 @@ export {
configLoader,
init,
staging
};
}
Loading