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

Added ignoreFiles and gitignore option to globby. #114

Merged
merged 1 commit into from
Feb 2, 2022
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
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