-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add dedicated command option for each step
- Loading branch information
Showing
18 changed files
with
448 additions
and
380 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,93 @@ | ||
const {isNil} = require('lodash'); | ||
const parseJson = require('parse-json'); | ||
const debug = require('debug')('semantic-release:exec'); | ||
const SemanticReleaseError = require('@semantic-release/error'); | ||
const execScript = require('./lib/exec-script'); | ||
const exec = require('./lib/exec'); | ||
const verifyConfig = require('./lib/verify-config'); | ||
|
||
async function verifyConditions(pluginConfig, context) { | ||
verifyConfig(pluginConfig); | ||
|
||
try { | ||
await execScript(pluginConfig, context); | ||
} catch (error) { | ||
throw new SemanticReleaseError(error.stdout, 'EVERIFYCONDITIONS'); | ||
if (!isNil(pluginConfig.verifyConditionsCmd) || !isNil(pluginConfig.cmd)) { | ||
verifyConfig('verifyConditionsCmd', pluginConfig); | ||
|
||
try { | ||
await exec('verifyConditionsCmd', pluginConfig, context); | ||
} catch (error) { | ||
throw new SemanticReleaseError(error.stdout, 'EVERIFYCONDITIONS'); | ||
} | ||
} | ||
} | ||
|
||
async function analyzeCommits(pluginConfig, context) { | ||
verifyConfig(pluginConfig); | ||
if (!isNil(pluginConfig.analyzeCommitsCmd) || !isNil(pluginConfig.cmd)) { | ||
verifyConfig('analyzeCommitsCmd', pluginConfig); | ||
|
||
const stdout = await execScript(pluginConfig, context); | ||
return stdout || undefined; | ||
const stdout = await exec('analyzeCommitsCmd', pluginConfig, context); | ||
return stdout || undefined; | ||
} | ||
} | ||
|
||
async function verifyRelease(pluginConfig, context) { | ||
verifyConfig(pluginConfig); | ||
|
||
try { | ||
await execScript(pluginConfig, context); | ||
} catch (error) { | ||
throw new SemanticReleaseError(error.stdout, 'EVERIFYRELEASE'); | ||
if (!isNil(pluginConfig.verifyReleaseCmd) || !isNil(pluginConfig.cmd)) { | ||
verifyConfig('verifyReleaseCmd', pluginConfig); | ||
|
||
try { | ||
await exec('verifyReleaseCmd', pluginConfig, context); | ||
} catch (error) { | ||
throw new SemanticReleaseError(error.stdout, 'EVERIFYRELEASE'); | ||
} | ||
} | ||
} | ||
|
||
async function generateNotes(pluginConfig, context) { | ||
verifyConfig(pluginConfig); | ||
if (!isNil(pluginConfig.generateNotesCmd) || !isNil(pluginConfig.cmd)) { | ||
verifyConfig('generateNotesCmd', pluginConfig); | ||
|
||
const stdout = await execScript(pluginConfig, context); | ||
return stdout; | ||
const stdout = await exec('generateNotesCmd', pluginConfig, context); | ||
return stdout; | ||
} | ||
} | ||
|
||
async function prepare(pluginConfig, context) { | ||
verifyConfig(pluginConfig); | ||
if (!isNil(pluginConfig.prepareCmd) || !isNil(pluginConfig.cmd)) { | ||
verifyConfig('prepareCmd', pluginConfig); | ||
|
||
await execScript(pluginConfig, context); | ||
await exec('prepareCmd', pluginConfig, context); | ||
} | ||
} | ||
|
||
async function publish(pluginConfig, context) { | ||
verifyConfig(pluginConfig); | ||
|
||
const stdout = await execScript(pluginConfig, context); | ||
|
||
try { | ||
return stdout ? parseJson(stdout) : undefined; | ||
} catch (error) { | ||
debug(stdout); | ||
debug(error); | ||
context.logger.log( | ||
`The command ${pluginConfig.cmd} wrote invalid JSON to stdout. The stdout content will be ignored.` | ||
); | ||
if (!isNil(pluginConfig.publishCmd) || !isNil(pluginConfig.cmd)) { | ||
verifyConfig('publishCmd', pluginConfig); | ||
|
||
const stdout = await exec('publishCmd', pluginConfig, context); | ||
|
||
try { | ||
return stdout ? parseJson(stdout) : undefined; | ||
} catch (error) { | ||
debug(stdout); | ||
debug(error); | ||
context.logger.log( | ||
`The command ${pluginConfig.publishCmd || | ||
pluginConfig.cmd} wrote invalid JSON to stdout. The stdout content will be ignored.` | ||
); | ||
} | ||
} | ||
} | ||
|
||
async function success(pluginConfig, context) { | ||
verifyConfig(pluginConfig); | ||
if (!isNil(pluginConfig.successCmd) || !isNil(pluginConfig.cmd)) { | ||
verifyConfig('successCmd', pluginConfig); | ||
|
||
await execScript(pluginConfig, context); | ||
await exec('successCmd', pluginConfig, context); | ||
} | ||
} | ||
|
||
async function fail(pluginConfig, context) { | ||
verifyConfig(pluginConfig); | ||
if (!isNil(pluginConfig.failCmd) || !isNil(pluginConfig.cmd)) { | ||
verifyConfig('failCmd', pluginConfig); | ||
|
||
await execScript(pluginConfig, context); | ||
await exec('failCmd', pluginConfig, context); | ||
} | ||
} | ||
|
||
module.exports = {verifyConditions, analyzeCommits, verifyRelease, generateNotes, prepare, publish, success, fail}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const url = require('url'); | ||
const {inspect} = require('util'); | ||
const {isString} = require('lodash'); | ||
const pkg = require('../../package.json'); | ||
|
||
const homepage = url.format({...url.parse(pkg.homepage), ...{hash: null}}); | ||
const stringify = obj => (isString(obj) ? obj : inspect(obj, {breakLength: Infinity, depth: 2, maxArrayLength: 5})); | ||
const linkify = file => `${homepage}/blob/master/${file}`; | ||
|
||
module.exports = { | ||
EINVALIDCMD: ({cmd, cmdProp}) => ({ | ||
message: `Invalid \`${cmdProp}\` option.`, | ||
details: `The [\`${cmdProp}\` option](${linkify( | ||
`README.md#${cmdProp}` | ||
)}) is required and must be a non empty \`String\`. | ||
Your configuration for the \`${cmdProp}\` option is \`${stringify(cmd)}\`.`, | ||
}), | ||
EINVALIDSHELL: ({shell}) => ({ | ||
message: 'Invalid `shell` option.', | ||
details: `The [\`shell\` option](${linkify( | ||
'README.md#options' | ||
)}) if defined, must be a non empty \`String\` or the value \`true\`. | ||
Your configuration for the \`shell\` option is \`${stringify(shell)}\`.`, | ||
}), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const SemanticReleaseError = require('@semantic-release/error'); | ||
const ERROR_DEFINITIONS = require('./definitions/errors'); | ||
|
||
module.exports = (code, ctx) => { | ||
const {message, details} = ERROR_DEFINITIONS[code](ctx); | ||
return new SemanticReleaseError(message, code, details); | ||
}; |
Oops, something went wrong.