From 3765e6ef189a1ec7c065f1da0638fea19d7a4ceb Mon Sep 17 00:00:00 2001 From: Jacob Page Date: Thu, 21 Dec 2023 11:35:38 -0800 Subject: [PATCH] Add `.docs` to `.gitignore` Add the default documentation output directory to the generated `.gitignore` file. --- packages/gasket-plugin-docs/CHANGELOG.md | 2 ++ packages/gasket-plugin-docs/lib/create.js | 5 +++++ packages/gasket-plugin-docs/lib/index.js | 2 ++ packages/gasket-plugin-docs/test/create.test.js | 17 +++++++++++++++++ packages/gasket-plugin-docs/test/index.test.js | 1 + 5 files changed, 27 insertions(+) create mode 100644 packages/gasket-plugin-docs/lib/create.js create mode 100644 packages/gasket-plugin-docs/test/create.test.js diff --git a/packages/gasket-plugin-docs/CHANGELOG.md b/packages/gasket-plugin-docs/CHANGELOG.md index f6bc66b0f..8baac9de8 100644 --- a/packages/gasket-plugin-docs/CHANGELOG.md +++ b/packages/gasket-plugin-docs/CHANGELOG.md @@ -1,5 +1,7 @@ # `@gasket/plugin-docs` +- Add the default docs directory `.docs` to `.gitignore` on project creation. + ### 6.37.0 - Jest refactor ([#504]) diff --git a/packages/gasket-plugin-docs/lib/create.js b/packages/gasket-plugin-docs/lib/create.js new file mode 100644 index 000000000..1f5e392dc --- /dev/null +++ b/packages/gasket-plugin-docs/lib/create.js @@ -0,0 +1,5 @@ +const { defaultConfig } = require('./configure'); + +module.exports = function create(_gasket, { gitignore }) { + gitignore?.add(defaultConfig.outputDir, 'Documentation'); +}; diff --git a/packages/gasket-plugin-docs/lib/index.js b/packages/gasket-plugin-docs/lib/index.js index 99e6e30b8..49ffb2a2b 100644 --- a/packages/gasket-plugin-docs/lib/index.js +++ b/packages/gasket-plugin-docs/lib/index.js @@ -1,3 +1,4 @@ +const create = require('./create'); const configure = require('./configure'); const getCommands = require('./get-commands'); const metadata = require('./metadata'); @@ -7,6 +8,7 @@ module.exports = { name: require('../package').name, hooks: { configure, + create, getCommands, metadata, docsSetup diff --git a/packages/gasket-plugin-docs/test/create.test.js b/packages/gasket-plugin-docs/test/create.test.js new file mode 100644 index 000000000..58335970c --- /dev/null +++ b/packages/gasket-plugin-docs/test/create.test.js @@ -0,0 +1,17 @@ +const { hooks: { create } } = require('../lib/index'); + +describe('the create hook', () => { + it('should add a gitignore entry for the .docs directory', () => { + const context = { gitignore: { add: jest.fn() } }; + + create({}, context); + + expect(context.gitignore.add).toHaveBeenCalledWith('.docs', 'Documentation'); + }); + + it('should handle when no `gitignore` is present in the create context', () => { + const context = {}; + + expect(() => create({}, context)).not.toThrow(Error); + }); +}); diff --git a/packages/gasket-plugin-docs/test/index.test.js b/packages/gasket-plugin-docs/test/index.test.js index fa34fc90d..7fcc43447 100644 --- a/packages/gasket-plugin-docs/test/index.test.js +++ b/packages/gasket-plugin-docs/test/index.test.js @@ -13,6 +13,7 @@ describe('Plugin', function () { it('has expected hooks', () => { const expected = [ 'configure', + 'create', 'getCommands', 'metadata', 'docsSetup'