Skip to content

Commit

Permalink
feat: add inquirer with new, develop and build cmds
Browse files Browse the repository at this point in the history
  • Loading branch information
schettn committed Jul 9, 2024
1 parent 4de34b0 commit 27ac0ff
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/pylon-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@getcronit/pylon": "*",
"@getcronit/pylon-builder": "*",
"@getcronit/pylon-server": "*",
"@inquirer/prompts": "^5.1.2",
"commander": "^10.0.0"
}
}
70 changes: 63 additions & 7 deletions packages/pylon-cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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>', 'Name of the project', 'my-pylon-project')
.argument('<rootPath>', '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()
}

0 comments on commit 27ac0ff

Please sign in to comment.