style: use es6 in src

This commit is contained in:
Stephan Bönnemann 2015-06-11 15:05:15 -07:00
parent 5a8c8639af
commit f0bb39a22e
12 changed files with 138 additions and 160 deletions

View File

@ -1,21 +1,15 @@
'use strict' import { parseRawCommit } from 'conventional-changelog/lib/git'
var parseRawCommit = require('conventional-changelog/lib/git').parseRawCommit export default function (commits) {
let type = null
module.exports = function (commits) {
var type = null
commits commits
.map(function (commit) { .map((commit) => parseRawCommit(`${commit.hash}\n${commit.message}`))
return parseRawCommit(commit.hash + '\n' + commit.message)
})
.filter(function (commit) { .filter((commit) => !!commit)
return !!commit
})
.every(function (commit) { .every((commit) => {
if (commit.breaks.length) { if (commit.breaks.length) {
type = 'major' type = 'major'
return false return false

View File

@ -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 export default function (from, cb) {
const range = (from ? from + '..' : '') + 'HEAD'
module.exports = function (from, cb) {
var range = (from ? from + '..' : '') + 'HEAD'
exec( exec(
'git log -E --format=%H==SPLIT==%B==END== ' + range, `git log -E --format=%H==SPLIT==%B==END== ${range}`,
efh(cb)(function (stdout) { efh(cb)((stdout) => {
cb(null, String(stdout).split('==END==\n') cb(null, String(stdout).split('==END==\n')
.filter(function (raw) { .filter((raw) => !!raw.trim())
return !!raw.trim()
})
.map(function (raw) { .map((raw) => {
var data = raw.split('==SPLIT==') const data = raw.split('==SPLIT==')
return { return {
hash: data[0], hash: data[0],
message: data[1] message: data[1]

View File

@ -1,14 +1,8 @@
'use strict' export const efh = require('error-first-handler')
export const standard = efh((err) => {
var efh = require('error-first-handler') console.log('Something went wrong:')
if (typeof err === 'string') return console.log(err)
module.exports = { if (err instanceof Error) return console.log(err.message, err.stack)
efh: efh, if (err.message) return console.log(err.message)
standard: efh(function (err) { console.log(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)
})
}

View File

@ -1,29 +1,30 @@
'use strict' import async from 'async'
import npmconf from 'npmconf'
import request from 'request'
var async = require('async') export default function (pkgName, cb) {
var npmconf = require('npmconf') const registry = process.env.npm_config_registry
var request = require('request')
module.exports = function (pkgName, cb) {
var registry = process.env.npm_config_registry
async.waterfall([ async.waterfall([
npmconf.load, npmconf.load,
function (conf, callback) { (conf, callback) => {
var cred = conf.getCredentialsByURI(registry) const cred = conf.getCredentialsByURI(registry)
var reqopts = { const reqopts = {
url: registry + pkgName.replace(/\//g, '%2F'), url: registry + pkgName.replace(/\//g, '%2F'),
headers: {} headers: {}
} }
if (cred.token) { if (cred.token) {
reqopts.headers.Authorization = 'Bearer ' + cred.token reqopts.headers.Authorization = `Bearer ${cred.token}`
} else if (cred.auth) { } else if (cred.auth) {
reqopts.headers.Authorization = 'Basic ' + cred.auth reqopts.headers.Authorization = `Basic ${cred.auth}`
} }
callback(null, reqopts) callback(null, reqopts)
}, },
request, request,
function (response, body, callback) { (response, body, callback) => {
var res = { let res = {
version: null, version: null,
gitHead: null, gitHead: null,
pkg: null pkg: null
@ -31,7 +32,7 @@ module.exports = function (pkgName, cb) {
if (response.statusCode === 404 || !body) return callback(null, res) 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) if (pkg.error) return callback(pkg.error)

View File

@ -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') export default function (cb) {
var parseUrl = require('github-url-from-git') const pkg = JSON.parse(readFile('./package.json'))
const repository = pkg.repository ? parseUrl(pkg.repository.url) : null
module.exports = function (cb) {
var pkg = JSON.parse(readFile('./package.json'))
var repository = pkg.repository ? parseUrl(pkg.repository.url) : null
changelog({ changelog({
version: pkg.version, version: pkg.version,

View File

@ -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 export function pre (argv, npmArgv, plugins) {
exports.pre = function (argv, npmArgv, plugins) {
// see src/restart.js // see src/restart.js
if (npmArgv['semantic-release-rerun']) { if (npmArgv['semantic-release-rerun']) {
if (!/semantically-released/.test(process.env.npm_package_version)) process.exit(0) 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(
console.log('Please verify that your setup is correct.') `There is something wrong with your setup, as a placeholder version is about to be released.
console.log('If you think this is a problem with semantic-release please open an issue.') Please verify that your setup is correct.
If you think this is a problem with semantic-release please open an issue.`
)
process.exit(1) process.exit(1)
} }
// the `prepublish` hook is also executed when the package is installed // 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') console.log('Determining new version')
var publish = false const publish = isAbbrev(npmArgv, 'publish')
if (isAbbrev(npmArgv, 'publish')) publish = true
// require a correct setup during 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) { if (!result) {
console.log('Nothing changed. Not publishing.') console.log('Nothing changed. Not publishing.')
process.exit(1) process.exit(1)
@ -43,14 +47,12 @@ exports.pre = function (argv, npmArgv, plugins) {
if (argv.debug) process.exit(1) if (argv.debug) process.exit(1)
require('./restart')(efh(function () { restartStep(efh(() => process.exit(1)))
process.exit(1)
}))
})) }))
} }
exports.post = function (argv, npmArgv, plugins) { export function post (argv, npmArgv, plugins) {
require('./post')(argv, plugins, efh(function () { postStep(argv, plugins, efh(function () {
// see src/restart.js // see src/restart.js
if (npmArgv['semantic-release-rerun']) { if (npmArgv['semantic-release-rerun']) {
console.log('Everything is alright :) npm will now print an error message that you can safely ignore.') 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 () { export function setup () {
require('./setup')() setupStep()
console.log('"package.json" is set up properly. Now configure your CI server.') console.log('"package.json" is set up properly. Now configure your CI server.')
console.log('https://github.com/boennemann/semantic-release#ci-server') console.log('https://github.com/boennemann/semantic-release#ci-server')
} }

View File

@ -1,38 +1,36 @@
'use strict' import {readFileSync as readFile } from 'fs'
import url from 'url'
var readFile = require('fs').readFileSync import gitHead from 'git-head'
var url = require('url') import GitHubApi from 'github'
import parseSlug from 'parse-github-repo-url'
var gitHead = require('git-head') import { efh } from './lib/error'
var GitHubApi = require('github')
var parseSlug = require('parse-github-repo-url')
var 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 repository = pkg.repository ? pkg.repository.url : null
var pkg = JSON.parse(readFile('./package.json'))
var repository = pkg.repository ? pkg.repository.url : null
if (!repository) return cb(new Error('Package must have a repository')) 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', version: '3.0.0',
port: config.port, port: config.port,
protocol: (config.protocol || '').split(':')[0] || null, protocol: (config.protocol || '').split(':')[0] || null,
host: config.hostname host: config.hostname
}) })
notesGenerator(efh(cb)(function (log) { notesGenerator(efh(cb)((log) => {
gitHead(efh(cb)(function (hash) { gitHead(efh(cb)((hash) => {
var ghRepo = parseSlug(repository) const ghRepo = parseSlug(repository)
var release = { const release = {
owner: ghRepo[0], owner: ghRepo[0],
repo: ghRepo[1], repo: ghRepo[1],
tag_name: 'v' + pkg.version, tag_name: `v${pkg.version}`,
target_commitish: hash, target_commitish: hash,
draft: options.debug, draft: options.debug,
body: log body: log
@ -43,9 +41,7 @@ module.exports = function (options, plugins, cb) {
token: options.token token: options.token
}) })
github.releases.createRelease(release, efh(cb)(function () { github.releases.createRelease(release, efh(cb)(() => cb(null, true)))
cb(null, true)
}))
})) }))
})) }))
} }

View File

@ -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') export default function (options, plugins, cb) {
var npmInfo = require('./lib/npm-info') const path = './package.json'
var efh = require('./lib/error').efh let pkg = JSON.parse(fs.readFileSync(path))
module.exports = function (options, plugins, cb) {
var path = './package.json'
var pkg = JSON.parse(fs.readFileSync(path))
if (!pkg.name) return cb(new Error('Package must have a name')) if (!pkg.name) return cb(new Error('Package must have a name'))
npmInfo(pkg.name, efh(cb)(function (res) { npmInfo(pkg.name, efh(cb)((res) => {
getCommits(res.gitHead, efh(cb)(function (commits) { getCommits(res.gitHead, efh(cb)((commits) => {
var analyzer = require(plugins.analyzer || './lib/analyzer') const analyzer = require(plugins.analyzer || './lib/analyzer')
var type = analyzer(commits) let type = analyzer(commits)
if (!type) return cb(null, null) if (!type) return cb(null, null)
@ -28,14 +26,14 @@ module.exports = function (options, plugins, cb) {
pkg.version = '1.0.0' pkg.version = '1.0.0'
} }
var writePkg = function () { function writePkg () {
if (!options.debug) fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + '\n') if (!options.debug) fs.writeFileSync(path, `${JSON.stringify(pkg, null, 2)}\n`)
cb(null, pkg.version) cb(null, pkg.version)
} }
if (!plugins.verification) return writePkg() if (!plugins.verification) return writePkg()
var opts = {} let opts = {}
if (typeof plugins.verification === 'string') { if (typeof plugins.verification === 'string') {
opts.path = plugins.verification opts.path = plugins.verification
@ -50,11 +48,11 @@ module.exports = function (options, plugins, cb) {
opts.version = res.version opts.version = res.version
opts.nextVersion = pkg.version opts.nextVersion = pkg.version
var verification = require(opts.path) const verification = require(opts.path)
console.log('Running verification hook...') console.log('Running verification hook...')
verification(opts, function (error, ok) { verification(opts, (error, ok) => {
if (!error && ok) return writePkg() if (!error && ok) return writePkg()
console.log('Verification failed' + (error ? ': ' + error : '')) console.log('Verification failed' + (error ? ': ' + error : ''))
process.exit(1) process.exit(1)

View File

@ -1,16 +1,14 @@
'use strict' import { spawn } from 'child_process'
var spawn = require('child_process').spawn export default function (cb) {
var exports = module.exports = function (cb) {
// npm loads package.json data before running the `prepublish` hook // npm loads package.json data before running the `prepublish` hook
// changing the version on `prepublish` has no effect // changing the version on `prepublish` has no effect
// see https://github.com/npm/npm/issues/7118 // see https://github.com/npm/npm/issues/7118
// to circumvent this behavior we are calling `npm publish` inside `prepublish` // 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 // the package.json is then loaded again and the correct version will be published
var child = spawn('npm', ['publish', '--semantic-release-rerun']) const child = spawn('npm', ['publish', '--semantic-release-rerun'])
var handler = exports.handleCloseAndExit.bind(null, cb) const handler = exports.handleCloseAndExit.bind(null, cb)
child.stdout.pipe(process.stdout) child.stdout.pipe(process.stdout)
child.stderr.pipe(process.stderr) child.stderr.pipe(process.stderr)
@ -20,11 +18,11 @@ var exports = module.exports = function (cb) {
child.on('error', cb) child.on('error', cb)
} }
exports.handleCloseAndExit = function (cb, code, signal) { export function handleCloseAndExit (cb, code, signal) {
if (code === 0) return cb(null) if (code === 0) return cb(null)
cb({ cb({
code: code, code,
signal: signal, signal,
message: 'npm publish failed' message: 'npm publish failed'
}) })
} }

View File

@ -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') export default function () {
var ghUrl = require('github-url-from-git') let pkg = JSON.parse(String(readFile('./package.json')))
module.exports = function () {
var pkg = JSON.parse(fs.readFileSync('./package.json') + '')
// ensure a yet unpublished version // ensure a yet unpublished version
pkg.version = '0.0.0-semantically-released' pkg.version = '0.0.0-semantically-released'
// set up scripts // set up scripts
var pre = 'semantic-release pre' const pre = 'semantic-release pre'
var post = 'semantic-release post' const post = 'semantic-release post'
if (!pkg.scripts) pkg.scripts = {} if (!pkg.scripts) pkg.scripts = {}
if (!pkg.scripts.prepublish) pkg.scripts.prepublish = pre 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 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 // set up repository
if (!pkg.repository || !pkg.repository.url) { if (!pkg.repository || !pkg.repository.url) {
var config = ini.decode(fs.readFileSync('./.git/config') + '') const config = ini.decode(String(readFile('./.git/config')))
var repo = config['remote "origin"'].url const repo = config['remote "origin"'].url
if (repo) pkg.repository = { type: 'git', url: ghUrl(repo) } if (repo) pkg.repository = { type: 'git', url: ghUrl(repo) }
} }
@ -35,8 +36,8 @@ module.exports = function () {
if (!pkg.devDependencies) pkg.devDependencies = {} if (!pkg.devDependencies) pkg.devDependencies = {}
if (!pkg.devDependencies['semantic-release']) { 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`)
} }

View File

@ -1,22 +1,21 @@
'use strict' import { readFileSync as readFile } from 'fs'
var fs = require('fs') export default function (input) {
const options = exports.verifyOptions(input)
var exports = module.exports = function (input) { const pkg = exports.verifyPackage()
var options = exports.verifyOptions(input) const travis = exports.verifyTravis()
var pkg = exports.verifyPackage()
var travis = exports.verifyTravis()
return options && pkg && travis return options && pkg && travis
} }
exports.verifyTravis = function () { export function verifyTravis () {
let travis
try { try {
var travis = fs.readFileSync('.travis.yml') + '' travis = String(readFile('.travis.yml'))
} catch (e) { } catch (e) {
return true return true
} }
var passed = true let passed = true
if (!/\sdeploy:/m.test(travis)) { if (!/\sdeploy:/m.test(travis)) {
console.error('You should configure deployments inside the ".travis.yml".') console.error('You should configure deployments inside the ".travis.yml".')
@ -31,11 +30,12 @@ exports.verifyTravis = function () {
return passed return passed
} }
exports.verifyPackage = function () { export function verifyPackage () {
var passed = true let passed = true
let pkg
try { try {
var pkg = fs.readFileSync('./package.json') + '' pkg = String(readFile('./package.json'))
} catch (e) { } catch (e) {
console.error('You must have a "package.json" present.') console.error('You must have a "package.json" present.')
passed = false passed = false
@ -62,7 +62,7 @@ exports.verifyPackage = function () {
return passed return passed
} }
exports.verifyOptions = function (options) { export function verifyOptions (options) {
if (!options) return true if (!options) return true
if (options.token) return true if (options.token) return true

View File

@ -2,7 +2,7 @@
var nock = require('nock') 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/' var registry = 'http://registry.npmjs.org/'