mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-09 13:36:14 +00:00
Addid basic templating to start building UI from here
This commit is contained in:
parent
2674f19961
commit
aeffe243b5
@ -378,13 +378,13 @@ class Embark {
|
|||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function generateUI(callback){
|
function generateUI(callback){
|
||||||
engine.events.on('outputDone', function () {
|
engine.events.on('contractsDeployed', function () {
|
||||||
let scaffold = new scaffoldPlugin(engine, options);
|
let scaffold = new scaffoldPlugin(engine, options);
|
||||||
let result = scaffold.generate(options.contract);
|
let result = scaffold.generate(options.contract);
|
||||||
engine.logger.info(result);
|
engine.logger.info(result);
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
self.build(options, engine, true);
|
self.build(options, engine, false);
|
||||||
}
|
}
|
||||||
], function (err, _result) {
|
], function (err, _result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
|
|
||||||
|
const Handlebars = require('handlebars');
|
||||||
|
|
||||||
|
const fs = require('../../core/fs');
|
||||||
|
const utils = require('../../utils/utils');
|
||||||
class ScaffoldingReact {
|
class ScaffoldingReact {
|
||||||
constructor(embark, options){
|
constructor(embark, options){
|
||||||
this.embark = embark;
|
this.embark = embark;
|
||||||
@ -6,9 +10,27 @@ class ScaffoldingReact {
|
|||||||
}
|
}
|
||||||
|
|
||||||
build(contract){
|
build(contract){
|
||||||
|
const filename = contract.className.toLowerCase() + '.html';
|
||||||
|
const filePath = './app/' + filename;
|
||||||
|
|
||||||
|
if (fs.existsSync(filePath)){
|
||||||
|
throw new Error("file '" + filePath + "' already exists");
|
||||||
|
}
|
||||||
|
|
||||||
|
const templatePath = fs.embarkPath('lib/modules/scaffolding-react/templates/index.tpl');
|
||||||
|
const source = fs.readFileSync(templatePath).toString();
|
||||||
|
const template = Handlebars.compile(source);
|
||||||
|
|
||||||
|
let data = {
|
||||||
|
'title': contract.className
|
||||||
|
};
|
||||||
|
|
||||||
|
// Write template
|
||||||
|
const result = template(data);
|
||||||
|
fs.writeFileSync(filePath, result);
|
||||||
|
|
||||||
|
return "File '" + filePath + "' created successfully";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = ScaffoldingReact;
|
module.exports = ScaffoldingReact;
|
||||||
|
12
lib/modules/scaffolding-react/templates/index.tpl
Normal file
12
lib/modules/scaffolding-react/templates/index.tpl
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en" dir="ltr">
|
||||||
|
<head>
|
||||||
|
<title>{{title}}</title>
|
||||||
|
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
|
||||||
|
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
|
||||||
|
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -2,7 +2,7 @@ const fs = require('fs');
|
|||||||
|
|
||||||
const commandName = "generate-ui";
|
const commandName = "generate-ui";
|
||||||
|
|
||||||
const formatReplyMsg = (message) => commandName + ": " + message;
|
const errorMessage = (message) => new Error(commandName + ": " + message);
|
||||||
|
|
||||||
class Scaffolding {
|
class Scaffolding {
|
||||||
constructor(embark, options){
|
constructor(embark, options){
|
||||||
@ -12,15 +12,6 @@ class Scaffolding {
|
|||||||
this.frameworkPlugin = null;
|
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){
|
isContract(contractName){
|
||||||
return this.embark.config.contractsConfig.contracts[contractName] !== undefined;
|
return this.embark.config.contractsConfig.contracts[contractName] !== undefined;
|
||||||
}
|
}
|
||||||
@ -34,26 +25,25 @@ class Scaffolding {
|
|||||||
} else {
|
} else {
|
||||||
let plugins = this.embark.plugins.getPluginsFor(this.framework);
|
let plugins = this.embark.plugins.getPluginsFor(this.framework);
|
||||||
if(plugins.length !== 1){
|
if(plugins.length !== 1){
|
||||||
return formatReplyMsg("Could not find plugin for framework '" + this.framework + "'");
|
throw errorMessage("Could not find plugin for framework '" + this.framework + "'");
|
||||||
}
|
}
|
||||||
frameworkPlugin = plugins[0].pluginModule;
|
frameworkPlugin = plugins[0].pluginModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
if(!this.isContract(contractName)){
|
|
||||||
return formatReplyMsg("contract '" + contractName + "' does not exist");
|
|
||||||
}
|
|
||||||
|
|
||||||
const contract = this.embark.config.contractsConfig.contracts[contractName];
|
if(!this.isContract(contractName)){
|
||||||
|
return errorMessage("contract '" + contractName + "' does not exist");
|
||||||
this.createDirectories(contractName);
|
|
||||||
let uiFramework = new frameworkPlugin(this.embark, this.options);
|
|
||||||
uiFramework.build(contract);
|
|
||||||
} catch(err){
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return formatReplyMsg("done!");
|
const contract = this.embark.config.contractsConfig.contracts[contractName];
|
||||||
|
|
||||||
|
try {
|
||||||
|
let uiFramework = new frameworkPlugin(this.embark, this.options);
|
||||||
|
let result = uiFramework.build(contract);
|
||||||
|
this.embark.logger.info(result);
|
||||||
|
} catch(err){
|
||||||
|
throw errorMessage(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@
|
|||||||
"globule": "^1.1.0",
|
"globule": "^1.1.0",
|
||||||
"hard-source-webpack-plugin": "^0.11.1",
|
"hard-source-webpack-plugin": "^0.11.1",
|
||||||
"http-proxy": "^1.17.0",
|
"http-proxy": "^1.17.0",
|
||||||
|
"handlebars": "^4.0.11",
|
||||||
"http-shutdown": "^1.2.0",
|
"http-shutdown": "^1.2.0",
|
||||||
"i18n": "^0.8.3",
|
"i18n": "^0.8.3",
|
||||||
"ipfs-api": "17.2.4",
|
"ipfs-api": "17.2.4",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user