-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.js
executable file
·53 lines (46 loc) · 1.49 KB
/
generator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// --{{
// Module to generate files
// }}
const fs = require('fs')
const path = require('path')
// Temlplates for files
let cssBase = `/*Genrated via blush-script*/\n
*{
padding:0px;
margin:0px;
box-sizing:border-box;
} `;
const startHTML = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<!-- GENERATED VIA blush-js -->`;
const closingHTML= `</body>\n</html>`;
//generateFiles function which takes three parameters: type of files, folderPath , array of files..
// The files are downloaded in home directory where the are found
exports.generateFiles = (type,folderPath,array)=>{
if(type=="css"){
let basecont=`${cssBase}\n`;
array.forEach(elem=>{
const cssfiles = fs.readFileSync(path.join(path.sep,`${folderPath}`,`blush-css`,`${elem}.css`),`utf8`)
basecont +=`\n${cssfiles}\n`
})
fs.writeFileSync(`style.css`,`${basecont}`)
console.log('css was generated at ./style.css')
}
else{
let basecont=``;
array.forEach(elem=>{
const htmlfiles = fs.readFileSync(path.join(path.sep,`${folderPath}`,`blush-html`,`${elem}.html`),`utf8`)
basecont +=`\n${htmlfiles}\n`
})
fs.writeFileSync(`index.html`,`${startHTML}\n${basecont}\n${closingHTML}`)
console.log('html was generated at ./index.html')
}
}