diff --git a/src.ts/_admin/create-release.ts b/src.ts/_admin/create-release.ts new file mode 100644 index 000000000..7b3fdc229 --- /dev/null +++ b/src.ts/_admin/create-release.ts @@ -0,0 +1,40 @@ +import { getChanges } from "./utils/changelog.js"; +import { getDateTime } from "./utils/date.js"; +import { resolve } from "./utils/path.js"; +import { run } from "./utils/run.js"; +import { getVersions } from "./utils/npm.js"; + + +const version = process.argv[2] || null; + +(async function() { + + // Get the change from the CHANGELOG + const changes = getChanges(); + const change = version ? changes.filter((c) => (c.version === version))[0]: changes.shift(); + if (change == null) { throw new Error(`version not found: ${ version }`); } + console.log(change); + + // Find the gitHead and release date + const versions = await getVersions("ethers"); + const ver = versions.filter((c) => (c.version === change.version))[0]; + if (ver == null) { throw new Error(`no npm version found: ${ change.version }`); } + console.log(ver); + + const title = `${ change.title.split("(")[0].trim() } (${ getDateTime(new Date(ver.date) ) })`; + + const args = [ + "release", "create", `v${ change.version }`, +// "--draft", // DEBUGGING + "--title", title, + "--target", ver.gitHead, + "--notes", change.body.join("\n"), + ]; + console.log(args); + const result = await run("gh", args, resolve(".")); + console.log("Published"); + console.log(`See: ${ (result.stdout || "").trim() }`); +})().catch((e) => { + console.log("ERROR"); + console.log(e); +}); diff --git a/src.ts/_admin/update-changelog.ts b/src.ts/_admin/update-changelog.ts index f2ea5544b..7f02cf7e9 100644 --- a/src.ts/_admin/update-changelog.ts +++ b/src.ts/_admin/update-changelog.ts @@ -4,6 +4,7 @@ import { getLogs } from "./utils/git.js"; import { loadJson } from "./utils/json.js"; import { resolve } from "./utils/path.js"; import { getVersions } from "./utils/npm.js"; +import { getDateTime } from "./utils/date.js"; function repeat(c: string, length: number): string { if (c.length === 0) { throw new Error("too short"); } @@ -11,27 +12,6 @@ function repeat(c: string, length: number): string { return c.substring(0, length); } -function zpad(value: number, length?: number): string { - if (length == null) { length = 2; } - const str = String(value); - return repeat("0", length - str.length) + str; -} - -function getDate(date: Date): string { - return [ - date.getFullYear(), - zpad(date.getMonth() + 1), - zpad(date.getDate()) - ].join("-"); -} - -export function getDateTime(date: Date): string { - return getDate(date) + " " + [ - zpad(date.getHours()) , - zpad(date.getMinutes() + 1) - ].join(":"); -} - type Change = { message: string; issues: Array; diff --git a/src.ts/_admin/utils/changelog.ts b/src.ts/_admin/utils/changelog.ts new file mode 100644 index 000000000..f3061dd9b --- /dev/null +++ b/src.ts/_admin/utils/changelog.ts @@ -0,0 +1,31 @@ +import fs from "fs"; +import { resolve } from "./path.js"; + +export type ChangeVersion = { + version: string; + title: string; + body: Array; +}; + +export function getChanges(): Array { + const changes: Array = [ + { title: "", version: "null", body: [ ] } + ]; + + const content = fs.readFileSync(resolve("CHANGELOG.md")).toString(); + for (const line of content.split("\n")) { + let match = line.match(/^ethers\/v(\S+)\s/); + if (match) { + changes.push({ version: match[1], title: line.trim(), body: [ ] }); + } else { + const l = line.trim(); + if (l && !l.match(/^-+$/)) { + changes[changes.length - 1].body.push(l); + } + } + } + + changes.shift(); + + return changes; +} diff --git a/src.ts/_admin/utils/date.ts b/src.ts/_admin/utils/date.ts new file mode 100644 index 000000000..0fa46f56e --- /dev/null +++ b/src.ts/_admin/utils/date.ts @@ -0,0 +1,27 @@ + +function repeat(c: string, length: number): string { + if (c.length === 0) { throw new Error("too short"); } + while(c.length < length) { c += c; } + return c.substring(0, length); +} + +function zpad(value: number, length?: number): string { + if (length == null) { length = 2; } + const str = String(value); + return repeat("0", length - str.length) + str; +} + +function getDate(date: Date): string { + return [ + date.getFullYear(), + zpad(date.getMonth() + 1), + zpad(date.getDate()) + ].join("-"); +} + +export function getDateTime(date: Date): string { + return getDate(date) + " " + [ + zpad(date.getHours()) , + zpad(date.getMinutes() + 1) + ].join(":"); +}