Skip to content

Commit

Permalink
Merge pull request #26 from aragon/develop
Browse files Browse the repository at this point in the history
Merge develop to master for release of 0.1.0
  • Loading branch information
eternauta1337 authored Feb 26, 2020
2 parents 117779d + 07648f1 commit 8f897c8
Show file tree
Hide file tree
Showing 23 changed files with 263 additions and 109 deletions.
9 changes: 8 additions & 1 deletion package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aragon/buidler-aragon",
"version": "0.0.7",
"version": "0.1.0",
"description": "Aragon Buidler plugin",
"main": "dist/src/index.js",
"author": "Aragon Association <[email protected]>",
Expand All @@ -13,7 +13,7 @@
],
"files": [
"typechain",
"dist/src",
"dist",
"src"
],
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { extendConfig, usePlugin } from '@nomiclabs/buidler/config'
import { defaultAragonConfig } from './params'
import path from 'path'
import { defaultAragonConfig } from './params'
// TODO: Don't use any type below, try to use something like these...
// import { ResolvedBuidlerConfig, BuidlerConfig } from '@nomiclabs/buidler/types'

Expand Down
40 changes: 40 additions & 0 deletions src/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,46 @@ export const aragenAccounts = [
privateKey:
'0xce8e3bda3b44269c147747a373646393b1504bfcbb73fc9564f5d753d8116608',
publicKey: '0x8401Eb5ff34cc943f096A32EF3d5113FEbE8D4Eb'
},
{
privateKey:
'0x8716d2701596f51aa39d061a685d5ae5ec946eb2c7adb059d29024b5bb3b02c8',
publicKey: '0x306469457266CBBe7c0505e8Aad358622235e768'
},
{
privateKey:
'0x62d7bb725787d84b059eb4950f6eea060d898183250ca3ea673a36b8e113018f',
publicKey: '0xd873F6DC68e3057e4B7da74c6b304d0eF0B484C7'
},
{
privateKey:
'0x705df2ae707e25fa37ca84461ac6eb83eb4921b653e98fdc594b60bea1bb4e52',
publicKey: '0xDcC5dD922fb1D0fd0c450a0636a8cE827521f0eD'
},
{
privateKey:
'0x6b12b45143fc6c7721d0ffbb9811905e773868376501fd1f46c64bf34ae29991',
publicKey: '0x27E9727FD9b8CdDdd0854F56712AD9DF647FaB74'
},
{
privateKey:
'0x33f3f34569f997abb165d6967895d963a2b15ec609efcec844e65b60ee8340c7',
publicKey: '0x9766D2e7FFde358AD0A40BB87c4B88D9FAC3F4dd'
},
{
privateKey:
'0x5a013cc48f0a3196b0986fc7a7a9dd320ac75e89e33302a7ff4ea6b9dc4f7b00',
publicKey: '0xBd7055AB500cD1b0b0B14c82BdBe83ADCc2e8D06'
},
{
privateKey:
'0x418cc0b07bfef998f577384b185b97ad544204b5be43ac9b3abf16db2012ab5c',
publicKey: '0xe8898A4E589457D979Da4d1BDc35eC2aaf5a3f8E'
},
{
privateKey:
'0x698eece6f9915b08b4d1a63958dc4f3996ee5a8d685b29d17c28beab912a77cd',
publicKey: '0xED6A91b1CFaae9882875614170CbC989fc5EfBF0'
}
]

