mirror of https://github.com/embarklabs/embark.git
bugfix(@embark/scaffolding): upgrade scaffolding so it can be used in embark v5
WIP: refactor so that embark-scaffolding can be used in embark v5 fix scaffold cmd fix generated files path
This commit is contained in:
parent
8f9f631758
commit
441db4fd18
|
@ -84,7 +84,6 @@
|
|||
"embark-i18n": "^5.0.0-alpha.5",
|
||||
"embark-logger": "^5.0.0-alpha.5",
|
||||
"embark-reset": "^5.0.0-alpha.5",
|
||||
"embark-scaffolding": "^5.0.0-alpha.9",
|
||||
"embark-utils": "^5.0.0-alpha.9",
|
||||
"eth-ens-namehash": "2.0.8",
|
||||
"ethereumjs-wallet": "0.6.3",
|
||||
|
|
|
@ -575,7 +575,7 @@ class EmbarkController {
|
|||
client: options.client,
|
||||
locale: options.locale,
|
||||
version: this.version,
|
||||
embarkConfig: 'embark.json',
|
||||
embarkConfig: options.embarkConfig || 'embark.json',
|
||||
interceptLogs: false,
|
||||
logFile: options.logFile,
|
||||
logLevel: options.logLevel,
|
||||
|
@ -593,47 +593,66 @@ class EmbarkController {
|
|||
engine.init({}, callback);
|
||||
},
|
||||
function (callback) {
|
||||
engine.startService("libraryManager").installAll((err) => callback(err ? err : null));
|
||||
},
|
||||
function startServices(callback) {
|
||||
engine.startService("scaffolding");
|
||||
callback();
|
||||
},
|
||||
function generateContract(callback) {
|
||||
engine.events.request('scaffolding:generate:contract', options, function (files) {
|
||||
files.forEach(file => engine.events.request('config:contractsFiles:add', file));
|
||||
callback();
|
||||
});
|
||||
},
|
||||
function initEngineServices(callback) {
|
||||
engine.registerModuleGroup("coreComponents");
|
||||
engine.registerModuleGroup("stackComponents");
|
||||
|
||||
engine.registerModuleGroup("compiler");
|
||||
engine.registerModuleGroup("contracts");
|
||||
engine.registerModulePackage("embark-scaffolding");
|
||||
|
||||
// load custom plugins
|
||||
engine.loadDappPlugins();
|
||||
let pluginList = engine.plugins.listPlugins();
|
||||
if (pluginList.length > 0) {
|
||||
engine.logger.info(__("loaded plugins") + ": " + pluginList.join(", "));
|
||||
}
|
||||
engine.startService("web3");
|
||||
engine.startService("processManager");
|
||||
engine.startService("codeRunner");
|
||||
engine.startService("deployment", { onlyCompile: true });
|
||||
|
||||
callback();
|
||||
engine.startEngine(async () => {
|
||||
callback();
|
||||
});
|
||||
},
|
||||
function deploy(callback) {
|
||||
engine.events.request('deploy:contracts', function (err) {
|
||||
callback(err);
|
||||
});
|
||||
},
|
||||
function generateUI(callback) {
|
||||
engine.events.request("scaffolding:generate:ui", options, () => {
|
||||
function generateContract(callback) {
|
||||
engine.logger.info(__("generating contract"));
|
||||
engine.events.request('scaffolding:generate:contract', options, function (err, files) {
|
||||
if (err) return callback(err);
|
||||
files.forEach(file => engine.events.request('config:contractsFiles:add', file));
|
||||
callback();
|
||||
});
|
||||
},
|
||||
function buildContracts(callback) {
|
||||
(async () => {
|
||||
try {
|
||||
const contractsFiles = await engine.events.request2("config:contractsFiles");
|
||||
const compiledContracts = await engine.events.request2("compiler:contracts:compile", contractsFiles);
|
||||
const contractsConfig = await engine.events.request2("config:contractsConfig");
|
||||
await engine.events.request2("contracts:build", cloneDeep(contractsConfig), compiledContracts);
|
||||
} catch (e) {
|
||||
return callback(e);
|
||||
}
|
||||
callback();
|
||||
})()
|
||||
},
|
||||
function generateUI(callback) {
|
||||
if (engine.config.embarkConfig.app) {
|
||||
engine.logger.info(__("generating ui"));
|
||||
return engine.events.request("scaffolding:generate:ui", options, (err, _files) => {
|
||||
if (err) return callback(err);
|
||||
callback();
|
||||
});
|
||||
}
|
||||
callback();
|
||||
}
|
||||
], function (err) {
|
||||
if (err) {
|
||||
engine.logger.error(__("Error generating the UI: "));
|
||||
engine.logger.error(__("Error generating the scaffold: "));
|
||||
engine.logger.error(err.message || err);
|
||||
}
|
||||
engine.logger.info(__("finished generating the UI").underline);
|
||||
engine.logger.info(__("To see the result, execute {{cmd}} and go to /{{contract}}.html", { cmd: 'embark run'.underline, contract: options.contract }));
|
||||
if (engine.config.embarkConfig.app) {
|
||||
engine.logger.info(__("finished generating the contracts and UI").underline);
|
||||
engine.logger.info(__("To see the result, execute {{cmd}} and go to /{{contract}}.html", { cmd: 'embark run'.underline, contract: options.contractOrFile }));
|
||||
} else {
|
||||
engine.logger.info(__("finished generating the contracts").underline);
|
||||
}
|
||||
|
||||
process.exit(err ? 1 : 0);
|
||||
});
|
||||
|
|
|
@ -39,9 +39,6 @@
|
|||
{
|
||||
"path": "../plugins/graph"
|
||||
},
|
||||
{
|
||||
"path": "../plugins/scaffolding"
|
||||
},
|
||||
{
|
||||
"path": "../plugins/solidity"
|
||||
},
|
||||
|
|
|
@ -47,7 +47,7 @@ export class ReactBuilder implements Builder {
|
|||
private updateEmbarkJson(contractName: string, files: string[]) {
|
||||
const embarkJsonPath = path.join(utils.dappPath(), "embark.json");
|
||||
const embarkJson = this.embark.fs.readJSONSync(embarkJsonPath);
|
||||
embarkJson.app[`js/${contractName}.js`] = `app/${contractName}.js`;
|
||||
embarkJson.app[`${contractName}.js`] = `app/${contractName}.js`;
|
||||
embarkJson.app[`${contractName}.html`] = `app/${contractName}.html`;
|
||||
|
||||
this.embark.fs.writeFileSync(embarkJsonPath, JSON.stringify(embarkJson, null, 2));
|
||||
|
@ -61,7 +61,7 @@ export class ReactBuilder implements Builder {
|
|||
const dappTemplate = Handlebars.compile(dappSource);
|
||||
|
||||
const indexData = {
|
||||
filename: contractName.toLowerCase(),
|
||||
filename: contractName,
|
||||
title: contractName,
|
||||
};
|
||||
|
||||
|
@ -70,9 +70,15 @@ export class ReactBuilder implements Builder {
|
|||
return [];
|
||||
}
|
||||
|
||||
const relativeGenerationDir = path.relative(
|
||||
utils.dappPath('app'),
|
||||
utils.dappPath(this.embark.config.embarkConfig.generationDir)
|
||||
);
|
||||
|
||||
const dappData = {
|
||||
contractName,
|
||||
functions: this.getFunctions(contract),
|
||||
relativeGenerationDir
|
||||
};
|
||||
|
||||
return [indexTemplate(indexData), dappTemplate(dappData)];
|
||||
|
@ -115,7 +121,11 @@ export class ReactBuilder implements Builder {
|
|||
}
|
||||
|
||||
private installDependencies() {
|
||||
const cmd = "npm install react react-bootstrap react-dom";
|
||||
let pkgManager = 'npm install';
|
||||
if (this.embark.fs.existsSync(utils.dappPath('yarn.lock'))) {
|
||||
pkgManager = 'yarn add';
|
||||
}
|
||||
const cmd = `${pkgManager} react react-bootstrap@^0.33.1 react-dom`;
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
utils.runCmd(cmd, null, (error: string) => {
|
||||
if (error) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import EmbarkJS from 'Embark/EmbarkJS';
|
||||
import {{contractName}} from 'Embark/contracts/{{contractName}}';
|
||||
import {{contractName}} from '{{relativeGenerationDir}}/contracts/{{contractName}}';
|
||||
|
||||
import React, { Component, Fragment } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
|
|
|
@ -11,6 +11,6 @@
|
|||
</head>
|
||||
<body class="container">
|
||||
<div id="app"></div>
|
||||
<script src="js/{{filename}}.js"></script>
|
||||
<script src="./{{filename}}.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,4 +1,4 @@
|
|||
import { Contract, Embark } from "embark-core";
|
||||
import { Callback, Contract, Embark } from "embark-core";
|
||||
import { CommandOptions, ContractLanguage, Framework } from "./commandOptions";
|
||||
import { SolidityBuilder } from "./contractLanguage/solidityBuilder";
|
||||
import { ReactBuilder } from "./framework/reactBuilder";
|
||||
|
@ -7,13 +7,23 @@ import { SmartContractsRecipe } from "./smartContractsRecipe";
|
|||
export default class Scaffolding {
|
||||
|
||||
constructor(private embark: Embark, private options: any) {
|
||||
this.embark.events.setCommandHandler("scaffolding:generate:contract", (cmdLineOptions: any, cb: (files: Array<(string|undefined)>) => void) => {
|
||||
this.generateContract(cmdLineOptions).then(cb);
|
||||
});
|
||||
this.embark.events.setCommandHandler(
|
||||
"scaffolding:generate:contract",
|
||||
(cmdLineOptions: any, cb: Callback<Array<(string|undefined)>>) => {
|
||||
this.generateContract(cmdLineOptions)
|
||||
.then(files => cb(null, files))
|
||||
.catch(cb);
|
||||
}
|
||||
);
|
||||
|
||||
this.embark.events.setCommandHandler("scaffolding:generate:ui", (cmdLineOptions: any, cb: (files: string[]) => void) => {
|
||||
this.generateUi(cmdLineOptions).then(cb);
|
||||
});
|
||||
this.embark.events.setCommandHandler(
|
||||
"scaffolding:generate:ui",
|
||||
(cmdLineOptions: any, cb: Callback<string[]>) => {
|
||||
this.generateUi(cmdLineOptions)
|
||||
.then(files => cb(null, files))
|
||||
.catch(cb);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private contractLanguageStrategy(recipe: SmartContractsRecipe, options: CommandOptions) {
|
||||
|
@ -53,10 +63,6 @@ export default class Scaffolding {
|
|||
}
|
||||
|
||||
private getContracts() {
|
||||
return new Promise<Contract[]>((resolve) => {
|
||||
this.embark.events.request("contracts:list", (_: null, contracts: Contract[]) => {
|
||||
resolve(contracts);
|
||||
});
|
||||
});
|
||||
return this.embark.events.request2("contracts:list") as Promise<Contract[]>;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue