Skip to content

Commit

Permalink
create-aragon-app: Use new boilerplates (#1572)
Browse files Browse the repository at this point in the history
* Use new boilerplates, default to react and remove inquier prompt
* Update packages/create-aragon-app/src/commands/create-aragon-app.js
* Fix tests
* Bump minor
  • Loading branch information
0xGabi authored Mar 21, 2020
1 parent 0810805 commit 96a5929
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 102 deletions.
39 changes: 3 additions & 36 deletions packages/create-aragon-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ create-aragon-app <app-name> [boilerplate]

- `app-name`: The name or ENS domain name for your app in an aragonPM Registry (e.g. `myapp` or `myapp.aragonpm.eth`). If only the name is provided it will create your app on the default `aragonpm.eth` registry.

- `boilerplate`: the Github repo name or alias for a boilerplate to set up your app. The currently available boilerplates are:
- `react`: this boilerplate contains a very basic Counter app and a webapp for interacting with it. It showcases the end-to-end interaction with an Aragon app, from the contracts to the webapp.
- `buidler`: (experimental) this boilerplates is similar to `react` using the [buidler](https://buidler.dev/) task runner with a custom plugin for developing Aragon apps.
- `bare`: (deprecated) this boilerplate will just set up your app directory structure but contains no functional code.
- `boilerplate`: the Github repo name or alias for a boilerplate to set up your app. It default to `react`. The currently available boilerplates are:
- `react`: this boilerplate contains a very basic Counter app and a webapp for interacting with it. It showcases the end-to-end interaction using the [buidler](https://buidler.dev/) task runner with a custom plugin for developing Aragon apps from the contracts to the webapp.
- `reactWithCli`: (deprecated) this is similar to the `react` boilerplate but use aragonCLI as development tool.

## Example

Expand All @@ -31,38 +30,6 @@ _Note: [npx](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner

In the root of the repository, run:

```sh
npm run pretest
```

And then in packages/create-aragon-app, run:

```sh
npm test
```

To test only one file, try:

```sh
npm test -- <path to test file>
```

## Local environment

Some commands like `aragon run` depend on a local dev environment (ipfs, ganache).

We set up this up during the `pretest` hook & tear it down during the `posttest` hook.

Pretest:

- Start IPFS
- Start Ganache
- Create a test app

Posttest:

- Stop IPFS
- Stop Ganache
- Delete the test app

**Tip**: Did a test fail and the local environment was cleaned up? Try `npm run test:clean`.
2 changes: 1 addition & 1 deletion packages/create-aragon-app/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions packages/create-aragon-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-aragon-app",
"version": "2.6.3",
"version": "2.7.0",
"description": "Aragon command-line tool to create aragon apps",
"bin": {
"create-aragon-app": "./dist/index.js"
Expand Down Expand Up @@ -48,7 +48,6 @@
"figures": "^3.0.0",
"fs-extra": "^8.0.1",
"git-clone": "^0.1.0",
"inquirer": "^7.0.4",
"listr": "^0.14.3",
"listr-silent-renderer": "^1.1.1",
"listr-update-renderer": "^0.5.0",
Expand Down
78 changes: 27 additions & 51 deletions packages/create-aragon-app/src/commands/create-aragon-app.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
const TaskList = require('listr')
const execa = require('execa')
const inquirer = require('inquirer')
const { promisify } = require('util')
const clone = promisify(require('git-clone'))
//
const defaultAPMName = require('../helpers/default-apm')
const isValidAragonId = require('../helpers/is-valid-aragonid')
const listrOpts = require('../helpers/listr-options')
const { installDeps, isValidAragonId } = require('../util')
const { installDeps } = require('../util')
const { checkProjectExists, prepareTemplate } = require('../lib')

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

Expand All @@ -47,18 +43,12 @@ exports.builder = yargs => {
templateOptions
).join(', ')})`,
coerce: function resolveTemplateName(tmpl) {
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 (!templateOptions[tmpl]) {
throw new Error(`No template named ${tmpl} exists`)
}
if (!templateOptions[tmpl]) {
throw new Error(`No template named ${tmpl} exists`)
}

return tmpl
},
default: 'react',
})
.option('install', {
description: 'Whether or not to install dependencies',
Expand All @@ -80,34 +70,18 @@ exports.handler = async function({
const basename = name.split('.')[0]
const projectPath = `${dirPath}/${basename}`

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 oldTemplate = template === 'reactWithCli'

let requiresIPFS = true

if (template === 'buidler') {
requiresIPFS = false
console.log(
`Warning: You are using the experimental "${template}" boilerplate.`
if (oldTemplate) {
reporter.warning(
`You are using a deprecated boilerplate that use the aragonCLI for development. We encourage the use of the Aragon buidler plugin instead.
`
)
}

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

const checkout = oldTemplate ? 'tags/react-with-cli' : ''

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

Expand All @@ -132,7 +106,7 @@ exports.handler = async function({
title: 'Cloning app template',
task: async (ctx, task) => {
task.output = `Cloning ${templateUrl} into ${projectPath}...`
await clone(templateUrl, projectPath, { shallow: true })
await clone(templateUrl, projectPath, { checkout })
},
},
{
Expand All @@ -154,7 +128,7 @@ exports.handler = async function({
},
{
title: 'Check IPFS',
enabled: () => requiresIPFS,
enabled: () => oldTemplate && install,
task: async (ctx, task) => {
try {
ctx.ipfsMissing = false
Expand All @@ -166,7 +140,7 @@ exports.handler = async function({
},
{
title: 'Installing IPFS',
enabled: ctx => requiresIPFS && ctx.ipfsMissing,
enabled: ctx => oldTemplate && install && ctx.ipfsMissing,
task: async (ctx, task) => {
await execa(
'npx',
Expand All @@ -180,16 +154,18 @@ exports.handler = async function({
)

return tasks.run().then(() => {
reporter.success(`Created new application ${name} in path ./${basename}/
Start your Aragon app by typing:
reporter.success(`Created new application ${name} in path ./${basename}/\n`)

cd ${basename}
npm start
if (template === 'react')
reporter.info(`Start your Aragon app by typing:
Visit https://hack.aragon.org/docs/cli-main-commands for more information.
cd ${basename}
npm start
Visit https://hack.aragon.org/docs for more information.
`)

`)
process.exit()
})
}
10 changes: 10 additions & 0 deletions packages/create-aragon-app/src/helpers/is-valid-aragonid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Validates an Aragon Id
* @param {string} aragonId Aragon Id
* @returns {boolean} `true` if valid
*/
function isValidAragonId(aragonId) {
return /^[a-z0-9-]+$/.test(aragonId)
}

module.exports = isValidAragonId
10 changes: 0 additions & 10 deletions packages/create-aragon-app/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,7 @@ const installDeps = (cwd, task) => {
})
}

/**
* Validates an Aragon Id
* @param {string} aragonId Aragon Id
* @returns {boolean} `true` if valid
*/
function isValidAragonId(aragonId) {
return /^[a-z0-9-]+$/.test(aragonId)
}

module.exports = {
installDeps,
isValidAragonId,
getNodePackageManager,
}
2 changes: 1 addition & 1 deletion packages/create-aragon-app/test/create-app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test('should create a new aragon app based on the buidler boilerplate', async t

const { stdout } = await runCreateAragonApp([
projectName,
'buidler',
'react',
'--path',
'./.tmp',
'--no-install',
Expand Down
2 changes: 1 addition & 1 deletion packages/create-aragon-app/test/lib.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from 'ava'
import fs from 'fs-extra'

import { checkProjectExists, prepareTemplate } from '../src/lib'
import { isValidAragonId } from '../src/util'
import isValidAragonId from '../src/helpers/is-valid-aragonid'

import defaultAPMName from '../src/helpers/default-apm'

Expand Down

0 comments on commit 96a5929

Please sign in to comment.