Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
kellymears committed Sep 4, 2023
1 parent 9895ae9 commit d9f6eb9
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import BudCommand from '@roots/bud/cli/commands'
import {Option} from '@roots/bud-support/clipanion'

/**
* Bud eslint command
* {@link BudCommand}
*/
export class BudEslintCommand extends BudCommand {
/**
Expand All @@ -19,6 +19,7 @@ export class BudEslintCommand extends BudCommand {
examples: [[`Run eslint on source files`, `$0 eslint`]],
})


public options = Option.Proxy({name: `eslint passthrough options`})

/**
Expand All @@ -28,8 +29,13 @@ export class BudEslintCommand extends BudCommand {
await this.makeBud()
await this.bud.run()

return await this.run([`eslint`, `bin`, `eslint.js`], this.options, [
this.bud.path(`@src`, `**`, `*.{ts,tsx,js,jsx}`),
const eslintrc = Object.values(this.bud.context.files).find((file) => file.name.includes(`eslintrc`) || file.name.includes(`eslint.config`))?.path

await this.run([`eslint`, `bin`, `eslint.js`], this.options, [
`--ext`,
`.js,.jsx,.ts,.tsx`,
...(eslintrc ? [`--config`, eslintrc]: []),
this.bud.relPath(`@src`),
])
}
}
2 changes: 1 addition & 1 deletion sources/create-bud-app/src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import buildTask from '../tasks/build.js'
import installDevDependenciesTask from '../tasks/install.dev.js'
import installProductionDependenciesTask from '../tasks/install.prod.js'
import writeConfigTask from '../tasks/write.bud.config.js'
import writeEslintConfigTask from '../tasks/write.eslint.config.js'
import writeEslintConfigTask from '../tasks/write.eslintrc.js'
import writeGitignoreConfigTask from '../tasks/write.gitignore.js'
import writePackageJSONTask from '../tasks/write.package.js'
import writePrettierConfigTask from '../tasks/write.prettier.config.js'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type CreateCommand from '../commands/create.js'
import formatSource from '../utilities/formatSource.js'
import templateEngine from '../utilities/templateEngine.js'

export default async function writeStylelintConfigTask(
export default async function writeEslintConfigTask(
command: CreateCommand,
) {
if (!command.support.includes(`eslint`)) return
Expand Down Expand Up @@ -39,7 +39,7 @@ export default async function writeStylelintConfigTask(
configExtends.push(`@roots/eslint-config/wordpress`)

const source = await command.fs.read(
join(command.createRoot, `templates`, `eslint.config.js.hbs`),
join(command.createRoot, `templates`, `.eslintrc.cjs.hbs`),
`utf8`,
)

Expand All @@ -48,7 +48,7 @@ export default async function writeStylelintConfigTask(

const result = template({extends: configExtends})

await command.fs.write(`eslint.config.js`, await formatSource(result))
await command.fs.write(`.eslintrc.cjs`, await formatSource(result))
} catch (error) {
spinner.fail()
throw error
Expand Down
4 changes: 3 additions & 1 deletion sources/create-bud-app/src/tasks/write.tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ export default async function writeTsConfig(command: CreateCommand) {
`@roots/bud-wordpress-manifests`,
)

types.push(`webpack/module`)

const source = `{
"extends": "@roots/bud/config/jsconfig.json",
"extends": ["@roots/bud/config/tsconfig.json"],
"compilerOptions": {
"allowJs": true,
"paths": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
module.exports = {
root: true,
{{#if extends}}
extends: [
Expand Down
66 changes: 63 additions & 3 deletions sources/create-bud-app/templates/types.d.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,64 @@
declare module '*.@(css|svg|jpg|jpeg|png|gif|webp|avif|woff|woff2|ttf|eot|otf)' {
const content: string;
export default content;
declare module '*.htm' {
const value: string
export default value
}
declare module '*.html' {
const value: string
export default value
}
declare module '*.json' {
const value: Record<string, any>
export default value
}
declare module '*.yml' {
const value: Record<string, any>
export default value
}
declare module '*.css' {
const content: string
export default content
}
declare module '*.sass' {
const content: string
export default content
}
declare module '*.scss' {
const content: string
export default content
}
declare module '*.gif' {
const value: string
export default value
}
declare module '*.jpg' {
const value: string
export default value
}
declare module '*.jpeg' {
const value: string
export default value
}
declare module '*.png' {
const value: string
export default value
}
declare module '*.svg' {
const value: string
export default value
}
declare module '*.webp' {
const value: string
export default value
}
declare module '*.mp4' {
const value: string
export default value
}
declare module '*.webm' {
const value: string
export default value
}
declare module '*.woff2' {
const value: string
export default value
}

0 comments on commit d9f6eb9

Please sign in to comment.