diff --git a/configuration/playwright.ts b/configuration/playwright.ts new file mode 100644 index 0000000..0dbed76 --- /dev/null +++ b/configuration/playwright.ts @@ -0,0 +1,13 @@ +import type { Template } from '../types' + +export const templates: Template = {} // Has no templates, highly customizable. + +export function createFile() { + return { + name: 'playwright.config.ts', + contents: `import { defineConfig } from '@playwright/test' +import { playwright } from './configuration.ts' + +export default defineConfig(playwright)`, + } +} diff --git a/index.ts b/index.ts index e4c7a14..154bbff 100644 --- a/index.ts +++ b/index.ts @@ -3,16 +3,21 @@ import { existsSync } from 'node:fs' import { join } from 'node:path' import { it } from 'avait' import Bun from 'bun' +import { create } from 'logua' import * as biome from './configuration/biome' import * as eslint from './configuration/eslint' import * as ignore from './configuration/gitignore' +import * as playwright from './configuration/playwright' import * as prettier from './configuration/prettier' import * as typescript from './configuration/typescript' import * as vscode from './configuration/vscode' +import type { Configuration } from './types' + +const log = create('zero-configuration', 'blue') // TODO validate inputs with zod. -const configurations = [ +const configurations: Configuration[] = [ { name: 'typescript', alias: 'tsconfig', @@ -34,6 +39,10 @@ const configurations = [ name: 'vscode', configuration: vscode, }, + { + name: 'playwright', + configuration: playwright, + }, ] const ignores: string[] = [] @@ -43,7 +52,7 @@ const packageJson = await Bun.file('./package.json').json() const { value: moduleContents } = await it(import(join(process.cwd(), './configuration.ts'))) if (!(moduleContents || Object.hasOwn(packageJson, 'configuration'))) { - console.warn('zero-configuration: No configurations detected') + log('No configurations detected', 'error') } const userConfiguration = packageJson.configuration ?? moduleContents @@ -64,10 +73,16 @@ for (const { name, alias, configuration } of configurations) { await Bun.write(file.name, file.contents) ignores.push(file.name) } + + if (value === true) { + const file = configuration.createFile() + await Bun.write(file.name, file.contents) + ignores.push(file.name) + } } if (ignores.length === 0) { - console.warn('zero-configuration: No configurations detected') + log('No configurations detected', 'error') } let userIgnores: string[] = userConfiguration.ignore ?? userConfiguration.gitignore ?? [] diff --git a/package.json b/package.json index 1f48cfe..43b88d3 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "types": "tsc --noEmit" }, "dependencies": { - "avait": "^1.0.0" + "avait": "^1.0.0", + "logua": "^3.0.3" }, "devDependencies": { "@biomejs/biome": "^1.6.4", diff --git a/test/fixture/file/configuration.ts b/test/fixture/file/configuration.ts index a1da2ce..feb3698 100644 --- a/test/fixture/file/configuration.ts +++ b/test/fixture/file/configuration.ts @@ -1 +1,19 @@ +import { devices } from '@playwright/test' + export const prettier = 'recommended' + +export const playwright = { + fullyParallel: true, + workers: process.env.CI ? 1 : undefined, + projects: [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, + ], + webServer: { + command: 'bun start', + url: 'http://localhost:3000', + reuseExistingServer: !process.env.CI, + }, +} diff --git a/test/fixture/package/package.json b/test/fixture/package/package.json index 134d45a..409dc86 100644 --- a/test/fixture/package/package.json +++ b/test/fixture/package/package.json @@ -4,6 +4,7 @@ "eslint": true, "prettier": "recommended", "biome": "recommended", + "playwright": true, "tsconfig": { "compilerOptions": { "target": "ES6" diff --git a/types.ts b/types.ts index ce5febf..506beda 100644 --- a/types.ts +++ b/types.ts @@ -1 +1,11 @@ export type Template = { [key: string]: T } + +export type Configuration = { + name: string + alias?: string + configuration: { + templates: Template + // biome-ignore lint/suspicious/noExplicitAny: Will be specified in file explicitly. + createFile: (value?: any) => { name: string; contents: string } + } +}