Skip to content

Commit

Permalink
feat: implement template branches
Browse files Browse the repository at this point in the history
  • Loading branch information
schettn committed Jul 11, 2024
1 parent 0daade2 commit b067717
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
15 changes: 11 additions & 4 deletions packages/pylon-cli/src/commands/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ const logger = getLogger()

export default async (
rootPath: string,
template: string,
template: {
url: string
branch?: string
},
options: {
name: string
clientPath?: string
Expand All @@ -21,7 +24,9 @@ export default async (

logger.info(`🚀 Starting project creation: ${name}`)
logger.info(`📁 Destination: ${rootPath}`)
logger.info(`🔖 Template: ${template}`)
logger.info(`🔖 Template: ${template.url}`, {
template
})

await new Promise(resolve => setTimeout(resolve, 100))

Expand Down Expand Up @@ -54,8 +59,10 @@ export default async (
logger.info(`Created directory: ${rootPath}`)

// Clone the template repository into the project directory
logger.info(`Cloning template from ${template} into ${projectDir}`)
await Bun.$`git clone ${template} "${projectDir}"`
logger.info(`Cloning template from ${template.url} into ${projectDir}`)
await Bun.$`git clone ${template.branch ? `-b ${template.branch}` : ''} ${
template.url
} "${projectDir}" --single-branch`

// Remove the .git directory from the project directory
logger.info('Removing existing .git directory')
Expand Down
19 changes: 15 additions & 4 deletions packages/pylon-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ const templates: {
{
name: 'Default',
description: 'Default template',
url: 'https://github.com/getcronit/pylon-template.git'
url: 'https://github.com/getcronit/pylon-template.git',
branch: 'beta'
},
{
name: 'Database (Prisma)',
Expand All @@ -55,7 +56,15 @@ program
.option('-n, --name <name>', 'Name of the pylon', 'my-pylon')
.argument('<rootPath>', 'Path to the pylon')
.argument('[template]', 'Template to use', templates[0].url)
.action(commands.new)
.action(async (rootPath, template, options) => {
return await commands.new(
rootPath,
{
url: template
},
options
)
})

if (!process.argv.slice(2).length) {
try {
Expand All @@ -79,11 +88,13 @@ if (!process.argv.slice(2).length) {
default: `./${name}`
})

const template = await select({
const templateIndex = await select({
message: 'Choose a pylon template',
choices: templates.map(t => ({name: t.name, value: t.url}))
choices: templates.map((t, i) => ({name: t.name, value: i}))
})

const template = templates[templateIndex]

const useClient = await confirm({
message:
'Would you like to enable an auto-generated client powered by GQty? (https://pylon.cronit.io/docs/client)',
Expand Down

0 comments on commit b067717

Please sign in to comment.