-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
113 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const version = require('./version'); | ||
|
||
const [,, release, prereleaseId] = process.argv; | ||
|
||
let newVersion; | ||
|
||
if (release) { | ||
newVersion = version.bump({ | ||
release, | ||
prereleaseId, | ||
}); | ||
} | ||
// if this was run with no arguments, get the current version with | ||
// updated build metadata | ||
else { | ||
newVersion = version.get(); | ||
} | ||
|
||
version.write(newVersion); | ||
console.log(newVersion); |
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
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
const child_process = require('child_process'); | ||
|
||
function run (cmd) { | ||
return child_process.execSync(cmd).toString().trim(); | ||
} | ||
|
||
module.exports = { | ||
short: () => run('git rev-parse --short HEAD'), | ||
}; |
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,4 +1,8 @@ | ||
const gitRev = require('./gitRev'); | ||
const version = require('./version'); | ||
|
||
module.exports = (input, versionOptions) => [ | ||
[ /[{]VERSION[}]/g, require('./getVersion')(versionOptions) ], | ||
[ /[{]YEAR[}]/g, new Date().getFullYear() ], | ||
[ /[{]VERSION[}]/g, version.get(versionOptions) ], | ||
[ /[{]YEAR[}]/g , new Date().getFullYear() ], | ||
[ /[{]GIT_REV[}]/g, gitRev.short() ], | ||
].reduce((result, [rx, str]) => result.replace(rx, str), input); |
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,51 @@ | ||
const child_process = require('child_process'); | ||
const fs = require('fs'); | ||
const semver = require('semver'); | ||
const gitRev = require('./gitRev'); | ||
|
||
const version = { | ||
get ({ updateMetadata = true } = {}) { | ||
const package = JSON.parse(fs.readFileSync('package.json').toString()); | ||
|
||
const parsed = semver.parse(package.version); | ||
const dirty = child_process.execSync(` | ||
git diff-index --quiet HEAD -- . ':!dist' ':!package.json' && | ||
git diff --quiet -- . ':!dist' || | ||
echo -dirty`).toString().trim(); | ||
const matchedMetadata = parsed.raw.match(/[+].*$/); | ||
const newMetadata = updateMetadata | ||
? `+sha.${gitRev.short()}`.trim() | ||
: matchedMetadata? matchedMetadata[0] : ''; | ||
|
||
return `v${parsed.version}${newMetadata}${dirty}`; | ||
}, | ||
|
||
bump ({ | ||
version: prev = version.get(), | ||
release = 'minor', | ||
prereleaseId, | ||
}) { | ||
const semverArgs = [prev, release, prereleaseId]; | ||
|
||
let newVersion = semver.inc(...semverArgs); | ||
|
||
if (newVersion === null) { | ||
throw `Invalid args to semver.inc (${semverArgs.join()})`; | ||
} | ||
|
||
if (release === 'prerelease') { | ||
newVersion += `+sha.${gitRev.short()}`; | ||
} | ||
|
||
return newVersion; | ||
}, | ||
|
||
write (newVersion) { | ||
const package = JSON.parse(fs.readFileSync('package.json').toString()); | ||
package.version = newVersion; | ||
|
||
fs.writeFileSync('package.json', `${JSON.stringify(package, null, 2)}\n`); | ||
}, | ||
}; | ||
|
||
module.exports = version; |
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