Skip to content

Commit 3a4ba4e

Browse files
committed
Some small script updates
1 parent b74859f commit 3a4ba4e

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

scripts/utils/changes.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
import { hasChangelog, readChangelog } from './packages.js';
1+
import { getPackageFile } from './packages.js';
2+
import { fileExists, readFile } from './fs.js';
23

4+
/** @typedef {{ version: string; date?: Date; body: string }} Changes */
35
/** @typedef {Record<string, Changes>} AllChanges */
46

57
/** @type (packageName: string) => AllChanges | null */
68
export function getAllChanges(packageName) {
7-
if (!hasChangelog(packageName)) {
9+
let changelogFile = getPackageFile(packageName, 'CHANGELOG.md');
10+
11+
if (!fileExists(changelogFile)) {
812
return null;
913
}
1014

11-
let changelog = readChangelog(packageName);
15+
let changelog = readFile(changelogFile);
1216
let parser = /^## ([a-z\d\.\-]+)(?: \(([^)]+)\))?$/gim;
1317

1418
/** @type {AllChanges} */
@@ -21,16 +25,14 @@ export function getAllChanges(packageName) {
2125
let version = versionString.startsWith('v') ? versionString.slice(1) : versionString;
2226
let date = dateString ? new Date(dateString) : undefined;
2327
let nextMatch = parser.exec(changelog);
24-
let changes = changelog.slice(lastIndex, nextMatch ? nextMatch.index : undefined).trim();
25-
result[version] = { version, date, changes };
28+
let body = changelog.slice(lastIndex, nextMatch ? nextMatch.index : undefined).trim();
29+
result[version] = { version, date, body };
2630
parser.lastIndex = lastIndex;
2731
}
2832

2933
return result;
3034
}
3135

32-
/** @typedef {{ version: string; date?: Date; changes: string }} Changes */
33-
3436
/** @type (packageName: string, version: string) => Changes | null */
3537
export function getChanges(packageName, version) {
3638
let allChanges = getAllChanges(packageName);

scripts/utils/fs.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ export function fileExists(filename) {
55
return fs.existsSync(filename);
66
}
77

8-
/** @type (filename: string) => string */
9-
export function readFile(filename) {
8+
/** @type (filename: string, encoding?: BufferEncoding) => string */
9+
export function readFile(filename, encoding = 'utf-8') {
1010
try {
11-
return fs.readFileSync(filename, 'utf-8');
11+
return fs.readFileSync(filename, encoding);
1212
} catch (error) {
1313
if (isFsError(error) && error.code === 'ENOENT') {
1414
console.error(`Not found: "${filename}"`);

scripts/utils/github-releases.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export async function createRelease(packageName, version) {
2222
repo: 'remix-the-web',
2323
tag_name: tagName,
2424
name: `${packageName} v${version}`,
25-
body: changes?.changes ?? 'No changes.',
25+
body: changes?.body ?? 'No changes.',
2626
});
2727

2828
if (response.status !== 201) {

0 commit comments

Comments
 (0)