From d72937432300eb37d0f2a91aa7794d7ee581c742 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Thu, 28 Jul 2022 15:31:13 -0400 Subject: [PATCH 1/4] fix: support files with .markdown extension --- __tests__/cmds/changelogs.test.js | 6 ++++++ __tests__/cmds/docs.test.js | 8 ++++++++ src/cmds/changelogs/single.js | 2 +- src/cmds/docs/single.js | 2 +- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/__tests__/cmds/changelogs.test.js b/__tests__/cmds/changelogs.test.js index f8ecc0cc1..459907894 100644 --- a/__tests__/cmds/changelogs.test.js +++ b/__tests__/cmds/changelogs.test.js @@ -367,6 +367,12 @@ describe('rdme changelogs:single', () => { ); }); + 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' + ); + }); + describe('new changelogs', () => { it('should create new changelog', async () => { const slug = 'new-doc'; diff --git a/__tests__/cmds/docs.test.js b/__tests__/cmds/docs.test.js index 71514d3f7..4a57434b3 100644 --- a/__tests__/cmds/docs.test.js +++ b/__tests__/cmds/docs.test.js @@ -570,6 +570,14 @@ describe('rdme docs:single', () => { ); }); + 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'; diff --git a/src/cmds/changelogs/single.js b/src/cmds/changelogs/single.js index 104a8e36e..eba0c5042 100644 --- a/src/cmds/changelogs/single.js +++ b/src/cmds/changelogs/single.js @@ -45,7 +45,7 @@ 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) { + if (!(filePath.endsWith('.md') || filePath.endsWith('.markdown'))) { return Promise.reject(new Error('The file path specified is not a markdown file.')); } diff --git a/src/cmds/docs/single.js b/src/cmds/docs/single.js index 6c12b6c4d..e10fbfa71 100644 --- a/src/cmds/docs/single.js +++ b/src/cmds/docs/single.js @@ -51,7 +51,7 @@ 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) { + if (!(filePath.endsWith('.md') || filePath.endsWith('.markdown'))) { return Promise.reject(new Error('The file path specified is not a markdown file.')); } From 21ba907ca774230366ff2fee6d872babe02137ef Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Thu, 28 Jul 2022 15:31:37 -0400 Subject: [PATCH 2/4] test: random cleanup fixing typo, removing unused version param, stricter error checks --- __tests__/cmds/changelogs.test.js | 12 ++++++------ __tests__/cmds/docs.test.js | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/__tests__/cmds/changelogs.test.js b/__tests__/cmds/changelogs.test.js index 459907894..9f86a5858 100644 --- a/__tests__/cmds/changelogs.test.js +++ b/__tests__/cmds/changelogs.test.js @@ -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 [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.' ); }); @@ -356,13 +356,13 @@ 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 [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( + await expect(changelogsSingle.run({ key, filePath: 'not-a-markdown-file' })).rejects.toThrow( 'The file path specified is not a markdown file.' ); }); diff --git a/__tests__/cmds/docs.test.js b/__tests__/cmds/docs.test.js index 4a57434b3..d5df4eb9a 100644 --- a/__tests__/cmds/docs.test.js +++ b/__tests__/cmds/docs.test.js @@ -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( From ab49be958b2ebfe4dbd91a66ba1c80b3934f6197 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Thu, 28 Jul 2022 16:50:44 -0400 Subject: [PATCH 3/4] chore: capitalize Markdown --- __tests__/cmds/changelogs.test.js | 4 ++-- __tests__/cmds/custompages.test.js | 4 ++-- __tests__/cmds/docs.test.js | 4 ++-- src/cmds/changelogs/single.js | 2 +- src/cmds/custompages/single.js | 2 +- src/cmds/docs/single.js | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/__tests__/cmds/changelogs.test.js b/__tests__/cmds/changelogs.test.js index 9f86a5858..f146ef69d 100644 --- a/__tests__/cmds/changelogs.test.js +++ b/__tests__/cmds/changelogs.test.js @@ -361,9 +361,9 @@ describe('rdme changelogs: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(changelogsSingle.run({ key, 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.' ); }); diff --git a/__tests__/cmds/custompages.test.js b/__tests__/cmds/custompages.test.js index a39e33106..f638a6f35 100644 --- a/__tests__/cmds/custompages.test.js +++ b/__tests__/cmds/custompages.test.js @@ -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.') ); }); diff --git a/__tests__/cmds/docs.test.js b/__tests__/cmds/docs.test.js index d5df4eb9a..bf2b23d2f 100644 --- a/__tests__/cmds/docs.test.js +++ b/__tests__/cmds/docs.test.js @@ -564,9 +564,9 @@ 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.' ); }); diff --git a/src/cmds/changelogs/single.js b/src/cmds/changelogs/single.js index eba0c5042..7b1ccd05e 100644 --- a/src/cmds/changelogs/single.js +++ b/src/cmds/changelogs/single.js @@ -46,7 +46,7 @@ module.exports = class SingleChangelogCommand { } if (!(filePath.endsWith('.md') || filePath.endsWith('.markdown'))) { - return Promise.reject(new Error('The file path specified is not a markdown file.')); + return Promise.reject(new Error('The file path specified is not a Markdown file.')); } const createdDoc = await pushDoc(key, undefined, dryRun, filePath, this.cmdCategory); diff --git a/src/cmds/custompages/single.js b/src/cmds/custompages/single.js index a56054ebb..3193e1907 100644 --- a/src/cmds/custompages/single.js +++ b/src/cmds/custompages/single.js @@ -46,7 +46,7 @@ module.exports = class SingleCustomPageCommand { } 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.')); + 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); diff --git a/src/cmds/docs/single.js b/src/cmds/docs/single.js index e10fbfa71..060f2deea 100644 --- a/src/cmds/docs/single.js +++ b/src/cmds/docs/single.js @@ -52,7 +52,7 @@ module.exports = class SingleDocCommand { } if (!(filePath.endsWith('.md') || filePath.endsWith('.markdown'))) { - return Promise.reject(new Error('The file path specified is not a markdown file.')); + return Promise.reject(new Error('The file path specified is not a Markdown file.')); } // TODO: should we allow version selection at all here? From 706cdaf8ec5011d16164a51f8406bf4a7a20c53f Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Thu, 28 Jul 2022 16:53:31 -0400 Subject: [PATCH 4/4] chore: lowercase all file extension checks --- src/cmds/changelogs/index.js | 4 +++- src/cmds/changelogs/single.js | 2 +- src/cmds/custompages/index.js | 5 ++++- src/cmds/custompages/single.js | 8 +++++++- src/cmds/docs/index.js | 4 +++- src/cmds/docs/single.js | 2 +- 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/cmds/changelogs/index.js b/src/cmds/changelogs/index.js index f0637b847..5912ebb55 100644 --- a/src/cmds/changelogs/index.js +++ b/src/cmds/changelogs/index.js @@ -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}`); diff --git a/src/cmds/changelogs/single.js b/src/cmds/changelogs/single.js index 7b1ccd05e..b13f63d9c 100644 --- a/src/cmds/changelogs/single.js +++ b/src/cmds/changelogs/single.js @@ -45,7 +45,7 @@ module.exports = class SingleChangelogCommand { return Promise.reject(new Error(`No file path provided. Usage \`${config.get('cli')} ${this.usage}\`.`)); } - if (!(filePath.endsWith('.md') || filePath.endsWith('.markdown'))) { + if (!(filePath.toLowerCase().endsWith('.md') || filePath.toLowerCase().endsWith('.markdown'))) { return Promise.reject(new Error('The file path specified is not a Markdown file.')); } diff --git a/src/cmds/custompages/index.js b/src/cmds/custompages/index.js index a62aa1e7e..5e9c9e802 100644 --- a/src/cmds/custompages/index.js +++ b/src/cmds/custompages/index.js @@ -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}`); diff --git a/src/cmds/custompages/single.js b/src/cmds/custompages/single.js index 3193e1907..39392054f 100644 --- a/src/cmds/custompages/single.js +++ b/src/cmds/custompages/single.js @@ -45,7 +45,13 @@ 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'))) { + 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.')); } diff --git a/src/cmds/docs/index.js b/src/cmds/docs/index.js index 46710adc4..a06cc1cfe 100644 --- a/src/cmds/docs/index.js +++ b/src/cmds/docs/index.js @@ -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}`); diff --git a/src/cmds/docs/single.js b/src/cmds/docs/single.js index 060f2deea..5949bd688 100644 --- a/src/cmds/docs/single.js +++ b/src/cmds/docs/single.js @@ -51,7 +51,7 @@ module.exports = class SingleDocCommand { return Promise.reject(new Error(`No file path provided. Usage \`${config.get('cli')} ${this.usage}\`.`)); } - if (!(filePath.endsWith('.md') || filePath.endsWith('.markdown'))) { + if (!(filePath.toLowerCase().endsWith('.md') || filePath.toLowerCase().endsWith('.markdown'))) { return Promise.reject(new Error('The file path specified is not a Markdown file.')); }