-
Notifications
You must be signed in to change notification settings - Fork 8
/
upgrade.js
33 lines (28 loc) · 1012 Bytes
/
upgrade.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
import { promises as fs } from 'node:fs'
import semver from 'semver'
/**
* Javascript script linked to `upgrade.sh`
*/
const upstreamPackage = 'lucide-static'
;(async () => {
const pkg = JSON.parse(await fs.readFile('./package.json', 'utf8'))
const pkgVersion = pkg.version
const check = await fetch(`https://registry.npmjs.com/${upstreamPackage}`).then((it) => it.json())
const newVersion = check['dist-tags']?.latest
if (!newVersion) {
console.error('no new version found :(')
process.exit(1)
}
if (newVersion === pkgVersion || !newVersion) {
console.log('no diff in version, ending')
process.exit(1)
}
if (!semver.gt(newVersion, pkgVersion)) {
console.log('package version', pkgVersion, 'higher than upstream version', newVersion, 'skipping update')
process.exit(1)
}
console.log('diff in version, update needed')
pkg.version = newVersion
pkg.devDependencies[upstreamPackage] = newVersion
await fs.writeFile('./package.json', JSON.stringify(pkg, undefined, '\t') + '\n')
})()