-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
base.js
49 lines (41 loc) · 1.42 KB
/
base.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const { preferPrettier } = require('@1stg/config')
const { isPkgAvailable } = require('@pkgr/core')
const isEslintAvailable = isPkgAvailable('eslint')
const isStylelintAvailable = isPkgAvailable('stylelint')
const useEslintPrettier = isEslintAvailable && !preferPrettier
const useStylelintPrettier = isStylelintAvailable && !preferPrettier
const ESLINT_PRETTIER_FILES =
'cjs,cts,js,json,jsonc,json5,jsx,html,md,mdx,mjs,mts,pug,svelte,toml,ts,tsx,vue,yaml,yml'
const STYLELINT_PRETTIER_FILES = 'css,less,sass,scss,styl,stylus,svelte,vue'
const config = [
`*.{*sh,env,env.*,gql,ini,properties,rb${
isEslintAvailable ? '' : ',' + ESLINT_PRETTIER_FILES
}${isStylelintAvailable ? '' : ',' + STYLELINT_PRETTIER_FILES}}`,
'.!(browserslist|nvm|yarn)rc',
'Dockerfile',
].reduce(
(acc, files) =>
Object.assign(acc, {
// eslint-disable-next-line sonarjs/no-duplicate-string
[files]: 'prettier --write',
}),
{},
)
if (isEslintAvailable) {
Object.assign(config, {
[`*.{${ESLINT_PRETTIER_FILES}}`]: [
'eslint --cache -f friendly --fix',
...(useEslintPrettier ? [] : ['prettier --write']),
],
})
}
if (isStylelintAvailable) {
config[`*.{${STYLELINT_PRETTIER_FILES}}`] = [
'stylelint --allow-empty-input --cache --fix',
...(useStylelintPrettier ? [] : ['prettier --write']),
]
}
if (isPkgAvailable('@pkgr/imagemin')) {
config['*.{gif,jpeg,jpg,png,svg,webp}'] = 'i'
}
module.exports = config