|
| 1 | +import { ensure, is, type Predicate } from "jsr:@core/unknownutil@^4.0.0"; |
| 2 | + |
| 3 | +export type SupportedVersions = { |
| 4 | + deno: string; |
| 5 | + vim: string; |
| 6 | + neovim: string; |
| 7 | +}; |
| 8 | + |
| 9 | +const isSupportedVersions = is.ObjectOf({ |
| 10 | + deno: is.String, |
| 11 | + vim: is.String, |
| 12 | + neovim: is.String, |
| 13 | +}) satisfies Predicate<SupportedVersions>; |
| 14 | + |
| 15 | +function getSupportedVersionJsonUrl(branch: string): URL { |
| 16 | + return new URL( |
| 17 | + `https://raw.githubusercontent.com/vim-denops/denops.vim/${branch}/denops/supported_versions.json`, |
| 18 | + ); |
| 19 | +} |
| 20 | + |
| 21 | +export async function loadSupportedVersions( |
| 22 | + branch?: string, |
| 23 | +): Promise<SupportedVersions> { |
| 24 | + const url = getSupportedVersionJsonUrl( |
| 25 | + branch ?? Deno.env.get("DENOPS_BRANCH") ?? "main", |
| 26 | + ); |
| 27 | + const resp = await fetch(url); |
| 28 | + const json = await resp.json(); |
| 29 | + return ensure(json, isSupportedVersions); |
| 30 | +} |
| 31 | + |
| 32 | +async function updateREADME( |
| 33 | + supportedVersions: SupportedVersions, |
| 34 | +): Promise<void> { |
| 35 | + const url = new URL(import.meta.resolve("../README.md")); |
| 36 | + let text = await Deno.readTextFile(url); |
| 37 | + // Deno |
| 38 | + text = text.replace( |
| 39 | + /Deno\s+\d+\.\d+\.\d+/, |
| 40 | + `Deno ${supportedVersions.deno}`, |
| 41 | + ); |
| 42 | + text = text.replace( |
| 43 | + /Deno-Support%20\d+\.\d+\.\d+/, |
| 44 | + `Deno-Support%20${supportedVersions.deno}`, |
| 45 | + ); |
| 46 | + text = text.replace( |
| 47 | + /https:\/\/github\.com\/denoland\/deno\/tree\/v\d+\.\d+\.\d+/, |
| 48 | + `https://github.com/denoland/deno/tree/v${supportedVersions.deno}`, |
| 49 | + ); |
| 50 | + // Vim |
| 51 | + text = text.replace( |
| 52 | + /Vim\s+\d+\.\d+\.\d+/, |
| 53 | + `Vim ${supportedVersions.vim}`, |
| 54 | + ); |
| 55 | + text = text.replace( |
| 56 | + /Vim-Support%20\d+\.\d+\.\d+/, |
| 57 | + `Vim-Support%20${supportedVersions.vim}`, |
| 58 | + ); |
| 59 | + text = text.replace( |
| 60 | + /https:\/\/github\.com\/vim\/vim\/tree\/v\d+\.\d+\.\d+/, |
| 61 | + `https://github.com/vim/vim/tree/v${supportedVersions.vim}`, |
| 62 | + ); |
| 63 | + // Neovim |
| 64 | + text = text.replace( |
| 65 | + /Neovim\s+\d+\.\d+\.\d+/, |
| 66 | + `Neovim ${supportedVersions.neovim}`, |
| 67 | + ); |
| 68 | + text = text.replace( |
| 69 | + /Neovim-Support%20\d+\.\d+\.\d+/, |
| 70 | + `Neovim-Support%20${supportedVersions.neovim}`, |
| 71 | + ); |
| 72 | + text = text.replace( |
| 73 | + /https:\/\/github\.com\/neovim\/neovim\/tree\/v\d+\.\d+\.\d+/, |
| 74 | + `https://github.com/neovim/neovim/tree/v${supportedVersions.neovim}`, |
| 75 | + ); |
| 76 | + await Deno.writeTextFile(url, text); |
| 77 | +} |
| 78 | + |
| 79 | +async function updateGithubWorkflowsTest( |
| 80 | + supportedVersions: SupportedVersions, |
| 81 | +): Promise<void> { |
| 82 | + const url = new URL(import.meta.resolve("../.github/workflows/test.yml")); |
| 83 | + let text = await Deno.readTextFile(url); |
| 84 | + // Deno |
| 85 | + text = text.replace( |
| 86 | + /deno_version:(.*?)"\d+\.\d+\.\d+"/s, |
| 87 | + `deno_version:$1"${supportedVersions.deno}"`, |
| 88 | + ); |
| 89 | + // Vim |
| 90 | + text = text.replace( |
| 91 | + /vim:(.*?)"v\d+\.\d+\.\d+"/s, |
| 92 | + `vim:$1"v${supportedVersions.vim}"`, |
| 93 | + ); |
| 94 | + // Neovim |
| 95 | + text = text.replace( |
| 96 | + /nvim:(.*?)"v\d+\.\d+\.\d+"/s, |
| 97 | + `nvim:$1"v${supportedVersions.neovim}"`, |
| 98 | + ); |
| 99 | + await Deno.writeTextFile(url, text); |
| 100 | +} |
| 101 | + |
| 102 | +async function main(): Promise<void> { |
| 103 | + const supportedVersions = await loadSupportedVersions(); |
| 104 | + await updateREADME(supportedVersions); |
| 105 | + await updateGithubWorkflowsTest(supportedVersions); |
| 106 | +} |
| 107 | + |
| 108 | +if (import.meta.main) { |
| 109 | + try { |
| 110 | + await main(); |
| 111 | + } catch (error) { |
| 112 | + console.error(error); |
| 113 | + Deno.exit(1); |
| 114 | + } |
| 115 | +} |
0 commit comments