Skip to content

Commit

Permalink
Merge pull request #114 from docsbydoxdox/hotfix/use-globby-ignorefiles
Browse files Browse the repository at this point in the history
Added ignoreFiles and gitignore option to globby.
  • Loading branch information
neogeek authored Feb 2, 2022
2 parents f9a98d8 + c0f37cd commit 709dfc5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 71 deletions.
21 changes: 9 additions & 12 deletions packages/doxdox-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@ import parseCmdArgs from 'parse-cmd-args';
import doxdox, {
findFileInPath,
findParentNodeModules,
getIgnoreConfigInPath,
getProjectPackage,
getRootDirPath,
parseIgnoreConfig,
loadPlugin,
sanitizePath,
getProjectPackage
parseIgnoreConfig,
sanitizePath
} from 'doxdox-core';

import { Doc, File } from 'doxdox-core';

const defaultPaths = ['**/*.js'];

const defaultIgnorePatterns = ['!node_modules/'];

const helpDocs = `Usage: doxdox <path> ... [options]
Options:
Expand Down Expand Up @@ -92,13 +89,13 @@ const overridePackage = args.flags['-p'] || args.flags['--package'];
}

const paths = await globby(
(args.input ? [args.input] : defaultPaths).concat([
...defaultIgnorePatterns,
...parseIgnoreConfig(overrideIgnore.split(',').join(EOL)),
...(await getIgnoreConfigInPath(cwd))
]),
(args.input ? [args.input] : defaultPaths).concat(
parseIgnoreConfig(overrideIgnore.split(',').join(EOL))
),
{
cwd
cwd,
ignoreFiles: ['.doxdoxignore'],
gitignore: true
}
);

Expand Down
30 changes: 0 additions & 30 deletions packages/doxdox-core/src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { join } from 'path';
import {
findFileInPath,
findParentNodeModules,
getIgnoreConfigInPath,
getProjectPackage,
getRootDirPath,
isDirectory,
Expand Down Expand Up @@ -57,35 +56,6 @@ describe('utils', () => {
});
});

describe('getIgnoreConfigInPath', () => {
it('find ignore config with input directory', async () => {
assert.deepEqual(await getIgnoreConfigInPath('./'), [
'!**/*.test.*',
'!./coverage/',
'!./dist/'
]);
});

it('find ignore config with input file', async () => {
assert.deepEqual(await getIgnoreConfigInPath('./.doxdoxignore'), [
'!**/*.test.*',
'!./coverage/',
'!./dist/'
]);
});

it('fail to find ignore config with input non .doxdoxignore file', async () => {
assert.deepEqual(
await getIgnoreConfigInPath('./jest.config.js'),
[]
);
});

it('fail to find ignore config with invalid directory', async () => {
assert.deepEqual(await getIgnoreConfigInPath('../testing'), []);
});
});

describe('getProjectPackage', () => {
it('gets contents from project package', async () => {
const { name, description, version, exports } = JSON.parse(
Expand Down
30 changes: 1 addition & 29 deletions packages/doxdox-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,32 +76,6 @@ export const findParentNodeModules = async (
return null;
};

/**
* Return list of ignored paths and files.
*
* console.log(await getIgnoreConfigInPath('./'));
* console.log(await getIgnoreConfigInPath('./.doxdoxignore'));
* console.log(await getIgnoreConfigInPath('~/git/github/doxdox/'));
*
* @param {string} [input] Directory to check for ignore config file.
* @return {Promise<string[]>} List of ignored paths and files.
* @public
*/

export const getIgnoreConfigInPath = async (
input: string
): Promise<string[]> => {
const ignorePath = await findFileInPath(input, '.doxdoxignore');

if (ignorePath) {
const ignoreContents = await fs.readFile(ignorePath, 'utf8');

return parseIgnoreConfig(ignoreContents);
}

return [];
};

/**
* Returns basic information from a projects package file.
*
Expand Down Expand Up @@ -169,9 +143,7 @@ export const isFile = async (path: string): Promise<boolean> => {
/**
* Parse contents of ignore file.
*
* console.log(await parseIgnoreConfig('./'));
* console.log(await getIgnoreConfigInPath('./.doxdoxignore'));
* console.log(await getIgnoreConfigInPath('~/git/github/doxdox/'));
* console.log(await parseIgnoreConfig('node_modules/'));
*
* @param {string} [contents] Contents of ignore file.
* @return {string[]} List of ignored paths and files.
Expand Down

0 comments on commit 709dfc5

Please sign in to comment.