Skip to content

Commit

Permalink
Refactor CLI build script to include prism parser and copy wasm file
Browse files Browse the repository at this point in the history
  • Loading branch information
sasamuku committed Dec 3, 2024
1 parent 3070097 commit 061c18b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
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

0 comments on commit 061c18b

Please sign in to comment.