-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env node | ||
|
||
import { readFile, writeFile, rename } from 'node:fs/promises'; | ||
import process from 'node:process'; | ||
|
||
async function main() { | ||
const version = JSON.parse(await readFile('./package.json', { encoding: 'utf8' })).version; | ||
const changesFile = 'CHANGELOG.md'; | ||
const changes = await readFile(changesFile, { encoding: 'utf8' }); | ||
const unreleasedRx = /^## Unreleased\n/m; | ||
if (!changes.match(unreleasedRx)) { | ||
console.error("Unable to find Unreleased section!"); | ||
process.exit(1); | ||
} | ||
if (changes.match(new RegExp(`^## ${version.replace('.', '\\.')} `, 'm'))) { | ||
console.error(`${version} section already exists!`); | ||
process.exit(1); | ||
} | ||
const date = new Date(); | ||
const dateString = [date.getUTCFullYear(), date.getUTCMonth()+1, date.getUTCDate()].map(d => d.toString().padStart(2, '0')).join('-'); | ||
const newChanges = changes.replace(/^## Unreleased\n/m, `## ${version} (${dateString})\n`); | ||
const newFile = `CHANGELOG.md.${process.pid}`; | ||
await writeFile(newFile, newChanges, { encoding: 'utf8' }); | ||
await rename(newFile, changesFile); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env node | ||
|
||
import process from 'node:process'; | ||
import child_process from 'node:child_process'; | ||
import { promisify } from 'node:util'; | ||
import { readFile } from 'node:fs/promises'; | ||
|
||
const execFile = promisify(child_process.execFile); | ||
|
||
async function main() { | ||
let version; | ||
if (process.argv.length == 2) { | ||
const content = await readFile('./package.json', { encoding: 'utf8' }); | ||
version = JSON.parse(content).version; | ||
} | ||
else if (process.argv.length == 3) { | ||
version = process.argv[2]; | ||
} | ||
else { | ||
throw new Error(`Invalid args ${process.argv.join(', ')}`); | ||
} | ||
|
||
const res = version.match(/^v?((([0-9]+)\.[0-9]+)\.[0-9]+)$/); | ||
if (res === null) { | ||
throw new Error(`Invalid version ${version}`); | ||
} | ||
|
||
const [ , patch, minor, major ] = res; | ||
|
||
const { stdout, stderr } = await execFile('git', ['rev-parse', '--verify', '--quiet', `v${patch}`]); | ||
if (stderr.length) { | ||
process.stderr.write(stderr); | ||
} | ||
const tagRef = stdout.trim(); | ||
|
||
for (const tag of [minor, major]) { | ||
await execFile('git', ['update-ref', `refs/tags/v${tag}`, tagRef]); | ||
process.stdout.write(`v${tag}\n`); | ||
} | ||
} | ||
|
||
main(); |