Expand Down
29 changes: 24 additions & 5 deletions src/tasks/start-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,24 @@ ${accountsStr}`)
)
}

const config: AragonConfig = bre.config.aragon as AragonConfig
await _checkPorts(config)
await _checkScripts(config.appSrcPath as string)

const { daoAddress, appAddress } = await startBackend(
bre,
appName,
appId,
params.silent
)
await startFrontend(bre, daoAddress, appAddress, !params.noBrowser)

const config: AragonConfig = bre.config.aragon as AragonConfig
const appExists = await _checkApp(config.appSrcPath as string)
if (appExists) {
await _checkPorts(config)
await _checkScripts(config.appSrcPath as string)

await startFrontend(bre, daoAddress, appAddress, !params.noBrowser)
} else {
// Keep process running.
return await new Promise(() => {})
}
})

async function _checkPorts(config: AragonConfig): Promise<void> {
Expand All @@ -80,6 +87,18 @@ async function _checkPorts(config: AragonConfig): Promise<void> {
}
}

async function _checkApp(appSrcPath: string): Promise<boolean> {
const appExists = await fsExtra.pathExists(appSrcPath)

if (!appExists) {
logMain(
'Warning: No front end found at app/, will continue development without building any front end.'
)
}

return appExists
}

async function _checkScripts(appSrcPath: string): Promise<void> {
const appPackageJson = await fsExtra.readJson(
path.join(appSrcPath, 'package.json')
Expand Down
26 changes: 6 additions & 20 deletions src/tasks/start/backend/create-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,27 @@ import {
RepoContract,
RepoInstance,
APMRegistryContract,
APMRegistryInstance
APMRegistryInstance,
AppStubInstance
} from '~/typechain'

interface InitializableApp extends Truffle.ContractInstance {
initialize: (...args: any[]) => void
}

export async function createApp(
appName: string,
appId: string,
dao: KernelInstance,
proxyInitParams: any[],
ensAddress: string,
apmAddress: string,
bre: BuidlerRuntimeEnvironment
): Promise<{
implementation: Truffle.ContractInstance
proxy: Truffle.ContractInstance
proxy: AppStubInstance
repo: RepoInstance
}> {
// Deploy first app implementation.
const implementation = await deployImplementation(bre.artifacts)

// Create an app proxy.
const proxy = await _createProxy(
implementation.address,
appId,
dao,
proxyInitParams,
bre
)
const proxy = await _createProxy(implementation.address, appId, dao, bre)

// Deploy a repo for the app.
const repo = await _createRepo(appName, appId, ensAddress, apmAddress, bre)
Expand All @@ -54,9 +44,8 @@ async function _createProxy(
implementationAddress: string,
appId: string,
dao: KernelInstance,
proxyInitParams: any[],
bre: BuidlerRuntimeEnvironment
): Promise<Truffle.ContractInstance> {
): Promise<AppStubInstance> {
const rootAccount: string = (await bre.web3.eth.getAccounts())[0]

// Create a new app proxy with base implementation.
Expand All @@ -72,10 +61,7 @@ async function _createProxy(
const proxyAddress: string = getLog(txResponse, 'NewAppProxy', 'proxy')
const mainContractName: string = getMainContractName()
const App: Truffle.Contract<any> = bre.artifacts.require(mainContractName)
const proxy: InitializableApp = await App.at(proxyAddress)

// Initialize the proxy.
await proxy.initialize(...proxyInitParams)
const proxy: AppStubInstance = await App.at(proxyAddress)

return proxy
}
Expand Down
4 changes: 3 additions & 1 deletion src/tasks/start/backend/start-ganache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export async function startGanache(
// Start a new ganache server.
server = ganache.server({
gasLimit: aragenGasLimit,
mnemonic: aragenMnemonic
mnemonic: aragenMnemonic,
/* eslint-disable @typescript-eslint/camelcase */
default_balance_ether: 100
})
const blockchain = await promisify(server.listen)(testnetPort)

Expand Down
6 changes: 3 additions & 3 deletions src/tasks/start/backend/update-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ export async function updateApp(
// Deploy a new app implementation.
const implementation = await deployImplementation(bre.artifacts)

// Update the proxy with the new implementation.
await _updateProxy(implementation.address, appId, dao, bre.web3)

// Update the repo with the new implementation.
const { version, uri } = await _updateRepo(
repo,
implementation.address,
appServePort
)

// Update the proxy with the new implementation.
await _updateProxy(implementation.address, appId, dao, bre.web3)

return { implementationAddress: implementation.address, version, uri }
}

Expand Down
78 changes: 65 additions & 13 deletions src/tasks/start/frontend/aragon-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import execa from 'execa'
import { logFront } from '~/src/ui/logger'
import liveServer from 'live-server'
import open from 'open'
import { BuidlerPluginError } from '@nomiclabs/buidler/plugins'

const defaultRepo = 'https://github.com/aragon/aragon'
const defaultVersion = '775edd606333a111eb2693df53900039722a95dc'
Expand All @@ -15,29 +16,79 @@ export async function installAragonClientIfNeeded(
repo: string = defaultRepo,
version: string = defaultVersion
): Promise<string> {
// Determine client path.
const clientPath: string = _getClientPath(version)

// Verify installation or install if needed.
if (fs.existsSync(path.resolve(clientPath))) {
logFront('Using cached client version.')
} else {
if (await _checkClientInstallationNeeded(clientPath)) {
fsExtra.ensureDirSync(clientPath, { recursive: true })

logFront(
`Installing client version ${version} locally (takes a couple of minutes)...`
)
const opts = { cwd: clientPath }
await execa('git', ['clone', '--', repo, clientPath])
await execa('git', ['checkout', version], opts)
await execa('npm', ['install'], opts)
await execa('npm', ['run', 'build:local'], opts)

let result

logFront(' cloning...')
result = await execa('git', [
'clone',
'--',
repo,
clientPath
]).catch(() => {})
await _abortClientInstallationOnFailure(clientPath, result)

logFront(' checking out version...')
result = await execa('git', ['checkout', version], opts).catch(() => {})
await _abortClientInstallationOnFailure(clientPath, result)

logFront(' installing...')
result = await execa('npm', ['install'], opts).catch(() => {})
await _abortClientInstallationOnFailure(clientPath, result)

logFront(' building...')
result = await execa('npm', ['run', 'build:local'], opts).catch(() => {})
await _abortClientInstallationOnFailure(clientPath, result)

logFront('Client installed.')
}

return clientPath
}

async function _checkClientInstallationNeeded(
clientPath: string
): Promise<boolean> {
if (!fs.existsSync(path.resolve(clientPath))) {
return true
}

if (!fs.existsSync(path.resolve(clientPath, 'build/index.html'))) {
logFront('Malformed client detected, removing it for re-installation.')
await fsExtra.remove(clientPath)
return true
}

logFront('Using cached client version.')
return false
}

async function _abortClientInstallationOnFailure(
clientPath: string,
result: any
): Promise<void> {
if (result && result.exitCode === 0) {
return
}

if (fs.existsSync(clientPath)) {
await fsExtra.remove(clientPath)
}

throw new BuidlerPluginError(
`There was an error while installing the Aragon client in ${clientPath}. Please make sure that this folder is deleted and try again.`
)
}

/**
* Prepares and starts the aragon client
* @return The URL at which the client is available
Expand All @@ -50,8 +101,9 @@ export async function startAragonClient(
const port: number = clientServePort
const clientPath: string = _getClientPath(defaultVersion)

logFront(`Starting client server at port ${port}...`)
await _createStaticWebserver(port, path.join(clientPath, 'build'))
const buildPath = path.join(clientPath, 'build')
logFront(`Serving client files at ${clientPath} at port ${port}...`)
await _createStaticWebserver(port, buildPath)

const url = `http://localhost:${port}/#/${subPath}`

