JS generation + embark.json configuration update
This commit is contained in:
parent
d1dd890407
commit
c4961d69b6
|
@ -1,35 +1,51 @@
|
|||
|
||||
const Handlebars = require('handlebars');
|
||||
|
||||
const fs = require('../../core/fs');
|
||||
const utils = require('../../utils/utils');
|
||||
|
||||
|
||||
class ScaffoldingReact {
|
||||
constructor(embark, options){
|
||||
this.embark = embark;
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
build(contract){
|
||||
const filename = contract.className.toLowerCase() + '.html';
|
||||
_generateFile(contract, templateFilename, extension, data){
|
||||
const filename = contract.className.toLowerCase() + '.' + extension;
|
||||
const filePath = './app/' + filename;
|
||||
|
||||
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 template = Handlebars.compile(source);
|
||||
|
||||
let data = {
|
||||
'title': contract.className
|
||||
};
|
||||
|
||||
// Write template
|
||||
const result = template(data);
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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')
|
||||
);
|
|
@ -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…
Reference in New Issue