forked from mobxjs/serializr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.js
executable file
·35 lines (30 loc) · 1.45 KB
/
publish.js
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
#!/usr/local/bin/nscript
/* To run this script, nscript is needed: [sudo] npm install -g nscript
/* Publish.js, publish a new version of the npm package as found in the current directory */
/* Run this file from the root of the repository */
module.exports = function(shell, npm, git) {
var pkg = JSON.parse(shell.read('package.json'));
// Bump version number
var nrs = pkg.version.split(".");
nrs[2] = 1 + parseInt(nrs[2], 10);
var version = pkg.version = shell.prompt("Please specify the new package version of '" + pkg.name + "' (Ctrl^C to abort)", nrs.join("."));
if (!version.match(/^\d+\.\d+\.\d+$/))
shell.exit(1, "Invalid semantic version: " + version);
// Check registery data
if (npm.silent().test("info", pkg.name)) {
//package is registered in npm?
var publishedPackageInfo = JSON.parse(npm.get("info", pkg.name, "--json"));
if (publishedPackageInfo.versions == version || publishedPackageInfo.versions.indexOf(version) != -1)
shell.exit(2, "Version " + pkg.version + " is already published to npm");
shell.write('package.json', JSON.stringify(pkg, null, 2));
// Finally, commit and publish!
npm("publish");
git("commit","-am","Published version " + version);
git("tag", version);
git("push");
git("push","--tags");
console.log("Published!");
}
else
shell.exit(1, pkg.name + " is not an existing npm package");
};