Skip to content

Commit

Permalink
aragon init: prepare template for environments
Browse files Browse the repository at this point in the history
* Update: prepare-template for environments

* Fix: update lint test folder

* Fix: update ava tests

* Fix: ava test

* Fix: changes after review
  • Loading branch information
0xGabi authored Feb 21, 2019
1 parent eb361c7 commit 85ca980
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build": "npm run extract-roles && babel -d dist src --copy-files",
"prepare": "npm run build",
"test": "ava",
"lint": "eslint src test && documentation lint src test",
"lint": "eslint src test/commands && documentation lint src test/commands",
"extract-roles": "node scripts/extract-roles"
},
"repository": {
Expand Down Expand Up @@ -116,7 +116,7 @@
"@babel/register"
],
"files": [
"test/**/*.js"
"test/commands/**/*.js"
]
},
"aragon": {
Expand Down
37 changes: 15 additions & 22 deletions src/lib/init/prepare-template.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
import path from 'path'
import fs from 'fs-extra'

export async function prepareTemplate(basename, appName) {
const arappPath = path.resolve(basename, 'arapp.json')
export async function prepareTemplate(dir, appName) {
const basename = appName.split('.')[0]
const arappPath = path.resolve(dir, 'arapp.json')
const arapp = await fs.readJson(arappPath)

// TODO remove once the old arapp.json is no longer supported
if (!arapp.environments) {
arapp.environments = {}
}
const defaultEnv = arapp.environments.default
const stagingEnv = arapp.environments.staging
const productionEnv = arapp.environments.production

const props = {
network: 'development',
appName: appName,
}
defaultEnv.appName = appName
stagingEnv.appName = stagingEnv.appName.replace(/^app/, basename)
productionEnv.appName = productionEnv.appName.replace(/^app/, basename)

if (arapp.environments.default) {
Object.assign(arapp.environments.default, props)
} else {
arapp.environments.default = props
}
Object.assign(arapp.environments.default, defaultEnv)
Object.assign(arapp.environments.staging, stagingEnv)
Object.assign(arapp.environments.production, productionEnv)

// remove old arapp.json props
delete arapp.appName
delete arapp.version
const gitFolderPath = path.resolve(dir, '.git')
const licensePath = path.resolve(dir, 'LICENSE')

const gitFolderPath = path.resolve(basename, '.git')
const licensePath = path.resolve(basename, 'LICENSE')

const packageJsonPath = path.resolve(basename, 'package.json')
const packageJsonPath = path.resolve(dir, 'package.json')
const packageJson = await fs.readJson(packageJsonPath)
delete packageJson.license

Expand Down
21 changes: 18 additions & 3 deletions test/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import fs from 'fs-extra'

import { checkProjectExists, prepareTemplate } from '../../src/lib/init'

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

const projectPath = './.tmp/aragon-app'

test.beforeEach(t => {
Expand All @@ -27,14 +29,25 @@ test('prepare project template', async t => {
const arappPath = `${projectPath}/arapp.json`
const packageJsonPath = `${projectPath}/package.json`
const licensePath = `${projectPath}/LICENSE`
const appName = 'TestApp'
const appName = defaultAPMName('TestApp')
const basename = appName.split('.')[0]

await fs.ensureDir(repoPath)
await fs.ensureFile(arappPath)
await fs.ensureFile(packageJsonPath)
await fs.ensureFile(licensePath)
await fs.writeJson(arappPath, {
appName: 'boilerplate-placeholder',
environments: {
default: {
appName: 'app.aragonpm.eth',
},
staging: {
appName: 'app.open.aragonpm.eth',
},
production: {
appName: 'app.open.aragonpm.eth',
},
},
})
await fs.writeJson(packageJsonPath, {
license: 'MIT',
Expand All @@ -48,5 +61,7 @@ test('prepare project template', async t => {
t.falsy(await fs.pathExists(repoPath))
t.is(undefined, packageJson.license)
t.falsy(fs.pathExistsSync(licensePath))
t.is(appName, project.environments.default.appName)
t.is(`${appName}`, project.environments.default.appName)
t.is(`${basename}.open.aragonpm.eth`, project.environments.staging.appName)
t.is(`${basename}.open.aragonpm.eth`, project.environments.production.appName)
})

0 comments on commit 85ca980

Please sign in to comment.