Skip to content

Commit 5f867d7

Browse files
committedJun 25, 2023
fix: extended postinstall script file checking
Signed-off-by: prisis <d.bannert@anolilab.de>
1 parent 2819457 commit 5f867d7

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed
 

‎packages/eslint-config/src/postinstall.ts

+15-10
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,24 @@ const writeFileAsync = promisify(writeFile);
1313

1414
console.log("Configuring @anolilab/eslint-config", projectPath, "\n");
1515

16+
const configFile = ".eslintrc";
17+
1618
/**
1719
* Writes .eslintrc.js if it doesn't exist. Warns if it exists.
1820
*/
1921
// eslint-disable-next-line sonarjs/cognitive-complexity
2022
const writeEslintRc = () => {
23+
// eslint-disable-next-line no-restricted-syntax
24+
for (const filename of [configFile, `${configFile}.js`, `${configFile}.cjs`, `${configFile}.json`, `${configFile}.yaml`, `${configFile}.yml`]) {
25+
if (existsSync(join(projectPath, filename))) {
26+
console.warn(`⚠️ ${filename} already exists;
27+
Make sure that it includes the following for @anolilab/eslint-config'
28+
to work as it should: { extends: ["@anolilab/eslint-config"] }.`);
29+
30+
return Promise.resolve();
31+
}
32+
}
33+
2134
const eslintPath = join(projectPath, ".eslintrc.js");
2235

2336
let pluginExtends = "";
@@ -97,15 +110,7 @@ ${packageIsTypeModule ? "export default" : "module.exports ="} {
97110
};
98111
`;
99112

100-
if (existsSync(eslintPath)) {
101-
console.warn(`⚠️ .eslintrc.cjs already exists;
102-
Make sure that it includes the following for @anolilab/eslint-config'
103-
to work as it should: { extends: ["@anolilab/eslint-config"] }.`);
104-
105-
return Promise.resolve();
106-
}
107-
108-
return writeFileAsync(eslintPath, content, "utf-8");
113+
return writeFileAsync(eslintPath, content, "utf8");
109114
};
110115

111116
/**
@@ -120,7 +125,7 @@ const writeEslintIgnore = () => {
120125
return Promise.resolve();
121126
}
122127

123-
return writeFileAsync(eslintIgnorePath, "", "utf-8");
128+
return writeFileAsync(eslintIgnorePath, "", "utf8");
124129
};
125130

126131
// eslint-disable-next-line unicorn/prefer-top-level-await

‎packages/stylelint-config/src/postinstall.ts

+13-8
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,23 @@ const writeFileAsync = promisify(writeFile);
1212

1313
console.log("Configuring @anolilab/stylelint-config", projectPath, "\n");
1414

15+
const file = ".stylelintrc";
16+
1517
/**
1618
* Writes .stylelintrc.cjs if it doesn't exist. Warns if it exists.
1719
*/
1820
const writeStylelintRc = () => {
21+
// eslint-disable-next-line no-restricted-syntax
22+
for (const filename of [file, `${file}.js`, `${file}.cjs`, `${file}.json`, `${file}.yaml`, `${file}.yml`, `stylelint.config.js`, `stylelint.config.cjs`]) {
23+
if (existsSync(join(projectPath, filename))) {
24+
console.warn(
25+
'⚠️ .stylelintrc.js already exists; Make sure that it includes the following for @anolilab/stylelint-config to work as it should: { "extends": ["@anolilab/stylelint-config"] }.',
26+
);
27+
28+
return Promise.resolve();
29+
}
30+
}
31+
1932
const stylelintPath = join(projectPath, ".stylelintrc.js");
2033
const content = `${packageIsTypeModule ? "export default" : "module.exports ="} {
2134
"extends": [
@@ -25,14 +38,6 @@ const writeStylelintRc = () => {
2538
2639
`;
2740

28-
if (existsSync(stylelintPath)) {
29-
console.warn(
30-
'⚠️ .stylelintrc.js already exists; Make sure that it includes the following for @anolilab/stylelint-config to work as it should: { "extends": ["@anolilab/stylelint-config"] }.',
31-
);
32-
33-
return Promise.resolve();
34-
}
35-
3641
return writeFileAsync(stylelintPath, content, "utf-8");
3742
};
3843

‎pnpm-lock.yaml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.