-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplaceAttributes.js
67 lines (49 loc) · 1.74 KB
/
replaceAttributes.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
62
63
64
65
66
67
'use strict'
const fs = require('fs');
const path = require('path');
var directoryJSON = "/Users/brennan/Downloads/render-tool-update/render_templates/customized/";
fs.readdir(directoryJSON, function(err, items) {
/*
//import CSV with Data
var csvImport = fs.readFileSync('import.csv','utf8')
var csvArray = csvImport.split(/\r?\n/);
var cleanedCSVFinal = [];
for(var f=1;f<csvArray.length;f++){
cleanedCSVFinal.push((csvArray[f]).split(','))
}
*/
//console.log(items)
//for files in above directory
for (var i=0; i<items.length; i++) {
//confirm using JSON file
var isJSON = false;
if(items[i].indexOf('json') > -1){isJSON = true}
if(isJSON == false){continue}
//set base templates + iteration file
var filePath = directoryJSON + items[i];
//set vars to inject
//for(var e=0;e<cleanedCSVFinal.length;e++){
// var designNumber = (cleanedCSVFinal[e][1])
//open file in loop
var currentFile = fs.readFileSync(filePath);
let fileJSON = JSON.parse(currentFile);
fileJSON["DPI"] = 210;
/*
//loop through currentJSON
for(var s=0;s < fileJSON["Backgrounds"].length;s++){
//make replacements
fileJSON["Backgrounds"][s].Path = (fileJSON["Backgrounds"][s].Path).replace("1036", '999')
}
*/
//prepare new data for export
let exportData = JSON.stringify(fileJSON, null, 2);
//set export file name
var exportFileName = (items[i]).replace("NAME","NAME")
var exportFileName = (items[i])
//export file
fs.writeFileSync(directoryJSON+"/"+exportFileName, exportData);
//log to console
console.log('saving ' + items[i] + ' as ' + exportFileName)
//}
}
});