|
| 1 | +import path from "node:path"; |
| 2 | + |
| 3 | +const releaseType: string = Deno.args[0]; |
| 4 | +if ( |
| 5 | + !releaseType || |
| 6 | + releaseType !== "patch" && releaseType !== "minor" && releaseType !== "major" |
| 7 | +) { |
| 8 | + console.error("Invalid release type"); |
| 9 | + Deno.exit(1); |
| 10 | +} |
| 11 | +const releaseNotes: string = Deno.args[1]; |
| 12 | +if (!releaseNotes) { |
| 13 | + console.error("Release notes are required"); |
| 14 | + Deno.exit(1); |
| 15 | +} |
| 16 | + |
| 17 | +const denoJsonPath = path.resolve( |
| 18 | + import.meta.dirname as string, |
| 19 | + "..", |
| 20 | + "deno.json", |
| 21 | +); |
| 22 | +const denoJson = JSON.parse(await Deno.readTextFile(denoJsonPath)) as { |
| 23 | + version: string; |
| 24 | +}; |
| 25 | + |
| 26 | +const [major, minor, patch] = denoJson.version.split(".").map(Number); |
| 27 | + |
| 28 | +let newVersion: string; |
| 29 | + |
| 30 | +if (releaseType === "patch") { |
| 31 | + newVersion = `${major}.${minor}.${patch + 1}`; |
| 32 | +} else if (releaseType === "minor") { |
| 33 | + newVersion = `${major}.${minor + 1}.0`; |
| 34 | +} else { |
| 35 | + newVersion = `${major + 1}.0.0`; |
| 36 | +} |
| 37 | + |
| 38 | +denoJson.version = newVersion; |
| 39 | + |
| 40 | +await Deno.writeTextFile( |
| 41 | + denoJsonPath, |
| 42 | + JSON.stringify(denoJson, null, 2) + "\n", |
| 43 | +); |
| 44 | + |
| 45 | +const changeLogPath = path.resolve( |
| 46 | + import.meta.dirname as string, |
| 47 | + "..", |
| 48 | + "CHANGELOG.md", |
| 49 | +); |
| 50 | +const currentChangeLog = await Deno.readTextFile(changeLogPath); |
| 51 | + |
| 52 | +const newContent = |
| 53 | + `## [${newVersion}] - ${new Date().toISOString().split("T")[0]}` + "\n\n" + |
| 54 | + releaseNotes + "\n"; |
| 55 | +const allContent = newContent + "\n" + currentChangeLog; |
| 56 | + |
| 57 | +await Deno.writeTextFile( |
| 58 | + changeLogPath, |
| 59 | + allContent, |
| 60 | +); |
| 61 | + |
| 62 | +console.log(newVersion); |
| 63 | +Deno.exit(0); |
0 commit comments