mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-09 21:46:12 +00:00
JS generation + embark.json configuration update
This commit is contained in:
parent
64f5a5f9a5
commit
4c37d50d05
@ -1,35 +1,51 @@
|
|||||||
|
|
||||||
const Handlebars = require('handlebars');
|
const Handlebars = require('handlebars');
|
||||||
|
|
||||||
const fs = require('../../core/fs');
|
const fs = require('../../core/fs');
|
||||||
const utils = require('../../utils/utils');
|
const utils = require('../../utils/utils');
|
||||||
|
|
||||||
|
|
||||||
class ScaffoldingReact {
|
class ScaffoldingReact {
|
||||||
constructor(embark, options){
|
constructor(embark, options){
|
||||||
this.embark = embark;
|
this.embark = embark;
|
||||||
this.options = options;
|
this.options = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
build(contract){
|
_generateFile(contract, templateFilename, extension, data){
|
||||||
const filename = contract.className.toLowerCase() + '.html';
|
const filename = contract.className.toLowerCase() + '.' + extension;
|
||||||
const filePath = './app/' + filename;
|
const filePath = './app/' + filename;
|
||||||
|
|
||||||
if (fs.existsSync(filePath)){
|
if (fs.existsSync(filePath)){
|
||||||
throw new Error("file '" + filePath + "' already exists");
|
// throw new Error("file '" + filePath + "' already exists");
|
||||||
}
|
}
|
||||||
|
|
||||||
const templatePath = fs.embarkPath('lib/modules/scaffolding-react/templates/index.tpl');
|
const templatePath = fs.embarkPath('lib/modules/scaffolding-react/templates/' + templateFilename);
|
||||||
const source = fs.readFileSync(templatePath).toString();
|
const source = fs.readFileSync(templatePath).toString();
|
||||||
const template = Handlebars.compile(source);
|
const template = Handlebars.compile(source);
|
||||||
|
|
||||||
let data = {
|
|
||||||
'title': contract.className
|
|
||||||
};
|
|
||||||
|
|
||||||
// Write template
|
// Write template
|
||||||
const result = template(data);
|
const result = template(data);
|
||||||
fs.writeFileSync(filePath, result);
|
fs.writeFileSync(filePath, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
build(contract){
|
||||||
|
const filename = contract.className.toLowerCase();
|
||||||
|
|
||||||
|
this._generateFile(contract, 'index.html.tpl', 'html',
|
||||||
|
{
|
||||||
|
'title': contract.className,
|
||||||
|
'filename': filename
|
||||||
|
});
|
||||||
|
|
||||||
|
this._generateFile(contract, 'dapp.js.tpl', 'js', {});
|
||||||
|
|
||||||
|
// Update config
|
||||||
|
const contents = fs.readFileSync("./embark.json");
|
||||||
|
let embarkJson = JSON.parse(contents);
|
||||||
|
embarkJson.app["js/" + filename + ".js"] = "app/" + filename + '.js';
|
||||||
|
embarkJson.app[filename + ".html"] = "app/" + filename + '.html';
|
||||||
|
fs.writeFileSync("./embark.json", JSON.stringify(embarkJson, null, 4));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return "File '" + filePath + "' created successfully";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
9
lib/modules/scaffolding-react/templates/dapp.js.tpl
Normal file
9
lib/modules/scaffolding-react/templates/dapp.js.tpl
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import ReactDOM from 'react-dom';
|
||||||
|
import { Tabs, Tab } from 'react-bootstrap';
|
||||||
|
|
||||||
|
ReactDOM.render(<div>
|
||||||
|
ABCDE
|
||||||
|
</div>,
|
||||||
|
document.getElementById('app')
|
||||||
|
);
|
10
lib/modules/scaffolding-react/templates/index.html.tpl
Normal file
10
lib/modules/scaffolding-react/templates/index.html.tpl
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en" dir="ltr">
|
||||||
|
<head>
|
||||||
|
<title>{{title}}</title>
|
||||||
|
</head>
|
||||||
|
<body class="container">
|
||||||
|
<div id="app"></div>
|
||||||
|
<script src="js/{{filename}}.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -1,12 +0,0 @@
|
|||||||
<!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>
|
|
Loading…
x
Reference in New Issue
Block a user