Fix scaffolding command logic so it works with Embark 3.2.2

This commit is contained in:
Richard Ramos 2018-10-03 16:34:36 -04:00 committed by Pascal Precht
parent 844e2ed5b0
commit c8d357e601
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
3 changed files with 103 additions and 17 deletions

View File

@ -329,20 +329,21 @@ class Cmd {
.command('scaffold [contract] [environment]')
.option('--framework <framework>', 'UI framework to use. (default: react)')
.action(function(contract, env, options){
let environment = env || 'development';
if(contract === undefined){
console.log("contract name is required");
process.exit(0);
}
embark.initConfig(environment, {
embarkConfig: 'embark.json', interceptLogs: false
});
checkDeps();
i18n.setOrDetectLocale(options.locale);
options.env = env || 'development';
options.logFile = options.logfile; // fix casing
options.logLevel = options.loglevel; // fix casing
options.onlyCompile = options.contracts;
options.client = options.client || 'geth';
options.webpackConfigName = options.pipeline || 'development';
options.contract = contract;
options.framework = options.framework || 'react';
options.env = environment;
embark.scaffold(options);
});
}

View File

@ -430,6 +430,86 @@ class EmbarkController {
console.log(`${dappOverrides}`.green);
}
scaffold(options) {
this.context = options.context || [constants.contexts.build];
const Scaffolding = require('../lib/cmds/scaffolding.js');
const Engine = require('../lib/core/engine.js');
const engine = new Engine({
env: options.env,
client: options.client,
locale: options.locale,
version: this.version,
embarkConfig: 'embark.json',
interceptLogs: false,
logFile: options.logFile,
logLevel: options.logLevel,
events: options.events,
logger: options.logger,
config: options.config,
plugins: options.plugins,
context: this.context,
webpackConfigName: options.webpackConfigName
});
async.waterfall([
function initEngine(callback) {
engine.init({}, callback);
},
function startServices(callback) {
let pluginList = engine.plugins.listPlugins();
if (pluginList.length > 0) {
engine.logger.info(__("loaded plugins") + ": " + pluginList.join(", "));
}
engine.startService("processManager");
engine.startService("libraryManager");
engine.startService("codeRunner");
engine.startService("web3");
if (!options.onlyCompile) {
engine.startService("pipeline");
}
engine.startService("deployment", {onlyCompile: options.onlyCompile});
if (!options.onlyCompile) {
engine.startService("storage");
engine.startService("codeGenerator");
}
callback();
},
function deploy(callback) {
engine.events.request('deploy:contracts', function (err) {
callback(err);
});
},
function waitForWriteFinish(callback) {
if (options.onlyCompile) {
engine.logger.info("Finished compiling".underline);
return callback(null, true);
}
engine.events.on('outputDone', (err) => {
let scaffold = new Scaffolding(engine, options);
scaffold.generate(options.contract);
engine.logger.info(__("finished generating the UI").underline);
callback(err, true);
});
}
], function (_err, canExit) {
// TODO: this should be moved out and determined somewhere else
if (canExit || !engine.config.contractsConfig.afterDeploy || !engine.config.contractsConfig.afterDeploy.length) {
process.exit();
}
engine.logger.info(__('Waiting for after deploy to finish...'));
engine.logger.info(__('You can exit with CTRL+C when after deploy completes'));
});
}
upload(options) {
this.context = options.context || [constants.contexts.upload, constants.contexts.build];

View File

@ -1,21 +1,22 @@
class Scaffolding {
constructor(embark, options){
this.embark = embark;
constructor(engine, options){
this.engine = engine;
this.options = options;
this.framework = options.framework;
this.frameworkPlugin = null;
}
isContract(contractName){
return this.embark.config.contractsConfig.contracts[contractName] !== undefined;
return this.engine.config.contractsConfig.contracts[contractName] !== undefined;
}
generate(contractName, contractConfiguration){
generate(contractName){
if(this.framework === 'react'){
this.embark.plugins.loadInternalPlugin('scaffolding-react', this.options);
this.engine.plugins.loadInternalPlugin('scaffolding-react', this.options);
}
let dappGenerators = this.embark.plugins.getPluginsFor('dappGenerator');
let dappGenerators = this.engine.plugins.getPluginsFor('dappGenerator');
let build = null;
dappGenerators.forEach((plugin) => {
plugin.dappGenerators.forEach((d) => {
@ -30,11 +31,15 @@ class Scaffolding {
}
if(!this.isContract(contractName)){
return new Error("contract '" + contractName + "' does not exist");
throw new Error("contract '" + contractName + "' does not exist");
}
const contract = contractConfiguration.contracts[contractName];
this.engine.events.request("contracts:list", (_err, contractsList) => {
if(_err) throw new Error(_err);
const contract = contractsList.find(x => x.className === contractName);
build(contract);
});
}
}