2018-05-09 21:02:17 +00:00
|
|
|
|
2018-05-10 15:25:31 +00:00
|
|
|
const Handlebars = require('handlebars');
|
|
|
|
|
|
|
|
const fs = require('../../core/fs');
|
|
|
|
const utils = require('../../utils/utils');
|
2018-05-09 21:02:17 +00:00
|
|
|
class ScaffoldingReact {
|
|
|
|
constructor(embark, options){
|
|
|
|
this.embark = embark;
|
|
|
|
this.options = options;
|
|
|
|
}
|
|
|
|
|
2018-05-10 15:25:31 +00:00
|
|
|
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);
|
2018-05-09 21:02:17 +00:00
|
|
|
|
2018-05-10 15:25:31 +00:00
|
|
|
let data = {
|
|
|
|
'title': contract.className
|
|
|
|
};
|
|
|
|
|
|
|
|
// Write template
|
|
|
|
const result = template(data);
|
|
|
|
fs.writeFileSync(filePath, result);
|
|
|
|
|
|
|
|
return "File '" + filePath + "' created successfully";
|
2018-05-09 21:02:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = ScaffoldingReact;
|