-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·62 lines (50 loc) · 1.43 KB
/
cli.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
53
54
55
56
57
58
59
60
61
#!/usr/bin/env node
const fs = require('fs');
const parseDir = require('./src/parse-directory.js');
const ProgressBar = require('progress')
const ejs = require('ejs')
const destinationPath = (process.argv[3] || ".")
const destinationFile = (destinationPath + "/Assets.elm")
if (!!process.argv[2]) {
var filesInPath = parseDir(process.argv[2]);
var bar =
new ProgressBar(':bar\n:current of :total svg files processed',
{ total: filesInPath.length, width: 80 }
);
console.log("Creating a new Assets.elm file in " + destinationPath);
if (fs.existsSync(destinationFile)) {
fs.unlink(destinationFile);
}
ejs.renderFile("./src/templates/Assets.header.elm.ejs",
{},
'utf8',
function(err, str){
fs.appendFileSync(destinationFile, str);
}
);
filesInPath.forEach(function(element) {
const svgContent =
fs.readFileSync(element.path, 'utf8')
.replace(/<!--(.*?)-->/gm, "");
ejs.renderFile("./src/templates/Assets.function.elm.ejs",
{ elmFunction: {
name: element.name,
body: svgContent
}
},
'utf8',
function(err, str) {
fs.appendFileSync(destinationFile, str);
}
);
bar.tick();
});
console.log();
} else {
console.error("No directory, please provide one a directory with svg files.");
process.exit(1);
}
process.on('uncaughtException', err => {
console.log(`Uncaught exception:\n`, err);
process.exit(1);
});