-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathupdate-version.mjs
More file actions
54 lines (42 loc) · 1.33 KB
/
update-version.mjs
File metadata and controls
54 lines (42 loc) · 1.33 KB
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
import {existsSync, readFileSync, writeFileSync} from 'node:fs';
import {join} from 'node:path';
// The suffix we use to publish to npm wip version of the libs
const SUFFIX = 'next';
const nextVersion = async ({project, currentVersion}) => {
const version = `${currentVersion}-${SUFFIX}-${new Date().toISOString().slice(0, 10)}`;
const {versions} = await (await fetch(`https://registry.npmjs.org/${project}`)).json();
// The wip version has never been published
if (versions[version] === undefined) {
return version;
}
// There was some wip versions already published so, we increment the version number
const count = Object.keys(versions).filter((v) => v.includes(version)).length;
return `${version}.${count}`;
};
const updateVersion = async () => {
const project = '@junobuild/cli';
const packagePath = join(process.cwd(), 'package.json');
if (!existsSync(packagePath)) {
console.log(`Target ${packagePath} does not exist.`);
return;
}
const packageJson = JSON.parse(readFileSync(packagePath, 'utf-8'));
// Build wip version number
const version = await nextVersion({
project,
currentVersion: packageJson.version
});
writeFileSync(
packagePath,
JSON.stringify(
{
...packageJson,
version
},
null,
2
),
'utf-8'
);
};
await updateVersion();