Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
hoshinotsuyoshi committed Nov 19, 2024
1 parent 4453dca commit fcf593b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion frontend/packages/cli/src/cli/runPreprocess.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('runPreprocess', () => {
const nonExistentPath = path.join(tmpDir, 'non-existent.sql')

expect(() => runPreprocess(nonExistentPath, tmpDir)).toThrow(
'Invalid input path. Please provide a valid .sql file.',
'Invalid input path. Please provide a valid file.',
)
})

Expand Down
8 changes: 6 additions & 2 deletions frontend/packages/cli/src/cli/runPreprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ import { parse } from '@liam/db-structure'

export function runPreprocess(inputPath: string | null, publicDir: string) {
if (inputPath && !fs.existsSync(inputPath)) {
throw new Error('Invalid input path. Please provide a valid .sql file.')
throw new Error('Invalid input path. Please provide a valid file.')
}

const input = inputPath ? readFileSync(inputPath, 'utf8') : ''
const json = parse(input, 'schemarb')

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

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

if (!fs.existsSync(publicDir)) {
Expand Down
24 changes: 24 additions & 0 deletions frontend/packages/cli/src/cli/smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@ beforeAll(async () => {
})

describe('CLI Smoke Test', () => {
it('should run the CLI command without errors', async () => {
try {
const { stdout, stderr } = await execAsync('npx --no-install . help')
expect(stderr).toBe('')
expect(stdout).toMatchInlineSnapshot(`
"Usage: liam [options] [command]
CLI tool for Liam
Options:
-V, --version output the version number
-h, --help display help for command
Commands:
erd ERD commands
help [command] display help for command
"
`)
} catch (error) {
// Fail the test if an error occurs
expect(error).toBeNull()
}
})

it('should run the CLI command without errors', async () => {
await execAsync('rm -rf ./dist')
try {
Expand Down

0 comments on commit fcf593b

Please sign in to comment.