From 1f3c5e885ee9ddc5ee38c3491480d76bcd0e38ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6nnemann?= Date: Wed, 10 Jun 2015 12:13:55 -0700 Subject: [PATCH 01/12] chore: allow es6 in src, wile keeping every commit addressable --- bin/semantic-release.js | 83 ++++++++--------------------------------- package.json | 21 ++++++----- src/main.js | 69 ++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 76 deletions(-) create mode 100644 src/main.js diff --git a/bin/semantic-release.js b/bin/semantic-release.js index 05521a6e..2f1ccba6 100755 --- a/bin/semantic-release.js +++ b/bin/semantic-release.js @@ -1,13 +1,9 @@ #!/usr/bin/env node -'use strict' var readFile = require('fs').readFileSync -var abbrev = require('abbrev') var minimist = require('minimist') -var efh = require('../lib/error').standard - var argv = minimist(process.argv.slice(2), { alias: { d: 'debug', @@ -23,72 +19,25 @@ var argv = minimist(process.argv.slice(2), { } }) -var plugins = JSON.parse(readFile('./package.json')).release || {} - var npmArgv = process.env.npm_config_argv ? minimist(JSON.parse(process.env.npm_config_argv).cooked) : {_: []} +var plugins = JSON.parse(readFile('./package.json')).release || {} + +var main + +try { + main = require('../dist/main') +} catch (e) { + require('babel/register') + main = require('../src/main') +} + if (~argv._.indexOf('pre')) { - // see src/restart.js - if (npmArgv['semantic-release-rerun']) { - if (!/semantically-released/.test(process.env.npm_package_version)) process.exit(0) - - console.log('There is something wrong with your setup, as a placeholder version is about to be released.') - console.log('Please verify that your setup is correct.') - console.log('If you think this is a problem with semantic-release please open an issue.') - process.exit(1) - } - // the `prepublish` hook is also executed when the package is installed - // in this case we abort the command and do nothing. - if ( - isAbbrev(npmArgv, 'install') || - isAbbrev(npmArgv, 'link') || - isAbbrev(npmArgv, 'pack') - ) process.exit(0) - - if (argv.debug) console.log('This is a dry run') - - console.log('Determining new version') - - var publish = false - if (isAbbrev(npmArgv, 'publish')) publish = true - - // require a correct setup during publish - if (publish && !argv.debug && !require('../src/verify')(argv)) process.exit(1) - - require('../src/pre')(argv, plugins, efh(function (result) { - if (!result) { - console.log('Nothing changed. Not publishing.') - process.exit(1) - } - - console.log('Publishing v' + result) - if (!publish) process.exit(0) - - if (argv.debug) process.exit(1) - - require('../src/restart')(efh(function () { - process.exit(1) - })) - })) -} - -if (~argv._.indexOf('post')) { - require('../src/post')(argv, plugins, efh(function () { - // see src/restart.js - if (npmArgv['semantic-release-rerun']) { - console.log('Everything is alright :) npm will now print an error message that you can safely ignore.') - } - })) -} - -if (~argv._.indexOf('setup')) { - require('../src/setup')() - console.log('"package.json" is set up properly. Now configure your CI server.') - console.log('https://github.com/boennemann/semantic-release#ci-server') -} - -function isAbbrev (argv, command) { - return argv._.some(Object.prototype.hasOwnProperty.bind(abbrev(command))) + main.pre(argv, npmArgv, plugins) +} else if (~argv._.indexOf('post')) { + main.post(argv, npmArgv, plugins) +} else if (~argv._.indexOf('setup')) { + main.setup(argv, npmArgv, plugins) } diff --git a/package.json b/package.json index b4fc952e..a0a8479e 100644 --- a/package.json +++ b/package.json @@ -43,16 +43,22 @@ "keywords": [ "author", "automation", - "release", - "publish", + "changelog", "module", "package", + "publish", + "release", "semver", - "version", - "changelog" + "version" ], "license": "MIT", "main": "index.js", + "optionalDependencies": { + "babel": "^5.5.6" + }, + "release": { + "verification": "cracks" + }, "repository": { "type": "git", "url": "https://github.com/boennemann/semantic-release.git" @@ -60,11 +66,8 @@ "scripts": { "postpublish": "./bin/semantic-release.js post", "prepublish": "./bin/semantic-release.js pre", - "test:style": "standard", + "test": "./bin/test", "test:integration": "node tests | tap-spec", - "test": "./bin/test" - }, - "release": { - "verification": "cracks" + "test:style": "standard" } } diff --git a/src/main.js b/src/main.js new file mode 100644 index 00000000..d99986b6 --- /dev/null +++ b/src/main.js @@ -0,0 +1,69 @@ +'use strict' + +var abbrev = require('abbrev') + +var efh = require('../lib/error').standard + +exports.pre = function (argv, npmArgv, plugins) { + // see src/restart.js + if (npmArgv['semantic-release-rerun']) { + if (!/semantically-released/.test(process.env.npm_package_version)) process.exit(0) + + console.log('There is something wrong with your setup, as a placeholder version is about to be released.') + console.log('Please verify that your setup is correct.') + console.log('If you think this is a problem with semantic-release please open an issue.') + process.exit(1) + } + // the `prepublish` hook is also executed when the package is installed + // in this case we abort the command and do nothing. + if ( + isAbbrev(npmArgv, 'install') || + isAbbrev(npmArgv, 'link') || + isAbbrev(npmArgv, 'pack') + ) process.exit(0) + + if (argv.debug) console.log('This is a dry run') + + console.log('Determining new version') + + var publish = false + if (isAbbrev(npmArgv, 'publish')) publish = true + + // require a correct setup during publish + if (publish && !argv.debug && !require('./verify')(argv)) process.exit(1) + + require('./pre')(argv, plugins, efh(function (result) { + if (!result) { + console.log('Nothing changed. Not publishing.') + process.exit(1) + } + + console.log('Publishing v' + result) + if (!publish) process.exit(0) + + if (argv.debug) process.exit(1) + + require('./restart')(efh(function () { + process.exit(1) + })) + })) +} + +exports.post = function (argv, npmArgv, plugins) { + require('./post')(argv, plugins, efh(function () { + // see src/restart.js + if (npmArgv['semantic-release-rerun']) { + console.log('Everything is alright :) npm will now print an error message that you can safely ignore.') + } + })) +} + +exports.setup = function () { + require('./setup')() + console.log('"package.json" is set up properly. Now configure your CI server.') + console.log('https://github.com/boennemann/semantic-release#ci-server') +} + +function isAbbrev (argv, command) { + return argv._.some(Object.prototype.hasOwnProperty.bind(abbrev(command))) +} From 40b48e375dd063d38c547ccacd72c23843263689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6nnemann?= Date: Wed, 10 Jun 2015 12:29:42 -0700 Subject: [PATCH 02/12] chore(package): update standard and tap-spec --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a0a8479e..ff946c89 100644 --- a/package.json +++ b/package.json @@ -30,8 +30,8 @@ "nixt": "^0.4.1", "nock": "^2.2.0", "sinopia": "^1.0.0", - "standard": "^3.11.1", - "tap-spec": "^3.0.0", + "standard": "^4.0.1", + "tap-spec": "^4.0.0", "tape": "^4.0.0" }, "engines": { From 825c0e66dd8d1012b40d499207dbe4f328de91f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6nnemann?= Date: Wed, 10 Jun 2015 12:51:01 -0700 Subject: [PATCH 03/12] chore(lib): move inside src folder --- {lib => src/lib}/analyzer.js | 0 {lib => src/lib}/commits.js | 0 {lib => src/lib}/error.js | 0 {lib => src/lib}/npm-info.js | 0 {lib => src/lib}/release-notes.js | 0 src/main.js | 2 +- src/post.js | 4 ++-- src/pre.js | 8 ++++---- 8 files changed, 7 insertions(+), 7 deletions(-) rename {lib => src/lib}/analyzer.js (100%) rename {lib => src/lib}/commits.js (100%) rename {lib => src/lib}/error.js (100%) rename {lib => src/lib}/npm-info.js (100%) rename {lib => src/lib}/release-notes.js (100%) diff --git a/lib/analyzer.js b/src/lib/analyzer.js similarity index 100% rename from lib/analyzer.js rename to src/lib/analyzer.js diff --git a/lib/commits.js b/src/lib/commits.js similarity index 100% rename from lib/commits.js rename to src/lib/commits.js diff --git a/lib/error.js b/src/lib/error.js similarity index 100% rename from lib/error.js rename to src/lib/error.js diff --git a/lib/npm-info.js b/src/lib/npm-info.js similarity index 100% rename from lib/npm-info.js rename to src/lib/npm-info.js diff --git a/lib/release-notes.js b/src/lib/release-notes.js similarity index 100% rename from lib/release-notes.js rename to src/lib/release-notes.js diff --git a/src/main.js b/src/main.js index d99986b6..cc559171 100644 --- a/src/main.js +++ b/src/main.js @@ -2,7 +2,7 @@ var abbrev = require('abbrev') -var efh = require('../lib/error').standard +var efh = require('./lib/error').standard exports.pre = function (argv, npmArgv, plugins) { // see src/restart.js diff --git a/src/post.js b/src/post.js index 5a3887fb..45c9a329 100644 --- a/src/post.js +++ b/src/post.js @@ -7,7 +7,7 @@ var gitHead = require('git-head') var GitHubApi = require('github') var parseSlug = require('parse-github-repo-url') -var efh = require('../lib/error').efh +var efh = require('./lib/error').efh module.exports = function (options, plugins, cb) { var pkg = JSON.parse(readFile('./package.json')) @@ -15,7 +15,7 @@ module.exports = function (options, plugins, cb) { if (!repository) return cb(new Error('Package must have a repository')) - var notesGenerator = require(plugins.notes || '../lib/release-notes') + var notesGenerator = require(plugins.notes || './lib/release-notes') var config = options['github-url'] ? url.parse(options['github-url']) : {} diff --git a/src/pre.js b/src/pre.js index 67ca98d1..a6e2c7ed 100644 --- a/src/pre.js +++ b/src/pre.js @@ -4,9 +4,9 @@ var fs = require('fs') var semver = require('semver') -var getCommits = require('../lib/commits') -var npmInfo = require('../lib/npm-info') -var efh = require('../lib/error').efh +var getCommits = require('./lib/commits') +var npmInfo = require('./lib/npm-info') +var efh = require('./lib/error').efh module.exports = function (options, plugins, cb) { var path = './package.json' @@ -16,7 +16,7 @@ module.exports = function (options, plugins, cb) { npmInfo(pkg.name, efh(cb)(function (res) { getCommits(res.gitHead, efh(cb)(function (commits) { - var analyzer = require(plugins.analyzer || '../lib/analyzer') + var analyzer = require(plugins.analyzer || './lib/analyzer') var type = analyzer(commits) if (!type) return cb(null, null) From 5a8c8639af534288e35b48bcdc74e1b7cf734f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6nnemann?= Date: Wed, 10 Jun 2015 15:23:55 -0700 Subject: [PATCH 04/12] chore(package): add build-step --- .gitignore | 4 ++++ .npmignore | 9 +++++++++ package.json | 6 ++++-- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 .npmignore diff --git a/.gitignore b/.gitignore index f1185067..ac1ff97c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# common node_modules *.log .tmp + +# build-artifacts +dist diff --git a/.npmignore b/.npmignore new file mode 100644 index 00000000..8f8a5d6a --- /dev/null +++ b/.npmignore @@ -0,0 +1,9 @@ +# common +node_modules +*.log +.tmp + +# source/config +src +*.yml +.gitignore diff --git a/package.json b/package.json index ff946c89..09252f93 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "version" ], "license": "MIT", - "main": "index.js", + "main": "dist/main.js", "optionalDependencies": { "babel": "^5.5.6" }, @@ -64,8 +64,10 @@ "url": "https://github.com/boennemann/semantic-release.git" }, "scripts": { + "build": "rm -rf dist && mkdir -p dist && babel src --out-dir dist", "postpublish": "./bin/semantic-release.js post", - "prepublish": "./bin/semantic-release.js pre", + "prepublish": "npm run build && ./bin/semantic-release.js pre", + "pretest": "npm run build", "test": "./bin/test", "test:integration": "node tests | tap-spec", "test:style": "standard" From f0bb39a22e0819cd3a8e2d2f58ac66f5cc9a4b60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6nnemann?= Date: Thu, 11 Jun 2015 15:05:15 -0700 Subject: [PATCH 05/12] style: use es6 in src --- src/lib/analyzer.js | 18 ++++++------------ src/lib/commits.js | 22 +++++++++------------- src/lib/error.js | 22 ++++++++-------------- src/lib/npm-info.js | 29 +++++++++++++++-------------- src/lib/release-notes.js | 14 ++++++-------- src/main.js | 40 +++++++++++++++++++++------------------- src/post.js | 40 ++++++++++++++++++---------------------- src/pre.js | 36 +++++++++++++++++------------------- src/restart.js | 16 +++++++--------- src/setup.js | 31 ++++++++++++++++--------------- src/verify.js | 28 ++++++++++++++-------------- tests/tap/npm-info.js | 2 +- 12 files changed, 138 insertions(+), 160 deletions(-) diff --git a/src/lib/analyzer.js b/src/lib/analyzer.js index ff6d8f8f..ce399d85 100644 --- a/src/lib/analyzer.js +++ b/src/lib/analyzer.js @@ -1,21 +1,15 @@ -'use strict' +import { parseRawCommit } from 'conventional-changelog/lib/git' -var parseRawCommit = require('conventional-changelog/lib/git').parseRawCommit - -module.exports = function (commits) { - var type = null +export default function (commits) { + let type = null commits - .map(function (commit) { - return parseRawCommit(commit.hash + '\n' + commit.message) - }) + .map((commit) => parseRawCommit(`${commit.hash}\n${commit.message}`)) - .filter(function (commit) { - return !!commit - }) + .filter((commit) => !!commit) - .every(function (commit) { + .every((commit) => { if (commit.breaks.length) { type = 'major' return false diff --git a/src/lib/commits.js b/src/lib/commits.js index 767db814..62bb8884 100644 --- a/src/lib/commits.js +++ b/src/lib/commits.js @@ -1,22 +1,18 @@ -'use strict' +import { exec } from 'child_process' -var exec = require('child_process').exec +import { efh } from './error' -var efh = require('./error').efh - -module.exports = function (from, cb) { - var range = (from ? from + '..' : '') + 'HEAD' +export default function (from, cb) { + const range = (from ? from + '..' : '') + 'HEAD' exec( - 'git log -E --format=%H==SPLIT==%B==END== ' + range, - efh(cb)(function (stdout) { + `git log -E --format=%H==SPLIT==%B==END== ${range}`, + efh(cb)((stdout) => { cb(null, String(stdout).split('==END==\n') - .filter(function (raw) { - return !!raw.trim() - }) + .filter((raw) => !!raw.trim()) - .map(function (raw) { - var data = raw.split('==SPLIT==') + .map((raw) => { + const data = raw.split('==SPLIT==') return { hash: data[0], message: data[1] diff --git a/src/lib/error.js b/src/lib/error.js index 72a5b002..48718d1e 100644 --- a/src/lib/error.js +++ b/src/lib/error.js @@ -1,14 +1,8 @@ -'use strict' - -var efh = require('error-first-handler') - -module.exports = { - efh: efh, - standard: efh(function (err) { - console.log('Something went wrong:') - if (typeof err === 'string') return console.log(err) - if (err instanceof Error) return console.log(err.message, err.stack) - if (err.message) return console.log(err.message) - console.log(err) - }) -} +export const efh = require('error-first-handler') +export const standard = efh((err) => { + console.log('Something went wrong:') + if (typeof err === 'string') return console.log(err) + if (err instanceof Error) return console.log(err.message, err.stack) + if (err.message) return console.log(err.message) + console.log(err) +}) diff --git a/src/lib/npm-info.js b/src/lib/npm-info.js index 24a10734..7686b1b2 100644 --- a/src/lib/npm-info.js +++ b/src/lib/npm-info.js @@ -1,29 +1,30 @@ -'use strict' +import async from 'async' +import npmconf from 'npmconf' +import request from 'request' -var async = require('async') -var npmconf = require('npmconf') -var request = require('request') +export default function (pkgName, cb) { + const registry = process.env.npm_config_registry -module.exports = function (pkgName, cb) { - var registry = process.env.npm_config_registry async.waterfall([ npmconf.load, - function (conf, callback) { - var cred = conf.getCredentialsByURI(registry) - var reqopts = { + (conf, callback) => { + const cred = conf.getCredentialsByURI(registry) + const reqopts = { url: registry + pkgName.replace(/\//g, '%2F'), headers: {} } + if (cred.token) { - reqopts.headers.Authorization = 'Bearer ' + cred.token + reqopts.headers.Authorization = `Bearer ${cred.token}` } else if (cred.auth) { - reqopts.headers.Authorization = 'Basic ' + cred.auth + reqopts.headers.Authorization = `Basic ${cred.auth}` } + callback(null, reqopts) }, request, - function (response, body, callback) { - var res = { + (response, body, callback) => { + let res = { version: null, gitHead: null, pkg: null @@ -31,7 +32,7 @@ module.exports = function (pkgName, cb) { if (response.statusCode === 404 || !body) return callback(null, res) - var pkg = JSON.parse(body) + const pkg = JSON.parse(body) if (pkg.error) return callback(pkg.error) diff --git a/src/lib/release-notes.js b/src/lib/release-notes.js index d1772982..cf358822 100644 --- a/src/lib/release-notes.js +++ b/src/lib/release-notes.js @@ -1,13 +1,11 @@ -'use strict' +import { readFileSync as readFile } from 'fs' -var readFile = require('fs').readFileSync +import changelog from 'conventional-changelog' +import parseUrl from 'github-url-from-git' -var changelog = require('conventional-changelog') -var parseUrl = require('github-url-from-git') - -module.exports = function (cb) { - var pkg = JSON.parse(readFile('./package.json')) - var repository = pkg.repository ? parseUrl(pkg.repository.url) : null +export default function (cb) { + const pkg = JSON.parse(readFile('./package.json')) + const repository = pkg.repository ? parseUrl(pkg.repository.url) : null changelog({ version: pkg.version, diff --git a/src/main.js b/src/main.js index cc559171..c8909ed6 100644 --- a/src/main.js +++ b/src/main.js @@ -1,17 +1,22 @@ -'use strict' +import abbrev from 'abbrev' +import { standard as efh } from './lib/error' -var abbrev = require('abbrev') +import postStep from './post' +import preStep from './pre' +import restartStep from './restart' +import setupStep from './setup' +import verifyStep from './verify' -var efh = require('./lib/error').standard - -exports.pre = function (argv, npmArgv, plugins) { +export function pre (argv, npmArgv, plugins) { // see src/restart.js if (npmArgv['semantic-release-rerun']) { if (!/semantically-released/.test(process.env.npm_package_version)) process.exit(0) - console.log('There is something wrong with your setup, as a placeholder version is about to be released.') - console.log('Please verify that your setup is correct.') - console.log('If you think this is a problem with semantic-release please open an issue.') + console.log( +`There is something wrong with your setup, as a placeholder version is about to be released. +Please verify that your setup is correct. +If you think this is a problem with semantic-release please open an issue.` + ) process.exit(1) } // the `prepublish` hook is also executed when the package is installed @@ -26,13 +31,12 @@ exports.pre = function (argv, npmArgv, plugins) { console.log('Determining new version') - var publish = false - if (isAbbrev(npmArgv, 'publish')) publish = true + const publish = isAbbrev(npmArgv, 'publish') // require a correct setup during publish - if (publish && !argv.debug && !require('./verify')(argv)) process.exit(1) + if (publish && !argv.debug && !verifyStep(argv)) process.exit(1) - require('./pre')(argv, plugins, efh(function (result) { + preStep(argv, plugins, efh((result) => { if (!result) { console.log('Nothing changed. Not publishing.') process.exit(1) @@ -43,14 +47,12 @@ exports.pre = function (argv, npmArgv, plugins) { if (argv.debug) process.exit(1) - require('./restart')(efh(function () { - process.exit(1) - })) + restartStep(efh(() => process.exit(1))) })) } -exports.post = function (argv, npmArgv, plugins) { - require('./post')(argv, plugins, efh(function () { +export function post (argv, npmArgv, plugins) { + postStep(argv, plugins, efh(function () { // see src/restart.js if (npmArgv['semantic-release-rerun']) { console.log('Everything is alright :) npm will now print an error message that you can safely ignore.') @@ -58,8 +60,8 @@ exports.post = function (argv, npmArgv, plugins) { })) } -exports.setup = function () { - require('./setup')() +export function setup () { + setupStep() console.log('"package.json" is set up properly. Now configure your CI server.') console.log('https://github.com/boennemann/semantic-release#ci-server') } diff --git a/src/post.js b/src/post.js index 45c9a329..6c6410a9 100644 --- a/src/post.js +++ b/src/post.js @@ -1,38 +1,36 @@ -'use strict' +import {readFileSync as readFile } from 'fs' +import url from 'url' -var readFile = require('fs').readFileSync -var url = require('url') +import gitHead from 'git-head' +import GitHubApi from 'github' +import parseSlug from 'parse-github-repo-url' -var gitHead = require('git-head') -var GitHubApi = require('github') -var parseSlug = require('parse-github-repo-url') +import { efh } from './lib/error' -var efh = require('./lib/error').efh - -module.exports = function (options, plugins, cb) { - var pkg = JSON.parse(readFile('./package.json')) - var repository = pkg.repository ? pkg.repository.url : null +export default function (options, plugins, cb) { + const pkg = JSON.parse(readFile('./package.json')) + const repository = pkg.repository ? pkg.repository.url : null if (!repository) return cb(new Error('Package must have a repository')) - var notesGenerator = require(plugins.notes || './lib/release-notes') + const notesGenerator = require(plugins.notes || './lib/release-notes') - var config = options['github-url'] ? url.parse(options['github-url']) : {} + const config = options['github-url'] ? url.parse(options['github-url']) : {} - var github = new GitHubApi({ + const github = new GitHubApi({ version: '3.0.0', port: config.port, protocol: (config.protocol || '').split(':')[0] || null, host: config.hostname }) - notesGenerator(efh(cb)(function (log) { - gitHead(efh(cb)(function (hash) { - var ghRepo = parseSlug(repository) - var release = { + notesGenerator(efh(cb)((log) => { + gitHead(efh(cb)((hash) => { + const ghRepo = parseSlug(repository) + const release = { owner: ghRepo[0], repo: ghRepo[1], - tag_name: 'v' + pkg.version, + tag_name: `v${pkg.version}`, target_commitish: hash, draft: options.debug, body: log @@ -43,9 +41,7 @@ module.exports = function (options, plugins, cb) { token: options.token }) - github.releases.createRelease(release, efh(cb)(function () { - cb(null, true) - })) + github.releases.createRelease(release, efh(cb)(() => cb(null, true))) })) })) } diff --git a/src/pre.js b/src/pre.js index a6e2c7ed..58581ca3 100644 --- a/src/pre.js +++ b/src/pre.js @@ -1,23 +1,21 @@ -'use strict' +import fs from 'fs' -var fs = require('fs') +import semver from 'semver' -var semver = require('semver') +import getCommits from './lib/commits' +import npmInfo from './lib/npm-info' +import { efh } from './lib/error' -var getCommits = require('./lib/commits') -var npmInfo = require('./lib/npm-info') -var efh = require('./lib/error').efh - -module.exports = function (options, plugins, cb) { - var path = './package.json' - var pkg = JSON.parse(fs.readFileSync(path)) +export default function (options, plugins, cb) { + const path = './package.json' + let pkg = JSON.parse(fs.readFileSync(path)) if (!pkg.name) return cb(new Error('Package must have a name')) - npmInfo(pkg.name, efh(cb)(function (res) { - getCommits(res.gitHead, efh(cb)(function (commits) { - var analyzer = require(plugins.analyzer || './lib/analyzer') - var type = analyzer(commits) + npmInfo(pkg.name, efh(cb)((res) => { + getCommits(res.gitHead, efh(cb)((commits) => { + const analyzer = require(plugins.analyzer || './lib/analyzer') + let type = analyzer(commits) if (!type) return cb(null, null) @@ -28,14 +26,14 @@ module.exports = function (options, plugins, cb) { pkg.version = '1.0.0' } - var writePkg = function () { - if (!options.debug) fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + '\n') + function writePkg () { + if (!options.debug) fs.writeFileSync(path, `${JSON.stringify(pkg, null, 2)}\n`) cb(null, pkg.version) } if (!plugins.verification) return writePkg() - var opts = {} + let opts = {} if (typeof plugins.verification === 'string') { opts.path = plugins.verification @@ -50,11 +48,11 @@ module.exports = function (options, plugins, cb) { opts.version = res.version opts.nextVersion = pkg.version - var verification = require(opts.path) + const verification = require(opts.path) console.log('Running verification hook...') - verification(opts, function (error, ok) { + verification(opts, (error, ok) => { if (!error && ok) return writePkg() console.log('Verification failed' + (error ? ': ' + error : '')) process.exit(1) diff --git a/src/restart.js b/src/restart.js index f542194f..167107e3 100644 --- a/src/restart.js +++ b/src/restart.js @@ -1,16 +1,14 @@ -'use strict' +import { spawn } from 'child_process' -var spawn = require('child_process').spawn - -var exports = module.exports = function (cb) { +export default function (cb) { // npm loads package.json data before running the `prepublish` hook // changing the version on `prepublish` has no effect // see https://github.com/npm/npm/issues/7118 // to circumvent this behavior we are calling `npm publish` inside `prepublish` // the package.json is then loaded again and the correct version will be published - var child = spawn('npm', ['publish', '--semantic-release-rerun']) - var handler = exports.handleCloseAndExit.bind(null, cb) + const child = spawn('npm', ['publish', '--semantic-release-rerun']) + const handler = exports.handleCloseAndExit.bind(null, cb) child.stdout.pipe(process.stdout) child.stderr.pipe(process.stderr) @@ -20,11 +18,11 @@ var exports = module.exports = function (cb) { child.on('error', cb) } -exports.handleCloseAndExit = function (cb, code, signal) { +export function handleCloseAndExit (cb, code, signal) { if (code === 0) return cb(null) cb({ - code: code, - signal: signal, + code, + signal, message: 'npm publish failed' }) } diff --git a/src/setup.js b/src/setup.js index 544065f5..032a027c 100644 --- a/src/setup.js +++ b/src/setup.js @@ -1,32 +1,33 @@ -'use strict' +import { + readFileSync as readFile, + writeFileSync as writeFile +} from 'fs' -var fs = require('fs') +import ini from 'ini' +import ghUrl from 'github-url-from-git' -var ini = require('ini') -var ghUrl = require('github-url-from-git') - -module.exports = function () { - var pkg = JSON.parse(fs.readFileSync('./package.json') + '') +export default function () { + let pkg = JSON.parse(String(readFile('./package.json'))) // ensure a yet unpublished version pkg.version = '0.0.0-semantically-released' // set up scripts - var pre = 'semantic-release pre' - var post = 'semantic-release post' + const pre = 'semantic-release pre' + const post = 'semantic-release post' if (!pkg.scripts) pkg.scripts = {} if (!pkg.scripts.prepublish) pkg.scripts.prepublish = pre - else if (!(new RegExp(pre).test(pkg.scripts.prepublish))) pkg.scripts.prepublish += ' && ' + pre + else if (!(new RegExp(pre).test(pkg.scripts.prepublish))) pkg.scripts.prepublish += ` && ${pre}` if (!pkg.scripts.postpublish) pkg.scripts.postpublish = post - else if (!(new RegExp(post).test(pkg.scripts.postpublish))) pkg.scripts.postpublish += ' && ' + post + else if (!(new RegExp(post).test(pkg.scripts.postpublish))) pkg.scripts.postpublish += ` && ${post}` // set up repository if (!pkg.repository || !pkg.repository.url) { - var config = ini.decode(fs.readFileSync('./.git/config') + '') - var repo = config['remote "origin"'].url + const config = ini.decode(String(readFile('./.git/config'))) + const repo = config['remote "origin"'].url if (repo) pkg.repository = { type: 'git', url: ghUrl(repo) } } @@ -35,8 +36,8 @@ module.exports = function () { if (!pkg.devDependencies) pkg.devDependencies = {} if (!pkg.devDependencies['semantic-release']) { - pkg.devDependencies['semantic-release'] = '^' + require('../package.json').version + pkg.devDependencies['semantic-release'] = `^${require('../package.json').version}` } - fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2) + '\n') + writeFile('./package.json', `${JSON.stringify(pkg, null, 2)}\n`) } diff --git a/src/verify.js b/src/verify.js index 33bd2dc9..49ae2c7c 100644 --- a/src/verify.js +++ b/src/verify.js @@ -1,22 +1,21 @@ -'use strict' +import { readFileSync as readFile } from 'fs' -var fs = require('fs') - -var exports = module.exports = function (input) { - var options = exports.verifyOptions(input) - var pkg = exports.verifyPackage() - var travis = exports.verifyTravis() +export default function (input) { + const options = exports.verifyOptions(input) + const pkg = exports.verifyPackage() + const travis = exports.verifyTravis() return options && pkg && travis } -exports.verifyTravis = function () { +export function verifyTravis () { + let travis try { - var travis = fs.readFileSync('.travis.yml') + '' + travis = String(readFile('.travis.yml')) } catch (e) { return true } - var passed = true + let passed = true if (!/\sdeploy:/m.test(travis)) { console.error('You should configure deployments inside the ".travis.yml".') @@ -31,11 +30,12 @@ exports.verifyTravis = function () { return passed } -exports.verifyPackage = function () { - var passed = true +export function verifyPackage () { + let passed = true + let pkg try { - var pkg = fs.readFileSync('./package.json') + '' + pkg = String(readFile('./package.json')) } catch (e) { console.error('You must have a "package.json" present.') passed = false @@ -62,7 +62,7 @@ exports.verifyPackage = function () { return passed } -exports.verifyOptions = function (options) { +export function verifyOptions (options) { if (!options) return true if (options.token) return true diff --git a/tests/tap/npm-info.js b/tests/tap/npm-info.js index fb8927e6..ad25efb0 100644 --- a/tests/tap/npm-info.js +++ b/tests/tap/npm-info.js @@ -2,7 +2,7 @@ var nock = require('nock') -var npmInfo = require('../../lib/npm-info.js') +var npmInfo = require('../../dist/lib/npm-info.js') var registry = 'http://registry.npmjs.org/' From bd715dfdf453b11908547deb4e3c434da8936538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6nnemann?= Date: Thu, 11 Jun 2015 15:12:02 -0700 Subject: [PATCH 06/12] test(createModule): not installing semantic-release's deps all over again --- tests/lib/commit-to-version-test.js | 2 +- tests/lib/create-module.js | 10 +++------- tests/scenarios/ignore.js | 2 +- tests/scenarios/postpublish.js | 4 ++-- tests/scenarios/setup.js | 2 +- tests/scenarios/verify.js | 2 +- 6 files changed, 9 insertions(+), 13 deletions(-) diff --git a/tests/lib/commit-to-version-test.js b/tests/lib/commit-to-version-test.js index f087ddcc..cfced0ed 100644 --- a/tests/lib/commit-to-version-test.js +++ b/tests/lib/commit-to-version-test.js @@ -16,7 +16,7 @@ module.exports = function (t, message, version, code, name, cwd) { .exec('git commit --allow-empty -m "' + message + '"') .run('npm run prepublish') .code(code) - .stdout(/> semantic-release pre\n\nDetermining new version\n/m) + .stdout(/semantic-release.js pre\n\nDetermining new version\n/m) .end(function (err) { t.error(err, 'nixt') diff --git a/tests/lib/create-module.js b/tests/lib/create-module.js index 3dc77e73..31725a69 100644 --- a/tests/lib/create-module.js +++ b/tests/lib/create-module.js @@ -13,12 +13,9 @@ module.exports = function (input) { var pkg = defaults((typeof input === 'object' ? input : {}), { name: id, version: '0.0.0', - devDependencies: { - 'semantic-release': 'file:../../../' - }, scripts: { - prepublish: 'semantic-release pre', - postpublish: 'semantic-release post' + prepublish: '../../../bin/semantic-release.js pre', + postpublish: '../../../bin/semantic-release.js post' }, publishConfig: { registry: 'http://localhost:4873/' @@ -36,8 +33,7 @@ module.exports = function (input) { 'git add . && ' + 'git config user.email "integration@test" && ' + 'git config user.name "Integration Test" && ' + - 'git commit -m "initial" && ' + - 'npm install' + 'git commit -m "initial"' , efh(cb)(function (stdout) { cb(null, id, cwd) })) diff --git a/tests/scenarios/ignore.js b/tests/scenarios/ignore.js index 3f5537ac..793d352e 100644 --- a/tests/scenarios/ignore.js +++ b/tests/scenarios/ignore.js @@ -26,7 +26,7 @@ module.exports = function (test, createModule) { .cwd(cwd) .run(command) .code(0) - .stdout(/> semantic-release pre\n$/m) + .stdout(/semantic-release.js pre\n$/m) .end(function (err) { t.is(pkg + '', fs.readFileSync(cwd + '/package.json') + '', 'package') t.error(err, 'nixt') diff --git a/tests/scenarios/postpublish.js b/tests/scenarios/postpublish.js index 302b04e9..d7ec9599 100644 --- a/tests/scenarios/postpublish.js +++ b/tests/scenarios/postpublish.js @@ -33,7 +33,7 @@ module.exports = function (test, createModule) { t.plan(1) base.clone() - .stdout(/> semantic-release post\n\nGenerating changelog from.*\nParsed/m) + .stdout(/semantic-release.js post\n\nGenerating changelog from.*\nParsed/m) .run('npm run postpublish') .end(function (err) { t.error(err, 'nixt') @@ -44,7 +44,7 @@ module.exports = function (test, createModule) { t.plan(1) base.clone() - .stdout(/> semantic-release post\n\nGenerating changelog from.*\nParsed/m) + .stdout(/semantic-release.js post\n\nGenerating changelog from.*\nParsed/m) .exec('git checkout `git rev-parse HEAD`') .run('npm run postpublish') .end(function (err) { diff --git a/tests/scenarios/setup.js b/tests/scenarios/setup.js index 707c3bfd..1670f435 100644 --- a/tests/scenarios/setup.js +++ b/tests/scenarios/setup.js @@ -20,7 +20,7 @@ module.exports = function (test, createModule) { nixt() .cwd(cwd) .exec('git remote add origin git@github.com:user/repo.git') - .run('./node_modules/.bin/semantic-release setup') + .run('../../../bin/semantic-release.js setup') .code(0) .end(function (err) { t.error(err, 'nixt') diff --git a/tests/scenarios/verify.js b/tests/scenarios/verify.js index ea251de1..cf333051 100644 --- a/tests/scenarios/verify.js +++ b/tests/scenarios/verify.js @@ -8,7 +8,7 @@ module.exports = function (test, createModule) { createModule({ repository: {}, scripts: { - prepublish: 'semantic-release pre --no-token' + prepublish: '../../../bin/semantic-release.js pre' } }, efh()(function (name, cwd) { t.test('verify package and options before publishing', function (t) { From 649af78c569c881878c4f7df4e6ed555b05ec0cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6nnemann?= Date: Thu, 11 Jun 2015 15:23:33 -0700 Subject: [PATCH 07/12] style(tests): require deps in every file --- tests/index.js | 22 +++++++++------------- tests/scenarios/custom-analyzer.js | 4 +++- tests/scenarios/custom-verification.js | 5 ++++- tests/scenarios/ignore.js | 5 ++++- tests/scenarios/postpublish.js | 5 ++++- tests/scenarios/prepublish.js | 4 +++- tests/scenarios/publish.js | 5 ++++- tests/scenarios/setup.js | 5 ++++- tests/scenarios/verify.js | 5 ++++- tests/tap/npm-info.js | 3 ++- 10 files changed, 41 insertions(+), 22 deletions(-) diff --git a/tests/index.js b/tests/index.js index dc61116b..e9c1c42d 100644 --- a/tests/index.js +++ b/tests/index.js @@ -1,15 +1,11 @@ 'use strict' -var test = require('tape') - -var createModule = require('./lib/create-module') - -require('./tap/npm-info')(test) -require('./scenarios/custom-analyzer')(test, createModule) -require('./scenarios/custom-verification')(test, createModule) -require('./scenarios/ignore')(test, createModule) -require('./scenarios/prepublish')(test, createModule) -require('./scenarios/postpublish')(test, createModule) -require('./scenarios/publish')(test, createModule) -require('./scenarios/verify')(test, createModule) -require('./scenarios/setup')(test, createModule) +require('./tap/npm-info')() +require('./scenarios/custom-analyzer')() +require('./scenarios/custom-verification')() +require('./scenarios/ignore')() +require('./scenarios/prepublish')() +require('./scenarios/postpublish')() +require('./scenarios/publish')() +require('./scenarios/verify')() +require('./scenarios/setup')() diff --git a/tests/scenarios/custom-analyzer.js b/tests/scenarios/custom-analyzer.js index d571cb78..aa38ce55 100644 --- a/tests/scenarios/custom-analyzer.js +++ b/tests/scenarios/custom-analyzer.js @@ -3,10 +3,12 @@ var path = require('path') var efh = require('error-first-handler') +var test = require('tape') +var createModule = require('../lib/create-module') var commitToVersionTest = require('../lib/commit-to-version-test') -module.exports = function (test, createModule) { +module.exports = function () { createModule({ release: { analyzer: path.join(__dirname, '../lib/custom-analyzer') diff --git a/tests/scenarios/custom-verification.js b/tests/scenarios/custom-verification.js index d9b05879..4f7b9f3f 100644 --- a/tests/scenarios/custom-verification.js +++ b/tests/scenarios/custom-verification.js @@ -4,8 +4,11 @@ var path = require('path') var efh = require('error-first-handler') var nixt = require('nixt') +var test = require('tape') -module.exports = function (test, createModule) { +var createModule = require('../lib/create-module') + +module.exports = function () { createModule({ release: { verification: path.join(__dirname, '../lib/custom-verification') diff --git a/tests/scenarios/ignore.js b/tests/scenarios/ignore.js index 793d352e..6190be7b 100644 --- a/tests/scenarios/ignore.js +++ b/tests/scenarios/ignore.js @@ -4,8 +4,11 @@ var fs = require('fs') var efh = require('error-first-handler') var nixt = require('nixt') +var test = require('tape') -module.exports = function (test, createModule) { +var createModule = require('../lib/create-module') + +module.exports = function () { createModule(efh()(function (name, cwd) { test('ignore', function (t) { ignoreTest(t, 'npm install', 'not doing anything when the module is installed') diff --git a/tests/scenarios/postpublish.js b/tests/scenarios/postpublish.js index d7ec9599..739fd186 100644 --- a/tests/scenarios/postpublish.js +++ b/tests/scenarios/postpublish.js @@ -5,6 +5,9 @@ var path = require('path') var efh = require('error-first-handler') var GitHubApi = require('github') var nixt = require('nixt') +var test = require('tape') + +var createModule = require('../lib/create-module') var github = new GitHubApi({ version: '3.0.0', @@ -18,7 +21,7 @@ github.authenticate({ token: '***' }) -module.exports = function (test, createModule) { +module.exports = function () { createModule({ version: '2.0.0', repository: { diff --git a/tests/scenarios/prepublish.js b/tests/scenarios/prepublish.js index 22b8e112..bda3d788 100644 --- a/tests/scenarios/prepublish.js +++ b/tests/scenarios/prepublish.js @@ -1,10 +1,12 @@ 'use strict' var efh = require('error-first-handler') +var test = require('tape') +var createModule = require('../lib/create-module') var commitToVersionTest = require('../lib/commit-to-version-test') -module.exports = function (test, createModule) { +module.exports = function () { createModule(efh()(function (name, cwd) { test('prepublish', function (t) { commitToVersionTest(t, 'refactor: change', '0.0.0', 1, 'abort publish w/o changes', cwd) diff --git a/tests/scenarios/publish.js b/tests/scenarios/publish.js index 4826d22f..9fd03029 100644 --- a/tests/scenarios/publish.js +++ b/tests/scenarios/publish.js @@ -2,8 +2,11 @@ var efh = require('error-first-handler') var nixt = require('nixt') +var test = require('tape') -module.exports = function (test, createModule) { +var createModule = require('../lib/create-module') + +module.exports = function () { test('publish', function (t) { publishTest(t, 'npm publish', 'pre and post hooks work as a part of publish') publishTest(t, 'npm pub', 'pre and post hooks work as a part of publish with abbrevd command') diff --git a/tests/scenarios/setup.js b/tests/scenarios/setup.js index 1670f435..01befe6e 100644 --- a/tests/scenarios/setup.js +++ b/tests/scenarios/setup.js @@ -5,8 +5,11 @@ var readFile = require('fs').readFileSync var efh = require('error-first-handler') var nixt = require('nixt') +var test = require('tape') -module.exports = function (test, createModule) { +var createModule = require('../lib/create-module') + +module.exports = function () { createModule({ repository: {}, scripts: { diff --git a/tests/scenarios/verify.js b/tests/scenarios/verify.js index cf333051..a1b86b61 100644 --- a/tests/scenarios/verify.js +++ b/tests/scenarios/verify.js @@ -2,8 +2,11 @@ var efh = require('error-first-handler') var nixt = require('nixt') +var test = require('tape') -module.exports = function (test, createModule) { +var createModule = require('../lib/create-module') + +module.exports = function () { test('verify', function (t) { createModule({ repository: {}, diff --git a/tests/tap/npm-info.js b/tests/tap/npm-info.js index ad25efb0..732dcc5d 100644 --- a/tests/tap/npm-info.js +++ b/tests/tap/npm-info.js @@ -1,5 +1,6 @@ 'use strict' +var test = require('tape') var nock = require('nock') var npmInfo = require('../../dist/lib/npm-info.js') @@ -19,7 +20,7 @@ var defaultModule = { process.env.npm_config_registry = registry -module.exports = function (test) { +module.exports = function () { test('npm-info', function (t) { var regMock = nock(registry, { reqheaders: { From 4e90e4b98b91dff14ece6abd253b5c453da2d7f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6nnemann?= Date: Thu, 11 Jun 2015 17:07:09 -0700 Subject: [PATCH 08/12] test: convert from tape to tap --- package.json | 5 +- tests/index.js | 11 --- tests/scenarios/custom-analyzer.js | 18 ++--- tests/scenarios/custom-verification.js | 60 +++++++------- tests/scenarios/ignore.js | 54 ++++++------- tests/scenarios/postpublish.js | 108 ++++++++++++------------- tests/scenarios/prepublish.js | 18 ++--- tests/scenarios/publish.js | 60 +++++++------- tests/scenarios/setup.js | 38 +++++---- tests/scenarios/verify.js | 86 ++++++++++---------- tests/tap/npm-info.js | 56 +++++++------ 11 files changed, 241 insertions(+), 273 deletions(-) delete mode 100644 tests/index.js diff --git a/package.json b/package.json index 09252f93..496cb443 100644 --- a/package.json +++ b/package.json @@ -31,8 +31,7 @@ "nock": "^2.2.0", "sinopia": "^1.0.0", "standard": "^4.0.1", - "tap-spec": "^4.0.0", - "tape": "^4.0.0" + "tap": "^1.2.0" }, "engines": { "iojs": "^1", @@ -69,7 +68,7 @@ "prepublish": "npm run build && ./bin/semantic-release.js pre", "pretest": "npm run build", "test": "./bin/test", - "test:integration": "node tests | tap-spec", + "test:integration": "tap tests/{scenarios,tap}/*.js", "test:style": "standard" } } diff --git a/tests/index.js b/tests/index.js deleted file mode 100644 index e9c1c42d..00000000 --- a/tests/index.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict' - -require('./tap/npm-info')() -require('./scenarios/custom-analyzer')() -require('./scenarios/custom-verification')() -require('./scenarios/ignore')() -require('./scenarios/prepublish')() -require('./scenarios/postpublish')() -require('./scenarios/publish')() -require('./scenarios/verify')() -require('./scenarios/setup')() diff --git a/tests/scenarios/custom-analyzer.js b/tests/scenarios/custom-analyzer.js index aa38ce55..6a1f53be 100644 --- a/tests/scenarios/custom-analyzer.js +++ b/tests/scenarios/custom-analyzer.js @@ -3,23 +3,21 @@ var path = require('path') var efh = require('error-first-handler') -var test = require('tape') +var test = require('tap').test var createModule = require('../lib/create-module') var commitToVersionTest = require('../lib/commit-to-version-test') -module.exports = function () { +test('custom-analyzer', function (t) { createModule({ release: { analyzer: path.join(__dirname, '../lib/custom-analyzer') } }, efh()(function (name, cwd) { - test('custom-analyzer', function (t) { - commitToVersionTest(t, 'HO', '0.0.0', 1, 'abort publish w/o changes', cwd) - commitToVersionTest(t, 'BAZ', '1.0.0', 0, 'release 1.0.0 if unpublished', cwd) - commitToVersionTest(t, 'BAZ', '1.0.1', 0, 'bump patch for fix', cwd) - commitToVersionTest(t, 'BAR', '1.1.0', 0, 'bump minor for feature', cwd) - commitToVersionTest(t, 'FOO', '2.0.0', 0, 'bump major for breaking change', cwd) - }) + commitToVersionTest(t, 'HO', '0.0.0', 1, 'abort publish w/o changes', cwd) + commitToVersionTest(t, 'BAZ', '1.0.0', 0, 'release 1.0.0 if unpublished', cwd) + commitToVersionTest(t, 'BAZ', '1.0.1', 0, 'bump patch for fix', cwd) + commitToVersionTest(t, 'BAR', '1.1.0', 0, 'bump minor for feature', cwd) + commitToVersionTest(t, 'FOO', '2.0.0', 0, 'bump major for breaking change', cwd) })) -} +}) diff --git a/tests/scenarios/custom-verification.js b/tests/scenarios/custom-verification.js index 4f7b9f3f..e9b9df88 100644 --- a/tests/scenarios/custom-verification.js +++ b/tests/scenarios/custom-verification.js @@ -4,45 +4,43 @@ var path = require('path') var efh = require('error-first-handler') var nixt = require('nixt') -var test = require('tape') +var test = require('tap').test var createModule = require('../lib/create-module') -module.exports = function () { +test('custom-verification', function (t) { createModule({ release: { verification: path.join(__dirname, '../lib/custom-verification') } }, efh()(function (name, cwd) { - test('custom-verification', function (t) { - t.test('even commit count', function (t) { - t.plan(1) - nixt() - .cwd(cwd) - .env('CI', true) - .env('npm_config_registry', 'http://127.0.0.1:4873/') - .exec('git commit --allow-empty -m "feat: commit"') - .run('npm run prepublish') - .code(0) - .end(function (err) { - t.error(err, 'nixt') - }) - }) + t.test('even commit count', function (t) { + t.plan(1) + nixt() + .cwd(cwd) + .env('CI', true) + .env('npm_config_registry', 'http://127.0.0.1:4873/') + .exec('git commit --allow-empty -m "feat: commit"') + .run('npm run prepublish') + .code(0) + .end(function (err) { + t.error(err, 'nixt') + }) + }) - t.test('odd commit count', function (t) { - t.plan(1) - nixt() - .cwd(cwd) - .env('CI', true) - .env('npm_config_registry', 'http://127.0.0.1:4873/') - .exec('git commit --allow-empty -m "feat: commit"') - .run('npm run prepublish') - .code(1) - .stdout(/Verification failed/) - .end(function (err) { - t.error(err, 'nixt') - }) - }) + t.test('odd commit count', function (t) { + t.plan(1) + nixt() + .cwd(cwd) + .env('CI', true) + .env('npm_config_registry', 'http://127.0.0.1:4873/') + .exec('git commit --allow-empty -m "feat: commit"') + .run('npm run prepublish') + .code(1) + .stdout(/Verification failed/) + .end(function (err) { + t.error(err, 'nixt') + }) }) })) -} +}) diff --git a/tests/scenarios/ignore.js b/tests/scenarios/ignore.js index 6190be7b..c92e063d 100644 --- a/tests/scenarios/ignore.js +++ b/tests/scenarios/ignore.js @@ -4,37 +4,35 @@ var fs = require('fs') var efh = require('error-first-handler') var nixt = require('nixt') -var test = require('tape') +var test = require('tap').test var createModule = require('../lib/create-module') -module.exports = function () { +test('ignore', function (t) { createModule(efh()(function (name, cwd) { - test('ignore', function (t) { - ignoreTest(t, 'npm install', 'not doing anything when the module is installed') - ignoreTest(t, 'npm i', 'not doing anything when the module is installed with abbrevd command') - ignoreTest(t, 'npm link', 'not doing anything when the module is linked') - ignoreTest(t, 'npm lin', 'not doing anything when the module is linked with abbrevd command') - ignoreTest(t, 'npm pack', 'not doing anything when the module is packed') - ignoreTest(t, 'npm pa', 'not doing anything when the module is packed with abbrevd command') - }) - - function ignoreTest (t, command, name, last) { - t.test(name, function (t) { - t.plan(2) - - var pkg = fs.readFileSync(cwd + '/package.json') - - nixt() - .cwd(cwd) - .run(command) - .code(0) - .stdout(/semantic-release.js pre\n$/m) - .end(function (err) { - t.is(pkg + '', fs.readFileSync(cwd + '/package.json') + '', 'package') - t.error(err, 'nixt') - }) - }) - } + ignoreTest(t, cwd, 'npm install', 'not doing anything when the module is installed') + ignoreTest(t, cwd, 'npm i', 'not doing anything when the module is installed with abbrevd command') + ignoreTest(t, cwd, 'npm link', 'not doing anything when the module is linked') + ignoreTest(t, cwd, 'npm lin', 'not doing anything when the module is linked with abbrevd command') + ignoreTest(t, cwd, 'npm pack', 'not doing anything when the module is packed') + ignoreTest(t, cwd, 'npm pa', 'not doing anything when the module is packed with abbrevd command') })) +}) + +function ignoreTest (t, cwd, command, name) { + t.test(name, function (t) { + t.plan(2) + + var pkg = fs.readFileSync(cwd + '/package.json') + + nixt() + .cwd(cwd) + .run(command) + .code(0) + .stdout(/semantic-release.js pre\n$/m) + .end(function (err) { + t.is(pkg + '', fs.readFileSync(cwd + '/package.json') + '', 'package') + t.error(err, 'nixt') + }) + }) } diff --git a/tests/scenarios/postpublish.js b/tests/scenarios/postpublish.js index 739fd186..0f5096cc 100644 --- a/tests/scenarios/postpublish.js +++ b/tests/scenarios/postpublish.js @@ -5,7 +5,7 @@ var path = require('path') var efh = require('error-first-handler') var GitHubApi = require('github') var nixt = require('nixt') -var test = require('tape') +var test = require('tap').test var createModule = require('../lib/create-module') @@ -21,7 +21,7 @@ github.authenticate({ token: '***' }) -module.exports = function () { +test('postpublish', function (t) { createModule({ version: '2.0.0', repository: { @@ -29,42 +29,40 @@ module.exports = function () { url: 'http://github.com/user/repo' } }, efh()(function (name, cwd) { - test('postpublish', function (t) { - var base = getBase(cwd) + var base = getBase(cwd) - t.test('publish new version to github releases', function (t) { - t.plan(1) + t.test('publish new version to github releases', function (t) { + t.plan(1) - base.clone() - .stdout(/semantic-release.js post\n\nGenerating changelog from.*\nParsed/m) - .run('npm run postpublish') - .end(function (err) { - t.error(err, 'nixt') - }) - }) - - t.test('publish new version (with detached HEAD) to github releases', function (t) { - t.plan(1) - - base.clone() - .stdout(/semantic-release.js post\n\nGenerating changelog from.*\nParsed/m) - .exec('git checkout `git rev-parse HEAD`') - .run('npm run postpublish') - .end(function (err) { - t.error(err, 'nixt') - }) - }) - - t.test('correct data published', function (t) { - t.plan(4) - - github.releases.getRelease({ owner: 'user', repo: 'repo', id: 1}, function (err, raw) { - var res = JSON.parse(raw) - t.error(err, 'github') - t.is(res.tag_name, 'v2.0.0', 'version') - t.is(res.author.login, 'user', 'user') - t.ok(/\n\n\n#### Features\n\n\* \*\*cool:\*\*\n.*the next big thing/.test(res.body), 'body') + base.clone() + .stdout(/semantic-release.js post\n\nGenerating changelog from.*\nParsed/m) + .run('npm run postpublish') + .end(function (err) { + t.error(err, 'nixt') }) + }) + + t.test('publish new version (with detached HEAD) to github releases', function (t) { + t.plan(1) + + base.clone() + .stdout(/semantic-release.js post\n\nGenerating changelog from.*\nParsed/m) + .exec('git checkout `git rev-parse HEAD`') + .run('npm run postpublish') + .end(function (err) { + t.error(err, 'nixt') + }) + }) + + t.test('correct data published', function (t) { + t.plan(4) + + github.releases.getRelease({ owner: 'user', repo: 'repo', id: 1}, function (err, raw) { + var res = JSON.parse(raw) + t.error(err, 'github') + t.is(res.tag_name, 'v2.0.0', 'version') + t.is(res.author.login, 'user', 'user') + t.ok(/\n\n\n#### Features\n\n\* \*\*cool:\*\*\n.*the next big thing/.test(res.body), 'body') }) }) })) @@ -79,33 +77,31 @@ module.exports = function () { notes: path.join(__dirname, '../lib/custom-release-notes') } }, efh()(function (name, cwd) { - test('custom-release-notes', function (t) { - var base = getBase(cwd) + var base = getBase(cwd) - t.test('publish new version (with custom notes) to github releases', function (t) { - t.plan(1) + t.test('publish new version (with custom notes) to github releases', function (t) { + t.plan(1) - base.clone() - .run('npm run postpublish') - .end(function (err) { - t.error(err, 'nixt') - }) - }) - - t.test('custom notes published', function (t) { - t.plan(4) - - github.releases.getRelease({ owner: 'user', repo: 'repo', id: 3}, function (err, raw) { - var res = JSON.parse(raw) - t.error(err, 'github') - t.is(res.tag_name, 'v2.0.0', 'version') - t.is(res.author.login, 'user', 'user') - t.ok(/custom log/.test(res.body), 'body') + base.clone() + .run('npm run postpublish') + .end(function (err) { + t.error(err, 'nixt') }) + }) + + t.test('custom notes published', function (t) { + t.plan(4) + + github.releases.getRelease({ owner: 'user', repo: 'repo', id: 3}, function (err, raw) { + var res = JSON.parse(raw) + t.error(err, 'github') + t.is(res.tag_name, 'v2.0.0', 'version') + t.is(res.author.login, 'user', 'user') + t.ok(/custom log/.test(res.body), 'body') }) }) })) -} +}) function getBase (cwd) { return nixt() diff --git a/tests/scenarios/prepublish.js b/tests/scenarios/prepublish.js index bda3d788..fdaf6aea 100644 --- a/tests/scenarios/prepublish.js +++ b/tests/scenarios/prepublish.js @@ -1,19 +1,17 @@ 'use strict' var efh = require('error-first-handler') -var test = require('tape') +var test = require('tap').test var createModule = require('../lib/create-module') var commitToVersionTest = require('../lib/commit-to-version-test') -module.exports = function () { +test('prepublish', function (t) { createModule(efh()(function (name, cwd) { - test('prepublish', function (t) { - commitToVersionTest(t, 'refactor: change', '0.0.0', 1, 'abort publish w/o changes', cwd) - commitToVersionTest(t, 'fix: change', '1.0.0', 0, 'release 1.0.0 if unpublished', cwd) - commitToVersionTest(t, 'fix: change', '1.0.1', 0, 'bump patch for fix', cwd) - commitToVersionTest(t, 'feat: change', '1.1.0', 0, 'bump minor for feature', cwd) - commitToVersionTest(t, 'fix: BREAKING CHANGE: change', '2.0.0', 0, 'bump major for breaking change', cwd) - }) + commitToVersionTest(t, 'refactor: change', '0.0.0', 1, 'abort publish w/o changes', cwd) + commitToVersionTest(t, 'fix: change', '1.0.0', 0, 'release 1.0.0 if unpublished', cwd) + commitToVersionTest(t, 'fix: change', '1.0.1', 0, 'bump patch for fix', cwd) + commitToVersionTest(t, 'feat: change', '1.1.0', 0, 'bump minor for feature', cwd) + commitToVersionTest(t, 'fix: BREAKING CHANGE: change', '2.0.0', 0, 'bump major for breaking change', cwd) })) -} +}) diff --git a/tests/scenarios/publish.js b/tests/scenarios/publish.js index 9fd03029..e7901774 100644 --- a/tests/scenarios/publish.js +++ b/tests/scenarios/publish.js @@ -2,39 +2,37 @@ var efh = require('error-first-handler') var nixt = require('nixt') -var test = require('tape') +var test = require('tap').test var createModule = require('../lib/create-module') -module.exports = function () { - test('publish', function (t) { - publishTest(t, 'npm publish', 'pre and post hooks work as a part of publish') - publishTest(t, 'npm pub', 'pre and post hooks work as a part of publish with abbrevd command') +test('publish', function (t) { + publishTest(t, 'npm publish', 'pre and post hooks work as a part of publish') + publishTest(t, 'npm pub', 'pre and post hooks work as a part of publish with abbrevd command') - function publishTest (t, command, testname, last) { - createModule({ - repository: { - type: 'git', - url: 'http://github.com/user/repo' - } - }, efh()(function (name, cwd) { - t.test(testname, function (t) { - t.plan(1) + function publishTest (t, command, testname, last) { + createModule({ + repository: { + type: 'git', + url: 'http://github.com/user/repo' + } + }, efh()(function (name, cwd) { + t.test(testname, function (t) { + t.plan(1) - nixt() - .cwd(cwd) - .env('CI', true) - .env('GH_URL', 'http://127.0.0.1:4343/') - .env('GH_TOKEN', '***') - .exec('git commit --allow-empty -m "feat: super"') - .run(command) - .code(1) - .stdout(/Everything is alright/) - .end(function (err) { - t.error(err, 'nixt') - }) - }) - })) - } - }) -} + nixt() + .cwd(cwd) + .env('CI', true) + .env('GH_URL', 'http://127.0.0.1:4343/') + .env('GH_TOKEN', '***') + .exec('git commit --allow-empty -m "feat: super"') + .run(command) + .code(1) + .stdout(/Everything is alright/) + .end(function (err) { + t.error(err, 'nixt') + }) + }) + })) + } +}) diff --git a/tests/scenarios/setup.js b/tests/scenarios/setup.js index 01befe6e..c82107b1 100644 --- a/tests/scenarios/setup.js +++ b/tests/scenarios/setup.js @@ -5,37 +5,35 @@ var readFile = require('fs').readFileSync var efh = require('error-first-handler') var nixt = require('nixt') -var test = require('tape') +var test = require('tap').test var createModule = require('../lib/create-module') -module.exports = function () { +test('setup', function (t) { createModule({ repository: {}, scripts: { postpublish: 'npm run gh-pages' } }, efh()(function (name, cwd) { - test('setup', function (t) { - t.test('setup "package.json"', function (t) { - t.plan(5) + t.test('setup "package.json"', function (t) { + t.plan(5) - nixt() - .cwd(cwd) - .exec('git remote add origin git@github.com:user/repo.git') - .run('../../../bin/semantic-release.js setup') - .code(0) - .end(function (err) { - t.error(err, 'nixt') + nixt() + .cwd(cwd) + .exec('git remote add origin git@github.com:user/repo.git') + .run('../../../bin/semantic-release.js setup') + .code(0) + .end(function (err) { + t.error(err, 'nixt') - var pkg = JSON.parse(readFile(join(cwd, 'package.json'))) + var pkg = JSON.parse(readFile(join(cwd, 'package.json'))) - t.is(pkg.version, '0.0.0-semantically-released', 'version') - t.is(pkg.repository.url, 'https://github.com/user/repo', 'repo') - t.is(pkg.scripts.prepublish, 'semantic-release pre', 'pre') - t.is(pkg.scripts.postpublish, 'npm run gh-pages && semantic-release post', 'post') - }) - }) + t.is(pkg.version, '0.0.0-semantically-released', 'version') + t.is(pkg.repository.url, 'https://github.com/user/repo', 'repo') + t.is(pkg.scripts.prepublish, 'semantic-release pre', 'pre') + t.is(pkg.scripts.postpublish, 'npm run gh-pages && semantic-release post', 'post') + }) }) })) -} +}) diff --git a/tests/scenarios/verify.js b/tests/scenarios/verify.js index a1b86b61..ab679b18 100644 --- a/tests/scenarios/verify.js +++ b/tests/scenarios/verify.js @@ -2,52 +2,50 @@ var efh = require('error-first-handler') var nixt = require('nixt') -var test = require('tape') +var test = require('tap').test var createModule = require('../lib/create-module') -module.exports = function () { - test('verify', function (t) { - createModule({ - repository: {}, - scripts: { - prepublish: '../../../bin/semantic-release.js pre' - } - }, efh()(function (name, cwd) { - t.test('verify package and options before publishing', function (t) { - t.plan(1) - nixt() - .cwd(cwd) - .env('CI', true) - .run('npm publish') - .stderr(new RegExp( - 'You must define a GitHub token\.\n' + - 'You must define your GitHub "repository" inside the "package.json"\.\n' + - 'You must define your "scripts" inside the "package.json"\.' - , 'm' - )) - .code(1) - .end(function (err) { - t.error(err, 'nixt') - }) - }) - })) +test('verify', function (t) { + createModule({ + repository: {}, + scripts: { + prepublish: '../../../bin/semantic-release.js pre --no-token' + } + }, efh()(function (name, cwd) { + t.test('verify package and options before publishing', function (t) { + t.plan(1) + nixt() + .cwd(cwd) + .env('CI', true) + .run('npm publish') + .stderr(new RegExp( + 'You must define a GitHub token\.\n' + + 'You must define your GitHub "repository" inside the "package.json"\.\n' + + 'You must define your "scripts" inside the "package.json"\.' + , 'm' + )) + .code(1) + .end(function (err) { + t.error(err, 'nixt') + }) + }) + })) - createModule({ - version: '1.0.0-semantically-released' - }, efh()(function (name, cwd) { - t.test('not publishing placeholder versions', function (t) { - t.plan(1) + createModule({ + version: '1.0.0-semantically-released' + }, efh()(function (name, cwd) { + t.test('not publishing placeholder versions', function (t) { + t.plan(1) - nixt() - .cwd(cwd) - .env('CI', true) - .run('npm publish --semantic-release-rerun') - .code(1) - .end(function (err) { - t.error(err, 'nixt') - }) - }) - })) - }) -} + nixt() + .cwd(cwd) + .env('CI', true) + .run('npm publish --semantic-release-rerun') + .code(1) + .end(function (err) { + t.error(err, 'nixt') + }) + }) + })) +}) diff --git a/tests/tap/npm-info.js b/tests/tap/npm-info.js index 732dcc5d..ca3b8e25 100644 --- a/tests/tap/npm-info.js +++ b/tests/tap/npm-info.js @@ -1,6 +1,6 @@ 'use strict' -var test = require('tape') +var test = require('tap').test var nock = require('nock') var npmInfo = require('../../dist/lib/npm-info.js') @@ -20,34 +20,32 @@ var defaultModule = { process.env.npm_config_registry = registry -module.exports = function () { - test('npm-info', function (t) { - var regMock = nock(registry, { - reqheaders: { - 'authorization': 'Bearer testtoken' - } - }) - .get('/express') - .reply(200, defaultModule) - .get('/@user%2Fmodule') - .reply(200, defaultModule) +test('npm-info', function (t) { + var regMock = nock(registry, { + reqheaders: { + 'authorization': 'Bearer testtoken' + } + }) + .get('/express') + .reply(200, defaultModule) + .get('/@user%2Fmodule') + .reply(200, defaultModule) - t.test('get unscoped module', function (t) { - t.plan(3) - npmInfo('express', function (err, info) { - t.error(err, 'error') - t.is(info.version, '1.0.0', 'version') - t.is(info.gitHead, 'HEAD', 'gitHead') - }) - }) - t.test('get scoped module', function (t) { - t.plan(3) - npmInfo('@user/module', function (err, info) { - t.error(err, 'error') - t.is(info.version, '1.0.0', 'version') - t.is(info.gitHead, 'HEAD', 'gitHead') - regMock.done() - }) + t.test('get unscoped module', function (t) { + t.plan(3) + npmInfo('express', function (err, info) { + t.error(err, 'error') + t.is(info.version, '1.0.0', 'version') + t.is(info.gitHead, 'HEAD', 'gitHead') }) }) -} + t.test('get scoped module', function (t) { + t.plan(3) + npmInfo('@user/module', function (err, info) { + t.error(err, 'error') + t.is(info.version, '1.0.0', 'version') + t.is(info.gitHead, 'HEAD', 'gitHead') + regMock.done() + }) + }) +}) From 384bc63e5d76ef4135680a5d08c3860a1b8dc7d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6nnemann?= Date: Fri, 12 Jun 2015 10:22:57 -0700 Subject: [PATCH 09/12] chore(tests): add build to allow es6 in tests --- .gitignore | 1 + .npmignore | 1 + package.json | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ac1ff97c..225b7875 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ node_modules *.log .tmp +.tests # build-artifacts dist diff --git a/.npmignore b/.npmignore index 8f8a5d6a..96afab14 100644 --- a/.npmignore +++ b/.npmignore @@ -2,6 +2,7 @@ node_modules *.log .tmp +.tests # source/config src diff --git a/package.json b/package.json index 496cb443..1dcb3402 100644 --- a/package.json +++ b/package.json @@ -67,8 +67,9 @@ "postpublish": "./bin/semantic-release.js post", "prepublish": "npm run build && ./bin/semantic-release.js pre", "pretest": "npm run build", + "pretest:integration": "rm -rf .tests && mkdir -p .tests && babel tests --out-dir .tests", "test": "./bin/test", - "test:integration": "tap tests/{scenarios,tap}/*.js", + "test:integration": "tap .tests/{scenarios,tap}/*.js", "test:style": "standard" } } From 191ae78a9f0fc07e9b5efa612deff379a8f6fd81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6nnemann?= Date: Fri, 12 Jun 2015 11:01:51 -0700 Subject: [PATCH 10/12] chore(tests): add coverage reports and coveralls --- .gitignore | 4 +++- .npmignore | 4 +++- .travis.yml | 13 +++++++------ README.md | 1 + bin/semantic-release.js | 1 + package.json | 18 +++++++++++++++--- 6 files changed, 30 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 225b7875..ed5d11aa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,10 @@ # common +coverage node_modules *.log -.tmp +.nyc_output .tests +.tmp # build-artifacts dist diff --git a/.npmignore b/.npmignore index 96afab14..e428f04f 100644 --- a/.npmignore +++ b/.npmignore @@ -1,8 +1,10 @@ # common +coverage node_modules *.log -.tmp +.nyc_output .tests +.tmp # source/config src diff --git a/.travis.yml b/.travis.yml index cf29732c..6534e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,15 @@ -language: node_js -node_js: -- iojs-v2 -- iojs-v1 -- '0.10' -- '0.12' sudo: false +language: node_js cache: directories: - node_modules notifications: email: false +node_js: +- iojs-v2 +- iojs-v1 +- '0.12' +- '0.10' before_install: - npm i -g npm@^2.0.0 before_script: @@ -18,6 +18,7 @@ before_script: after_success: - python travis_after_all.py - export $(cat .to_export_back) +- if [[ $BUILD_LEADER = YES ]]; then npm run coveralls; fi after_failure: - python travis_after_all.py - export $(cat .to_export_back) diff --git a/README.md b/README.md index c5fcfc09..165f95db 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # semantic-release [![Build Status](https://travis-ci.org/boennemann/semantic-release.svg?branch=master)](https://travis-ci.org/boennemann/semantic-release) +[![Coverage Status](https://coveralls.io/repos/boennemann/semantic-release/badge.svg)](https://coveralls.io/r/boennemann/semantic-release) [![Dependency Status](https://david-dm.org/boennemann/semantic-release.svg)](https://david-dm.org/boennemann/semantic-release) [![devDependency Status](https://david-dm.org/boennemann/semantic-release/dev-status.svg)](https://david-dm.org/boennemann/semantic-release#info=devDependencies) diff --git a/bin/semantic-release.js b/bin/semantic-release.js index 2f1ccba6..d60dab52 100755 --- a/bin/semantic-release.js +++ b/bin/semantic-release.js @@ -27,6 +27,7 @@ var plugins = JSON.parse(readFile('./package.json')).release || {} var main +/* istanbul ignore next */ try { main = require('../dist/main') } catch (e) { diff --git a/package.json b/package.json index 1dcb3402..50eff27a 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,14 @@ "bugs": { "url": "https://github.com/boennemann/semantic-release/issues" }, + "config": { + "nyc": { + "exclude": [ + ".tests", + "node_modules" + ] + } + }, "dependencies": { "abbrev": "^1.0.5", "async": "^1.0.0", @@ -23,12 +31,14 @@ "semver": "^4.3.3" }, "devDependencies": { + "coveralls": "^2.11.2", "cracks": "^2.0.1", "github-release-fake-server": "^1.3.0", "lodash.defaults": "^3.0.0", "nano-uid": "^0.2.0", "nixt": "^0.4.1", "nock": "^2.2.0", + "nyc": "^2.3.0", "sinopia": "^1.0.0", "standard": "^4.0.1", "tap": "^1.2.0" @@ -64,12 +74,14 @@ }, "scripts": { "build": "rm -rf dist && mkdir -p dist && babel src --out-dir dist", + "build:tests": "rm -rf .tests && mkdir -p .tests && babel tests --out-dir .tests", + "coverage": "nyc report", + "coveralls": "npm run coverage -- --reporter=lcovonly && cat coverage/lcov.info | coveralls", "postpublish": "./bin/semantic-release.js post", "prepublish": "npm run build && ./bin/semantic-release.js pre", - "pretest": "npm run build", - "pretest:integration": "rm -rf .tests && mkdir -p .tests && babel tests --out-dir .tests", + "pretest:integration": "npm run build && npm run build:tests", "test": "./bin/test", - "test:integration": "tap .tests/{scenarios,tap}/*.js", + "test:integration": "nyc tap --no-cov .tests/{scenarios,tap}/*.js", "test:style": "standard" } } From 889f5f4360d022744d2cab458d8d00d17e98a2bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6nnemann?= Date: Fri, 12 Jun 2015 13:24:44 -0700 Subject: [PATCH 11/12] style: use es6 in tests --- tests/lib/commit-to-version-test.js | 20 +++++---- tests/lib/create-module.js | 38 +++++++++-------- tests/lib/custom-analyzer.js | 6 +-- tests/lib/custom-release-notes.js | 2 - tests/lib/custom-verification.js | 2 - tests/scenarios/custom-analyzer.js | 16 ++++---- tests/scenarios/custom-verification.js | 28 +++++-------- tests/scenarios/ignore.js | 24 +++++------ tests/scenarios/postpublish.js | 56 +++++++++++--------------- tests/scenarios/prepublish.js | 14 +++---- tests/scenarios/publish.js | 20 ++++----- tests/scenarios/setup.js | 24 +++++------ tests/scenarios/verify.js | 34 +++++++--------- tests/tap/npm-info.js | 24 +++++------ 14 files changed, 132 insertions(+), 176 deletions(-) diff --git a/tests/lib/commit-to-version-test.js b/tests/lib/commit-to-version-test.js index cfced0ed..5dba11f4 100644 --- a/tests/lib/commit-to-version-test.js +++ b/tests/lib/commit-to-version-test.js @@ -1,34 +1,32 @@ -'use strict' +const fs = require('fs') +const exec = require('child_process').exec -var fs = require('fs') -var exec = require('child_process').exec - -var nixt = require('nixt') +const nixt = require('nixt') module.exports = function (t, message, version, code, name, cwd) { - t.test(name, function (t) { + t.test(name, (t) => { t.plan(3) nixt() .cwd(cwd) .env('CI', true) .env('npm_config_registry', 'http://127.0.0.1:4873/') - .exec('git commit --allow-empty -m "' + message + '"') + .exec(`git commit --allow-empty -m "${message}"`) .run('npm run prepublish') .code(code) .stdout(/semantic-release.js pre\n\nDetermining new version\n/m) - .end(function (err) { + .end((err) => { t.error(err, 'nixt') - var pkg = JSON.parse(fs.readFileSync(cwd + '/package.json')) + const pkg = JSON.parse(fs.readFileSync(`${cwd}/package.json`)) t.is(pkg.version, version, 'version') if (code === 1) { return t.error(null, 'no publish') } - exec('npm publish --ignore-scripts', {cwd: cwd}, function (err) { - setTimeout(function () { + exec('npm publish --ignore-scripts', {cwd}, (err) => { + setTimeout(() => { t.error(err, 'publish') }, 300) }) diff --git a/tests/lib/create-module.js b/tests/lib/create-module.js index 31725a69..b07efc47 100644 --- a/tests/lib/create-module.js +++ b/tests/lib/create-module.js @@ -1,16 +1,14 @@ -'use strict' +const exec = require('child_process').exec +const join = require('path').join -var exec = require('child_process').exec -var join = require('path').join - -var efh = require('error-first-handler') -var defaults = require('lodash.defaults') -var uid = require('nano-uid')() +const efh = require('error-first-handler') +const defaults = require('lodash.defaults') +const uid = require('nano-uid')() module.exports = function (input) { - var cb = Array.prototype.pop.call(arguments) - uid.generate(5, efh(cb)(function (id) { - var pkg = defaults((typeof input === 'object' ? input : {}), { + const cb = Array.prototype.pop.call(arguments) + uid.generate(5, efh(cb)((id) => { + const pkg = defaults((typeof input === 'object' ? input : {}), { name: id, version: '0.0.0', scripts: { @@ -23,18 +21,18 @@ module.exports = function (input) { }) id = pkg.name - var cwd = join(__dirname, '../../.tmp/modules', id) + const cwd = join(__dirname, '../../.tmp/modules', id) exec( - 'mkdir ' + cwd + ' && ' + - 'cd ' + cwd + ' && ' + - 'git init && ' + - 'echo \'' + JSON.stringify(pkg, null, 2) + '\' >> package.json && ' + - 'git add . && ' + - 'git config user.email "integration@test" && ' + - 'git config user.name "Integration Test" && ' + - 'git commit -m "initial"' - , efh(cb)(function (stdout) { + `mkdir ${cwd} && + cd ${cwd} && + git init && + echo '${JSON.stringify(pkg, null, 2)}' >> package.json && + git add . && + git config user.email "integration@test" && + git config user.name "Integration Test" && + git commit -m "initial"` + , efh(cb)((stdout) => { cb(null, id, cwd) })) })) diff --git a/tests/lib/custom-analyzer.js b/tests/lib/custom-analyzer.js index cd548e70..5964ae69 100644 --- a/tests/lib/custom-analyzer.js +++ b/tests/lib/custom-analyzer.js @@ -1,9 +1,7 @@ -'use strict' - module.exports = function (commits) { - var type = null + let type = null - commits.every(function (commit) { + commits.every((commit) => { if (/FOO/.test(commit.message)) { type = 'major' return false diff --git a/tests/lib/custom-release-notes.js b/tests/lib/custom-release-notes.js index f9527d51..d6913c16 100644 --- a/tests/lib/custom-release-notes.js +++ b/tests/lib/custom-release-notes.js @@ -1,5 +1,3 @@ -'use strict' - module.exports = function (cb) { cb(null, 'custom log') } diff --git a/tests/lib/custom-verification.js b/tests/lib/custom-verification.js index aae19461..48432356 100644 --- a/tests/lib/custom-verification.js +++ b/tests/lib/custom-verification.js @@ -1,5 +1,3 @@ -'use strict' - module.exports = function (opts, cb) { cb(null, !(opts.commits.length % 2)) } diff --git a/tests/scenarios/custom-analyzer.js b/tests/scenarios/custom-analyzer.js index 6a1f53be..078afa68 100644 --- a/tests/scenarios/custom-analyzer.js +++ b/tests/scenarios/custom-analyzer.js @@ -1,19 +1,17 @@ -'use strict' +const path = require('path') -var path = require('path') +const efh = require('error-first-handler') +const test = require('tap').test -var efh = require('error-first-handler') -var test = require('tap').test +const createModule = require('../lib/create-module') +const commitToVersionTest = require('../lib/commit-to-version-test') -var createModule = require('../lib/create-module') -var commitToVersionTest = require('../lib/commit-to-version-test') - -test('custom-analyzer', function (t) { +test('custom-analyzer', (t) => { createModule({ release: { analyzer: path.join(__dirname, '../lib/custom-analyzer') } - }, efh()(function (name, cwd) { + }, efh()((name, cwd) => { commitToVersionTest(t, 'HO', '0.0.0', 1, 'abort publish w/o changes', cwd) commitToVersionTest(t, 'BAZ', '1.0.0', 0, 'release 1.0.0 if unpublished', cwd) commitToVersionTest(t, 'BAZ', '1.0.1', 0, 'bump patch for fix', cwd) diff --git a/tests/scenarios/custom-verification.js b/tests/scenarios/custom-verification.js index e9b9df88..a72ec7d7 100644 --- a/tests/scenarios/custom-verification.js +++ b/tests/scenarios/custom-verification.js @@ -1,20 +1,18 @@ -'use strict' +const path = require('path') -var path = require('path') +const efh = require('error-first-handler') +const nixt = require('nixt') +const test = require('tap').test -var efh = require('error-first-handler') -var nixt = require('nixt') -var test = require('tap').test +const createModule = require('../lib/create-module') -var createModule = require('../lib/create-module') - -test('custom-verification', function (t) { +test('custom-verification', (t) => { createModule({ release: { verification: path.join(__dirname, '../lib/custom-verification') } - }, efh()(function (name, cwd) { - t.test('even commit count', function (t) { + }, efh()((name, cwd) => { + t.test('even commit count', (t) => { t.plan(1) nixt() .cwd(cwd) @@ -23,12 +21,10 @@ test('custom-verification', function (t) { .exec('git commit --allow-empty -m "feat: commit"') .run('npm run prepublish') .code(0) - .end(function (err) { - t.error(err, 'nixt') - }) + .end((err) => t.error(err, 'nixt')) }) - t.test('odd commit count', function (t) { + t.test('odd commit count', (t) => { t.plan(1) nixt() .cwd(cwd) @@ -38,9 +34,7 @@ test('custom-verification', function (t) { .run('npm run prepublish') .code(1) .stdout(/Verification failed/) - .end(function (err) { - t.error(err, 'nixt') - }) + .end((err) => t.error(err, 'nixt')) }) })) }) diff --git a/tests/scenarios/ignore.js b/tests/scenarios/ignore.js index c92e063d..bae6fa30 100644 --- a/tests/scenarios/ignore.js +++ b/tests/scenarios/ignore.js @@ -1,15 +1,13 @@ -'use strict' +const fs = require('fs') -var fs = require('fs') +const efh = require('error-first-handler') +const nixt = require('nixt') +const test = require('tap').test -var efh = require('error-first-handler') -var nixt = require('nixt') -var test = require('tap').test +const createModule = require('../lib/create-module') -var createModule = require('../lib/create-module') - -test('ignore', function (t) { - createModule(efh()(function (name, cwd) { +test('ignore', (t) => { + createModule(efh()((name, cwd) => { ignoreTest(t, cwd, 'npm install', 'not doing anything when the module is installed') ignoreTest(t, cwd, 'npm i', 'not doing anything when the module is installed with abbrevd command') ignoreTest(t, cwd, 'npm link', 'not doing anything when the module is linked') @@ -20,18 +18,18 @@ test('ignore', function (t) { }) function ignoreTest (t, cwd, command, name) { - t.test(name, function (t) { + t.test(name, (t) => { t.plan(2) - var pkg = fs.readFileSync(cwd + '/package.json') + const pkg = String(fs.readFileSync(cwd + '/package.json')) nixt() .cwd(cwd) .run(command) .code(0) .stdout(/semantic-release.js pre\n$/m) - .end(function (err) { - t.is(pkg + '', fs.readFileSync(cwd + '/package.json') + '', 'package') + .end((err) => { + t.is(pkg, String(fs.readFileSync(`${cwd}/package.json`)), 'package') t.error(err, 'nixt') }) }) diff --git a/tests/scenarios/postpublish.js b/tests/scenarios/postpublish.js index 0f5096cc..227f483d 100644 --- a/tests/scenarios/postpublish.js +++ b/tests/scenarios/postpublish.js @@ -1,15 +1,13 @@ -'use strict' +const path = require('path') -var path = require('path') +const efh = require('error-first-handler') +const GitHubApi = require('github') +const nixt = require('nixt') +const test = require('tap').test -var efh = require('error-first-handler') -var GitHubApi = require('github') -var nixt = require('nixt') -var test = require('tap').test +const createModule = require('../lib/create-module') -var createModule = require('../lib/create-module') - -var github = new GitHubApi({ +const github = new GitHubApi({ version: '3.0.0', port: 4343, protocol: 'http', @@ -21,44 +19,40 @@ github.authenticate({ token: '***' }) -test('postpublish', function (t) { +test('postpublish', (t) => { createModule({ version: '2.0.0', repository: { type: 'git', url: 'http://github.com/user/repo' } - }, efh()(function (name, cwd) { - var base = getBase(cwd) + }, efh()((name, cwd) => { + const base = getBase(cwd) - t.test('publish new version to github releases', function (t) { + t.test('publish new version to github releases', (t) => { t.plan(1) base.clone() .stdout(/semantic-release.js post\n\nGenerating changelog from.*\nParsed/m) .run('npm run postpublish') - .end(function (err) { - t.error(err, 'nixt') - }) + .end((err) => t.error(err, 'nixt')) }) - t.test('publish new version (with detached HEAD) to github releases', function (t) { + t.test('publish new version (with detached HEAD) to github releases', (t) => { t.plan(1) base.clone() .stdout(/semantic-release.js post\n\nGenerating changelog from.*\nParsed/m) .exec('git checkout `git rev-parse HEAD`') .run('npm run postpublish') - .end(function (err) { - t.error(err, 'nixt') - }) + .end((err) => t.error(err, 'nixt')) }) - t.test('correct data published', function (t) { + t.test('correct data published', (t) => { t.plan(4) - github.releases.getRelease({ owner: 'user', repo: 'repo', id: 1}, function (err, raw) { - var res = JSON.parse(raw) + github.releases.getRelease({ owner: 'user', repo: 'repo', id: 1}, (err, raw) => { + const res = JSON.parse(raw) t.error(err, 'github') t.is(res.tag_name, 'v2.0.0', 'version') t.is(res.author.login, 'user', 'user') @@ -76,24 +70,22 @@ test('postpublish', function (t) { release: { notes: path.join(__dirname, '../lib/custom-release-notes') } - }, efh()(function (name, cwd) { - var base = getBase(cwd) + }, efh()((name, cwd) => { + const base = getBase(cwd) - t.test('publish new version (with custom notes) to github releases', function (t) { + t.test('publish new version (with custom notes) to github releases', (t) => { t.plan(1) base.clone() .run('npm run postpublish') - .end(function (err) { - t.error(err, 'nixt') - }) + .end((err) => t.error(err, 'nixt')) }) - t.test('custom notes published', function (t) { + t.test('custom notes published', (t) => { t.plan(4) - github.releases.getRelease({ owner: 'user', repo: 'repo', id: 3}, function (err, raw) { - var res = JSON.parse(raw) + github.releases.getRelease({ owner: 'user', repo: 'repo', id: 3}, (err, raw) => { + const res = JSON.parse(raw) t.error(err, 'github') t.is(res.tag_name, 'v2.0.0', 'version') t.is(res.author.login, 'user', 'user') diff --git a/tests/scenarios/prepublish.js b/tests/scenarios/prepublish.js index fdaf6aea..32390411 100644 --- a/tests/scenarios/prepublish.js +++ b/tests/scenarios/prepublish.js @@ -1,13 +1,11 @@ -'use strict' +const efh = require('error-first-handler') +const test = require('tap').test -var efh = require('error-first-handler') -var test = require('tap').test +const createModule = require('../lib/create-module') +const commitToVersionTest = require('../lib/commit-to-version-test') -var createModule = require('../lib/create-module') -var commitToVersionTest = require('../lib/commit-to-version-test') - -test('prepublish', function (t) { - createModule(efh()(function (name, cwd) { +test('prepublish', (t) => { + createModule(efh()((name, cwd) => { commitToVersionTest(t, 'refactor: change', '0.0.0', 1, 'abort publish w/o changes', cwd) commitToVersionTest(t, 'fix: change', '1.0.0', 0, 'release 1.0.0 if unpublished', cwd) commitToVersionTest(t, 'fix: change', '1.0.1', 0, 'bump patch for fix', cwd) diff --git a/tests/scenarios/publish.js b/tests/scenarios/publish.js index e7901774..61636b86 100644 --- a/tests/scenarios/publish.js +++ b/tests/scenarios/publish.js @@ -1,12 +1,10 @@ -'use strict' +const efh = require('error-first-handler') +const nixt = require('nixt') +const test = require('tap').test -var efh = require('error-first-handler') -var nixt = require('nixt') -var test = require('tap').test +const createModule = require('../lib/create-module') -var createModule = require('../lib/create-module') - -test('publish', function (t) { +test('publish', (t) => { publishTest(t, 'npm publish', 'pre and post hooks work as a part of publish') publishTest(t, 'npm pub', 'pre and post hooks work as a part of publish with abbrevd command') @@ -16,8 +14,8 @@ test('publish', function (t) { type: 'git', url: 'http://github.com/user/repo' } - }, efh()(function (name, cwd) { - t.test(testname, function (t) { + }, efh()((name, cwd) => { + t.test(testname, (t) => { t.plan(1) nixt() @@ -29,9 +27,7 @@ test('publish', function (t) { .run(command) .code(1) .stdout(/Everything is alright/) - .end(function (err) { - t.error(err, 'nixt') - }) + .end((err) => t.error(err, 'nixt')) }) })) } diff --git a/tests/scenarios/setup.js b/tests/scenarios/setup.js index c82107b1..8910ff91 100644 --- a/tests/scenarios/setup.js +++ b/tests/scenarios/setup.js @@ -1,22 +1,20 @@ -'use strict' +const join = require('path').join +const readFile = require('fs').readFileSync -var join = require('path').join -var readFile = require('fs').readFileSync +const efh = require('error-first-handler') +const nixt = require('nixt') +const test = require('tap').test -var efh = require('error-first-handler') -var nixt = require('nixt') -var test = require('tap').test +const createModule = require('../lib/create-module') -var createModule = require('../lib/create-module') - -test('setup', function (t) { +test('setup', (t) => { createModule({ repository: {}, scripts: { postpublish: 'npm run gh-pages' } - }, efh()(function (name, cwd) { - t.test('setup "package.json"', function (t) { + }, efh()((name, cwd) => { + t.test('setup "package.json"', (t) => { t.plan(5) nixt() @@ -24,10 +22,10 @@ test('setup', function (t) { .exec('git remote add origin git@github.com:user/repo.git') .run('../../../bin/semantic-release.js setup') .code(0) - .end(function (err) { + .end((err) => { t.error(err, 'nixt') - var pkg = JSON.parse(readFile(join(cwd, 'package.json'))) + const pkg = JSON.parse(readFile(join(cwd, 'package.json'))) t.is(pkg.version, '0.0.0-semantically-released', 'version') t.is(pkg.repository.url, 'https://github.com/user/repo', 'repo') diff --git a/tests/scenarios/verify.js b/tests/scenarios/verify.js index ab679b18..e6d8a191 100644 --- a/tests/scenarios/verify.js +++ b/tests/scenarios/verify.js @@ -1,41 +1,37 @@ -'use strict' +const efh = require('error-first-handler') +const nixt = require('nixt') +const test = require('tap').test -var efh = require('error-first-handler') -var nixt = require('nixt') -var test = require('tap').test +const createModule = require('../lib/create-module') -var createModule = require('../lib/create-module') - -test('verify', function (t) { +test('verify', (t) => { createModule({ repository: {}, scripts: { prepublish: '../../../bin/semantic-release.js pre --no-token' } - }, efh()(function (name, cwd) { - t.test('verify package and options before publishing', function (t) { + }, efh()((name, cwd) => { + t.test('verify package and options before publishing', (t) => { t.plan(1) nixt() .cwd(cwd) .env('CI', true) .run('npm publish') .stderr(new RegExp( - 'You must define a GitHub token\.\n' + - 'You must define your GitHub "repository" inside the "package.json"\.\n' + - 'You must define your "scripts" inside the "package.json"\.' +`You must define a GitHub token\. +You must define your GitHub "repository" inside the "package.json"\. +You must define your "scripts" inside the "package.json"\.` , 'm' )) .code(1) - .end(function (err) { - t.error(err, 'nixt') - }) + .end((err) => t.error(err, 'nixt')) }) })) createModule({ version: '1.0.0-semantically-released' - }, efh()(function (name, cwd) { - t.test('not publishing placeholder versions', function (t) { + }, efh()((name, cwd) => { + t.test('not publishing placeholder versions', (t) => { t.plan(1) nixt() @@ -43,9 +39,7 @@ test('verify', function (t) { .env('CI', true) .run('npm publish --semantic-release-rerun') .code(1) - .end(function (err) { - t.error(err, 'nixt') - }) + .end((err) => t.error(err, 'nixt')) }) })) }) diff --git a/tests/tap/npm-info.js b/tests/tap/npm-info.js index ca3b8e25..841fc538 100644 --- a/tests/tap/npm-info.js +++ b/tests/tap/npm-info.js @@ -1,13 +1,11 @@ -'use strict' +const test = require('tap').test +const nock = require('nock') -var test = require('tap').test -var nock = require('nock') +const npmInfo = require('../../dist/lib/npm-info.js') -var npmInfo = require('../../dist/lib/npm-info.js') +const registry = 'http://registry.npmjs.org/' -var registry = 'http://registry.npmjs.org/' - -var defaultModule = { +const defaultModule = { 'dist-tags': { latest: '1.0.0' }, @@ -20,8 +18,8 @@ var defaultModule = { process.env.npm_config_registry = registry -test('npm-info', function (t) { - var regMock = nock(registry, { +test('npm-info', (t) => { + const regMock = nock(registry, { reqheaders: { 'authorization': 'Bearer testtoken' } @@ -31,17 +29,17 @@ test('npm-info', function (t) { .get('/@user%2Fmodule') .reply(200, defaultModule) - t.test('get unscoped module', function (t) { + t.test('get unscoped module', (t) => { t.plan(3) - npmInfo('express', function (err, info) { + npmInfo('express', (err, info) => { t.error(err, 'error') t.is(info.version, '1.0.0', 'version') t.is(info.gitHead, 'HEAD', 'gitHead') }) }) - t.test('get scoped module', function (t) { + t.test('get scoped module', (t) => { t.plan(3) - npmInfo('@user/module', function (err, info) { + npmInfo('@user/module', (err, info) => { t.error(err, 'error') t.is(info.version, '1.0.0', 'version') t.is(info.gitHead, 'HEAD', 'gitHead') From 630bf630347da7a7f17c449ee6eb00d4f587827f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6nnemann?= Date: Fri, 12 Jun 2015 13:50:51 -0700 Subject: [PATCH 12/12] style: backport import to require --- src/lib/analyzer.js | 4 ++-- src/lib/commits.js | 6 +++--- src/lib/error.js | 4 ++-- src/lib/npm-info.js | 8 ++++---- src/lib/release-notes.js | 10 +++++----- src/main.js | 26 ++++++++++---------------- src/post.js | 16 ++++++++-------- src/pre.js | 12 ++++++------ src/restart.js | 6 +++--- src/setup.js | 20 ++++++++++---------- src/verify.js | 14 +++++++------- 11 files changed, 60 insertions(+), 66 deletions(-) diff --git a/src/lib/analyzer.js b/src/lib/analyzer.js index ce399d85..c15b6de2 100644 --- a/src/lib/analyzer.js +++ b/src/lib/analyzer.js @@ -1,6 +1,6 @@ -import { parseRawCommit } from 'conventional-changelog/lib/git' +const { parseRawCommit } = require('conventional-changelog/lib/git') -export default function (commits) { +module.exports = function (commits) { let type = null commits diff --git a/src/lib/commits.js b/src/lib/commits.js index 62bb8884..094f9538 100644 --- a/src/lib/commits.js +++ b/src/lib/commits.js @@ -1,8 +1,8 @@ -import { exec } from 'child_process' +const { exec } = require('child_process') -import { efh } from './error' +const { efh } = require('./error') -export default function (from, cb) { +module.exports = function (from, cb) { const range = (from ? from + '..' : '') + 'HEAD' exec( `git log -E --format=%H==SPLIT==%B==END== ${range}`, diff --git a/src/lib/error.js b/src/lib/error.js index 48718d1e..e987adbf 100644 --- a/src/lib/error.js +++ b/src/lib/error.js @@ -1,5 +1,5 @@ -export const efh = require('error-first-handler') -export const standard = efh((err) => { +exports.efh = require('error-first-handler') +exports.standard = exports.efh((err) => { console.log('Something went wrong:') if (typeof err === 'string') return console.log(err) if (err instanceof Error) return console.log(err.message, err.stack) diff --git a/src/lib/npm-info.js b/src/lib/npm-info.js index 7686b1b2..29a93529 100644 --- a/src/lib/npm-info.js +++ b/src/lib/npm-info.js @@ -1,8 +1,8 @@ -import async from 'async' -import npmconf from 'npmconf' -import request from 'request' +const async = require('async') +const npmconf = require('npmconf') +const request = require('request') -export default function (pkgName, cb) { +module.exports = function (pkgName, cb) { const registry = process.env.npm_config_registry async.waterfall([ diff --git a/src/lib/release-notes.js b/src/lib/release-notes.js index cf358822..ee0ab381 100644 --- a/src/lib/release-notes.js +++ b/src/lib/release-notes.js @@ -1,10 +1,10 @@ -import { readFileSync as readFile } from 'fs' +const { readFileSync } = require('fs') -import changelog from 'conventional-changelog' -import parseUrl from 'github-url-from-git' +const changelog = require('conventional-changelog') +const parseUrl = require('github-url-from-git') -export default function (cb) { - const pkg = JSON.parse(readFile('./package.json')) +module.exports = function (cb) { + const pkg = JSON.parse(readFileSync('./package.json')) const repository = pkg.repository ? parseUrl(pkg.repository.url) : null changelog({ diff --git a/src/main.js b/src/main.js index c8909ed6..b9143621 100644 --- a/src/main.js +++ b/src/main.js @@ -1,13 +1,7 @@ -import abbrev from 'abbrev' -import { standard as efh } from './lib/error' +const abbrev = require('abbrev') +const efh = require('./lib/error').standard -import postStep from './post' -import preStep from './pre' -import restartStep from './restart' -import setupStep from './setup' -import verifyStep from './verify' - -export function pre (argv, npmArgv, plugins) { +exports.pre = function (argv, npmArgv, plugins) { // see src/restart.js if (npmArgv['semantic-release-rerun']) { if (!/semantically-released/.test(process.env.npm_package_version)) process.exit(0) @@ -34,9 +28,9 @@ If you think this is a problem with semantic-release please open an issue.` const publish = isAbbrev(npmArgv, 'publish') // require a correct setup during publish - if (publish && !argv.debug && !verifyStep(argv)) process.exit(1) + if (publish && !argv.debug && !require('./verify')(argv)) process.exit(1) - preStep(argv, plugins, efh((result) => { + require('./pre')(argv, plugins, efh((result) => { if (!result) { console.log('Nothing changed. Not publishing.') process.exit(1) @@ -47,12 +41,12 @@ If you think this is a problem with semantic-release please open an issue.` if (argv.debug) process.exit(1) - restartStep(efh(() => process.exit(1))) + require('./restart')(efh(() => process.exit(1))) })) } -export function post (argv, npmArgv, plugins) { - postStep(argv, plugins, efh(function () { +exports.post = function (argv, npmArgv, plugins) { + require('./post')(argv, plugins, efh(function () { // see src/restart.js if (npmArgv['semantic-release-rerun']) { console.log('Everything is alright :) npm will now print an error message that you can safely ignore.') @@ -60,8 +54,8 @@ export function post (argv, npmArgv, plugins) { })) } -export function setup () { - setupStep() +exports.setup = function () { + require('./setup')() console.log('"package.json" is set up properly. Now configure your CI server.') console.log('https://github.com/boennemann/semantic-release#ci-server') } diff --git a/src/post.js b/src/post.js index 6c6410a9..d535f3b6 100644 --- a/src/post.js +++ b/src/post.js @@ -1,14 +1,14 @@ -import {readFileSync as readFile } from 'fs' -import url from 'url' +const { readFileSync } = require('fs') +const url = require('url') -import gitHead from 'git-head' -import GitHubApi from 'github' -import parseSlug from 'parse-github-repo-url' +const gitHead = require('git-head') +const GitHubApi = require('github') +const parseSlug = require('parse-github-repo-url') -import { efh } from './lib/error' +const efh = require('./lib/error').efh -export default function (options, plugins, cb) { - const pkg = JSON.parse(readFile('./package.json')) +module.exports = function (options, plugins, cb) { + const pkg = JSON.parse(readFileSync('./package.json')) const repository = pkg.repository ? pkg.repository.url : null if (!repository) return cb(new Error('Package must have a repository')) diff --git a/src/pre.js b/src/pre.js index 58581ca3..f40f0f4b 100644 --- a/src/pre.js +++ b/src/pre.js @@ -1,12 +1,12 @@ -import fs from 'fs' +const fs = require('fs') -import semver from 'semver' +const semver = require('semver') -import getCommits from './lib/commits' -import npmInfo from './lib/npm-info' -import { efh } from './lib/error' +const getCommits = require('./lib/commits') +const npmInfo = require('./lib/npm-info') +const { efh } = require('./lib/error') -export default function (options, plugins, cb) { +module.exports = function (options, plugins, cb) { const path = './package.json' let pkg = JSON.parse(fs.readFileSync(path)) diff --git a/src/restart.js b/src/restart.js index 167107e3..2568a738 100644 --- a/src/restart.js +++ b/src/restart.js @@ -1,6 +1,6 @@ -import { spawn } from 'child_process' +const { spawn } = require('child_process') -export default function (cb) { +let exports = module.exports = function (cb) { // npm loads package.json data before running the `prepublish` hook // changing the version on `prepublish` has no effect // see https://github.com/npm/npm/issues/7118 @@ -18,7 +18,7 @@ export default function (cb) { child.on('error', cb) } -export function handleCloseAndExit (cb, code, signal) { +exports.handleCloseAndExit = function (cb, code, signal) { if (code === 0) return cb(null) cb({ code, diff --git a/src/setup.js b/src/setup.js index 032a027c..be1d33cd 100644 --- a/src/setup.js +++ b/src/setup.js @@ -1,13 +1,13 @@ -import { - readFileSync as readFile, - writeFileSync as writeFile -} from 'fs' +const { + readFileSync, + writeFileSync +} = require('fs') -import ini from 'ini' -import ghUrl from 'github-url-from-git' +const ini = require('ini') +const ghUrl = require('github-url-from-git') -export default function () { - let pkg = JSON.parse(String(readFile('./package.json'))) +module.exports = function () { + let pkg = JSON.parse(String(readFileSync('./package.json'))) // ensure a yet unpublished version pkg.version = '0.0.0-semantically-released' @@ -26,7 +26,7 @@ export default function () { // set up repository if (!pkg.repository || !pkg.repository.url) { - const config = ini.decode(String(readFile('./.git/config'))) + const config = ini.decode(String(readFileSync('./.git/config'))) const repo = config['remote "origin"'].url if (repo) pkg.repository = { type: 'git', url: ghUrl(repo) } @@ -39,5 +39,5 @@ export default function () { pkg.devDependencies['semantic-release'] = `^${require('../package.json').version}` } - writeFile('./package.json', `${JSON.stringify(pkg, null, 2)}\n`) + writeFileSync('./package.json', `${JSON.stringify(pkg, null, 2)}\n`) } diff --git a/src/verify.js b/src/verify.js index 49ae2c7c..1ac2fca7 100644 --- a/src/verify.js +++ b/src/verify.js @@ -1,16 +1,16 @@ -import { readFileSync as readFile } from 'fs' +const { readFileSync } = require('fs') -export default function (input) { +let exports = module.exports = function (input) { const options = exports.verifyOptions(input) const pkg = exports.verifyPackage() const travis = exports.verifyTravis() return options && pkg && travis } -export function verifyTravis () { +exports.verifyTravis = function () { let travis try { - travis = String(readFile('.travis.yml')) + travis = String(readFileSync('.travis.yml')) } catch (e) { return true } @@ -30,12 +30,12 @@ export function verifyTravis () { return passed } -export function verifyPackage () { +exports.verifyPackage = function () { let passed = true let pkg try { - pkg = String(readFile('./package.json')) + pkg = String(readFileSync('./package.json')) } catch (e) { console.error('You must have a "package.json" present.') passed = false @@ -62,7 +62,7 @@ export function verifyPackage () { return passed } -export function verifyOptions (options) { +exports.verifyOptions = function (options) { if (!options) return true if (options.token) return true