@@ -14,31 +14,43 @@ const writeFileAsync = promisify(writeFile);
14
14
15
15
console . log ( "Configuring @anolilab/prettier-config" , projectPath , "\n" ) ;
16
16
17
+ const configFile = ".prettierrc" ;
18
+
17
19
/**
18
20
* Writes .prettierrc.${m|c}js if it doesn't exist. Warns if it exists.
19
21
*/
20
22
const writePrettierRc = ( ) => {
21
- const prettierPath = join ( projectPath , ".prettierrc.js" ) ;
22
-
23
- if (
24
- existsSync ( prettierPath )
25
- || existsSync ( prettierPath . replace ( ".js" , "" ) )
26
- || existsSync ( prettierPath . replace ( ".js" , `.${ packageIsTypeModule ? "m" : "c" } js` ) )
27
- ) {
28
- console . warn ( `⚠️ .prettierrc.{m|c}js already exists;
23
+ // eslint-disable-next-line no-restricted-syntax
24
+ for ( const filename of [
25
+ configFile ,
26
+ `${ configFile } .js` ,
27
+ `${ configFile } .cjs` ,
28
+ `${ configFile } .json` ,
29
+ `${ configFile } .json5` ,
30
+ `${ configFile } .yaml` ,
31
+ `${ configFile } .yml` ,
32
+ `${ configFile } .toml` ,
33
+ "prettier.config.js" ,
34
+ "prettier.config.cjs" ,
35
+ ] ) {
36
+ if ( existsSync ( join ( projectPath , filename ) ) ) {
37
+ console . warn ( `⚠️ ${ filename } already exists;
29
38
Make sure that it includes the following for @anolilab/prettier-config to work as it should:
30
39
${ JSON . stringify ( content , undefined , 4 ) } \n`) ;
31
40
32
- return Promise . resolve ( ) ;
41
+ return Promise . resolve ( ) ;
42
+ }
33
43
}
34
44
45
+ const prettierPath = join ( projectPath , ".prettierrc.js" ) ;
46
+
35
47
return writeFileAsync (
36
48
prettierPath ,
37
49
`${ packageIsTypeModule ? "export default" : "module.exports =" } ${ JSON . stringify ( content , undefined , 2 ) . replace (
38
50
"rangeEnd: null," ,
39
51
"rangeEnd: Number.POSITIVE_INFINITY," ,
40
52
) } \n`,
41
- "utf-8 " ,
53
+ "utf8 " ,
42
54
) ;
43
55
} ;
44
56
@@ -54,7 +66,11 @@ const writePrettierIgnore = () => {
54
66
return Promise . resolve ( ) ;
55
67
}
56
68
57
- return writeFileAsync ( prettierPath , "" , "utf-8" ) ;
69
+ return writeFileAsync (
70
+ prettierPath ,
71
+ `${ [ "*.md" , "*.sh" , "*.yml" , "*.svg" , "*.gif" , "*.log" , ".DS_Store" , "CNAME" , "AUTHORS" , "LICENSE" , "es/" , "lib/" , "dist/" , "coverage/" ] . join ( "\n" ) } \n` ,
72
+ "utf8" ,
73
+ ) ;
58
74
} ;
59
75
60
76
// eslint-disable-next-line unicorn/prefer-top-level-await
0 commit comments