From ee79d7d00589bd06530c8a4768ea6fa716400f8a Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Sat, 11 Nov 2023 17:58:48 -0500 Subject: [PATCH] admin: added diff scripts for build page --- src.ts/_admin/generate-diffs.ts | 20 ++++++++++++++++---- src.ts/_admin/utils/git.ts | 7 +++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src.ts/_admin/generate-diffs.ts b/src.ts/_admin/generate-diffs.ts index 9959f4ee2..71de44066 100644 --- a/src.ts/_admin/generate-diffs.ts +++ b/src.ts/_admin/generate-diffs.ts @@ -1,13 +1,25 @@ +import fs from "fs"; + import { getVersions } from "./utils/npm.js"; import { resolve } from "./utils/path.js"; import { getDiff } from "./utils/git.js"; +function escver(v: string): string { + return v.replace(/\./, "-"); +} + (async function() { let versions = await getVersions("ethers"); versions = versions.filter((h) => (h.version.match(/^6\.[0-9]+\.[0-9]+$/))); - for (let i = 1; i < versions.length; i++) { - const tag0 = versions[i - 1].gitHead, tag1 = versions[i].gitHead; - const diff = await getDiff(resolve("dist/ethers.js"), tag0, tag1); - console.log(diff); + fs.writeFileSync(resolve("misc/diffs/versions.txt"), versions.map((h) => h.version).join(",")); + for (let i = 0; i < versions.length; i++) { + for (let j = i + 1; j < versions.length; j++) { + const filename = resolve(`misc/diffs/diff-${ escver(versions[i].version) }_${ escver(versions[j].version) }.txt`); + if (fs.existsSync(filename)) { continue; } + const tag0 = versions[i].gitHead, tag1 = versions[j].gitHead; + const diff = await getDiff(resolve("src.ts"), tag0, tag1); + console.log({ diff }); + fs.writeFileSync(filename, diff); + } } })(); diff --git a/src.ts/_admin/utils/git.ts b/src.ts/_admin/utils/git.ts index d8194f95c..fae54f1cf 100644 --- a/src.ts/_admin/utils/git.ts +++ b/src.ts/_admin/utils/git.ts @@ -37,6 +37,7 @@ export async function getModifiedTime(filename: string): Promise return null; } + export interface GitLog { commit: string; author: string; @@ -89,3 +90,9 @@ export async function getDiff(filename: string, tag0: string, tag1: string): Pro if (!result.ok) { throw new Error(`git log error`); } return result.stdout.trim(); } + +export async function getTags(): Promise> { + const result = await run("git", [ "tag" ]); + if (!result.ok) { throw new Error(`git log error`); } + return result.stdout.trim().split("\n"); +}