Expand Down Expand Up @@ -95,8 +147,8 @@ function _getClientPath(version: string): string {
export function _createStaticWebserver(port: number, root = '.'): void {
liveServer.start({
open: false,
cors: true,
root,
port,
cors: '*'
port
})
}
18 changes: 9 additions & 9 deletions src/tasks/start/frontend/generate-artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,10 @@ export async function generateAppArtifacts(
artifacts: TruffleEnvironmentArtifacts
): Promise<void> {
await _copyManifest(appBuildOutputPath)
await _generateUriArtifacts(appBuildOutputPath, artifacts)
await generateUriArtifacts(appBuildOutputPath, artifacts)
}

async function _copyManifest(appBuildOutputPath: string): Promise<void> {
await fsExtra.copy(
manifestPath,
path.join(appBuildOutputPath as string, manifestPath)
)
}

async function _generateUriArtifacts(
export async function generateUriArtifacts(
appBuildOutputPath: string,
artifacts: TruffleEnvironmentArtifacts
): Promise<void> {
Expand All @@ -56,3 +49,10 @@ async function _generateUriArtifacts(
{ spaces: 2 }
)
}

async function _copyManifest(appBuildOutputPath: string): Promise<void> {
await fsExtra.copy(
manifestPath,
path.join(appBuildOutputPath as string, manifestPath)
)
}
Loading

0 comments on commit 8f897c8

Please sign in to comment.