Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added support for external templates #69

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs'
import path from 'path'
import fs from 'node:fs'
import path from 'node:path'
import confirm from '@inquirer/confirm'
import input from '@inquirer/input'
import select from '@inquirer/select'
Expand Down Expand Up @@ -62,9 +62,7 @@ program
),
)
.addOption(
new Option('-t, --template <template>', 'Template to use').choices(
templates,
),
new Option('-t, --template <template>', 'Template to use either one '),
)
.addOption(
new Option('-o, --offline', 'Use offline mode')
Expand Down Expand Up @@ -126,10 +124,6 @@ async function main(
throw new Error('No template selected')
}

if (!templates.includes(templateName)) {
throw new Error(`Invalid template selected: ${templateName}`)
}

if (fs.existsSync(target)) {
if (fs.readdirSync(target).length > 0) {
const response = await confirm({
Expand All @@ -147,14 +141,25 @@ async function main(
const targetDirectoryPath = path.join(process.cwd(), target)
const spinner = createSpinner('Cloning the template').start()

await downloadTemplate(
`gh:${config.user}/${config.repository}/${config.directory}/${templateName}#${config.ref}`,
{
dir: targetDirectoryPath,
offline,
force: true,
},
).then(() => spinner.success())
let repo: string
const isExternalTemplate = !templates.includes(templateName)

if (isExternalTemplate) {
console.log(
chalk.bgYellow.black(' Warning '),
chalk.yellow(
'You are downloading an external template. Please review the template before running it.',
),
)
repo = templateName
} else
repo = `gh:${config.user}/${config.repository}/${config.directory}/${templateName}#${config.ref}`

await downloadTemplate(repo, {
dir: targetDirectoryPath,
offline,
force: true,
}).then(() => spinner.success())

registerInstallationHook(templateName, install, pm)

Expand Down