-
Notifications
You must be signed in to change notification settings - Fork 200
Preserve App, Package and Directory addresses #120
Changes from all commits
be360d6
c7e6818
2589e2f
dba82e8
61f4d48
0f4d51b
c44a0e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,36 @@ | ||
import BasePackageProject from "./BasePackageProject"; | ||
import App from "../app/App"; | ||
import Package from "../package/Package"; | ||
import { DeployError } from '../utils/errors/DeployError'; | ||
import _ from 'lodash'; | ||
|
||
export default class AppProject extends BasePackageProject { | ||
static async fetch(appAddress, name, txParams) { | ||
const app = await App.fetch(appAddress, txParams) | ||
const packageInfo = await app.getPackage(name) | ||
const project = new this(app, name, packageInfo.version, txParams) | ||
project.package = packageInfo.package | ||
return project | ||
} | ||
|
||
static async deploy(name = 'main', version = '0.1.0', txParams = {}) { | ||
const thepackage = await Package.deploy(txParams) | ||
const directory = await thepackage.newVersion(version) | ||
const app = await App.deploy(txParams) | ||
await app.setPackage(name, thepackage.address, version) | ||
const project = new this(app, name, version, txParams) | ||
project.directory = directory | ||
project.package = thepackage | ||
return project | ||
static async fetchOrDeploy(name = 'main', version = '0.1.0', txParams = {}, { appAddress = undefined, packageAddress = undefined }) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need the default values for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say so, it simplifies usage of the Project class directly |
||
let thepackage, directory, app | ||
try { | ||
app = appAddress | ||
? await App.fetch(appAddress, txParams) | ||
: await App.deploy(txParams) | ||
if (packageAddress) { | ||
thepackage = await Package.fetch(packageAddress, txParams) | ||
} else if (await app.hasPackage(name, version)) { | ||
thepackage = (await app.getPackage(name)).package | ||
} else { | ||
thepackage = await Package.deploy(txParams) | ||
} | ||
directory = await thepackage.hasVersion(version) | ||
? await thepackage.getDirectory(version) | ||
: await thepackage.newVersion(version) | ||
|
||
if (!await app.hasPackage(name, version)) await app.setPackage(name, thepackage.address, version) | ||
const project = new this(app, name, version, txParams) | ||
project.directory = directory | ||
project.package = thepackage | ||
|
||
return project | ||
} catch(deployError) { | ||
throw new DeployError(deployError.message, { thepackage, directory, app }) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about splitting this method a bit to sth like: static async fetchOrDeploy(name = 'main', version = '0.1.0', txParams = {}, { appAddress = undefined, packageAddress = undefined }) {
try {
const app = await this.fetchOrDeployApp(...)
const thepackage = await this.fetchOrDeployPackage(...)
const directory = await this.fetchOrDeployDirectory(...)
return this.buildProject(...)
} catch(deployError) {
throw new DeployError(deployError.message, { thepackage, directory, app })
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've discussed this offline. It's not a good idea to merge |
||
} | ||
|
||
constructor(app, name = 'main', version = '0.1.0', txParams = {}) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,30 @@ | ||
import BasePackageProject from "./BasePackageProject"; | ||
import Package from "../package/Package"; | ||
import { DeployError } from '../utils/errors/DeployError'; | ||
|
||
export default class LibProject extends BasePackageProject { | ||
static async fetch(packageAddress, version = '0.1.0', txParams) { | ||
const thepackage = await Package.fetch(packageAddress, txParams) | ||
return new this(thepackage, version, txParams) | ||
} | ||
|
||
static async deploy(version = '0.1.0', txParams = {}) { | ||
const thepackage = await Package.deploy(txParams) | ||
const directory = await thepackage.newVersion(version) | ||
const project = new this(thepackage, version, txParams) | ||
project.directory = directory | ||
return project | ||
static async fetchOrDeploy(version = '0.1.0', txParams = {}, { packageAddress = undefined }) { | ||
let thepackage, directory | ||
try { | ||
thepackage = packageAddress | ||
? await Package.fetch(packageAddress, txParams) | ||
: await Package.deploy(txParams) | ||
directory = await thepackage.hasVersion(version) | ||
? await thepackage.getDirectory(version) | ||
: await thepackage.newVersion(version) | ||
|
||
const project = new this(thepackage, version, txParams) | ||
project.directory = directory | ||
|
||
return project | ||
} catch(deployError) { | ||
throw new DeployError(deployError.message, { thepackage, directory }) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we may want to split this one too, it is not that large tho |
||
} | ||
|
||
constructor(thepackage, version = '0.1.0', txParams = {}) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict' | ||
|
||
export class DeployError extends Error { | ||
constructor(message, props) { | ||
super(message) | ||
Object.keys(props).forEach(prop => this[prop] = props[prop]) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