boilerplate.js
Version:
Development Tools
64 lines (45 loc) • 2.17 kB
JavaScript
function createPageComponent(param) {
var pathCC = (toCamelCase(param[0]));
if (param.length > 2) { createPageSubComponent(param); return; }
var filePath = path.resolve(config.js.dir + `/page/${pathCC}/${param[1]}.js`);
fs.createFile(filePath, err => {
if (!err) {
if (fs.readFileSync(filePath).toString().length === 0) {
fs.appendFileSync(filePath, `// How To Use -> $this.${param[1]}();
page('${pathCC.split('/').join('.')}.components.${param[1]}', () => {
// Your Code Here
});
`);
console.log('Created: ' + filePath);
} else {
console.log('Already Exists: ' + filePath);
}
}
});
}
function createPageSubComponent(param) {
var pathCC = (toCamelCase(param[0]));
var folder = param[1];
var fileName = param[2];
var filePath = path.resolve(config.js.dir + `/page/${pathCC}/${folder}/${fileName}.js`);
fs.createFile(filePath, err => {
if (!err) {
if (fs.readFileSync(filePath).toString().length === 0) {
fs.appendFileSync(filePath, `// How To Use From Anywhere -> page.${pathCC.split('/').join('.')}.components.${folder}.${fileName}();
// How To Use From Current Page -> $this.${folder}.${fileName}();
page('${pathCC.split('/').join('.')}.components.${folder}.${fileName}', () => {
// Your Code Here
});
`);
console.log('Created: ' + filePath);
// fs.readFile(global.jsInit, function (err, data) {
// data.indexOf(`${pathCC.split('/').join('.')}.components.${folder} = {};`) < 0 ? fs.appendFileSync(global.jsInit, `\r\n${pathCC.split('/').join('.')}.components.${folder} = {};`) : console.log('Object Already Exists In init.js');;
// });
// console.log('Adding Component To init.js');
} else {
console.log('Already Exists: ' + filePath);
}
}
});
}
module.exports = { createPageComponent };