diff --git a/frontend/packages/cli/bin/cli.ts b/frontend/packages/cli/bin/cli.ts index a52c160cf..0750194ae 100755 --- a/frontend/packages/cli/bin/cli.ts +++ b/frontend/packages/cli/bin/cli.ts @@ -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) diff --git a/frontend/packages/cli/package.json b/frontend/packages/cli/package.json index 9c3447759..d3314e7a2 100644 --- a/frontend/packages/cli/package.json +++ b/frontend/packages/cli/package.json @@ -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" diff --git a/frontend/packages/cli/rollup.config.js b/frontend/packages/cli/rollup.config.js index c4ce15345..4ee908073 100644 --- a/frontend/packages/cli/rollup.config.js +++ b/frontend/packages/cli/rollup.config.js @@ -21,5 +21,5 @@ export default { }), execute('chmod +x dist-cli/bin/cli.js'), ], - external: ['commander'], + external: ['commander', 'inquirer'], } diff --git a/frontend/packages/cli/src/cli/smoke.test.ts b/frontend/packages/cli/src/cli/smoke.test.ts index 0a685563f..3bd1f934b 100644 --- a/frontend/packages/cli/src/cli/smoke.test.ts +++ b/frontend/packages/cli/src/cli/smoke.test.ts @@ -35,6 +35,7 @@ describe('CLI Smoke Test', () => { Commands: erd ERD commands + init Initialize the setup process for your database or ORM help [command] display help for command " `) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 19dfa554b..dae823cc4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -130,6 +130,9 @@ importers: commander: specifier: 12.1.0 version: 12.1.0 + inquirer: + specifier: 12.3.0 + version: 12.3.0(@types/node@22.9.0) react: specifier: 18.3.1 version: 18.3.1 @@ -1017,6 +1020,86 @@ packages: cpu: [x64] os: [win32] + '@inquirer/checkbox@4.0.4': + resolution: {integrity: sha512-fYAKCAcGNMdfjL6hZTRUwkIByQ8EIZCXKrIQZH7XjADnN/xvRUhj8UdBbpC4zoUzvChhkSC/zRKaP/tDs3dZpg==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + + '@inquirer/confirm@5.1.1': + resolution: {integrity: sha512-vVLSbGci+IKQvDOtzpPTCOiEJCNidHcAq9JYVoWTW0svb5FiwSLotkM+JXNXejfjnzVYV9n0DTBythl9+XgTxg==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + + '@inquirer/core@10.1.2': + resolution: {integrity: sha512-bHd96F3ezHg1mf/J0Rb4CV8ndCN0v28kUlrHqP7+ECm1C/A+paB7Xh2lbMk6x+kweQC+rZOxM/YeKikzxco8bQ==} + engines: {node: '>=18'} + + '@inquirer/editor@4.2.1': + resolution: {integrity: sha512-xn9aDaiP6nFa432i68JCaL302FyL6y/6EG97nAtfIPnWZ+mWPgCMLGc4XZ2QQMsZtu9q3Jd5AzBPjXh10aX9kA==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + + '@inquirer/expand@4.0.4': + resolution: {integrity: sha512-GYocr+BPyxKPxQ4UZyNMqZFSGKScSUc0Vk17II3J+0bDcgGsQm0KYQNooN1Q5iBfXsy3x/VWmHGh20QnzsaHwg==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + + '@inquirer/figures@1.0.9': + resolution: {integrity: sha512-BXvGj0ehzrngHTPTDqUoDT3NXL8U0RxUk2zJm2A66RhCEIWdtU1v6GuUqNAgArW4PQ9CinqIWyHdQgdwOj06zQ==} + engines: {node: '>=18'} + + '@inquirer/input@4.1.1': + resolution: {integrity: sha512-nAXAHQndZcXB+7CyjIW3XuQZZHbQQ0q8LX6miY6bqAWwDzNa9JUioDBYrFmOUNIsuF08o1WT/m2gbBXvBhYVxg==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + + '@inquirer/number@3.0.4': + resolution: {integrity: sha512-DX7a6IXRPU0j8kr2ovf+QaaDiIf+zEKaZVzCWdLOTk7XigqSXvoh4cul7x68xp54WTQrgSnW7P1WBJDbyY3GhA==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + + '@inquirer/password@4.0.4': + resolution: {integrity: sha512-wiliQOWdjM8FnBmdIHtQV2Ca3S1+tMBUerhyjkRCv1g+4jSvEweGu9GCcvVEgKDhTBT15nrxvk5/bVrGUqSs1w==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + + '@inquirer/prompts@7.2.1': + resolution: {integrity: sha512-v2JSGri6/HXSfoGIwuKEn8sNCQK6nsB2BNpy2lSX6QH9bsECrMv93QHnj5+f+1ZWpF/VNioIV2B/PDox8EvGuQ==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + + '@inquirer/rawlist@4.0.4': + resolution: {integrity: sha512-IsVN2EZdNHsmFdKWx9HaXb8T/s3FlR/U1QPt9dwbSyPtjFbMTlW9CRFvnn0bm/QIsrMRD2oMZqrQpSWPQVbXXg==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + + '@inquirer/search@3.0.4': + resolution: {integrity: sha512-tSkJk2SDmC2MEdTIjknXWmCnmPr5owTs9/xjfa14ol1Oh95n6xW7SYn5fiPk4/vrJPys0ggSWiISdPze4LTa7A==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + + '@inquirer/select@4.0.4': + resolution: {integrity: sha512-ZzYLuLoUzTIW9EJm++jBpRiTshGqS3Q1o5qOEQqgzaBlmdsjQr6pA4TUNkwu6OBYgM2mIRbCz6mUhFDfl/GF+w==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + + '@inquirer/type@3.0.2': + resolution: {integrity: sha512-ZhQ4TvhwHZF+lGhQ2O/rsjo80XoZR5/5qhOY3t6FJuX5XBg5Be8YzYTvaUGJnc12AUGI2nr4QSUE4PhKSigx7g==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + '@isaacs/cliui@8.0.2': resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==} engines: {node: '>=12'} @@ -2606,6 +2689,10 @@ packages: resolution: {integrity: sha512-FxqpkPPwu1HjuN93Omfm4h8uIanXofW0RxVEW3k5RKx+mJJYSthzNhp32Kzxxy3YAEZ/Dc/EWN1vZRY0+kOhbw==} engines: {node: '>= 10'} + cli-width@4.1.0: + resolution: {integrity: sha512-ouuZd4/dm2Sw5Gmqy6bGyNNNe1qt9RpmxveLSO7KcgsTnU7RXfsw+/bukWGo1abgBiMAic068rclZsO4IWmmxQ==} + engines: {node: '>= 12'} + client-only@0.0.1: resolution: {integrity: sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==} @@ -3623,6 +3710,12 @@ packages: inline-style-parser@0.2.4: resolution: {integrity: sha512-0aO8FkhNZlj/ZIbNi7Lxxr12obT7cL1moPfE4tg1LkX7LlLfC6DeX4l2ZEud1ukP9jNQyNnfzQVqwbwmAATY4Q==} + inquirer@12.3.0: + resolution: {integrity: sha512-3NixUXq+hM8ezj2wc7wC37b32/rHq1MwNZDYdvx+d6jokOD+r+i8Q4Pkylh9tISYP114A128LCX8RKhopC5RfQ==} + engines: {node: '>=18'} + peerDependencies: + '@types/node': '>=18' + inquirer@7.3.3: resolution: {integrity: sha512-JG3eIAj5V9CwcGvuOmoo6LB9kbAYT8HXffUl6memuszlwDC/qvFAJw49XJ5NROSFNPxp3iQg1GqkFhaY/CR0IA==} engines: {node: '>=8.0.0'} @@ -4296,6 +4389,10 @@ packages: mute-stream@0.0.8: resolution: {integrity: sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==} + mute-stream@2.0.0: + resolution: {integrity: sha512-WWdIxpyjEn+FhQJQQv9aQAYlHoNVdzIzUySNV1gHUPDSdZJ3yZn7pAAbQcV7B56Mvu881q9FZV+0Vx2xC44VWA==} + engines: {node: ^18.17.0 || >=20.5.0} + mz@2.7.0: resolution: {integrity: sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==} @@ -4997,6 +5094,10 @@ packages: resolution: {integrity: sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ==} engines: {node: '>=0.12.0'} + run-async@3.0.0: + resolution: {integrity: sha512-540WwVDOMxA6dN6We19EcT9sc3hkXPw5mzRNGM3FkdN/vtE9NFvj5lFAPNwUDmJjXidm3v7TC1cTE7t17Ulm1Q==} + engines: {node: '>=0.12.0'} + run-parallel@1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} @@ -5846,6 +5947,10 @@ packages: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} + yoctocolors-cjs@2.1.2: + resolution: {integrity: sha512-cYVsTjKl8b+FrnidjibDWskAv7UKOfcwaVZdp/it9n1s9fU3IkgDbhdIRKCW4JDsAlECJY0ytoVPT3sK6kideA==} + engines: {node: '>=18'} + zod@3.23.8: resolution: {integrity: sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==} @@ -6494,6 +6599,112 @@ snapshots: '@img/sharp-win32-x64@0.33.5': optional: true + '@inquirer/checkbox@4.0.4(@types/node@22.9.0)': + dependencies: + '@inquirer/core': 10.1.2(@types/node@22.9.0) + '@inquirer/figures': 1.0.9 + '@inquirer/type': 3.0.2(@types/node@22.9.0) + '@types/node': 22.9.0 + ansi-escapes: 4.3.2 + yoctocolors-cjs: 2.1.2 + + '@inquirer/confirm@5.1.1(@types/node@22.9.0)': + dependencies: + '@inquirer/core': 10.1.2(@types/node@22.9.0) + '@inquirer/type': 3.0.2(@types/node@22.9.0) + '@types/node': 22.9.0 + + '@inquirer/core@10.1.2(@types/node@22.9.0)': + dependencies: + '@inquirer/figures': 1.0.9 + '@inquirer/type': 3.0.2(@types/node@22.9.0) + ansi-escapes: 4.3.2 + cli-width: 4.1.0 + mute-stream: 2.0.0 + signal-exit: 4.1.0 + strip-ansi: 6.0.1 + wrap-ansi: 6.2.0 + yoctocolors-cjs: 2.1.2 + transitivePeerDependencies: + - '@types/node' + + '@inquirer/editor@4.2.1(@types/node@22.9.0)': + dependencies: + '@inquirer/core': 10.1.2(@types/node@22.9.0) + '@inquirer/type': 3.0.2(@types/node@22.9.0) + '@types/node': 22.9.0 + external-editor: 3.1.0 + + '@inquirer/expand@4.0.4(@types/node@22.9.0)': + dependencies: + '@inquirer/core': 10.1.2(@types/node@22.9.0) + '@inquirer/type': 3.0.2(@types/node@22.9.0) + '@types/node': 22.9.0 + yoctocolors-cjs: 2.1.2 + + '@inquirer/figures@1.0.9': {} + + '@inquirer/input@4.1.1(@types/node@22.9.0)': + dependencies: + '@inquirer/core': 10.1.2(@types/node@22.9.0) + '@inquirer/type': 3.0.2(@types/node@22.9.0) + '@types/node': 22.9.0 + + '@inquirer/number@3.0.4(@types/node@22.9.0)': + dependencies: + '@inquirer/core': 10.1.2(@types/node@22.9.0) + '@inquirer/type': 3.0.2(@types/node@22.9.0) + '@types/node': 22.9.0 + + '@inquirer/password@4.0.4(@types/node@22.9.0)': + dependencies: + '@inquirer/core': 10.1.2(@types/node@22.9.0) + '@inquirer/type': 3.0.2(@types/node@22.9.0) + '@types/node': 22.9.0 + ansi-escapes: 4.3.2 + + '@inquirer/prompts@7.2.1(@types/node@22.9.0)': + dependencies: + '@inquirer/checkbox': 4.0.4(@types/node@22.9.0) + '@inquirer/confirm': 5.1.1(@types/node@22.9.0) + '@inquirer/editor': 4.2.1(@types/node@22.9.0) + '@inquirer/expand': 4.0.4(@types/node@22.9.0) + '@inquirer/input': 4.1.1(@types/node@22.9.0) + '@inquirer/number': 3.0.4(@types/node@22.9.0) + '@inquirer/password': 4.0.4(@types/node@22.9.0) + '@inquirer/rawlist': 4.0.4(@types/node@22.9.0) + '@inquirer/search': 3.0.4(@types/node@22.9.0) + '@inquirer/select': 4.0.4(@types/node@22.9.0) + '@types/node': 22.9.0 + + '@inquirer/rawlist@4.0.4(@types/node@22.9.0)': + dependencies: + '@inquirer/core': 10.1.2(@types/node@22.9.0) + '@inquirer/type': 3.0.2(@types/node@22.9.0) + '@types/node': 22.9.0 + yoctocolors-cjs: 2.1.2 + + '@inquirer/search@3.0.4(@types/node@22.9.0)': + dependencies: + '@inquirer/core': 10.1.2(@types/node@22.9.0) + '@inquirer/figures': 1.0.9 + '@inquirer/type': 3.0.2(@types/node@22.9.0) + '@types/node': 22.9.0 + yoctocolors-cjs: 2.1.2 + + '@inquirer/select@4.0.4(@types/node@22.9.0)': + dependencies: + '@inquirer/core': 10.1.2(@types/node@22.9.0) + '@inquirer/figures': 1.0.9 + '@inquirer/type': 3.0.2(@types/node@22.9.0) + '@types/node': 22.9.0 + ansi-escapes: 4.3.2 + yoctocolors-cjs: 2.1.2 + + '@inquirer/type@3.0.2(@types/node@22.9.0)': + dependencies: + '@types/node': 22.9.0 + '@isaacs/cliui@8.0.2': dependencies: string-width: 5.1.2 @@ -8410,6 +8621,8 @@ snapshots: cli-width@3.0.0: {} + cli-width@4.1.0: {} + client-only@0.0.1: {} cliui@8.0.1: @@ -9752,6 +9965,17 @@ snapshots: inline-style-parser@0.2.4: {} + inquirer@12.3.0(@types/node@22.9.0): + dependencies: + '@inquirer/core': 10.1.2(@types/node@22.9.0) + '@inquirer/prompts': 7.2.1(@types/node@22.9.0) + '@inquirer/type': 3.0.2(@types/node@22.9.0) + '@types/node': 22.9.0 + ansi-escapes: 4.3.2 + mute-stream: 2.0.0 + run-async: 3.0.0 + rxjs: 7.8.1 + inquirer@7.3.3: dependencies: ansi-escapes: 4.3.2 @@ -10648,6 +10872,8 @@ snapshots: mute-stream@0.0.8: {} + mute-stream@2.0.0: {} + mz@2.7.0: dependencies: any-promise: 1.3.0 @@ -11471,6 +11697,8 @@ snapshots: run-async@2.4.1: {} + run-async@3.0.0: {} + run-parallel@1.2.0: dependencies: queue-microtask: 1.2.3 @@ -12437,6 +12665,8 @@ snapshots: yocto-queue@0.1.0: {} + yoctocolors-cjs@2.1.2: {} + zod@3.23.8: {} zustand@4.5.5(@types/react@18.3.12)(react@18.3.1):