Skip to content

Commit

Permalink
Update MAX_ALLOWED_SECTION_SIZE to 50 in src/contentStructureValidato…
Browse files Browse the repository at this point in the history
…r.ts, import flatten and fileURLToPath from lodash-es and url respectively in temp-runners/importSongsFromRcByAuthors.ts, add ignoreUniquenessErrors argument in parse function in src/songParser.ts, and update parse function in temp-runners/importSongsFromRcByIds.ts.
  • Loading branch information
ioanlucut committed Oct 1, 2023
1 parent cb7202a commit a54f543
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/contentStructureValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
import assert from 'node:assert';

const EXPECTED_SUB_SECTIONS_LENGTH = 2;
const MAX_ALLOWED_SECTION_SIZE = 43;
const MAX_ALLOWED_SECTION_SIZE = 50;

const REGEX_SUPPLIERS = {
[SequenceChar.VERSE]: () => getVerseRegex(),
Expand Down
15 changes: 13 additions & 2 deletions src/songParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,17 @@ import { COMMA, EMPTY_STRING, UNSET_META } from './constants.js';
* It's important to note that the song should be valid.
*
* @param songAsString The content of the song
* @param ignoreUniquenessErrors if the uniqueness errors should be ignored
* if
*/
export const parse = (songAsString: string) => {
export const parse = (
songAsString: string,
{
ignoreUniquenessErrors,
}: {
ignoreUniquenessErrors?: boolean;
} = {},
) => {
const sectionTuples = getSongInSectionTuples(songAsString);

const songAST = {
Expand Down Expand Up @@ -101,7 +110,9 @@ export const parse = (songAsString: string) => {
}
}

assertUniqueness(songAST.sectionOrder);
if (!ignoreUniquenessErrors) {
assertUniqueness(songAST.sectionOrder);
}

return songAST;
};
15 changes: 10 additions & 5 deletions temp-runners/importSongsFromRcByAuthors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import fsExtra from 'fs-extra';
import dotenv from 'dotenv';
import recursive from 'recursive-readdir';
import pMap from 'p-map';
import { flatten } from 'lodash-es';
import { fileURLToPath } from 'url';
import { parse } from '../src/songParser.js';
import { print } from '../src/songPrinter.js';
import {
logFileWithLinkInConsole,
logProcessingFile,
NEW_LINE,
} from '../src/index.js';
import { flatten } from 'lodash-es';

import { fileURLToPath } from 'url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

Expand Down Expand Up @@ -42,20 +41,26 @@ const readFiles = async (dir: string) =>
const runFor = async (songsDirs: string[]) => {
const allSongsInRepo = flatten(
await Promise.all(songsDirs.map(readFiles)),
).map(({ contentAsString }) => parse(contentAsString));
).map(({ contentAsString }) =>
parse(contentAsString, {
ignoreUniquenessErrors: true,
}),
);
const allRcIds = allSongsInRepo.map(({ rcId }) => rcId).filter(Boolean);

await pMap(rcAuthorPathsToProcess, async (pathConfig) => {
const [counts, composer, authorPath] = pathConfig.split(':');
const dirToImportFrom = `${RC_DIR}/${authorPath}`;
(await readFiles(dirToImportFrom)).forEach(
({ contentAsString, filePath, fileName }) => {
const rcSongAST = parse(contentAsString);
logProcessingFile(
fileName,
`Import from RC from ${composer}; Counts: ${counts}.`,
);
logFileWithLinkInConsole(filePath);
const rcSongAST = parse(contentAsString, {
ignoreUniquenessErrors: true,
});

if (allRcIds.includes(rcSongAST.rcId)) {
console.log(
Expand Down
6 changes: 5 additions & 1 deletion temp-runners/importSongsFromRcByIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ const readFiles = async (dir: string) =>
const runFor = async (songsDirs: string[]) => {
const allSongsInRepo = flatten(
await Promise.all(songsDirs.map(readFiles)),
).map(({ contentAsString }) => parse(contentAsString));
).map(({ contentAsString }) =>
parse(contentAsString, {
ignoreUniquenessErrors: true,
}),
);
const allExistingRcIds = allSongsInRepo
.map(({ rcId }) => rcId)
.filter(Boolean);
Expand Down

0 comments on commit a54f543

Please sign in to comment.