-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (41 loc) · 979 Bytes
/
index.js
File metadata and controls
49 lines (41 loc) · 979 Bytes
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
const updateJson = require('update-json');
const minimist = require('minimist');
const {
_: [ version ],
path = './package.json',
silent = false,
safe = false
} = minimist(process.argv.slice(2));
// Check version - Throw error if it is undefined
if (['undefined', 'null', '', undefined, null].some(value => value === version)) {
return throwError('Expected version but got: ' + version);
}
// Update package
updateJson(path, {version}, error => {
if (error) {
return throwError('Couldn\'t found package.json at path: ' + path);
}
log('Package version updated to: ' + version);
});
/**
* Log messages if silent mode isn't active
*
* @param {string} message
* @returns {void}
*/
function log(message) {
if (silent) { return; }
console.log(message);
}
/**
* Throw error if safe mode isn't active
*
* @param {string} message
* @returns {void}
*/
function throwError(message) {
if (safe) {
return console.warn(message);
}
throw new Error(message);
}