// This script creates custom epi elements from our style classes // Parameters [SourceFile, Destination, Regex(without flags), OuterTemplate, InnerTemplate] // Use a grunt plugin such as 'execute' to run this script as a task, run it as a sub task when multiple instances are needed, pass it the correct parameters listed above and below // Example format: //execute: { // colours: { // options: { // Parameters [SourceFile, Destination, Regex(without flags), OuterTemplate, InnerTemplate] // args: ['ClientResources/Styles/ColorClasses.css', 'ClientResources/Scripts/templates/ColorClasses2.html', 'brand(\\-\\w+)+', '
\n', '`\t
${match}
\n`'] // }, // src: ['Static/Scripts/customcomponents/epi-css-property.js'] // } //} //Backup parameters for use in the grunt task //icomoon classes //regex: /icon(\-\w+)+/mgi -> 'icon(\\-\\w+)+' //outer template: `
\n\t\n\t
\n` //inner template: `\t
${matches[i]}
\n` //colour classes //regex: /brand(\-\w+)+/g -> 'brand(\\-\\w+)+' //outer template: `
` //inner template: `\t
{{match}}
\n` if (process.argv.length < 7) { throw new Error("epi-css-property: Incorrect number of arguments, see documentation"); } else { var fileSrc = process.argv[2]; var fileDest = process.argv[3]; var regex = new RegExp(process.argv[4], 'gim'); var page = process.argv[5]; var template = process.argv[6]; var fs = require('fs'); const vm = require('vm'); } if (fs.existsSync(fileSrc)) { //Open the source file try { var lines = fs.readFileSync(fileSrc, 'utf-8'); } catch (e) { console.log('Error: ', e.stack); } //console.log(lines); //scrape the source file with the regex to exrtract the classes if (lines) { var matches = lines.match(regex) //console.log(matches) } if (matches) { //Create the output template and iterate over the classes to generate elements from var numProperties = matches.length; for (var i = 0; i < numProperties; i++) { //page += `\t
${matches[i]}
\n`; page += vm.runInNewContext(template, { match: matches[i] }) } //closing div tag page += `
`; //console.log(page) //Save the HTML file to the destination specified fs.writeFile(fileDest, page, (err) => { if (err) throw err; console.log('Created: ' + fileDest); }); } else { console.log("No matches we're found, the epi properties html file was not created."); } } else { console.log("Source file does not exist: " + fileSrc); }