Skip to content

Commit 47f0006

Browse files
committed
fix: configure eslint and jest to ignore output directory
1 parent 0c8c4cf commit 47f0006

File tree

5 files changed

+41
-12
lines changed

5 files changed

+41
-12
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,19 @@ To configure your project manually, follow these steps:
6868
]
6969
```
7070

71-
1. Add the output directory to `.gitignore`
71+
1. Add the output directory to `.gitignore` and `.eslintignore`
7272

7373
```gitignore
7474
# generated files by bob
7575
lib/
7676
```
7777

78+
1. Add the output directory to `jest.modulePathIgnorePatterns` if you use [Jest](https://jestjs.io)
79+
80+
```json
81+
"modulePathIgnorePatterns": ["<rootDir>/lib/"]
82+
```
83+
7884
And we're done 🎉
7985

8086
## LICENSE

src/cli.ts

+27-8
Original file line numberDiff line numberDiff line change
@@ -192,18 +192,37 @@ yargs
192192
}),
193193
};
194194

195+
if (pkg.jest) {
196+
const entry = `<rootDir>/${output}/`;
197+
198+
if (pkg.jest.modulePathIgnorePatterns) {
199+
const { modulePathIgnorePatterns } = pkg.jest;
200+
201+
if (!modulePathIgnorePatterns.includes(entry)) {
202+
modulePathIgnorePatterns.push(entry);
203+
}
204+
} else {
205+
pkg.jest.modulePathIgnorePatterns = [entry];
206+
}
207+
}
208+
195209
await fs.writeFile(pak, JSON.stringify(pkg, null, 2));
196210

197-
const gitignore = path.join(root, '.gitignore');
211+
const ignorefiles = [
212+
path.join(root, '.gitignore'),
213+
path.join(root, '.eslintignore'),
214+
];
198215

199-
if (await fs.pathExists(gitignore)) {
200-
const content = await fs.readFile(gitignore, 'utf-8');
216+
for (const ignorefile of ignorefiles) {
217+
if (await fs.pathExists(ignorefile)) {
218+
const content = await fs.readFile(ignorefile, 'utf-8');
201219

202-
if (!content.split('\n').includes(`${output}/`)) {
203-
await fs.writeFile(
204-
gitignore,
205-
`${content}\n# generated by bob\n${output}/\n`
206-
);
220+
if (!content.split('\n').includes(`${output}/`)) {
221+
await fs.writeFile(
222+
ignorefile,
223+
`${content}\n# generated by bob\n${output}/\n`
224+
);
225+
}
207226
}
208227
}
209228

src/targets/commonjs.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import path from 'path';
2+
import chalk from 'chalk';
13
import del from 'del';
24
import compile from '../utils/compile';
35
import { Input } from '../types';
@@ -13,7 +15,7 @@ export default async function build({
1315
options,
1416
report
1517
}: Options) {
16-
report.info('Cleaning up previous build');
18+
report.info(`Cleaning up previous build at ${chalk.blue(path.relative(root, output))}`);
1719

1820
await del([output]);
1921

src/targets/module.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import path from 'path';
2+
import chalk from 'chalk';
13
import del from 'del';
24
import compile from '../utils/compile';
35
import { Input } from '../types';
@@ -13,7 +15,7 @@ export default async function build({
1315
options,
1416
report
1517
}: Options) {
16-
report.info('Cleaning up previous build');
18+
report.info(`Cleaning up previous build at ${chalk.blue(path.relative(root, output))}`);
1719

1820
await del([output]);
1921

src/targets/typescript.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import del from 'del';
66
import { Input } from '../types';
77

88
export default async function build({ root, output, report }: Input) {
9-
report.info('Cleaning up previous build');
9+
report.info(`Cleaning up previous build at ${chalk.blue(path.relative(root, output))}`);
1010

1111
await del([output]);
1212

0 commit comments

Comments
 (0)