mirror of https://github.com/embarklabs/embark.git
Fix scaffolding command logic so it works with Embark 3.2.2
This commit is contained in:
parent
844e2ed5b0
commit
c8d357e601
15
cmd/cmd.js
15
cmd/cmd.js
|
@ -329,20 +329,21 @@ class Cmd {
|
||||||
.command('scaffold [contract] [environment]')
|
.command('scaffold [contract] [environment]')
|
||||||
.option('--framework <framework>', 'UI framework to use. (default: react)')
|
.option('--framework <framework>', 'UI framework to use. (default: react)')
|
||||||
.action(function(contract, env, options){
|
.action(function(contract, env, options){
|
||||||
let environment = env || 'development';
|
|
||||||
|
|
||||||
if(contract === undefined){
|
if(contract === undefined){
|
||||||
console.log("contract name is required");
|
console.log("contract name is required");
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
embark.initConfig(environment, {
|
checkDeps();
|
||||||
embarkConfig: 'embark.json', interceptLogs: false
|
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.contract = contract;
|
||||||
options.framework = options.framework || 'react';
|
options.framework = options.framework || 'react';
|
||||||
options.env = environment;
|
|
||||||
embark.scaffold(options);
|
embark.scaffold(options);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -430,6 +430,86 @@ class EmbarkController {
|
||||||
console.log(`${dappOverrides}`.green);
|
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) {
|
upload(options) {
|
||||||
this.context = options.context || [constants.contexts.upload, constants.contexts.build];
|
this.context = options.context || [constants.contexts.upload, constants.contexts.build];
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,22 @@
|
||||||
class Scaffolding {
|
class Scaffolding {
|
||||||
constructor(embark, options){
|
constructor(engine, options){
|
||||||
this.embark = embark;
|
this.engine = engine;
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.framework = options.framework;
|
this.framework = options.framework;
|
||||||
this.frameworkPlugin = null;
|
this.frameworkPlugin = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
isContract(contractName){
|
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'){
|
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;
|
let build = null;
|
||||||
dappGenerators.forEach((plugin) => {
|
dappGenerators.forEach((plugin) => {
|
||||||
plugin.dappGenerators.forEach((d) => {
|
plugin.dappGenerators.forEach((d) => {
|
||||||
|
@ -30,11 +31,15 @@ class Scaffolding {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!this.isContract(contractName)){
|
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) => {
|
||||||
build(contract);
|
if(_err) throw new Error(_err);
|
||||||
|
|
||||||
|
const contract = contractsList.find(x => x.className === contractName);
|
||||||
|
build(contract);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue