style: use es6 in src
This commit is contained in:
parent
5a8c8639af
commit
f0bb39a22e
@ -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
|
||||
|
@ -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]
|
||||
|
@ -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)
|
||||
})
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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,
|
||||
|
40
src/main.js
40
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')
|
||||
}
|
||||
|
40
src/post.js
40
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)))
|
||||
}))
|
||||
}))
|
||||
}
|
||||
|
36
src/pre.js
36
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)
|
||||
|
@ -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'
|
||||
})
|
||||
}
|
||||
|
31
src/setup.js
31
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`)
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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/'
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user