mirror of https://github.com/embarklabs/embark.git
Adding base command logic for scaffolding generation
This commit is contained in:
parent
6d0f4b67ae
commit
0eaafb77f1
24
cmd/cmd.js
24
cmd/cmd.js
|
@ -46,6 +46,7 @@ class Cmd {
|
|||
this.reset();
|
||||
this.ejectWebpack();
|
||||
this.graph();
|
||||
this.scaffold();
|
||||
this.upload();
|
||||
this.versionCmd();
|
||||
this.helpCmd();
|
||||
|
@ -323,6 +324,29 @@ class Cmd {
|
|||
});
|
||||
}
|
||||
|
||||
scaffold() {
|
||||
program
|
||||
.command('scaffold [contract] [environment]')
|
||||
.option('--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
|
||||
});
|
||||
|
||||
options.contract = contract;
|
||||
options.framework = options.framework || 'react';
|
||||
options.env = environment;
|
||||
embark.scaffold(options);
|
||||
});
|
||||
}
|
||||
|
||||
reset() {
|
||||
program
|
||||
.command('reset')
|
||||
|
|
|
@ -123,6 +123,10 @@ Plugin.prototype.registerPipeline = function(matcthingFiles, cb) {
|
|||
this.addPluginType('pipeline');
|
||||
};
|
||||
|
||||
Plugin.prototype.registerCustomType = function(type){
|
||||
this.pluginTypes.push(type);
|
||||
}
|
||||
|
||||
Plugin.prototype.addFileToPipeline = function(file, intendedPath, options) {
|
||||
this.pipelineFiles.push({file: file, intendedPath: intendedPath, options: options});
|
||||
this.addPluginType('pipelineFiles');
|
||||
|
|
36
lib/index.js
36
lib/index.js
|
@ -358,6 +358,42 @@ class Embark {
|
|||
resetCmd();
|
||||
}
|
||||
|
||||
scaffold(options) {
|
||||
// initialise embark engine
|
||||
let engine = new Engine({
|
||||
env: options.env,
|
||||
version: this.version,
|
||||
embarkConfig: options.embarkConfig || 'embark.json',
|
||||
logfile: options.logfile
|
||||
});
|
||||
engine.init();
|
||||
|
||||
// load plugins
|
||||
this.plugins.loadInternalPlugin('scaffolding', options);
|
||||
let scaffoldPlugin = this.plugins.plugins.filter(x => x.name == "scaffolding")[0].pluginModule;
|
||||
let self = this;
|
||||
|
||||
async.waterfall([
|
||||
function generateUI(callback){
|
||||
engine.events.on('outputDone', function () {
|
||||
let scaffold = new scaffoldPlugin(engine, options);
|
||||
let result = scaffold.generate(options.contract);
|
||||
engine.logger.info(result);
|
||||
callback();
|
||||
});
|
||||
self.build(options, engine, true);
|
||||
}
|
||||
], function (err, _result) {
|
||||
if (err) {
|
||||
engine.logger.error(err.message);
|
||||
engine.logger.debug(err.stack);
|
||||
} else {
|
||||
engine.logger.info("Finished generating ui");
|
||||
}
|
||||
process.exit();
|
||||
});
|
||||
}
|
||||
|
||||
upload(options) {
|
||||
this.context = options.context || [constants.contexts.upload, constants.contexts.build];
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
class ScaffoldingReact {
|
||||
constructor(embark, options){
|
||||
this.embark = embark;
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
build(contract){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = ScaffoldingReact;
|
|
@ -0,0 +1,61 @@
|
|||
const fs = require('fs');
|
||||
|
||||
const commandName = "generate-ui";
|
||||
|
||||
const formatReplyMsg = (message) => commandName + ": " + message;
|
||||
|
||||
class Scaffolding {
|
||||
constructor(embark, options){
|
||||
this.embark = embark;
|
||||
this.options = options;
|
||||
this.framework = options.framework;
|
||||
this.frameworkPlugin = null;
|
||||
}
|
||||
|
||||
createDirectories(contractName){
|
||||
const dir = './app/' + contractName;
|
||||
if (!fs.existsSync(dir)){
|
||||
fs.mkdirSync(dir);
|
||||
} else {
|
||||
throw formatReplyMsg("directory ./app/" + contractName + " already exists");
|
||||
}
|
||||
}
|
||||
|
||||
isContract(contractName){
|
||||
return this.embark.config.contractsConfig.contracts[contractName] !== undefined;
|
||||
}
|
||||
|
||||
generate(contractName){
|
||||
let frameworkPlugin;
|
||||
|
||||
if(this.framework == 'react'){
|
||||
this.embark.plugins.loadInternalPlugin('scaffolding-react', this.options);
|
||||
frameworkPlugin = this.embark.plugins.plugins.filter(x => x.name == "scaffolding-react")[0].pluginModule;
|
||||
} else {
|
||||
let plugins = this.embark.plugins.getPluginsFor(this.framework);
|
||||
if(plugins.length !== 1){
|
||||
return formatReplyMsg("Could not find plugin for framework '" + this.framework + "'");
|
||||
}
|
||||
frameworkPlugin = plugins[0].pluginModule;
|
||||
}
|
||||
|
||||
try {
|
||||
if(!this.isContract(contractName)){
|
||||
return formatReplyMsg("contract '" + contractName + "' does not exist");
|
||||
}
|
||||
|
||||
const contract = this.embark.config.contractsConfig.contracts[contractName];
|
||||
|
||||
this.createDirectories(contractName);
|
||||
let uiFramework = new frameworkPlugin(this.embark, this.options);
|
||||
uiFramework.build(contract);
|
||||
} catch(err){
|
||||
return err;
|
||||
}
|
||||
|
||||
return formatReplyMsg("done!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = Scaffolding;
|
Loading…
Reference in New Issue