Skip to content

Commit 73bca95

Browse files
tsvetomirgyoshev
authored andcommitted
feat: add --validate-config/-v option
1 parent 9494663 commit 73bca95

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

bin/semantic-prerelease.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
#!/usr/bin/env node
22

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

10-
let command = [ 'npm', 'publish' ];
13+
if (validate) {
14+
validateConfig(config);
15+
return;
16+
}
1117

1218
if (tag) {
1319
command.push('--tag', tag);

validateConfig.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
function validateConfig(config) {
2+
let valid = true;
3+
const assert = (msg, rule) => {
4+
if (!rule()) {
5+
console.error(msg);
6+
valid = false;
7+
}
8+
};
9+
10+
assert('Expected to see "semantic-prerelase publish" in "semantic-release" script', () =>
11+
config.scripts['semantic-release']
12+
.indexOf('semantic-prerelease publish') != -1);
13+
14+
const release = config.release;
15+
assert('Expected to see release section in package.json', () => release);
16+
17+
assert('Expected to see release.branchTags section in package.json', () =>
18+
release.branchTags && Object.keys(release.branchTags).length > 0);
19+
20+
assert('Expected to see release.fallbackTags section in package.json', () =>
21+
release.branchTags && Object.keys(release.fallbackTags).length > 0);
22+
23+
['analyzeCommits', 'generateNotes', 'getLastRelease', 'verifyConditions', 'verifyRelease']
24+
.forEach((plugin) => {
25+
assert(`Expected release.${ plugin } to be set to "@telerik/semantic-prerelease/${ plugin }"`, () =>
26+
release[plugin] == `@telerik/semantic-prerelease/${ plugin }`);
27+
});
28+
29+
if (!valid) {
30+
process.exit(1);
31+
}
32+
}
33+
34+
module.exports = validateConfig;

0 commit comments

Comments
 (0)