-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdeployPackage.js
60 lines (45 loc) · 1.54 KB
/
deployPackage.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
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
import fs from 'fs';
import { exec, execSync } from 'child_process'
import fetch from 'node-fetch';
async function updatePackageNumber(version) {
return new Promise(async (resolve, reject) => {
try {
const packageJson = fs.readFileSync('package.json')
const jsonifiedPackageJson = await JSON.parse(packageJson);
// Step 1: update the package #
let splits = version.split('.');
let numberVer = parseInt(splits[2])
splits[2] = (numberVer += 1).toString();
const newVersion = splits.join('.');
jsonifiedPackageJson['version'] = newVersion;
fs.writeFileSync('package.json', JSON.stringify(jsonifiedPackageJson, null, 2));
resolve();
} catch (e) {
reject(e);
}
})
}
async function getLatestVersionFromNPM() {
return new Promise(async (resolve, reject) => {
try {
const response = await fetch('https://registry.npmjs.org/bagels')
const parsedResponse = await response.json(response);
const latestVersion = parsedResponse['dist-tags']['latest']
resolve(latestVersion);
} catch (e) {
reject(e);
}
})
}
async function main() {
console.time('Got latest version from NPM')
const latestVersion = await getLatestVersionFromNPM();
console.timeEnd('Got latest version from NPM')
console.time('updated package number')
await updatePackageNumber(latestVersion);
console.timeEnd('updated package number')
console.time('done publishing')
execSync('npm publish');
console.timeEnd('done publishing')
}
main();