Skip to content

Commit

Permalink
apply nitpicks
Browse files Browse the repository at this point in the history
  • Loading branch information
vishvamsinh28 committed Dec 14, 2024
1 parent 89f7fbc commit ccc22cb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions scripts/build-post-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function buildPostList(postDirectories, basePath, writeFilePath) {
const missing = [];
if (!basePath) missing.push('basePath');
if (!writeFilePath) missing.push('writeFilePath');
throw new Error(`Error while building post list: ${missing.join(' and ')} ${missing.length > 1 ? 'are' : 'is'} required`);
throw new Error(`${missing.join(' and ')} ${missing.length > 1 ? 'are' : 'is'} required`);
}

if (postDirectories.length === 0) {
Expand All @@ -57,10 +57,9 @@ async function walkDirectories(directories, resultObj, basePath, sectionTitle, s

for (let file of files) {
let details;
const fileName = posix.join(directory, file);
const fileNameWithSection = posix.join(fileName, '_section.mdx')
const normalizedSlug = posix.join('/', relative(basePath, fileName))
const slug = normalizedSlug.replace(/\\/g, '/')
const fileName = normalize(join(directory, file));
const fileNameWithSection = normalize(join(fileName, '_section.mdx'))
const slug = '/' + normalize(relative(basePath, fileName)).replace(/\\/g, '/')
const slugElements = slug.split('/')

if (await isDirectory(fileName)) {
Expand Down
4 changes: 2 additions & 2 deletions tests/build-post-list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,15 @@ describe('buildPostList', () => {
await expect(
buildPostList(postDirectories, undefined, writeFilePath),
).rejects.toThrow(
"Error while building post list: Error while building post list: basePath is required",
"Error while building post list: basePath is required",
);
});

it('throws specific error message when writeFilePath parameter is undefined', async () => {
await expect(
buildPostList(postDirectories, tempDir, undefined),
).rejects.toThrow(
"Error while building post list: Error while building post list: writeFilePath is required",
"Error while building post list: writeFilePath is required",
);
});

Expand Down

0 comments on commit ccc22cb

Please sign in to comment.