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

Add interactive list of templates to choose from to resolve #812 #832

Merged
merged 1 commit into from
Oct 24, 2019
Merged
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
64 changes: 48 additions & 16 deletions packages/create-aragon-app/src/commands/create-aragon-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,24 @@ const TaskList = require('listr')
const { installDeps, isValidAragonId } = require('../util')
const defaultAPMName = require('../helpers/default-apm')
const listrOpts = require('../helpers/listr-options')
const inquirer = require('inquirer')
const execa = require('execa')

const templateOptions = {
bare: {
repo: 'aragon/aragon-bare-boilerplate',
name: 'Aragon bare boilerplate',
},
react: {
repo: 'aragon/aragon-react-boilerplate',
name: 'Aragon React boilerplate',
},
tutorial: {
repo: 'aragon/your-first-aragon-app',
name: 'Your first Aragon app (tutorial)',
},
}

exports.command = '* <name> [template]'

exports.describe = 'Create a new aragon application'
Expand All @@ -21,35 +37,51 @@ exports.builder = yargs => {
default: process.cwd(),
})
.positional('template', {
description: 'The template to scaffold from',
default: 'react',
description: `The template to scaffold from (${Object.keys(
templateOptions
).join(', ')})`,
coerce: function resolveTemplateName(tmpl) {
const aliases = {
bare: 'aragon/aragon-bare-boilerplate',
react: 'aragon/aragon-react-boilerplate',
tutorial: 'aragon/your-first-aragon-app',
}

if (!tmpl.includes('/')) {
if (tmpl && !tmpl.includes('/')) {
if (tmpl === 'react-kit') {
throw new Error(
`The 'react-kit' boilerplate has been deprecated and merged with 'react' boilerplate.`
)
} else if (!aliases[tmpl]) {
} else if (!templateOptions[tmpl]) {
throw new Error(`No template named ${tmpl} exists`)
}
tmpl = aliases[tmpl]
}

return `https://github.com/${tmpl}`
return tmpl
},
})
}

exports.handler = function({ reporter, name, template, silent, debug }) {
exports.handler = async function({ reporter, name, template, silent, debug }) {
name = defaultAPMName(name)
const basename = name.split('.')[0]

if (!template && !silent) {
const { templateChoice } = await inquirer.prompt([
{
type: 'list',
name: 'templateChoice',
message: 'Chose a template to scaffold from',
choices: Object.entries(templateOptions).map(([id, { name }]) => ({
name,
value: id,
})),
},
])
template = templateChoice
} else if (silent) {
template = 'react'
}

const repo = (templateOptions[template] || {}).repo
if (!repo) throw new Error(`No template repo found for ${template}`)

const templateUrl = `https://github.com/${repo}`

const tasks = new TaskList(
[
{
Expand All @@ -70,8 +102,8 @@ exports.handler = function({ reporter, name, template, silent, debug }) {
{
title: 'Cloning app template',
task: async (ctx, task) => {
task.output = `Cloning ${template} into ${basename}...`
await clone(template, basename, { shallow: true })
task.output = `Cloning ${templateUrl} into ${basename}...`
await clone(templateUrl, basename, { shallow: true })
},
},
{
Expand All @@ -80,7 +112,7 @@ exports.handler = function({ reporter, name, template, silent, debug }) {
task.output = 'Initiliazing arapp.json and removing Git repository'
await prepareTemplate(basename, name)
},
enabled: () => !template.includes('your-first-aragon-app'),
enabled: () => !templateUrl.includes('your-first-aragon-app'),
},
{
title: 'Installing package dependencies',
Expand Down