-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgenerate.js
More file actions
49 lines (41 loc) · 1.03 KB
/
generate.js
File metadata and controls
49 lines (41 loc) · 1.03 KB
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
var fs = require('fs');
var ejs = require("ejs");
var path = require('path');
/**
*
*/
function getDestPath(srcPath) {
var arr = srcPath.split('/');
var filename = arr[arr.length - 1].slice(0, arr.length - 5) + ".html";
return path.resolve(srcPath, '..', '..', 'html', filename);
}
/**
*
*/
function ejs2html(_srcPath, information) {
if (!_srcPath.includes('.')) {
console.log("Wrong path. Include extension within the path.")
}
var srcPath = __dirname + "/" + _srcPath;
var destPath = getDestPath(srcPath);
console.log('src path', srcPath);
console.log('dest path', destPath);
fs.readFile(srcPath, 'utf8', function (err, data) {
if (err) {
console.log(err);
}
var ejs_string = data,
template = ejs.compile(ejs_string, {
filename: srcPath
}),
html = template(information);
fs.writeFile(destPath, html, function(err) {
if (err) {
console.log(err);
}
console.log(destPath + ' is generated');
});
});
}
var arg = process.argv[2];
ejs2html(arg);