|
| 1 | +import { version } from './version.ts'; |
| 2 | + |
| 3 | +const p = version.split('.').map(s => parseInt(s)) |
| 4 | +const versions = [ |
| 5 | + `${p[0]}.${p[1]}.${p[2] + 1}`, |
| 6 | + `${p[0]}.${p[1] + 1}.0`, |
| 7 | + `${p[0] + 1}.0.0`, |
| 8 | +] |
| 9 | + |
| 10 | +async function ask(question: string = '', stdin = Deno.stdin, stdout = Deno.stdout) { |
| 11 | + const buf = new Uint8Array(1024) |
| 12 | + await stdout.write(new TextEncoder().encode(question)) |
| 13 | + const n = <number>await stdin.read(buf) |
| 14 | + const answer = new TextDecoder().decode(buf.subarray(0, n)) |
| 15 | + return answer.trim() |
| 16 | +} |
| 17 | + |
| 18 | +async function run(...cmd: string[]) { |
| 19 | + const p = Deno.run({ |
| 20 | + cmd, |
| 21 | + stdout: 'piped', |
| 22 | + stderr: 'piped' |
| 23 | + }) |
| 24 | + Deno.stdout.write(await p.output()) |
| 25 | + Deno.stderr.write(await p.stderrOutput()) |
| 26 | + p.close() |
| 27 | +} |
| 28 | + |
| 29 | +async function main() { |
| 30 | + const answer = await ask([...versions.map((v, i) => `${i + 1}. v${v}`), 'upgrade to: '].join('\n')) |
| 31 | + const v = parseInt(answer) |
| 32 | + if (!isNaN(v) && v > 0 && v <= 3) { |
| 33 | + const up = versions[v - 1] |
| 34 | + if (await ask('are you sure? (y/n) ') === 'y') { |
| 35 | + await Deno.writeTextFile('./version.ts', `export const version = '${up}'\n`) |
| 36 | + await run('git', 'add', '.', '--all') |
| 37 | + await run('git', 'commit', '-m', `v${up}`) |
| 38 | + await run('git', 'tag', `v${up}`) |
| 39 | + } |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +if (import.meta.main) { |
| 44 | + main() |
| 45 | +} |
0 commit comments