diff --git a/README.md b/README.md index cd6c26b6f..2a785749d 100644 --- a/README.md +++ b/README.md @@ -68,13 +68,19 @@ To configure your project manually, follow these steps: ] ``` -1. Add the output directory to `.gitignore` +1. Add the output directory to `.gitignore` and `.eslintignore` ```gitignore # generated files by bob lib/ ``` +1. Add the output directory to `jest.modulePathIgnorePatterns` if you use [Jest](https://jestjs.io) + + ```json + "modulePathIgnorePatterns": ["/lib/"] + ``` + And we're done 🎉 ## LICENSE diff --git a/src/cli.ts b/src/cli.ts index 48a35ee2b..3a324e7d7 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -192,18 +192,37 @@ yargs }), }; + if (pkg.jest) { + const entry = `/${output}/`; + + if (pkg.jest.modulePathIgnorePatterns) { + const { modulePathIgnorePatterns } = pkg.jest; + + if (!modulePathIgnorePatterns.includes(entry)) { + modulePathIgnorePatterns.push(entry); + } + } else { + pkg.jest.modulePathIgnorePatterns = [entry]; + } + } + await fs.writeFile(pak, JSON.stringify(pkg, null, 2)); - const gitignore = path.join(root, '.gitignore'); + const ignorefiles = [ + path.join(root, '.gitignore'), + path.join(root, '.eslintignore'), + ]; - if (await fs.pathExists(gitignore)) { - const content = await fs.readFile(gitignore, 'utf-8'); + for (const ignorefile of ignorefiles) { + if (await fs.pathExists(ignorefile)) { + const content = await fs.readFile(ignorefile, 'utf-8'); - if (!content.split('\n').includes(`${output}/`)) { - await fs.writeFile( - gitignore, - `${content}\n# generated by bob\n${output}/\n` - ); + if (!content.split('\n').includes(`${output}/`)) { + await fs.writeFile( + ignorefile, + `${content}\n# generated by bob\n${output}/\n` + ); + } } } diff --git a/src/targets/commonjs.ts b/src/targets/commonjs.ts index 3cef027ec..d5d486c54 100644 --- a/src/targets/commonjs.ts +++ b/src/targets/commonjs.ts @@ -1,3 +1,5 @@ +import path from 'path'; +import chalk from 'chalk'; import del from 'del'; import compile from '../utils/compile'; import { Input } from '../types'; @@ -13,7 +15,7 @@ export default async function build({ options, report }: Options) { - report.info('Cleaning up previous build'); + report.info(`Cleaning up previous build at ${chalk.blue(path.relative(root, output))}`); await del([output]); diff --git a/src/targets/module.ts b/src/targets/module.ts index 09d04e84c..5a501aae3 100644 --- a/src/targets/module.ts +++ b/src/targets/module.ts @@ -1,3 +1,5 @@ +import path from 'path'; +import chalk from 'chalk'; import del from 'del'; import compile from '../utils/compile'; import { Input } from '../types'; @@ -13,7 +15,7 @@ export default async function build({ options, report }: Options) { - report.info('Cleaning up previous build'); + report.info(`Cleaning up previous build at ${chalk.blue(path.relative(root, output))}`); await del([output]); diff --git a/src/targets/typescript.ts b/src/targets/typescript.ts index ea9df56d5..e75de7ae2 100644 --- a/src/targets/typescript.ts +++ b/src/targets/typescript.ts @@ -6,7 +6,7 @@ import del from 'del'; import { Input } from '../types'; export default async function build({ root, output, report }: Input) { - report.info('Cleaning up previous build'); + report.info(`Cleaning up previous build at ${chalk.blue(path.relative(root, output))}`); await del([output]);