015a7dd9ee
Make templates actual executable tests to that we ensure there are no regressions. It also makes the setup easier. Also changes the layout to typescript because that's what we want to use by default anyway. Also refactors helper function to use plop specific `{{ toFileName name }}` syntax for easier template modification. Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
const { quote } = require('shell-quote')
|
|
const { ESLint } = require('eslint')
|
|
|
|
const eslint = new ESLint()
|
|
const isWin = process.platform === 'win32'
|
|
|
|
module.exports = {
|
|
'**/*.{js,jsx,ts,tsx}': (filenames) => {
|
|
const escapedFileNames = filenames
|
|
.map((filename) => (isWin ? filename : escape([filename])))
|
|
.join(' ')
|
|
return [
|
|
`prettier --with-node-modules --ignore-path .prettierignore_staged --write ${escapedFileNames}`,
|
|
`eslint --no-ignore --max-warnings=0 --fix ${filenames
|
|
.filter((file) => !eslint.isPathIgnored(file))
|
|
.map((f) => `"${f}"`)
|
|
.join(' ')}`,
|
|
`git add ${escapedFileNames}`,
|
|
]
|
|
},
|
|
'**/*.{json,md,mdx,css,html,yml,yaml,scss}': (filenames) => {
|
|
const escapedFileNames = filenames
|
|
.map((filename) => (isWin ? filename : escape([filename])))
|
|
.join(' ')
|
|
return [
|
|
`prettier --with-node-modules --ignore-path .prettierignore_staged --write ${escapedFileNames}`,
|
|
`git add ${escapedFileNames}`,
|
|
]
|
|
},
|
|
}
|
|
|
|
function escape(str) {
|
|
const escaped = quote(str)
|
|
return escaped.replace(/\\@/g, '@')
|
|
}
|