Skip to content

Commit ce46703

Browse files
committed
feat(yarn): try to add list of ignore files from Yarn for ESLint and Prettier
1 parent e5cda33 commit ce46703

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

src/actions/CreateFileAction.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
import { withCurrentDir, writeContentToFile } from "../process";
1+
import { getFileStats, withCurrentDir, writeContentToFile } from "../process";
22
import { Action } from "./Action";
33

44
export class CreateFileAction extends Action {
5-
constructor(private fileName: string, private content: string) {
5+
constructor(private fileName: string, private content: string, private tryUpdateOnly = false) {
66
super();
77
}
88

99
async exec(): Promise<void> {
10-
await writeContentToFile(withCurrentDir(this.fileName), this.content);
10+
const filePath = withCurrentDir(this.fileName);
11+
12+
if (this.tryUpdateOnly) {
13+
const stats = await getFileStats(filePath);
14+
stats && stats.isFile() && (await writeContentToFile(filePath, this.content, "a"));
15+
} else {
16+
await writeContentToFile(filePath, this.content);
17+
}
1118
}
1219
}

src/configs.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,18 @@ export const eslintBaseConfigs = {
3131
rules: {},
3232
};
3333

34+
export const ignoreYarn2 = `
35+
# Yarn
36+
.yarn
37+
.pnp.*
38+
`;
39+
3440
export const ignoreFiles = `
3541
# Builds
3642
lib
3743
dist
3844
build
3945
40-
# Yarn
41-
.yarn
42-
.pnp.*
43-
4446
# Test
4547
coverage
4648

src/generators/Yarn2Generator.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Action } from "../actions/Action";
2+
import { CreateFileAction } from "../actions/CreateFileAction";
23
import { CreateYarn2ConfigsAction } from "../actions/CreateYarn2ConfigsAction";
4+
import { ignoreYarn2 } from "../configs";
35
import { Formatter } from "../formatters/Formatter";
46
import { InquirerConfigs } from "../types";
57
import { Generator } from "./Generator";
@@ -15,6 +17,10 @@ export class Yarn2Generator extends Generator {
1517
userConfigs: InquirerConfigs,
1618
formatter: Formatter,
1719
): Action[] {
18-
return [new CreateYarn2ConfigsAction(userConfigs)];
20+
return [
21+
new CreateYarn2ConfigsAction(userConfigs),
22+
new CreateFileAction(".eslintignore", ignoreYarn2, true),
23+
new CreateFileAction(".prettierignore", ignoreYarn2, true),
24+
];
1925
}
2026
}

src/process.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export async function getFileStats(file: string): Promise<Stats | undefined> {
6060
}
6161
}
6262

63-
export async function writeContentToFile(file: string, content: string, flag = "a+") {
63+
export async function writeContentToFile(file: string, content: string, flag = "a") {
6464
const stats = await getFileStats(file);
6565

6666
if (stats) {

0 commit comments

Comments
 (0)