This commit does a lot but it's all connected and tries to make everything more extensible and future proof. 1. CLI arguments and options from the "package.json" are no longer treated as two different things. You can now pass options either way. BREAKING CHANGE: cli arguments are now normalized to camelCase, so e.g. `options['github-url']` is now `options.githubUrl` 2. Plugins no longer receive config they need one by one, but in one huge object. This way it's easier to pass more info in the future w/o breaking existing plugins that rely on the position of the callback in the arguments array. BREAKING CHANGE: Plugins now need to read their passed options from one huge config object. Old: ```js module.exports = function (pluginConfig, foo, bar, cb) {…} ``` New: ```js // ES5 module.exports = function(pluginConfig, config, cb) { var foo = config.foo var bar = config.bar … } // ES6 module.exports = function (pluginConfig, {foo, bar}, cb) {…} ```
45 lines
1.0 KiB
JavaScript
45 lines
1.0 KiB
JavaScript
const parseSlug = require('parse-github-repo-url')
|
|
|
|
const SemanticReleaseError = require('@semantic-release/error')
|
|
|
|
module.exports = function ({pkg, options, env}) {
|
|
let errors = []
|
|
|
|
if (!pkg.name) {
|
|
errors.push(new SemanticReleaseError(
|
|
'No "name" found in package.json.',
|
|
'ENOPKGNAME'
|
|
))
|
|
}
|
|
|
|
if (!pkg.repository || !pkg.repository.url) {
|
|
errors.push(new SemanticReleaseError(
|
|
'No "repository" found in package.json.',
|
|
'ENOPKGREPO'
|
|
))
|
|
} else if (!parseSlug(pkg.repository.url)) {
|
|
errors.push(new SemanticReleaseError(
|
|
'The "repository" field in the package.json is malformed.',
|
|
'EMALFORMEDPKGREPO'
|
|
))
|
|
}
|
|
|
|
if (options.debug) return errors
|
|
|
|
if (!options.githubToken) {
|
|
errors.push(new SemanticReleaseError(
|
|
'No github token specified.',
|
|
'ENOGHTOKEN'
|
|
))
|
|
}
|
|
|
|
if (!(env.NPM_TOKEN || (env.NPM_OLD_TOKEN && env.NPM_EMAIL))) {
|
|
errors.push(new SemanticReleaseError(
|
|
'No npm token specified.',
|
|
'ENONPMTOKEN'
|
|
))
|
|
}
|
|
|
|
return errors
|
|
}
|