Skip to content

Commit

Permalink
Let the user write out some release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
MMK21Hub committed Oct 30, 2022
1 parent 80d21d7 commit 658dfe7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ dep.svg

# Local package installation
node_modules/

# Log files
yarn-error.log
log.txt

# Caches
.cache
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const cache = new Map<string, any>()
const commandLineArg = process.argv[2]

const targetVersions: MinecraftVersionFancyRange = {
start: "22w42a",
start: "22w43a",
}
// const targetVersions = "1.19.2"
// const targetVersions: StartAndEnd<string> = ["1.19.1-pre1", null]
Expand Down
43 changes: 31 additions & 12 deletions src/publisher/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import ModrinthClient from "./ModrinthClient.js"
import dotenv from "dotenv"
import { Blob } from "node-fetch"
import { readFile } from "fs/promises"
import { readFile, writeFile } from "fs/promises"
import { join } from "path"
import { OutFileIndex, OutFileMetadata } from "../builder.js"
import { createInterface } from "readline"
import { ensureDir } from "../util.js"
import { exec } from "child_process"

/**
* Goes through all the files in the index.
Expand Down Expand Up @@ -49,12 +51,27 @@ function findPackVersion(packIndex: OutFileIndex): string {
return packVersion
}

function generateChangelog({
minecraftVersion,
versionBrand,
index,
totalFiles,
}: OutFileMetadata): string {
async function askForChangelog(): Promise<string> {
const releaseConfigFolder = "release"
const changelogFileName = "changelog.md"
const changelogFilePath = join(releaseConfigFolder, changelogFileName)
await ensureDir(releaseConfigFolder)
await writeFile(changelogFilePath, Buffer.from(""), {
flag: "a",
})

return new Promise(async (resolve) => {
exec(`editor "${changelogFilePath}"`, async () => {
const fileContent = await readFile(changelogFilePath, "utf-8")
resolve(fileContent)
})
})
}

function generateChangelog(
{ minecraftVersion, versionBrand, index, totalFiles }: OutFileMetadata,
releaseNotes: string
): string {
if (!versionBrand)
return `Development build for Minecraft ${minecraftVersion}`

Expand All @@ -78,15 +95,15 @@ ${minecraftVersion} is ${versionsBehindString} versions behind the latest Minecr
return `
${olderVersionsNote}
Fixed a single translation string
${releaseNotes}
----
[*View this release on Github*](${githubRelease})
`.trim()
}

async function publishReleases() {
async function publishReleases(changelogBody: string) {
if (!process.env.MODRINTH_PROJECT_ID)
throw new Error(
"MODRINTH_PROJECT_ID must be provided to specify the Modrinth project to publish the releases to."
Expand All @@ -106,7 +123,7 @@ async function publishReleases() {
name: name,
project_id: process.env.MODRINTH_PROJECT_ID,
version_number: `${packVersion}-${minecraftVersion}`,
changelog: generateChangelog(fileInfo),
changelog: generateChangelog(fileInfo, changelogBody),
})
.catch((e) => {
console.error(e)
Expand Down Expand Up @@ -157,7 +174,7 @@ if (carefulMode) {
// Bypass asking for user input if the VSCode debugger is being used
// It would be better to check for an interactive shell instead
const isVscode = !!process.env.VSCODE_INSPECTOR_OPTIONS
if (isVscode) await publishReleases()
if (isVscode) await publishReleases("Dummy changelog text")

const hint = carefulMode ? "(yes/NO)" : "(Y/n)"

Expand All @@ -172,8 +189,10 @@ rl.question(
)
if (answer.at(0) === "n") return console.log("Goodbye then!")

const changelogText = await askForChangelog()

// There's no going back now!
const newReleases = await publishReleases()
const newReleases = await publishReleases(changelogText)
console.log(`Published ${newReleases.length} release(s) to Modrinth!`)
process.exit(0)
}
Expand Down

0 comments on commit 658dfe7

Please sign in to comment.