-
Notifications
You must be signed in to change notification settings - Fork 0
/
xls-php-parser.js
50 lines (47 loc) · 2.13 KB
/
xls-php-parser.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
// Node app for parsing xls file and php file and merging the xls info into the php file.
// var unparse = require('php-unparser');
var php_category_parser = require('./modules/php_category_parser.js');
var xls_dealer_parser = require('./modules/xls_dealer_parser.js');
var php_dealer_parser = require('./modules/php_dealer_parser.js');
var php_maker = require('./modules/php_dealer_creater');
var updates_array_creator = require('./modules/updates_array_creator.js');
var fs = require('fs');
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('What is the path to the XLS file? ', (answer1) => {
answer1 = 'dealers.xls';
var dealersXLSInfo = xls_dealer_parser(answer1);
rl.question('What is the path to the dealers PHP file? ', (answer2) => {
answer2 = 'dealers.php';
var dealersPHPInfo = php_dealer_parser(answer2);
rl.question('What is the path to the categories PHP file? ', (answer3) => {
answer3 = 'categories.php';
var categories = php_category_parser(answer3);
if (typeof dealersXLSInfo[0] === 'string') {
console.log("Error: ", dealersXLSInfo[0]);
} else if (typeof dealersPHPInfo[0] === 'string') {
console.log("Error: ", dealersPHPInfo[0]);
} else if (typeof categories[0] === 'string') {
console.log("Error: ", categories[0]);
} else {
var dealersToUpdate = updates_array_creator(categories, dealersXLSInfo);
dealersToUpateCreator(dealersToUpdate, dealersPHPInfo);
php_maker(dealersPHPInfo[0], dealersPHPInfo[1]);
}
rl.close();
});
});
});
function dealersToUpateCreator(dealersToUpdate, dealersPHPInfo) {
dealersToUpdate.map(function(updatedInfo, index) {
var key = Object.keys(updatedInfo)[0];
if ( key === dealersPHPInfo[0][index][0]) {
dealersPHPInfo[0][index][2] = updatedInfo[key].emails_cc;
dealersPHPInfo[0][index][3] = updatedInfo[key].models;
}
return updatedInfo;
});
}