Skip to content

Commit

Permalink
cli init-command
Browse files Browse the repository at this point in the history
  • Loading branch information
hoshinotsuyoshi committed Dec 26, 2024
1 parent 033f956 commit b80f963
Show file tree
Hide file tree
Showing 4 changed files with 316 additions and 1 deletion.
84 changes: 84 additions & 0 deletions frontend/packages/cli/bin/cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,88 @@
#!/usr/bin/env node
import fs from 'node:fs/promises'
import path from 'node:path'
import inquirer from 'inquirer'
import { program } from '../src/index.js'

type WorkflowType = 'dsl' | 'pg_dump' | 'unsupported'

// Helper function to generate workflows
function generateWorkflow(type: WorkflowType) {
const workflows = {
dsl: 'Generating GitHub Actions Workflow for DSL-based parsing and ER build...',
pg_dump: 'Generating GitHub Actions Workflow for pg_dump and ERD build...',
unsupported:
'Error: Not supported. Please visit our documentation or discussion for help.',
}
console.info(workflows[type])

if (type !== 'unsupported') {
const fileName = 'liam-erd-workflow.yml'
const filePath = path.resolve(process.cwd(), fileName)
fs.writeFile(
filePath,
`# Example workflow for ${type}
# This is a placeholder for the actual workflow content.`,
)
console.info(`Workflow generated: ${filePath}`)
}
}

type DatabaseOrOrmTitle =
| 'Ruby on Rails'
| 'PostgreSQL'
| 'Prisma'
| 'Drizzle'
| 'Other'
type DatabaseOrOrmParseStrategy = 'nativeParsing' | 'usePgDump' | 'unsupported'
type DatabaseOrOrm = {
title: DatabaseOrOrmTitle
parseStrategy: DatabaseOrOrmParseStrategy
}

const databaseOrOrms: DatabaseOrOrm[] = [
{ title: 'Ruby on Rails', parseStrategy: 'nativeParsing' },
{ title: 'PostgreSQL', parseStrategy: 'usePgDump' },
{ title: 'Prisma', parseStrategy: 'unsupported' },
{ title: 'Drizzle', parseStrategy: 'unsupported' },
{ title: 'Other', parseStrategy: 'unsupported' },
]

async function runSetup() {
const databaseOrOrmTitles = databaseOrOrms.map(
(databaseOrOrm) => databaseOrOrm.title,
)
const { databaseOrOrm } = (await inquirer.prompt([
{
type: 'list',
name: 'databaseOrOrm',
message: 'Select Database or ORM:',
choices: databaseOrOrmTitles,
},
])) as { databaseOrOrm: DatabaseOrOrmTitle }
console.info(`Selected: ${databaseOrOrm}`)

const databaseOrOrm2 = databaseOrOrms.find((d) => d.title === databaseOrOrm)
if (databaseOrOrm2 === undefined) {
return
}
if (databaseOrOrm2.parseStrategy === 'nativeParsing') {
generateWorkflow('dsl')
return
}
if (databaseOrOrm2.parseStrategy === 'usePgDump') {
generateWorkflow('pg_dump')
} else {
generateWorkflow('unsupported')
}
}

program
.command('init')
.description('Initialize the setup process for your database or ORM')
.action(async () => {
console.info('Welcome to the @liam-hq/cli setup process!')
await runSetup()
})

program.parse(process.argv)
1 change: 1 addition & 0 deletions frontend/packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"dependencies": {
"commander": "12.1.0",
"inquirer": "12.3.0",
"react": "18.3.1",
"react-dom": "18",
"valibot": "^1.0.0-beta.5"
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/cli/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export default {
}),
execute('chmod +x dist-cli/bin/cli.js'),
],
external: ['commander'],
external: ['commander', 'inquirer'],
}
Loading

0 comments on commit b80f963

Please sign in to comment.