-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate-creator.js
45 lines (34 loc) · 1.37 KB
/
template-creator.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
const fs = require('fs');
fs.readFile( './alopeyk.build.json', function (err, data) {
if (err) {
throw err;
}
const jsonContent = JSON.parse(data);
let srcFile = Object.keys(jsonContent.templates)[0];
let targetFile = jsonContent.templates[srcFile];
let finalObj = {};
fs.readFile( './build_scripts/local-variable.sh', function( err, data ){
for( let item of jsonContent.variables )
{
fileContext = data.toString();
const regex = new RegExp("(?=" + item.toString() + ")(.*)");
let fetchedData = regex.exec( fileContext );
nextRegex = /=(.*)/g;
fetchedData = nextRegex.exec( fetchedData[0].trim() );
finalObj[item] = fetchedData[0].replace("=", "");
}
fs.createReadStream( srcFile ).pipe(fs.createWriteStream( targetFile ));
fs.readFile( targetFile, function( err, data ){
fileContext = data.toString();
jsonContent.variables.map( item => {
fileContext = fileContext.replace( '<' + item.trim() + '>', finalObj[item]);
});
fs.writeFile( targetFile, fileContext, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
});
});
});