shelljs-changelog
Advanced tools
Comparing version 0.2.5 to 0.2.6
57
index.js
#!/usr/bin/env node | ||
var assert = require('assert'); | ||
require('shelljs-plugin-sleep'); | ||
require('shelljs/global'); | ||
@@ -8,2 +10,11 @@ | ||
// The maximum number of deletions for updating the changelog should | ||
// be 5 lines. Typically, the "Unreleased" and "Full Changelog" links | ||
// are changed because the version increases. | ||
var MAX_DELETIONS = 5; | ||
// Command line option: --force | ||
// Skips validating the number of deletions in the changelog diff. | ||
var force = (process.argv.indexOf('--force') >= 0); | ||
function parseGitUri(uri) { | ||
@@ -14,5 +25,35 @@ return uri.match(/https:..github.com\/([^./]+)\/([^./]+).*/) || | ||
function verifyChangelog() { | ||
var diff = exec('git diff HEAD CHANGELOG.md').split('\n'); | ||
var changelog = cat('CHANGELOG.md').split('\n'); | ||
if (changelog[changelog.length - 1] === '') changelog.pop(); | ||
var isOneLine = (changelog.length === 1); | ||
var deletions = diff.filter(function (x) { | ||
return /^-/.test(x); | ||
}).length; | ||
var containsError = false; | ||
diff.forEach(function (line) { | ||
if (line.indexOf('Make a POST first') >= 0) containsError = true; | ||
}); | ||
assert( | ||
changelog.length > 1, | ||
'Changelog was reduced to one line, this is an error.' | ||
); | ||
assert( | ||
!containsError, | ||
'Changelog contains an error message.' | ||
); | ||
assert( | ||
deletions < MAX_DELETIONS, | ||
'Too many deletions (-' + deletions + '), this is probably an error.\n' + | ||
'Run with --force to ignore this error.' | ||
); | ||
} | ||
function revertChanges() { | ||
exec('git checkout -- .'); | ||
} | ||
function run() { | ||
echo('...generating changelog (be patient)'); | ||
config.silent = true; | ||
@@ -34,3 +75,3 @@ var urls = exec('git remote show -n origin') | ||
do { | ||
exec('sleep 1'); | ||
sleep(1); | ||
newLog = exec('curl "' + url + '"'); | ||
@@ -43,6 +84,16 @@ } while (newLog.match(/^Working, try again.*/)); | ||
exec('git ls-files --exclude-standard --modified --others').split('\n').forEach(function (file) { | ||
if ( file === 'CHANGELOG.md') changelog_was_updated = true; | ||
if (file === 'CHANGELOG.md') changelog_was_updated = true; | ||
}); | ||
if (changelog_was_updated) { | ||
if (!force) { | ||
try { | ||
echo('...verifying changelog'); | ||
verifyChangelog(); | ||
} catch (err) { | ||
revertChanges(); | ||
console.error(err.message); | ||
process.exit(1); | ||
} | ||
} | ||
echo('...committing updated changelog'); | ||
@@ -49,0 +100,0 @@ var current_user = exec('git config user.name').trimRight(); |
{ | ||
"name": "shelljs-changelog", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"description": "A simple script to create & update a changelog", | ||
@@ -29,7 +29,8 @@ "main": "index.js", | ||
"dependencies": { | ||
"shelljs": "^0.7.0" | ||
"shelljs": "^0.8.5", | ||
"shelljs-plugin-sleep": "^0.2.1" | ||
}, | ||
"devDependencies": { | ||
"shelljs-release": "^0.2.0" | ||
"shelljs-release": "^0.5.1" | ||
} | ||
} |
@@ -35,1 +35,8 @@ # Changelog.js | ||
For best results, try to run this after every time you publish. | ||
## Command line options | ||
### `--force` | ||
By default, this script verifies that the changelog diff contains no more than | ||
5 deletions. With `--force` enabled, this step is skipped. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6135
96
42
2
5
+ Addedshelljs-plugin-sleep@^0.2.1
+ Addednan@2.22.0(transitive)
+ Addedshelljs@0.8.5(transitive)
+ Addedshelljs-plugin-sleep@0.2.2(transitive)
+ Addedsleep@3.0.1(transitive)
- Removedshelljs@0.7.8(transitive)
Updatedshelljs@^0.8.5