release-it
Advanced tools
Comparing version 2.8.0 to 2.8.2
@@ -46,2 +46,3 @@ { | ||
"preRelease": false, | ||
"draft": false, | ||
"tokenRef": "GITHUB_TOKEN" | ||
@@ -48,0 +49,0 @@ }, |
@@ -108,3 +108,3 @@ 'use strict'; | ||
mergedOptions.verbose = this.cliArguments['non-interactive'] || mergedOptions.verbose; | ||
mergedOptions.verbose = mergedOptions['non-interactive'] || mergedOptions.debug || mergedOptions.verbose; | ||
@@ -120,2 +120,6 @@ this.options = fixDeprecatedOptions(mergedOptions); | ||
setRuntimeOption(key, value) { | ||
if(this.isDebug) { | ||
value = key === 'github_token' ? '********' : value; | ||
console.log(`[debug] Setting runtime option "${key}" to`, value); | ||
} | ||
this.runtimeOptions[key] = value; | ||
@@ -122,0 +126,0 @@ } |
const util = require('./util'), | ||
config = require('./config'), | ||
inquirer = require('inquirer'), | ||
when = require('when'), | ||
sequence = require('when/sequence'); | ||
@@ -20,4 +19,4 @@ | ||
const version = config.getRuntimeOption('version'), | ||
noop = when.resolve(true); | ||
const version = config.getRuntimeOption('version'); | ||
const noop = Promise.resolve(); | ||
@@ -24,0 +23,0 @@ const prompts = { |
110
lib/git.js
@@ -5,4 +5,2 @@ const util = require('./util'), | ||
config = require('./config'), | ||
when = require('when'), | ||
sequence = require('when/sequence'), | ||
GitHubApi = require('github'), | ||
@@ -14,18 +12,18 @@ repoPathParse = require('parse-repo'), | ||
const noop = when.resolve(true), | ||
commitRefRe = /#.+$/; | ||
const noop = Promise.resolve(); | ||
const commitRefRe = /#.+$/; | ||
var _githubClient = null; | ||
function isGitRepo() { | ||
return run('!git', 'rev-parse --git-dir'); | ||
return run('!git rev-parse --git-dir', {isReadOnly: true}); | ||
} | ||
function tagExists(tag) { | ||
return run('!git', `show-ref --tags --quiet --verify -- "refs/tags/${tag}"`).then(() => true, () => false); | ||
return run(`!git show-ref --tags --quiet --verify -- "refs/tags/${tag}"`, {isReadOnly: true}).then(() => true, () => false); | ||
} | ||
function getRemoteUrl() { | ||
return run('!git', 'config --get remote.origin.url').then(result => { | ||
if(result && result.output) { | ||
return result.output.trim(); | ||
return run('!git config --get remote.origin.url', {isReadOnly: true}).then(stdout => { | ||
if(stdout) { | ||
return stdout.trim(); | ||
} | ||
@@ -37,3 +35,3 @@ throw new Error('Could not get remote Git url.'); | ||
function isWorkingDirClean(requireCleanWorkingDir) { | ||
return requireCleanWorkingDir ? run('!git', 'diff-index --name-only HEAD --exit-code').catch(() => { | ||
return requireCleanWorkingDir ? run('!git diff-index --name-only HEAD --exit-code', {isReadOnly: true}).catch(() => { | ||
throw new Error('Working dir must be clean.'); | ||
@@ -45,8 +43,6 @@ }) : noop; | ||
// Inverted: reject if run promise is resolved (i.e. `git diff-index` returns exit code 0) | ||
return when.promise(resolve => { | ||
run('!git', 'diff-index --name-only HEAD --exit-code').then(() => { | ||
if(!config.isDryRun) { | ||
config.setRuntimeOption(`${repo}_has_changes`, false); | ||
log.warn(`Nothing to commit in ${repo} repo. The latest commit will be tagged.`); | ||
} | ||
return new Promise(resolve => { | ||
run('!git diff-index --name-only HEAD --exit-code', {isReadOnly: true}).then(() => { | ||
config.setRuntimeOption(`${repo}_has_changes`, false); | ||
log.warn(`No changes in ${repo} repo.`); | ||
resolve(); | ||
@@ -58,9 +54,11 @@ }).catch(resolve); | ||
function clone(repo, dir) { | ||
const commitRef = repo.match(commitRefRe), | ||
branch = commitRef && commitRef[0] ? commitRef[0].replace(/^\#/, '') : 'master'; | ||
repo = repo.replace(commitRef, ''); | ||
return sequence([ | ||
run.bind(null, 'rm', '-rf', dir), | ||
run.bind(null, 'git', 'clone', repo, '-b', branch, '--single-branch', dir) | ||
]); | ||
const commitRef = repo.match(commitRefRe); | ||
const branch = commitRef && commitRef[0] ? commitRef[0].replace(/^\#/, '') : 'master'; | ||
const cleanRepo = repo.replace(commitRef, ''); | ||
return run(`rm -rf ${dir}`).then(() => { | ||
return run(`git clone ${cleanRepo} -b ${branch} --single-branch ${dir}`).catch(err => { | ||
log.error(`Unable to clone ${repo}`); | ||
throw new Error(err); | ||
}) | ||
}); | ||
} | ||
@@ -71,3 +69,3 @@ | ||
const files = typeof file === 'string' ? file : file.join(' '); | ||
return run('git', 'add', files).catch(err => { | ||
return run(`git add ${files}`).catch(err => { | ||
log.debug(err); | ||
@@ -83,12 +81,9 @@ log.warn(`Could not stage ${file}`); | ||
baseDir = baseDir || '.'; | ||
return run('git', util.format('add %s --all', baseDir)); | ||
return run(`git add ${baseDir} --all`); | ||
} | ||
function status() { | ||
return run( | ||
'!git', | ||
'status --short --untracked-files=no' | ||
).then(result => { | ||
return run('!git status --short --untracked-files=no', {isReadOnly: true}).then(stdout => { | ||
// Output also when not verbose | ||
!config.isVerbose && log.log(result.output); | ||
!config.isVerbose && log.log(stdout); | ||
}); | ||
@@ -98,11 +93,7 @@ } | ||
function commit(path, message, version) { | ||
return run( | ||
'git', | ||
'commit', | ||
config.isForce ? '--allow-empty' : '', | ||
`--message="${util.format(message, version)}"`, | ||
return run(`git commit ${config.isForce ? '--allow-empty ' : ''}--message="${util.format(message, version)}"`, | ||
path | ||
).catch(err => { | ||
log.debug(err); | ||
log.warn('Nothing to commit. The latest commit will be tagged.'); | ||
log.warn('No changes to commit. The latest commit will be tagged.'); | ||
}); | ||
@@ -112,10 +103,6 @@ } | ||
function tag(version, tag, annotation) { | ||
return run( | ||
'git', | ||
'tag', | ||
config.isForce ? '--force' : '', | ||
'--annotate', | ||
`--message="${util.format(annotation, version)}"`, | ||
util.format(tag, version) | ||
).then(() => { | ||
const force = config.isForce ? '--force ' : ''; | ||
const message = util.format(annotation, version); | ||
const formattedVersion = util.format(tag, version); | ||
return run(`git tag ${force}--annotate --message="${message}" ${formattedVersion}`).then(() => { | ||
config.setRuntimeOption('tag_set', true); | ||
@@ -128,4 +115,4 @@ }).catch(() => { | ||
function getLatestTag() { | ||
return run('!git', 'describe --tags --abbrev=0').then(result => { | ||
const latestTag = result && result.output ? result.output.trim() : null; | ||
return run('!git describe --tags --abbrev=0', {isReadOnly: true}).then(stdout => { | ||
const latestTag = stdout ? stdout.trim() : null; | ||
return latestTag; | ||
@@ -137,3 +124,3 @@ }); | ||
const repository = pushUrl || ''; | ||
return run('git', 'push', repository).catch(err => { | ||
return run(`git push ${repository}`).catch(err => { | ||
log.error('Please make sure an upstream remote repository is configured for the current branch. Example commands:\n' + | ||
@@ -148,9 +135,3 @@ `git remote add origin ${remoteUrl}\n` + | ||
const repository = pushUrl || ''; | ||
return run( | ||
'git', | ||
'push', | ||
'--follow-tags', | ||
config.isForce ? '--force' : '', | ||
repository | ||
).catch(() => { | ||
return run(`git push --follow-tags ${config.isForce ? '--force ' : ''}${repository}`).catch(() => { | ||
log.error(`Could not push tag(s). Does tag "${version}" already exist? Use --force to move a tag.`); | ||
@@ -190,5 +171,7 @@ }); | ||
function runChangelogCommand(command) { | ||
return run(command).then(result => { | ||
process.stdout.write('\n'); | ||
config.setRuntimeOption('changelog', result.output); | ||
return run(command, {isReadOnly: true}).then(stdout => { | ||
if(config.isVerbose) { | ||
process.stdout.write('\n'); | ||
} | ||
config.setRuntimeOption('changelog', stdout); | ||
return options; | ||
@@ -237,3 +220,4 @@ }); | ||
body: config.getRuntimeOption('changelog'), | ||
prerelease: options.github.preRelease | ||
prerelease: options.github.preRelease, | ||
draft: options.github.draft | ||
}, (err, response) => { | ||
@@ -247,4 +231,4 @@ if(err) { | ||
config.setRuntimeOption('githubReleaseId', response.data.id); | ||
log.execution('node-github releases#createRelease (success)', response.meta.location, response.data.tag_name, response.data.name); | ||
log.verbose(response); | ||
log.execution(`node-github releases#createRelease (success) ${response.meta.location} ${response.data.tag_name} "${response.data.name}"`); | ||
log.debug(response); | ||
resolve(); | ||
@@ -275,3 +259,3 @@ } | ||
log.execution('node-github releases#uploadAsset (success)', response.data.browser_download_url); | ||
log.verbose(response); | ||
log.debug(response); | ||
resolve(); | ||
@@ -289,2 +273,6 @@ }); | ||
return new Promise((resolve, reject) => { | ||
if (Object.prototype.toString.call(assets) === '[object Array]') { | ||
assets = `{${assets.join(',')}}`; | ||
} | ||
glob(assets, function (err, files) { | ||
@@ -291,0 +279,0 @@ if(err) return reject(err); |
@@ -46,3 +46,3 @@ const fs = require('graceful-fs'), // Contains fix for the EMFILE (too many open files) issue | ||
function copyAsync(source, target) { | ||
return mkdirAsync(path.dirname(target)).then(() => when.promise((resolve, reject) => { | ||
return mkdirAsync(path.dirname(target)).then(() => new Promise((resolve, reject) => { | ||
const is = fs.createReadStream(source), | ||
@@ -49,0 +49,0 @@ os = fs.createWriteStream(target); |
/* eslint-disable no-console */ | ||
const util = require('util'), | ||
_ = require('lodash'), | ||
chalk = require('chalk'), | ||
@@ -31,3 +32,3 @@ config = require('./config'); | ||
if(config.isVerbose) { | ||
log.apply(null, arguments); | ||
log.apply(null, [].concat.apply(['[verbose]'], arguments)); | ||
} | ||
@@ -44,3 +45,4 @@ } | ||
if(config.isDebug) { | ||
log.apply(null, arguments); | ||
const args = _.toArray(arguments); | ||
log.apply(null, ['[debug]'].concat(args)); | ||
} | ||
@@ -56,4 +58,6 @@ } | ||
function execution() { | ||
const args = [].concat.apply([!config.isDryRun ? '[execute]' : '[dry-run]'], arguments); | ||
verbose.apply(this, args); | ||
const args = _.toArray(arguments); | ||
if(config.isVerbose && args.join('').length) { | ||
log.apply(null, [!config.isDryRun ? '[execute]' : '[dry-run]'].concat(args)); | ||
} | ||
} | ||
@@ -60,0 +64,0 @@ |
@@ -5,4 +5,3 @@ const cli = require('./cli'), | ||
tasks = require('./tasks'), | ||
when = require('when'), | ||
noop = when.resolve(true); | ||
noop = Promise.resolve(); | ||
@@ -42,3 +41,3 @@ function fromCli(args) { | ||
if(config.isDebug) { | ||
throw error; | ||
throw new Error(error); | ||
} | ||
@@ -45,0 +44,0 @@ |
@@ -9,51 +9,41 @@ const path = require('path'), | ||
when = require('when'), | ||
sequence = require('when/sequence'), | ||
fn = require('when/node'), | ||
noop = when.resolve(true); | ||
noop = Promise.resolve(); | ||
const forcedCmdRe = /^!/; | ||
function run(command, commandArgs) { // eslint-disable-line no-unused-vars | ||
function run(command, options) { // eslint-disable-line no-unused-vars | ||
const shellCommand = getShellCommand(command.replace(forcedCmdRe, '')), | ||
cmd = [].slice.call(arguments).join(' '), | ||
normalizedCmd = cmd.replace(forcedCmdRe, ''), | ||
args = [].slice.call(arguments, 1), | ||
silentState = shell.config.silent; | ||
options = options || {}; | ||
shell.config.silent = !config.isVerbose; | ||
const normalizedCmd = command.replace(forcedCmdRe, ''); | ||
const program = normalizedCmd.split(' ')[0]; | ||
const programArgs = normalizedCmd.split(' ').slice(1); | ||
const isSilent = shell.config.silent; | ||
log.execution(normalizedCmd); | ||
if(normalizedCmd === cmd && config.isDryRun) { | ||
if(config.isDryRun && !options.isReadOnly) { | ||
return noop; | ||
} | ||
return when.promise((resolve, reject) => { | ||
return new Promise((resolve, reject) => { | ||
if(shellCommand === 'exec') { | ||
const cb = (code, stdout, stderr) => { | ||
log.debug({command, options, code, stdout: stdout.toString(), stderr}); | ||
shell.config.silent = isSilent; | ||
if(code === 0) { | ||
resolve(stdout); | ||
} else { | ||
reject(stderr); | ||
} | ||
}; | ||
shell.exec(normalizedCmd, (code, output, stderr) => { | ||
if(code === 0) { | ||
resolve({ | ||
code, | ||
output | ||
}); | ||
} else { | ||
reject(stderr); | ||
} | ||
}); | ||
} else if(shellCommand) { | ||
resolve(shell[shellCommand].apply(shell, args)); | ||
if(program in shell && typeof shell[program] === 'function') { | ||
shell.config.silent = !config.isVerbose; | ||
cb(0, shell[program].apply(shell, programArgs)); | ||
} else { | ||
resolve(command.apply(null, args)); | ||
shell.exec(normalizedCmd, {async: true, silent: !config.isVerbose}, cb); | ||
} | ||
shell.config.silent = silentState; | ||
}); | ||
@@ -67,19 +57,12 @@ | ||
function getShellCommand(command) { | ||
return command && command in shell && typeof shell[command] === 'function' ? command : 'exec'; | ||
} | ||
function pushd(path) { | ||
return run('pushd', path); | ||
return run(`pushd ${path}`, {isReadOnly: true}); | ||
} | ||
function popd() { | ||
return run('popd'); | ||
return run('popd', {isReadOnly: true}); | ||
} | ||
function mkCleanDir(dir) { | ||
return sequence([ | ||
run.bind(null, 'rm', '-rf', dir), | ||
run.bind(null, 'mkdir', '-p', dir) | ||
]); | ||
return run(`rm -rf ${dir}`).then(() => run(`mkdir -p ${dir}`)); | ||
} | ||
@@ -95,3 +78,3 @@ | ||
const publishPath = path || '.'; | ||
return run('npm', 'publish', publishPath, '--tag', tag); | ||
return run(`npm publish ${publishPath} --tag ${tag}`); | ||
} | ||
@@ -98,0 +81,0 @@ |
@@ -6,7 +6,6 @@ const _ = require('lodash'), | ||
enquiry = require('./enquiry'), | ||
when = require('when'), | ||
util = require('./util'), | ||
config = require('./config'), | ||
sequence = require('when/sequence'), | ||
noop = when.resolve.bind(when, true); | ||
noop = () => Promise.resolve(); | ||
@@ -43,5 +42,2 @@ function parseVersion() { | ||
config.setRuntimeOption('remoteUrl', remoteUrl); | ||
}).catch(err => { | ||
log.debug(err); | ||
throw new Error('Unable to get remote Git url.') | ||
}); | ||
@@ -108,2 +104,3 @@ } | ||
repo.release, | ||
repo.uploadAssets, | ||
repo.publish | ||
@@ -130,3 +127,3 @@ ) | ||
if(!options.dist.repo) { | ||
log.verbose('No distRepo provided, done.'); | ||
log.verbose('No "dist.repo" configuration provided, done.'); | ||
return noop(); | ||
@@ -133,0 +130,0 @@ } |
{ | ||
"name": "release-it", | ||
"version": "2.8.0", | ||
"version": "2.8.2", | ||
"description": "Interactive release tool for Git repositories. Increment version, commit, tag, push, build, publish to npm. Supports to build and release to a distribution/component repository.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -143,2 +143,3 @@ # Release It! | ||
"preRelease": false, | ||
"draft": false, | ||
"tokenRef": "GITHUB_TOKEN" | ||
@@ -145,0 +146,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47983
279
1134