Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(docs/single): support files with .markdown extension #549

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions __tests__/cmds/changelogs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ describe('rdme changelogs', () => {
});

it('should error if no folder provided', () => {
return expect(changelogs.run({ key, version: '1.0.0' })).rejects.toThrow(
return expect(changelogs.run({ key })).rejects.toThrow(
'No folder provided. Usage `rdme changelogs <folder> [options]`.'
);
});

it('should error if the argument isnt a folder', () => {
return expect(changelogs.run({ key, version: '1.0.0', folder: 'not-a-folder' })).rejects.toThrow(
it('should error if the argument is not a folder', () => {
return expect(changelogs.run({ key, folder: 'not-a-folder' })).rejects.toThrow(
"ENOENT: no such file or directory, scandir 'not-a-folder'"
);
});

it('should error if the folder contains no markdown files', () => {
return expect(changelogs.run({ key, version: '1.0.0', folder: '.github/workflows' })).rejects.toThrow(
return expect(changelogs.run({ key, folder: '.github/workflows' })).rejects.toThrow(
'We were unable to locate Markdown files in .github/workflows.'
);
});
Expand Down Expand Up @@ -356,14 +356,20 @@ describe('rdme changelogs:single', () => {
});

it('should error if no file path provided', () => {
return expect(changelogsSingle.run({ key, version: '1.0.0' })).rejects.toThrow(
return expect(changelogsSingle.run({ key })).rejects.toThrow(
'No file path provided. Usage `rdme changelogs:single <file> [options]`.'
);
});

it('should error if the argument is not a markdown file', async () => {
await expect(changelogsSingle.run({ key, version: '1.0.0', filePath: 'not-a-markdown-file' })).rejects.toThrow(
'The file path specified is not a markdown file.'
it('should error if the argument is not a Markdown file', async () => {
await expect(changelogsSingle.run({ key, filePath: 'not-a-markdown-file' })).rejects.toThrow(
'The file path specified is not a Markdown file.'
);
});

it('should support .markdown files but error if file path cannot be found', async () => {
await expect(changelogsSingle.run({ key, filePath: 'non-existent-file.markdown' })).rejects.toThrow(
'ENOENT: no such file or directory'
);
});

Expand Down
4 changes: 2 additions & 2 deletions __tests__/cmds/custompages.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,9 @@ describe('rdme custompages:single', () => {
);
});

it('should error if the argument is not a markdown file', async () => {
it('should error if the argument is not a Markdown file', async () => {
await expect(customPagesSingle.run({ key, filePath: 'not-a-markdown-file' })).rejects.toStrictEqual(
new Error('The file path specified is not a markdown or HTML file.')
new Error('The file path specified is not a Markdown or HTML file.')
);
});

Expand Down
14 changes: 11 additions & 3 deletions __tests__/cmds/docs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('rdme docs', () => {
);
});

it('should error if the argument isnt a folder', async () => {
it('should error if the argument is not a folder', async () => {
const versionMock = getApiNock().get(`/api/v1/version/${version}`).basicAuth({ user: key }).reply(200, { version });

await expect(docs.run({ key, version: '1.0.0', folder: 'not-a-folder' })).rejects.toThrow(
Expand Down Expand Up @@ -564,12 +564,20 @@ describe('rdme docs:single', () => {
);
});

it('should error if the argument is not a markdown file', async () => {
it('should error if the argument is not a Markdown file', async () => {
await expect(docsSingle.run({ key, version: '1.0.0', filePath: 'not-a-markdown-file' })).rejects.toThrow(
'The file path specified is not a markdown file.'
'The file path specified is not a Markdown file.'
);
});

it('should support .markdown files but error if file path cannot be found', async () => {
const versionMock = getApiNock().get(`/api/v1/version/${version}`).basicAuth({ user: key }).reply(200, { version });
await expect(docsSingle.run({ key, version: '1.0.0', filePath: 'non-existent-file.markdown' })).rejects.toThrow(
'ENOENT: no such file or directory'
);
versionMock.done();
});

describe('new docs', () => {
it('should create new doc', async () => {
const slug = 'new-doc';
Expand Down
4 changes: 3 additions & 1 deletion src/cmds/changelogs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ module.exports = class ChangelogsCommand {
};

// Strip out non-markdown files
const files = readdirRecursive(folder).filter(file => file.endsWith('.md') || file.endsWith('.markdown'));
const files = readdirRecursive(folder).filter(
file => file.toLowerCase().endsWith('.md') || file.toLowerCase().endsWith('.markdown')
);

debug(`number of files: ${files.length}`);

Expand Down
4 changes: 2 additions & 2 deletions src/cmds/changelogs/single.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ module.exports = class SingleChangelogCommand {
return Promise.reject(new Error(`No file path provided. Usage \`${config.get('cli')} ${this.usage}\`.`));
}

if (filePath.endsWith('.md') === false || !filePath.endsWith('.markdown') === false) {
return Promise.reject(new Error('The file path specified is not a markdown file.'));
if (!(filePath.toLowerCase().endsWith('.md') || filePath.toLowerCase().endsWith('.markdown'))) {
return Promise.reject(new Error('The file path specified is not a Markdown file.'));
}

const createdDoc = await pushDoc(key, undefined, dryRun, filePath, this.cmdCategory);
Expand Down
5 changes: 4 additions & 1 deletion src/cmds/custompages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ module.exports = class CustomPagesCommand {

// Strip out non-markdown files
const files = readdirRecursive(folder).filter(
file => file.endsWith('.html') || file.endsWith('.md') || file.endsWith('.markdown')
file =>
file.toLowerCase().endsWith('.html') ||
file.toLowerCase().endsWith('.md') ||
file.toLowerCase().endsWith('.markdown')
);

debug(`number of files: ${files.length}`);
Expand Down
10 changes: 8 additions & 2 deletions src/cmds/custompages/single.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,14 @@ module.exports = class SingleCustomPageCommand {
return Promise.reject(new Error(`No file path provided. Usage \`${config.get('cli')} ${this.usage}\`.`));
}

if (!(filePath.endsWith('.html') || filePath.endsWith('.md') || filePath.endsWith('.markdown'))) {
return Promise.reject(new Error('The file path specified is not a markdown or HTML file.'));
if (
!(
filePath.toLowerCase().endsWith('.html') ||
filePath.toLowerCase().endsWith('.md') ||
filePath.toLowerCase().endsWith('.markdown')
)
) {
return Promise.reject(new Error('The file path specified is not a Markdown or HTML file.'));
}

const createdDoc = await pushDoc(key, undefined, dryRun, filePath, this.cmdCategory);
Expand Down
4 changes: 3 additions & 1 deletion src/cmds/docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ module.exports = class DocsCommand {
};

// Strip out non-markdown files
const files = readdirRecursive(folder).filter(file => file.endsWith('.md') || file.endsWith('.markdown'));
const files = readdirRecursive(folder).filter(
file => file.toLowerCase().endsWith('.md') || file.toLowerCase().endsWith('.markdown')
);

debug(`number of files: ${files.length}`);

Expand Down
4 changes: 2 additions & 2 deletions src/cmds/docs/single.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ module.exports = class SingleDocCommand {
return Promise.reject(new Error(`No file path provided. Usage \`${config.get('cli')} ${this.usage}\`.`));
}

if (filePath.endsWith('.md') === false || !filePath.endsWith('.markdown') === false) {
return Promise.reject(new Error('The file path specified is not a markdown file.'));
if (!(filePath.toLowerCase().endsWith('.md') || filePath.toLowerCase().endsWith('.markdown'))) {
return Promise.reject(new Error('The file path specified is not a Markdown file.'));
}

// TODO: should we allow version selection at all here?
Expand Down