diff --git a/utility/amend-readme/index.js b/utility/amend-readme/index.js index e13f1def7..7cc57fbf2 100644 --- a/utility/amend-readme/index.js +++ b/utility/amend-readme/index.js @@ -1,16 +1,17 @@ +"use strict"; + const fs = require("fs-extra"); const path = require("path"); const parseVariantsData = require("../export-data/parse-variants-data"); const parseLigationData = require("../export-data/ligation-data"); const getCharMapAndSupportedLanguageList = require("../export-data/supported-languages"); +const execMain = require("../shared/execMain"); const charMapPath = process.argv[2]; const charMapItalicPath = process.argv[3]; const charMapObliquePath = process.argv[4]; -main().catch(e => { - console.error(e); - process.exit(1); -}); + +execMain(main); ///////////////////////////////////////////////////////////////////////////////////////////////////// async function main() { diff --git a/utility/export-data/index.js b/utility/export-data/index.js index a39d067b2..de5336881 100644 --- a/utility/export-data/index.js +++ b/utility/export-data/index.js @@ -1,7 +1,10 @@ +"use strict"; + const fs = require("fs-extra"); const parseVariantsData = require("./parse-variants-data"); const parseLigationData = require("./ligation-data"); const getCharMapAndSupportedLanguageList = require("./supported-languages"); +const execMain = require("../shared/execMain"); const version = require("../../package.json").version; @@ -9,10 +12,8 @@ const charMapPath = process.argv[2]; const charMapItalicPath = process.argv[3]; const charMapObliquePath = process.argv[4]; const exportPath = process.argv[5]; -main().catch(e => { - console.error(e); - process.exit(1); -}); + +execMain(main); ///////////////////////////////////////////////////////////////////////////////////////////////////// async function main() { diff --git a/utility/generate-change-log/index.js b/utility/generate-change-log/index.js new file mode 100644 index 000000000..49df0cd8e --- /dev/null +++ b/utility/generate-change-log/index.js @@ -0,0 +1,49 @@ +"use strict"; + +const path = require("path"); +const fs = require("fs-extra"); +const semver = require("semver"); +const execMain = require("../shared/execMain"); + +const ChangeFileDir = path.join(__dirname, "../../changes"); +const ModifiedSinceVersion = "2.x"; +const Version = process.argv[2]; +const outputPath = process.argv[3]; + +execMain(main); + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +async function main() { + const out = new Output(); + await GenerateChangeList(out); + await fs.writeFile(outputPath, out.buffer); +} + +class Output { + constructor() { + this.buffer = ""; + } + log(...s) { + this.buffer += s.join("") + "\n"; + } +} + +async function GenerateChangeList(out) { + const changeFiles = await fs.readdir(ChangeFileDir); + const fragments = new Map(); + for (const file of changeFiles) { + const filePath = path.join(ChangeFileDir, file); + const fileParts = path.parse(filePath); + if (fileParts.ext !== ".md") continue; + if (!semver.valid(fileParts.name) || semver.lt(Version, fileParts.name)) continue; + fragments.set(fileParts.name, await fs.readFile(filePath, "utf8")); + } + const sortedFragments = Array.from(fragments).sort((a, b) => semver.compare(b[0], a[0])); + + out.log(`## Modifications since version ${ModifiedSinceVersion}`); + for (const [version, notes] of sortedFragments) { + out.log(`\n### ${version}\n`); + out.log(notes.trimEnd() + "\n"); + } +} diff --git a/utility/generate-release-note/index.js b/utility/generate-release-note/index.js index f5ad55dd2..012c0d61f 100644 --- a/utility/generate-release-note/index.js +++ b/utility/generate-release-note/index.js @@ -3,12 +3,28 @@ const path = require("path"); const fs = require("fs-extra"); const semver = require("semver"); +const execMain = require("../shared/execMain"); const ChangeFileDir = path.join(__dirname, "../../changes"); -const ModifiedSinceVersion = "2.x"; const Version = process.argv[2]; const outputPath = process.argv[3]; +execMain(main); + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +async function main() { + const out = new Output(); + + await GenerateChangeList(out); + await CopyMarkdown(out, "packages-desc.md"); + await GeneratePackageList(out); + await CopyMarkdown(out, "package-reorg.md"); + + await fs.ensureDir(path.join(__dirname, `../../release-archives/`)); + await fs.writeFile(outputPath, out.buffer); +} + class Output { constructor() { this.buffer = ""; @@ -18,23 +34,6 @@ class Output { } } -async function main() { - const out = new Output(); - - await CopyMarkdown(out, "packages-desc.md"); - await GeneratePackageList(out); - await CopyMarkdown(out, "package-reorg.md"); - await GenerateChangeList(out); - - await fs.ensureDir(path.join(__dirname, `../../release-archives/`)); - await fs.writeFile(outputPath, out.buffer); -} - -main().catch(e => { - console.error(e); - process.exit(1); -}); - /////////////////////////////////////////////////////////////////////////////////////////////////// // Copy Markdown @@ -61,11 +60,10 @@ async function GenerateChangeList(out) { } const sortedFragments = Array.from(fragments).sort((a, b) => semver.compare(b[0], a[0])); - out.log(`## Modifications since version ${ModifiedSinceVersion}`); - for (const [version, notes] of sortedFragments) { - out.log(` * **${version}**`); - out.log((notes.trimEnd() + "\n").replace(/^/gm, " ")); - } + const [version, notes] = sortedFragments[0]; + out.log(``); + out.log(`## Changes of version ${version}`); + out.log(notes.trimEnd() + "\n"); } /////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/utility/generate-snapshot-page/index.js b/utility/generate-snapshot-page/index.js index f69fb9bce..8f5b3b928 100644 --- a/utility/generate-snapshot-page/index.js +++ b/utility/generate-snapshot-page/index.js @@ -1,16 +1,16 @@ +"use strict"; + const ejs = require("ejs"); const fs = require("fs-extra"); const path = require("path"); const parseVariantsData = require("../export-data/parse-variants-data"); const getLigationData = require("../export-data/ligation-data"); +const execMain = require("../shared/execMain"); const inputPath = process.argv[2]; const outputPath = process.argv[3]; -main().catch(e => { - console.error(e); - process.exit(1); -}); +execMain(main); ///////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/utility/shared/execMain.js b/utility/shared/execMain.js new file mode 100644 index 000000000..fdf6ab699 --- /dev/null +++ b/utility/shared/execMain.js @@ -0,0 +1,10 @@ +module.exports = function (main) { + setTimeout( + () => + main().catch(e => { + console.error(e); + process.exit(1); + }), + 0 + ); +}; diff --git a/utility/update-package-json-version/index.js b/utility/update-package-json-version/index.js index 9f07b5df5..8ae086a28 100644 --- a/utility/update-package-json-version/index.js +++ b/utility/update-package-json-version/index.js @@ -3,23 +3,23 @@ const path = require("path"); const fs = require("fs-extra"); const semver = require("semver"); +const execMain = require("../shared/execMain"); const ChangeFileDir = path.join(__dirname, "../../changes"); const PackageJsonPath = path.join(__dirname, "../../package.json"); -main().catch(e => { - console.error(e); - process.exit(1); -}); +execMain(main); + +/////////////////////////////////////////////////////////////////////////////////////////////////// async function main() { - const version = await GenerateChangeList(); + const version = await GetLatestVersion(); const packageJson = await fs.readJson(PackageJsonPath); packageJson.version = version; await fs.writeJson(PackageJsonPath, packageJson, { spaces: 2 }); } -async function GenerateChangeList() { +async function GetLatestVersion() { const changeFiles = await fs.readdir(ChangeFileDir); const versions = new Set(); for (const file of changeFiles) { diff --git a/verdafile.js b/verdafile.js index 77832893d..26b6417d5 100644 --- a/verdafile.js +++ b/verdafile.js @@ -819,6 +819,11 @@ const ChangeFileList = oracle.make( () => `release:change-file-list`, target => FileList({ under: "changes", pattern: "*.md" })(target) ); + +const ReleaseNotes = task(`release:release-note`, async t => { + const [version] = await t.need(Version); + await t.need(ReleaseNotesFile(version)); +}); const ReleaseNotesFile = file.make( version => `${ARCHIVE_DIR}/release-notes-${version}.md`, async (t, out, version) => { @@ -828,9 +833,16 @@ const ReleaseNotesFile = file.make( await run("node", "utility/generate-release-note/index", version, out.full); } ); -const ReleaseNotes = task(`release:release-note`, async t => { + +const ChangeLog = task(`release:change-log`, async t => { + await t.need(ChangeLogFile); +}); +const ChangeLogFile = file(`CHANGELOG.md`, async (t, out) => { const [version] = await t.need(Version); - await t.need(ReleaseNotesFile(version)); + await t.need(UtilScripts, de(ARCHIVE_DIR)); + const [changeFiles] = await t.need(ChangeFileList()); + await t.need(changeFiles.map(fu)); + await run("node", "utility/generate-change-log/index", version, out.full); }); phony(`clean`, async () => { @@ -841,7 +853,7 @@ phony(`clean`, async () => { }); phony(`release`, async target => { await target.need(AllTtfArchives, CollectionArchives, AllTtcArchives); - await target.need(SampleImages, Pages, ReleaseNotes); + await target.need(SampleImages, Pages, ReleaseNotes, ChangeLog); }); ///////////////////////////////////////////////////////////