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