Skip to content

Commit 60969e9

Browse files
committed
Update to Prettier v3 and fix promise error
1 parent 6250b4f commit 60969e9

File tree

8 files changed

+23
-24
lines changed

8 files changed

+23
-24
lines changed

Diff for: package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "in-song-list",
2+
"name": "it-song-list",
33
"version": "1.0.0",
4-
"main": "index.js",
54
"license": "MIT",
5+
"repository": "https://github.com/itsektionen/songlist",
66
"scripts": {
77
"build": "ts-node src/scripts build",
88
"script": "ts-node src/scripts",
@@ -11,15 +11,14 @@
1111
"format": "prettier --write dist songs src test README.md .prettierrc jest.config.js package.json tsconfig.json",
1212
"github": "ts-node src/github"
1313
},
14-
"dependencies": {},
1514
"devDependencies": {
1615
"@types/jest": "^29.5.14",
1716
"@types/node": "^22.13.10",
1817
"dayjs": "^1.11.13",
1918
"gray-matter": "^4.0.3",
2019
"jest": "^29.7.0",
2120
"jest-expect-message": "^1.1.3",
22-
"prettier": "^2.8.8",
21+
"prettier": "^3.5.3",
2322
"ts-jest": "^29.2.6",
2423
"ts-node": "^10.9.2",
2524
"typescript": "^5.8.2"

Diff for: src/scripts/build.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import { isoDateRegex } from '../util/regex';
1111
import createSongs from '../util/createSongs';
1212
import dayjs from 'dayjs';
1313

14-
export default function build(customUpdatedAt: string | undefined): void {
14+
export default async function build(customUpdatedAt: string | undefined): Promise<void> {
1515
const updatedAt = customUpdatedAt?.match(isoDateRegex)
1616
? customUpdatedAt
1717
: dayjs().format('YYYY-MM-DD');
1818

1919
const buildSongs = createSongs(updatedAt);
2020

21-
writeJson(buildSongs.json);
21+
writeJson(await buildSongs.json);
2222
writeXml(buildSongs.xml);
2323
writeXmlWithoutIds(buildSongs.xmlNoIds);
2424
console.log('Build complete and saved');
@@ -31,7 +31,7 @@ export default function build(customUpdatedAt: string | undefined): void {
3131
});
3232
if (filesToRemove.length)
3333
console.log(
34-
`Removed ${filesToRemove.length} unneeded file${filesToRemove.length !== 1 ? 's' : ''}`
34+
`Removed ${filesToRemove.length} unneeded file${filesToRemove.length !== 1 ? 's' : ''}`,
3535
);
3636
}
3737

Diff for: src/scripts/create.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { SONGS_FOLDER_PATH } from '../definitions/paths';
88
import pushIds from '../util/pushIds';
99
import { getAllSongPaths } from '../util/songs';
1010

11-
export default function create(title: string, ...args: string[]): void {
11+
export default async function create(title: string, ...args: string[]): Promise<void> {
1212
if (!title) return console.error('A title for the new song must be provided!');
1313
const { id, ...parsedArgs } = parseArgs(args);
1414

@@ -18,23 +18,23 @@ export default function create(title: string, ...args: string[]): void {
1818

1919
if (id !== undefined) pushIds(id);
2020

21-
writeFileSync(join(SONGS_FOLDER_PATH, newTitle), newContent);
21+
writeFileSync(join(SONGS_FOLDER_PATH, newTitle), await newContent);
2222
}
2323

2424
function nextId(): number {
2525
return getAllSongPaths().length;
2626
}
2727

28-
function generateDefaultSongFileContent(
28+
async function generateDefaultSongFileContent(
2929
title: string,
3030
{
3131
author,
3232
melody,
3333
composer,
3434
tags = [],
3535
content,
36-
}: Omit<Song, 'id' | 'title' | 'deleted' | 'content'> & { content?: string }
37-
): string {
36+
}: Omit<Song, 'id' | 'title' | 'deleted' | 'content'> & { content?: string },
37+
): Promise<string> {
3838
let contentBuilder = `---\ntitle: ${title}\n`;
3939
contentBuilder += `author: ${author || ''}\n`;
4040
contentBuilder += `melody: ${melody || ''}\n`;
@@ -43,11 +43,11 @@ function generateDefaultSongFileContent(
4343
contentBuilder += '---\n';
4444
if (content) contentBuilder += content;
4545

46-
return format(contentBuilder, { parser: 'markdown' });
46+
return await format(contentBuilder, { parser: 'markdown' });
4747
}
4848

4949
function parseArgs(
50-
args: string[]
50+
args: string[],
5151
): Partial<Omit<Song, 'title' | 'deleted' | 'tags'>> & { tags: Tag[] } {
5252
const [idString] = getArgValues(args, 'id');
5353
const [author] = getArgValues(args, 'author');

Diff for: src/util/songs.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export function sortXmlifyableSongs(songs: XmlifyableSong[]): XmlifyableSong[] {
8181
.sort(
8282
(a, b) =>
8383
LEGACY_ORDER.findIndex((category) => a.category === category) -
84-
LEGACY_ORDER.findIndex((category) => b.category === category)
84+
LEGACY_ORDER.findIndex((category) => b.category === category),
8585
)
8686
.sort((a, b) => (b.sorting || 0) - (a.sorting || 0));
8787
}
@@ -91,7 +91,7 @@ export function sortSongs(songs: Song[]): Song[] {
9191
.sort(
9292
(a, b) =>
9393
CATEGORY_ORDER.findIndex((category) => a.tags[0] === category) -
94-
CATEGORY_ORDER.findIndex((category) => b.tags[0] === category)
94+
CATEGORY_ORDER.findIndex((category) => b.tags[0] === category),
9595
)
9696
.sort((a, b) => (b.sorting || 0) - (a.sorting || 0));
9797
}

Diff for: src/util/xml.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function songContentToXml(content: Song['content']): string {
3535
paragraph
3636
.split('\n')
3737
.map((s) => s.substring(2))
38-
.join('\n')
38+
.join('\n'),
3939
)}</comment>\n`;
4040
} else {
4141
xml += `\t\t<p>${xmlifyParagraph(paragraph)}</p>\n`;

Diff for: test/songFiles.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('All songs have valid data', () => {
2020
Object.keys(metaKeys).forEach((metaKey) => {
2121
expect(
2222
validMetaKeys,
23-
`Value ${metaKey} not a valid metadata property (found in ${path})`
23+
`Value ${metaKey} not a valid metadata property (found in ${path})`,
2424
).toContain(metaKey);
2525
});
2626
});
@@ -43,7 +43,7 @@ describe('All songs have valid data', () => {
4343
const invalidTag = song.tags.find((tag) => !TAGS.includes(tag));
4444
expect(
4545
invalidTag,
46-
`Song with ID=${song.id} and title '${song.title}' contains the invalid tag '${invalidTag}'`
46+
`Song with ID=${song.id} and title '${song.title}' contains the invalid tag '${invalidTag}'`,
4747
).toBeUndefined();
4848
});
4949
});

Diff for: test/validIds.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('All IDs are valid', () => {
4848
songs.forEach((song) => {
4949
expect(
5050
song.id,
51-
`No song ID can be greater than 4095 (found in song with title ${song.title})`
51+
`No song ID can be greater than 4095 (found in song with title ${song.title})`,
5252
).toBeLessThanOrEqual(4095);
5353
});
5454
});

Diff for: yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -1927,10 +1927,10 @@ pkg-dir@^4.2.0:
19271927
dependencies:
19281928
find-up "^4.0.0"
19291929

1930-
prettier@^2.8.8:
1931-
version "2.8.8"
1932-
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
1933-
integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==
1930+
prettier@^3.5.3:
1931+
version "3.5.3"
1932+
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.5.3.tgz#4fc2ce0d657e7a02e602549f053b239cb7dfe1b5"
1933+
integrity sha512-QQtaxnoDJeAkDvDKWCLiwIXkTgRhwYDEQCghU9Z6q03iyek/rxRh/2lC3HB7P8sWT2xC/y5JDctPLBIGzHKbhw==
19341934

19351935
pretty-format@^29.0.0, pretty-format@^29.7.0:
19361936
version "29.7.0"

0 commit comments

Comments
 (0)