diff --git a/packages/pylon-cli/package.json b/packages/pylon-cli/package.json index efaf3b7..5f73850 100644 --- a/packages/pylon-cli/package.json +++ b/packages/pylon-cli/package.json @@ -22,6 +22,7 @@ "@getcronit/pylon": "*", "@getcronit/pylon-builder": "*", "@getcronit/pylon-server": "*", + "@inquirer/prompts": "^5.1.2", "commander": "^10.0.0" } } diff --git a/packages/pylon-cli/src/index.ts b/packages/pylon-cli/src/index.ts index be52f21..90e1f28 100644 --- a/packages/pylon-cli/src/index.ts +++ b/packages/pylon-cli/src/index.ts @@ -1,7 +1,7 @@ #!/usr/bin/env bun import {Command} from 'commander' - +import {input, select, confirm} from '@inquirer/prompts' import packageJson from './utils/package-json.js' import * as commands from './commands/index.js' import {cliName} from './constants.js' @@ -24,16 +24,72 @@ program .description('Build the application') .action(commands.build) +const templates: { + name: string + description: string + url: string +}[] = [ + { + name: 'Default', + description: 'Default template', + url: 'https://github.com/getcronit/pylon-template.git' + } +] + program .command('new') .description('Create a new project') .option('-n, --name ', 'Name of the project', 'my-pylon-project') .argument('', 'Path to the project') - .argument( - '[template]', - 'Template to use', - 'https://github.com/getcronit/pylon-template.git' - ) + .argument('[template]', 'Template to use', templates[0].url) .action(commands.new) -program.parse() +if (!process.argv.slice(2).length) { + ;(async () => { + const answer = await select({ + message: 'What do you want to do?', + choices: [ + {name: 'New', value: 'new'}, + {name: 'Develop', value: 'develop'}, + {name: 'Build', value: 'build'} + ] + }) + + if (answer === 'new') { + const name = await input({ + message: 'Name of the project', + default: 'my-pylon-project' + }) + + const rootPath = await input({ + message: 'Path to the project', + default: `./${name}` + }) + + const template = await select({ + message: 'Select a template', + choices: templates.map(t => ({name: t.name, value: t.url})) + }) + + const useClient = await confirm({ + message: + 'Do you want to enable a auto-generated client? (https://pylon.cronit.io/docs/client)', + default: false + }) + + await commands.new(rootPath, template, {name, clientPath}) + await commands.new(rootPath, template, {name}) + } else if (answer === 'develop') { + const port = await input({ + message: 'Port to run the server on', + default: '3000' + }) + + await commands.develop({port}) + } else if (answer === 'build') { + await commands.build({}) + } + })() +} else { + program.parse() +}