Skip to content

Commit

Permalink
Merge pull request #134 from liam-hq/remove_pegjs_parser
Browse files Browse the repository at this point in the history
Remove pegjs parser
  • Loading branch information
sasamuku authored Dec 3, 2024
2 parents 6bd128a + 0337f11 commit 8bd97ba
Show file tree
Hide file tree
Showing 17 changed files with 1,097 additions and 4,352 deletions.
2,039 changes: 993 additions & 1,046 deletions frontend/docs/packages-license.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion frontend/packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
},
"scripts": {
"build": "pnpm run '/^build:.*/'",
"build:cli": "rollup -c",
"build:cli": "rollup -c && pnpm run cp:prism",
"build:vite": "vite build",
"command:build": "node ./dist-cli/bin/cli.js erd build --input fixtures/input.schema.rb",
"cp:prism": "cp ../db-structure/node_modules/@ruby/prism/src/prism.wasm ./dist-cli/bin/prism.wasm",
"dev": "pnpm command:build && cp dist/schema.json public/ && pnpm run '/^dev:.*/'",
"dev:app": "vite",
"dev:css": "tcm src --watch",
Expand Down
8 changes: 4 additions & 4 deletions frontend/packages/cli/src/cli/runPreprocess.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { describe, expect, it } from 'vitest'
import { runPreprocess } from './runPreprocess'

describe('runPreprocess', () => {
it('should create schema.json with the SQL content in the specified directory', () => {
it('should create schema.json with the SQL content in the specified directory', async () => {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'test-distDir-'))
const inputPath = path.join(tmpDir, 'input.sql')

const sqlContent = 'CREATE TABLE test (id INT, name VARCHAR(255));'
fs.writeFileSync(inputPath, sqlContent, 'utf8')

const outputFilePath = runPreprocess(inputPath, tmpDir)
const outputFilePath = await runPreprocess(inputPath, tmpDir)
if (!outputFilePath) throw new Error('Implement the test')

expect(fs.existsSync(outputFilePath)).toBe(true)
Expand All @@ -21,11 +21,11 @@ describe('runPreprocess', () => {
expect(outputContent.tables).toBeDefined()
})

it('should throw an error if the input file does not exist', () => {
it('should throw an error if the input file does not exist', async () => {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'test-distDir-'))
const nonExistentPath = path.join(tmpDir, 'non-existent.sql')

expect(() => runPreprocess(nonExistentPath, tmpDir)).toThrow(
await expect(runPreprocess(nonExistentPath, tmpDir)).rejects.toThrow(
'Invalid input path. Please provide a valid file.',
)
})
Expand Down
4 changes: 2 additions & 2 deletions frontend/packages/cli/src/cli/runPreprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs, { readFileSync } from 'node:fs'
import path from 'node:path'
import { parse } from '@liam-hq/db-structure/parser'

export function runPreprocess(inputPath: string, outputDir: string) {
export async function runPreprocess(inputPath: string, outputDir: string) {
if (!fs.existsSync(inputPath)) {
throw new Error('Invalid input path. Please provide a valid file.')
}
Expand All @@ -11,7 +11,7 @@ export function runPreprocess(inputPath: string, outputDir: string) {

// TODO: Expand support to additional formats, e.g., 'postgres'
const format = 'schemarb'
const json = parse(input, format)
const json = await parse(input, format)

const filePath = path.join(outputDir, 'schema.json')

Expand Down
4 changes: 0 additions & 4 deletions frontend/packages/db-structure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@
"@biomejs/biome": "1.9.3",
"@liam-hq/configs": "workspace:*",
"@pgsql/types": "15.0.2",
"lodash-es": "4.17.21",
"peggy": "4.1.1",
"pluralize-esm": "9.0.5",
"typescript": "5",
"vitest": "2.1.4"
},
"scripts": {
"build": "tsc",
"fmt": "pnpm run '/^fmt:.*/'",
"fmt:biome": "biome check --write --unsafe .",
"gen:parser": "./scripts/generateParser.sh",
"lint": "pnpm run '/^lint:.*/'",
"lint:biome": "biome check .",
"lint:tsc": "tsc --noEmit",
Expand Down
12 changes: 0 additions & 12 deletions frontend/packages/db-structure/scripts/generateParser.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ exports[`parse > should parse schema.rb to JSON correctly 1`] = `
"default": null,
"increment": false,
"name": "id",
"notNull": false,
"notNull": true,
"primary": true,
"type": "varchar",
"unique": false,
"type": "uuid",
"unique": true,
},
"is_deleted": {
"check": null,
Expand Down
5 changes: 1 addition & 4 deletions frontend/packages/db-structure/src/parser/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { DBStructure } from 'src/schema/index.js'
import { processor as schemarbPrismProcessor } from './schemarb-prism/index.js'
import { processor as schemarbProcessor } from './schemarb/index.js'
import { processor as postgresqlProcessor } from './sql/index.js'

type SupportedFormat = 'schemarb' | 'postgres' | 'schemarb-prism'
type SupportedFormat = 'schemarb' | 'postgres'

// TODO: Add error handling and tests
export const parse = (
Expand All @@ -13,8 +12,6 @@ export const parse = (
switch (format) {
case 'schemarb':
return schemarbProcessor(str)
case 'schemarb-prism':
return schemarbPrismProcessor(str)
case 'postgres':
return postgresqlProcessor(str)
default:
Expand Down
170 changes: 0 additions & 170 deletions frontend/packages/db-structure/src/parser/schemarb-prism/index.test.ts

This file was deleted.

This file was deleted.

33 changes: 0 additions & 33 deletions frontend/packages/db-structure/src/parser/schemarb/converter.ts

This file was deleted.

Loading

0 comments on commit 8bd97ba

Please sign in to comment.