style: backport import to require
This commit is contained in:
parent
889f5f4360
commit
630bf63034
@ -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
|
let type = null
|
||||||
|
|
||||||
commits
|
commits
|
||||||
|
@ -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'
|
const range = (from ? from + '..' : '') + 'HEAD'
|
||||||
exec(
|
exec(
|
||||||
`git log -E --format=%H==SPLIT==%B==END== ${range}`,
|
`git log -E --format=%H==SPLIT==%B==END== ${range}`,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
export const efh = require('error-first-handler')
|
exports.efh = require('error-first-handler')
|
||||||
export const standard = efh((err) => {
|
exports.standard = exports.efh((err) => {
|
||||||
console.log('Something went wrong:')
|
console.log('Something went wrong:')
|
||||||
if (typeof err === 'string') return console.log(err)
|
if (typeof err === 'string') return console.log(err)
|
||||||
if (err instanceof Error) return console.log(err.message, err.stack)
|
if (err instanceof Error) return console.log(err.message, err.stack)
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import async from 'async'
|
const async = require('async')
|
||||||
import npmconf from 'npmconf'
|
const npmconf = require('npmconf')
|
||||||
import request from 'request'
|
const request = require('request')
|
||||||
|
|
||||||
export default function (pkgName, cb) {
|
module.exports = function (pkgName, cb) {
|
||||||
const registry = process.env.npm_config_registry
|
const registry = process.env.npm_config_registry
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { readFileSync as readFile } from 'fs'
|
const { readFileSync } = require('fs')
|
||||||
|
|
||||||
import changelog from 'conventional-changelog'
|
const changelog = require('conventional-changelog')
|
||||||
import parseUrl from 'github-url-from-git'
|
const parseUrl = require('github-url-from-git')
|
||||||
|
|
||||||
export default function (cb) {
|
module.exports = function (cb) {
|
||||||
const pkg = JSON.parse(readFile('./package.json'))
|
const pkg = JSON.parse(readFileSync('./package.json'))
|
||||||
const repository = pkg.repository ? parseUrl(pkg.repository.url) : null
|
const repository = pkg.repository ? parseUrl(pkg.repository.url) : null
|
||||||
|
|
||||||
changelog({
|
changelog({
|
||||||
|
26
src/main.js
26
src/main.js
@ -1,13 +1,7 @@
|
|||||||
import abbrev from 'abbrev'
|
const abbrev = require('abbrev')
|
||||||
import { standard as efh } from './lib/error'
|
const efh = require('./lib/error').standard
|
||||||
|
|
||||||
import postStep from './post'
|
exports.pre = function (argv, npmArgv, plugins) {
|
||||||
import preStep from './pre'
|
|
||||||
import restartStep from './restart'
|
|
||||||
import setupStep from './setup'
|
|
||||||
import verifyStep from './verify'
|
|
||||||
|
|
||||||
export function pre (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)
|
||||||
@ -34,9 +28,9 @@ If you think this is a problem with semantic-release please open an issue.`
|
|||||||
const publish = isAbbrev(npmArgv, 'publish')
|
const publish = isAbbrev(npmArgv, 'publish')
|
||||||
|
|
||||||
// require a correct setup during 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) {
|
if (!result) {
|
||||||
console.log('Nothing changed. Not publishing.')
|
console.log('Nothing changed. Not publishing.')
|
||||||
process.exit(1)
|
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)
|
if (argv.debug) process.exit(1)
|
||||||
|
|
||||||
restartStep(efh(() => process.exit(1)))
|
require('./restart')(efh(() => process.exit(1)))
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
export function post (argv, npmArgv, plugins) {
|
exports.post = function (argv, npmArgv, plugins) {
|
||||||
postStep(argv, plugins, efh(function () {
|
require('./post')(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.')
|
||||||
@ -60,8 +54,8 @@ export function post (argv, npmArgv, plugins) {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setup () {
|
exports.setup = function () {
|
||||||
setupStep()
|
require('./setup')()
|
||||||
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')
|
||||||
}
|
}
|
||||||
|
16
src/post.js
16
src/post.js
@ -1,14 +1,14 @@
|
|||||||
import {readFileSync as readFile } from 'fs'
|
const { readFileSync } = require('fs')
|
||||||
import url from 'url'
|
const url = require('url')
|
||||||
|
|
||||||
import gitHead from 'git-head'
|
const gitHead = require('git-head')
|
||||||
import GitHubApi from 'github'
|
const GitHubApi = require('github')
|
||||||
import parseSlug from 'parse-github-repo-url'
|
const parseSlug = require('parse-github-repo-url')
|
||||||
|
|
||||||
import { efh } from './lib/error'
|
const efh = require('./lib/error').efh
|
||||||
|
|
||||||
export default function (options, plugins, cb) {
|
module.exports = function (options, plugins, cb) {
|
||||||
const pkg = JSON.parse(readFile('./package.json'))
|
const pkg = JSON.parse(readFileSync('./package.json'))
|
||||||
const repository = pkg.repository ? pkg.repository.url : null
|
const 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'))
|
||||||
|
12
src/pre.js
12
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'
|
const getCommits = require('./lib/commits')
|
||||||
import npmInfo from './lib/npm-info'
|
const npmInfo = require('./lib/npm-info')
|
||||||
import { efh } from './lib/error'
|
const { efh } = require('./lib/error')
|
||||||
|
|
||||||
export default function (options, plugins, cb) {
|
module.exports = function (options, plugins, cb) {
|
||||||
const path = './package.json'
|
const path = './package.json'
|
||||||
let pkg = JSON.parse(fs.readFileSync(path))
|
let pkg = JSON.parse(fs.readFileSync(path))
|
||||||
|
|
||||||
|
@ -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
|
// 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
|
||||||
@ -18,7 +18,7 @@ export default function (cb) {
|
|||||||
child.on('error', cb)
|
child.on('error', cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function handleCloseAndExit (cb, code, signal) {
|
exports.handleCloseAndExit = function (cb, code, signal) {
|
||||||
if (code === 0) return cb(null)
|
if (code === 0) return cb(null)
|
||||||
cb({
|
cb({
|
||||||
code,
|
code,
|
||||||
|
20
src/setup.js
20
src/setup.js
@ -1,13 +1,13 @@
|
|||||||
import {
|
const {
|
||||||
readFileSync as readFile,
|
readFileSync,
|
||||||
writeFileSync as writeFile
|
writeFileSync
|
||||||
} from 'fs'
|
} = require('fs')
|
||||||
|
|
||||||
import ini from 'ini'
|
const ini = require('ini')
|
||||||
import ghUrl from 'github-url-from-git'
|
const ghUrl = require('github-url-from-git')
|
||||||
|
|
||||||
export default function () {
|
module.exports = function () {
|
||||||
let pkg = JSON.parse(String(readFile('./package.json')))
|
let pkg = JSON.parse(String(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'
|
||||||
@ -26,7 +26,7 @@ export default function () {
|
|||||||
|
|
||||||
// set up repository
|
// set up repository
|
||||||
if (!pkg.repository || !pkg.repository.url) {
|
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
|
const repo = config['remote "origin"'].url
|
||||||
|
|
||||||
if (repo) pkg.repository = { type: 'git', url: ghUrl(repo) }
|
if (repo) pkg.repository = { type: 'git', url: ghUrl(repo) }
|
||||||
@ -39,5 +39,5 @@ export default function () {
|
|||||||
pkg.devDependencies['semantic-release'] = `^${require('../package.json').version}`
|
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`)
|
||||||
}
|
}
|
||||||
|
@ -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 options = exports.verifyOptions(input)
|
||||||
const pkg = exports.verifyPackage()
|
const pkg = exports.verifyPackage()
|
||||||
const travis = exports.verifyTravis()
|
const travis = exports.verifyTravis()
|
||||||
return options && pkg && travis
|
return options && pkg && travis
|
||||||
}
|
}
|
||||||
|
|
||||||
export function verifyTravis () {
|
exports.verifyTravis = function () {
|
||||||
let travis
|
let travis
|
||||||
try {
|
try {
|
||||||
travis = String(readFile('.travis.yml'))
|
travis = String(readFileSync('.travis.yml'))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -30,12 +30,12 @@ export function verifyTravis () {
|
|||||||
return passed
|
return passed
|
||||||
}
|
}
|
||||||
|
|
||||||
export function verifyPackage () {
|
exports.verifyPackage = function () {
|
||||||
let passed = true
|
let passed = true
|
||||||
|
|
||||||
let pkg
|
let pkg
|
||||||
try {
|
try {
|
||||||
pkg = String(readFile('./package.json'))
|
pkg = String(readFileSync('./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 @@ export function verifyPackage () {
|
|||||||
return passed
|
return passed
|
||||||
}
|
}
|
||||||
|
|
||||||
export function verifyOptions (options) {
|
exports.verifyOptions = function (options) {
|
||||||
if (!options) return true
|
if (!options) return true
|
||||||
if (options.token) return true
|
if (options.token) return true
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user