Skip to content

Commit

Permalink
fix: configure eslint and jest to ignore output directory
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Apr 28, 2019
1 parent 0c8c4cf commit 47f0006
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": ["<rootDir>/lib/"]
```

And we're done 🎉

## LICENSE
Expand Down
35 changes: 27 additions & 8 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,37 @@ yargs
}),
};

if (pkg.jest) {
const entry = `<rootDir>/${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`
);
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/targets/commonjs.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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]);

Expand Down
4 changes: 3 additions & 1 deletion src/targets/module.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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]);

Expand Down
2 changes: 1 addition & 1 deletion src/targets/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down

0 comments on commit 47f0006

Please sign in to comment.