Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add --validate-config/-v option #5

Merged
merged 1 commit into from
May 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion bin/semantic-prerelease.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#!/usr/bin/env node

const path = require('path');
const validateConfig = require('../validateConfig');
const config = require(path.resolve('package.json'));
const branch = process.env.TRAVIS_BRANCH || process.env.GIT_LOCAL_BRANCH;
const branchTags = config.release && config.release.branchTags;
const tag = branchTags && branchTags[branch];
const dryRun = process.argv.find(arg => /^(--dry-run|-n)$/.test(arg));
const validate = process.argv.find(arg => /^(--validate|-v)$/.test(arg));
const command = [ 'npm', 'publish' ];

let command = [ 'npm', 'publish' ];
if (validate) {
validateConfig(config);
return;
}

if (tag) {
command.push('--tag', tag);
Expand Down
34 changes: 34 additions & 0 deletions validateConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
function validateConfig(config) {
let valid = true;
const assert = (msg, rule) => {
if (!rule()) {
console.error(msg);
valid = false;
}
};

assert('Expected to see "semantic-prerelase publish" in "semantic-release" script', () =>
config.scripts['semantic-release']
.indexOf('semantic-prerelease publish') != -1);

const release = config.release;
assert('Expected to see release section in package.json', () => release);

assert('Expected to see release.branchTags section in package.json', () =>
release.branchTags && Object.keys(release.branchTags).length > 0);

assert('Expected to see release.fallbackTags section in package.json', () =>
release.branchTags && Object.keys(release.fallbackTags).length > 0);

['analyzeCommits', 'generateNotes', 'getLastRelease', 'verifyConditions', 'verifyRelease']
.forEach((plugin) => {
assert(`Expected release.${ plugin } to be set to "@telerik/semantic-prerelease/${ plugin }"`, () =>
release[plugin] == `@telerik/semantic-prerelease/${ plugin }`);
});

if (!valid) {
process.exit(1);
}
}

module.exports = validateConfig;