style: backport import to require

This commit is contained in:
Stephan Bönnemann 2015-06-12 13:50:51 -07:00
parent 889f5f4360
commit 630bf63034
11 changed files with 60 additions and 66 deletions

View File

@ -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

View File

@ -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}`,

View File

@ -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)

View File

@ -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([

View File

@ -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({

View File

@ -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')
}

View File

@ -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'))

View File

@ -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))

View File

@ -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,

View File

@ -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`)
}

View File

@ -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