-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
executable file
·43 lines (36 loc) · 1.16 KB
/
index.ts
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
#!/usr/bin/env node
import fs = require('fs');
import path = require('path');
import residence = require('residence');
import ErrnoException = NodeJS.ErrnoException;
export type ErrnoExceptionFn = (e: ErrnoException) => void;
let syncSetup = function () {
const projectRoot = residence.findProjectRoot(process.cwd());
const pkgPath = path.resolve(projectRoot + '/package.json');
const pkg = require(pkgPath);
pkg.b3val = pkg.b3val || 0;
pkg.b3val++;
return {pkg, pkgPath};
};
let getStringifiedData = function(pkg: Object){
return JSON.stringify(pkg, null, 2);
};
export const bumpSync = function () : void {
const {pkg, pkgPath} = syncSetup();
return fs.writeFileSync(pkgPath, getStringifiedData(pkg));
};
export const bumpp = function () {
return new Promise<Error | void>(function (resolve, reject) {
const {pkg, pkgPath} = syncSetup();
fs.writeFile(pkgPath, getStringifiedData(pkg), function (err) {
err ? reject(err) : resolve();
});
});
};
export const bump = function (cb: ErrnoExceptionFn) {
const {pkg, pkgPath} = syncSetup();
fs.writeFile(pkgPath, getStringifiedData(pkg), cb);
};
if (require.main === module) {
bumpSync();
}