- fetchで公式のreleasesのlatestを取得する
- jsonから最新のバージョンを確定する
- biome.jsonの$shemaのバージョンを書き換える
- pnpm updateなどでバージョンをあげる
import { readFileSync, writeFileSync } from "fs";
const f = await fetch(
"https://api.github.com/repos/biomejs/biome/releases/latest",
);
const fetchedJson = await f.json();
/*
cli/v1.4.1 -> 1.4.1
*/
const getVersion = (str) => {
const arr = str.split("/");
const version = arr[arr.length - 1];
/* vを取る */
if (version[0] === "v") {
return version.slice(1);
}
return version;
};
const tag_name = getVersion(fetchedJson.tag_name);
/* biome.jsonの中身も書き換える */
const biomejson = JSON.parse(readFileSync("./biome.json", "utf-8"));
const result = {
...biomejson,
$schema: `https://biomejs.dev/schemas/${tag_name}/schema.json`,
};
/* over write */
writeFileSync("./biome.json", JSON.stringify(result, null, 2));
/* install */
await $`pnpm update --save-exact @biomejs/biome@${tag_name}`;
モノレポのプロジェクトごとにバージョンあげるの面倒臭くなったので。
zxで動かします。これをbiome_updateみたいなコマンドにしておいて、turborepoで実行してあげれば自動的にすべてのプロジェクトでbiomeのバージョンが上がります。
バージョンの取得部分がちょっと汚いが、まあ動けばOK……。
const fとかも雑プログラムの悪いところが出ているが、次にスクリプトに手を入れるときに綺麗にしよう。