Skip to content

Commit

Permalink
Merge pull request #57 from aaarichter/dependency-updates
Browse files Browse the repository at this point in the history
refactor: drop Node 6/8 support & upgrade dependencies
  • Loading branch information
aaarichter authored Feb 5, 2020
2 parents 29c7a05 + 239ae9a commit a9dd920
Show file tree
Hide file tree
Showing 42 changed files with 1,768 additions and 1,083 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "groupon/node6"
"extends": "groupon"
}
11 changes: 4 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
language: node_js
node_js:
- 6.14.3
- 8.11.3
- 10.5.0
- '10'
- '12'
deploy:
- provider: script
script: ./bin/nlm.js release
script: npx nlm release
skip_cleanup: true
'on':
branch: master
node: 10.5.0
before_install:
- npm i -g npm@^6
node: '12'
2 changes: 2 additions & 0 deletions bin/nlm.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

'use strict';

require('../lib/cli.js');
20 changes: 13 additions & 7 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,21 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/*eslint no-process-exit: "off"*/

'use strict';

const path = require('path');

const minimist = require('minimist');

const rc = require('rc');

const COMMANDS = {
changelog: require('./commands/changelog'),
release: require('./commands/release'),
verify: require('./commands/verify'),
};

const USAGE = [
'Usage: nlm changelog # Preview the changelog for the next release',
' nlm release # Create a release, push to github & npm',
Expand All @@ -56,7 +58,6 @@ const USAGE = [
' -v, --version Print nlm version',
' -h, --help Print usage information',
].join('\n');

const argv = rc(
'nlm',
{
Expand All @@ -67,7 +68,11 @@ const argv = rc(
minimist(process.argv.slice(2), {
boolean: ['help', 'version', 'yes', 'commit'],
string: ['pr'],
alias: { help: 'h', version: 'v', yes: 'y' },
alias: {
help: 'h',
version: 'v',
yes: 'y',
},
default: {
yes: !!process.env.CI || !process.stdout.isTTY,
commit: !!process.env.CI,
Expand All @@ -82,6 +87,7 @@ function prettyPrintErrorAndExit(error) {
if (error.body && error.statusCode) {
console.error('Response %j: %j', error.statusCode, error.body);
}

const errorMessage = error.message.split('\n').join('\n! ');
console.error(`\n!\n! ${errorMessage}\n!\n! NOT OK`);
process.exit(1);
Expand All @@ -95,10 +101,10 @@ if (argv.version) {
process.exit(argv.help ? 0 : 1);
} else {
const cwd = process.cwd();
const packageJsonFile = path.join(cwd, 'package.json');
const packageJsonFile = path.join(cwd, 'package.json'); // eslint-disable-next-line import/no-dynamic-require

// eslint-disable-next-line import/no-dynamic-require
const pkg = require(packageJsonFile);
command(cwd, pkg, Object.assign({}, argv, pkg.nlm)).catch(
prettyPrintErrorAndExit
);

command(cwd, pkg, { ...argv, ...pkg.nlm }).catch(prettyPrintErrorAndExit);
}
11 changes: 6 additions & 5 deletions lib/commands/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@

'use strict';

const co = require('co');

const ensureTag = require('../git/ensure-tag');

const getPendingChanges = require('../steps/pending-changes');

const generateChangeLog = require('../steps/changelog');

const showChangelog = co.wrap(function*(cwd, pkg, options) {
async function showChangelog(cwd, pkg, options) {
function ensureVersionTag() {
return ensureTag(cwd, `v${pkg.version}`);
}
Expand All @@ -53,8 +53,9 @@ const showChangelog = co.wrap(function*(cwd, pkg, options) {

const tasks = [ensureVersionTag, getPendingChanges, generateChangeLog];

for (const task of tasks) yield Promise.resolve(runTask(task));
for (const task of tasks) await runTask(task);

return printChangelog();
});
}

module.exports = showChangelog;
19 changes: 15 additions & 4 deletions lib/commands/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,19 @@
'use strict';

const debug = require('debug')('nlm:command:release');

const semver = require('semver');
const co = require('co');

const generateChangeLog = require('../steps/changelog');

const createVersionCommit = require('../steps/version-commit');

const pushReleaseToRemote = require('../steps/push-to-remote');

const createGithubRelease = require('../steps/github-release');

const publishToNpm = require('../steps/publish-to-npm');

const executePrepareHookCommand = require('../steps/execute-prepare-hook-command');

const runVerify = require('./verify');
Expand All @@ -49,9 +54,11 @@ function bumpVersion(version, type) {
if (type === 'none') {
throw new Error('Cannot publish without changes');
}

if (/^0\./.test(version)) {
return '1.0.0';
}

return semver.inc(version, type);
}

Expand Down Expand Up @@ -81,31 +88,35 @@ function release(cwd, pkg, options) {
return task(cwd, pkg, options);
}

const runPublishTasks = co.wrap(function*() {
async function runPublishTasks() {
if (options.pr) {
debug('Never publishing from a PR');
return null;
}

if (!options.commit) {
debug('Skipping publish');
return null;
}

if (!options.distTag) {
debug('Skipping publish, no dist-tag');
return null;
}

if (options.releaseType === 'none') {
debug('No changes; just verifying NPM publish');
publishTasks = [publishToNpm];
}

for (const task of publishTasks) yield Promise.resolve(runTask(task));
for (const task of publishTasks) await runTask(task);

return null;
});
}

return runVerify(cwd, pkg, options).then(
options.commit ? runPublishTasks : () => {}
);
}

module.exports = release;
19 changes: 14 additions & 5 deletions lib/commands/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,21 @@
'use strict';

const fs = require('fs');
const path = require('path');

const co = require('co');
const path = require('path');

const addLicenseHeaders = require('../license');

const verifyClean = require('../git/verify-clean');

const ensureTag = require('../git/ensure-tag');

const determineReleaseInfo = require('../steps/release-info');

const tagPullRequest = require('../steps/tag-pr');

const getPendingChanges = require('../steps/pending-changes');

const detectBranch = require('../steps/detect-branch');

function verifyLicenseHeaders(cwd, pkg, options) {
Expand All @@ -55,13 +58,17 @@ function verifyLicenseHeaders(cwd, pkg, options) {

function getPullRequestId() {
const travisId = process.env.TRAVIS_PULL_REQUEST;

if (travisId && travisId !== 'false') {
return travisId;
}

const dotciId = process.env.DOTCI_PULL_REQUEST;

if (dotciId && dotciId !== 'false') {
return dotciId;
}

return '';
}

Expand All @@ -72,6 +79,7 @@ function verify(cwd, pkg, options) {
if (err.code === 'ENOENT') {
return Promise.resolve();
}

throw err;
}

Expand Down Expand Up @@ -105,10 +113,11 @@ function verify(cwd, pkg, options) {
return task(cwd, pkg, options);
}

const runVerifyTasks = co.wrap(function*() {
for (const task of verifyTasks) yield Promise.resolve(runTask(task));
});
async function runVerifyTasks() {
for (const task of verifyTasks) await runTask(task);
}

return runVerifyTasks();
}

module.exports = verify;
13 changes: 10 additions & 3 deletions lib/git/commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'use strict';

const commitParser = require('conventional-commits-parser');

const debug = require('debug')('nlm:git:commits');

const run = require('../run');
Expand All @@ -48,33 +49,36 @@ function parseCommit(commit) {
.trim()
.split(' ');
const message = commit.slice(metaEndIdx + 1);

const sha = meta.shift();
const parentSha = meta.shift() || null;

const data = commitParser.sync(message, {
issuePrefixes: ['#', 'https?://[\\w\\.-/]*[-/]+'],
});
const prMatch = message.match(PR_MERGE_PATTERN);

if (prMatch) {
const prId = prMatch[1];
data.type = 'pr';
data.pullId = prId;
const mergeRef = data.references.find(ref => {
return ref.issue === prId;
});

if (!mergeRef) {
throw new Error(`Couldn't find reference to merge of PR #${prId}`);
}

Object.assign(mergeRef, {
action: 'Merges',
owner: prMatch[2],
});

if (!mergeRef.repository) {
mergeRef.repository = null;
}
}
return Object.assign({}, data, { sha: sha || data.sha, parentSha });

return { ...data, sha: sha || data.sha, parentSha };
}

function isNotRandomMerge(commit) {
Expand All @@ -98,13 +102,15 @@ function gracefulEmptyState(error) {
debug('Assuming this was executed before the first commit was made');
return [];
}

throw error;
}

function createRange(fromRevision) {
if (fromRevision && fromRevision !== 'v0.0.0') {
return `${fromRevision}..HEAD`;
}

return [];
}

Expand All @@ -119,4 +125,5 @@ function getCommits(directory, fromRevision) {
}
).then(parseLogOutput, gracefulEmptyState);
}

module.exports = getCommits;
1 change: 1 addition & 0 deletions lib/git/current-branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ function getCurrentBranch(directory) {
cwd: directory,
}).then(s => s.trim());
}

module.exports = getCurrentBranch;
8 changes: 6 additions & 2 deletions lib/git/ensure-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
'use strict';

const path = require('path');

const fs = require('fs');

const run = require('../run');

function fetchTag(cwd, tag) {
return run('git', ['fetch', 'origin', 'tag', tag], { cwd: cwd });
return run('git', ['fetch', 'origin', 'tag', tag], { cwd });
}

/**
* Ensure that a tag was fetched from the remote
*
Expand All @@ -49,20 +49,24 @@ function fetchTag(cwd, tag) {
* This checks if a tag exists locally. If it doesn't, it will
* fetch the tag from `origin`.
*/

function ensureTag(cwd, tag) {
if (tag === 'v0.0.0') {
// There is no such thing (most likely)
return null;
}

const tagFile = path.join(cwd, '.git', 'refs', 'tags', tag);

try {
return fs.readFileSync(tagFile);
} catch (error) {
if (error.code !== 'ENOENT') {
throw error;
}

return fetchTag(cwd, tag);
}
}

module.exports = ensureTag;
1 change: 1 addition & 0 deletions lib/git/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ function gitPush(directory, origin, refs) {
cwd: directory,
}).then(s => s.trim());
}

module.exports = gitPush;
Loading

0 comments on commit a9dd920

Please sign in to comment.