Skip to content

Commit

Permalink
feat(configuration): add drizzle configuration
Browse files Browse the repository at this point in the history
Remove dependency check as output not visible in postinstall script. release-npm
  • Loading branch information
tobua committed Jul 5, 2024
1 parent d77ac06 commit 1a2097e
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 40 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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', ...]
Expand Down
3 changes: 0 additions & 3 deletions configuration/biome.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { checkDependency } from '../helper'

const base = (rules: object) => ({
$schema: 'node_modules/@biomejs/biome/configuration_schema.json',
organizeImports: {
Expand Down Expand Up @@ -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) }
}
26 changes: 26 additions & 0 deletions configuration/drizzle.ts
Original file line number Diff line number Diff line change
@@ -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 }
}
6 changes: 6 additions & 0 deletions configuration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -41,6 +42,7 @@ export type ConfigurationKeys =
| 'metro'
| 'react-native'
| 'reactNative'
| 'drizzle'
| 'vercel'
| 'license'
// Require separate logic, not found in configuraitons below.
Expand Down Expand Up @@ -110,6 +112,10 @@ export const configurations: Configuration[] = [
name: 'metro',
configuration: metro,
},
{
name: 'drizzle',
configuration: drizzle,
},
{
name: 'react-native',
alias: 'reactNative',
Expand Down
2 changes: 0 additions & 2 deletions configuration/playwright.ts
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 0 additions & 2 deletions configuration/rsbuild.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
3 changes: 0 additions & 3 deletions configuration/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { checkDependency } from '../helper'

export const templates = {
recommended: {
compilerOptions: {
Expand Down Expand Up @@ -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) }
}
28 changes: 1 addition & 27 deletions helper.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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')
}
}
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions test/fixture/file/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ export const eslint = true
export const reactNative = {
name: "break'a'bit",
displayName: "break'a'bit",
}

export const drizzle = {
dialect: 'postgresql'
}

0 comments on commit 1a2097e

Please sign in to comment.