From 1a2097e78b1b28f4e11cbff236c774431219f246 Mon Sep 17 00:00:00 2001 From: Matthias Giger Date: Fri, 5 Jul 2024 18:41:28 +0200 Subject: [PATCH] feat(configuration): add drizzle configuration Remove dependency check as output not visible in postinstall script. release-npm --- README.md | 3 ++- configuration/biome.ts | 3 --- configuration/drizzle.ts | 26 ++++++++++++++++++++++++++ configuration/index.ts | 6 ++++++ configuration/playwright.ts | 2 -- configuration/rsbuild.ts | 2 -- configuration/typescript.ts | 3 --- helper.ts | 28 +--------------------------- package.json | 2 -- test/basic.test.ts | 1 + test/fixture/file/configuration.ts | 4 ++++ 11 files changed, 40 insertions(+), 40 deletions(-) create mode 100644 configuration/drizzle.ts diff --git a/README.md b/README.md index 02cfd74..10193e2 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Many web development projects often contain numerous configuration files in the project's root directory, with little to no actual source code. While many plugins nowadays require configuration files, this plugin aims to generate them without the necessity of committing anything to the source code. - No configuration files in your source code. -- Support for **gitignore**, **TypeScript**, **ESLint**, **Prettier**, **Biome**, **VS Code**, **Playwright**, **Cypress**, **Tailwind**, **PostCSS**, **babel**, **Metro**, **Vercel** and **Vitest**. +- Support for **gitignore**, **TypeScript**, **ESLint**, **Prettier**, **Biome**, **VS Code**, **Playwright**, **Cypress**, **Tailwind**, **PostCSS**, **babel**, **Metro**, **Drizzle**, **Vercel** and **Vitest**. - Quickly configure bundlers like **Vite** and **Rsbuild**. - Generate boilerplate before publishing: **LICENSE.md**. - JSON based configuration in `package.json`. @@ -101,6 +101,7 @@ export const postcss = object | File export const babel = object | File (JavaScript only) export const metro = object | 'react-native' | File (JavaScript only) export const reactNative = object | File +export const drizzle = 'basic' | object | File export const vercel = 'spa' | 'SPA' | 'single-page-application' | 'spa-routes' | 'github-silent' | { extends: 'spa', routes: { ... }} export const license = 'MIT' | 'mit' export const ignore = true | 'recommended' | 'bundle' | 'numic' | string[] | ['extends:bundle', ...] diff --git a/configuration/biome.ts b/configuration/biome.ts index a958745..26dde14 100644 --- a/configuration/biome.ts +++ b/configuration/biome.ts @@ -1,5 +1,3 @@ -import { checkDependency } from '../helper' - const base = (rules: object) => ({ $schema: 'node_modules/@biomejs/biome/configuration_schema.json', organizeImports: { @@ -41,6 +39,5 @@ export const templates = { } export function createFile(configuration: object) { - checkDependency('@biomejs/biome') return { name: 'biome.json', contents: JSON.stringify(configuration, null, 2) } } diff --git a/configuration/drizzle.ts b/configuration/drizzle.ts new file mode 100644 index 0000000..e996455 --- /dev/null +++ b/configuration/drizzle.ts @@ -0,0 +1,26 @@ +import { state } from '../state' + +export const templates = { + basic: { + dialect: 'postgresql', + schema: './schema.ts', + out: './drizzle', + dbCredentials: { + url: process.env.DATABASE_URL, + }, + }, +} + +export const extension = (path: string) => ({ extends: path }) + +export function createFile(configuration: object | string) { + let contents = `import { drizzle } from './configuration.${state.extension}' + +export default drizzle` + + if (typeof configuration === 'object' && state.extension === 'json') { + contents = `export default ${JSON.stringify(configuration, null, 2)}` + } + + return { name: `drizzle.config.${state.extension === 'json' ? 'js' : state.extension}`, contents } +} diff --git a/configuration/index.ts b/configuration/index.ts index eb87ba3..c816a4c 100644 --- a/configuration/index.ts +++ b/configuration/index.ts @@ -2,6 +2,7 @@ import type { Configuration } from '../types' import * as babel from './babel' import * as biome from './biome' import * as cypress from './cypress' +import * as drizzle from './drizzle' import * as eslint from './eslint' import * as ignore from './gitignore' import * as license from './license' @@ -41,6 +42,7 @@ export type ConfigurationKeys = | 'metro' | 'react-native' | 'reactNative' + | 'drizzle' | 'vercel' | 'license' // Require separate logic, not found in configuraitons below. @@ -110,6 +112,10 @@ export const configurations: Configuration[] = [ name: 'metro', configuration: metro, }, + { + name: 'drizzle', + configuration: drizzle, + }, { name: 'react-native', alias: 'reactNative', diff --git a/configuration/playwright.ts b/configuration/playwright.ts index 9f30f61..2683868 100644 --- a/configuration/playwright.ts +++ b/configuration/playwright.ts @@ -1,10 +1,8 @@ -import { checkDependency } from '../helper' import { state } from '../state' export const extension = (path: string) => ({ extends: path }) export function createFile(configuration: object | string) { - checkDependency('@playwright/test') let contents = `import { playwright } from './configuration.${state.extension}' export default playwright` diff --git a/configuration/rsbuild.ts b/configuration/rsbuild.ts index a21bee3..e03eaac 100644 --- a/configuration/rsbuild.ts +++ b/configuration/rsbuild.ts @@ -1,10 +1,8 @@ -import { checkDependency } from '../helper' import { state } from '../state' export const extension = (path: string) => ({ extends: path }) export function createFile(configuration: object | string) { - checkDependency('@rsbuild/core') let contents = `import { rsbuild } from './configuration.${state.extension}' import { extendConfiguration } from 'zero-configuration' diff --git a/configuration/typescript.ts b/configuration/typescript.ts index 8515e73..b565bfa 100644 --- a/configuration/typescript.ts +++ b/configuration/typescript.ts @@ -1,5 +1,3 @@ -import { checkDependency } from '../helper' - export const templates = { recommended: { compilerOptions: { @@ -47,6 +45,5 @@ export const templates = { export const extension = (path: string) => ({ extends: path }) export function createFile(configuration: object) { - checkDependency('typescript') return { name: 'tsconfig.json', contents: JSON.stringify(configuration, null, 2) } } diff --git a/helper.ts b/helper.ts index 3a41cc3..c06361d 100644 --- a/helper.ts +++ b/helper.ts @@ -1,9 +1,8 @@ -import { existsSync, lstatSync, mkdirSync, readFileSync, symlinkSync } from 'node:fs' +import { existsSync, lstatSync, mkdirSync, symlinkSync } from 'node:fs' import { dirname, join } from 'node:path' import { it } from 'avait' import Bun from 'bun' import glob from 'fast-glob' -import isCi from 'is-ci' import { parse } from 'parse-gitignore' import { merge } from 'ts-deepmerge' import { z } from 'zod' @@ -196,28 +195,3 @@ export async function writeFile(file: File, ignores: string[]) { ignores.push(file.name) } } - -export function checkDependency(dependency: string) { - if (isCi || process.env.NODE_ENV === 'test') { - return - } - - const packageJsonPath = root('./package.json') - - if (!existsSync(packageJsonPath)) { - log(`package.json not found in ${root('.')}`, 'warning') - return - } - - const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')) - const dependencies = { - ...packageJson.dependencies, - ...packageJson.devDependencies, - ...packageJson.peerDependencies, - ...packageJson.optionalDependencies, - } - - if (!Object.hasOwn(dependencies, dependency)) { - log(`Dependency ${dependency} not installed in project but configuration exists`, 'warning') - } -} diff --git a/package.json b/package.json index 888fbf9..9b59232 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,6 @@ "dependencies": { "avait": "^1.0.1", "fast-glob": "^3.3.2", - "is-ci": "^3.0.1", "logua": "^3.0.3", "parse-gitignore": "^2.0.0", "ts-deepmerge": "^7.0.0", @@ -24,7 +23,6 @@ "devDependencies": { "@biomejs/biome": "^1.8.3", "@types/bun": "^1.1.6", - "@types/is-ci": "^3.0.4", "@types/parse-gitignore": "^1.0.2", "eslint-config-airbnb": "^19.0.4", "typescript": "^5.5.3" diff --git a/test/basic.test.ts b/test/basic.test.ts index c68d8ef..e627d61 100644 --- a/test/basic.test.ts +++ b/test/basic.test.ts @@ -41,6 +41,7 @@ test('Adds configuration files for basic file setup.', async () => { expect(existsSync(join(fixturePath, 'biome.json'))).toBe(true) expect(existsSync(join(fixturePath, 'vitest.config.ts'))).toBe(true) expect(existsSync(join(fixturePath, 'cypress.config.ts'))).toBe(true) + expect(existsSync(join(fixturePath, 'drizzle.config.ts'))).toBe(true) expect(existsSync(join(fixturePath, 'app.json'))).toBe(true) // TODO should not work with TS. expect(existsSync(join(fixturePath, 'eslint.config.js'))).toBe(true) diff --git a/test/fixture/file/configuration.ts b/test/fixture/file/configuration.ts index 25e479d..30ad3c4 100644 --- a/test/fixture/file/configuration.ts +++ b/test/fixture/file/configuration.ts @@ -45,4 +45,8 @@ export const eslint = true export const reactNative = { name: "break'a'bit", displayName: "break'a'bit", +} + +export const drizzle = { + dialect: 'postgresql' } \ No newline at end of file