diff --git a/bin/semantic-release b/bin/semantic-release index 8d768535..24b1d564 100755 --- a/bin/semantic-release +++ b/bin/semantic-release @@ -40,6 +40,9 @@ if (~argv._.indexOf('pre')) { var publish = false if (isAbbrev(npmArgv, 'publish')) publish = true + // require a correct setup during publish + if (publish && !argv.debug && !require('../src/verify')(argv)) process.exit(1) + require('../src/pre')(argv, efh(function (result) { if (!result) { console.log('Nothing changed. Not publishing.') diff --git a/src/verify.js b/src/verify.js new file mode 100644 index 00000000..33bd2dc9 --- /dev/null +++ b/src/verify.js @@ -0,0 +1,71 @@ +'use strict' + +var fs = require('fs') + +var exports = module.exports = function (input) { + var options = exports.verifyOptions(input) + var pkg = exports.verifyPackage() + var travis = exports.verifyTravis() + return options && pkg && travis +} + +exports.verifyTravis = function () { + try { + var travis = fs.readFileSync('.travis.yml') + '' + } catch (e) { + return true + } + + var passed = true + + if (!/\sdeploy:/m.test(travis)) { + console.error('You should configure deployments inside the ".travis.yml".') + passed = false + } + + if (!/skip_cleanup:/m.test(travis)) { + console.error('You must set "skip_cleanup" to "true" inside the ".travis.yml".') + passed = false + } + + return passed +} + +exports.verifyPackage = function () { + var passed = true + + try { + var pkg = fs.readFileSync('./package.json') + '' + } catch (e) { + console.error('You must have a "package.json" present.') + passed = false + pkg = '{}' + } + + try { + pkg = JSON.parse(pkg) + } catch (e) { + console.error('You must have a "package.json" that is valid JSON.') + return false + } + + if (!pkg.repository || !pkg.repository.url) { + console.error('You must define your GitHub "repository" inside the "package.json".') + passed = false + } + + if (!pkg.scripts || !pkg.scripts.prepublish || !pkg.scripts.postpublish) { + console.error('You must define your "scripts" inside the "package.json".') + passed = false + } + + return passed +} + +exports.verifyOptions = function (options) { + if (!options) return true + if (options.token) return true + + console.error('You must define a GitHub token.') + return false +}