This repository has been archived by the owner on May 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
version
executable file
·69 lines (57 loc) · 2.16 KB
/
version
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env node
var path = require('path');
var bump = require('bump-version');
var unreleased = require('unreleased');
var fs = require('fs');
function run(cmd, done) {
var exec = require('child_process').exec;
var proc = exec(cmd, done);
proc.stdout.pipe(process.stdout);
proc.stderr.pipe(process.stderr);
}
function replaceDistScriptNames(str, scriptName, version, bumpedVersion) {
var v = version.split(".");
var vb = bumpedVersion.split(".");
var regExp = new RegExp(scriptName + "-" + v[0] + "(\." + v[1] + ")?(\." + v[2] + ")?(\.min)?.js", "g");
return str.replace(regExp, function (_, minor, patch, min) {
var r = [scriptName + "-" + vb[0]];
if (minor) r.push(vb[1]);
if (patch) r.push(vb[2]);
if (min) r.push("min");
r.push("js");
return r.join(".");
});
}
function replaceDistScriptNamesInFile(filePath, scriptName, version, bumpedVersion) {
var str = fs.readFileSync(filePath, "utf8");
var bumpedStr = replaceDistScriptNames(str, scriptName, version, bumpedVersion);
fs.writeFileSync(filePath, bumpedStr);
}
try {
var version = require('../package.json').version;
var rootDir = path.resolve(__dirname, '..');
var res = bump(rootDir, process.argv.pop());
replaceDistScriptNamesInFile("README.md", "lock-passwordless", version, res.version);
unreleased(res.version, rootDir, 'auth0/lock-passwordless', function (err, changelog) {
if (err) { return process.exit(1); }
changelog = new Buffer(changelog + '\n\n');
var file = path.join(rootDir, 'CHANGELOG.md');
var data = fs.readFileSync(file); //read existing contents into data
var fd = fs.openSync(file, 'w+');
fs.writeSync(fd, changelog, 0, changelog.length); //write new data
fs.writeSync(fd, data, 0, data.length); //append old data
fs.close(fd);
run('git commit -am "Release: ' + res.version + '"', function (err) {
if (!err) { return process.exit(0); }
// restore original status
console.error(err.message);
run('git checkout .', function (err) {
if (err) { console.error(err.message); }
process.exit(1);
});
});
});
} catch (err) {
console.error(err.message);
process.exit(1);
}