|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -var Promise = require('bluebird'); |
4 | | -var fs = Promise.promisifyAll(require('fs')); |
5 | | -var path = require('path'); |
| 3 | +const Promise = require('bluebird'); |
| 4 | + |
| 5 | +const fs = Promise.promisifyAll(require('fs')); |
| 6 | +const path = require('path'); |
6 | 7 |
|
7 | 8 | require('graceful-fs').gracefulify(fs); |
8 | 9 |
|
9 | | -var PATH = path.join(__dirname, require('./constants').ROOT_FOLDER + 'proc/'); |
10 | | -var RWY_REGEXP = /^\d\d[LCR]?$/; |
| 10 | +const PATH = path.join(__dirname, `${require('./utils').ROOT_FOLDER}proc/`); |
| 11 | +const RWY_REGEXP = /^\d\d[LCR]?$/; |
11 | 12 |
|
12 | | -var waypoints = require('./compiled-data/waypoints.json'); |
13 | | -var navaids = require('./compiled-data/navaids.json'); |
| 13 | +const waypoints = require('./compiled-data/waypoints.json'); |
| 14 | +const navaids = require('./compiled-data/navaids.json'); |
| 15 | +const fileList = require('./utils').readDir(PATH); |
14 | 16 |
|
15 | | -var promises = []; |
16 | | -var fileList = require('./constants').readDir(PATH); |
17 | | -var SID = {}; |
| 17 | +let promises = [], SID = {}; |
18 | 18 |
|
19 | | -fileList.forEach(function (file) { |
20 | | - promises.push(new Promise(function (resolve, reject) { |
21 | | - var airportName = file.substring(0, file.indexOf('.txt')); |
| 19 | +fileList.forEach(file => { |
| 20 | + promises.push(new Promise(resolve => { |
| 21 | + const airportName = file.substring(0, file.indexOf('.txt')); |
22 | 22 |
|
23 | 23 | fs.readFileAsync(PATH + file, 'utf-8') |
24 | | - .then(function (data) { parseFile(data, airportName); }) |
| 24 | + .then(data => parseFile(data, airportName)) |
25 | 25 | .then(resolve); |
26 | 26 | })); |
27 | 27 | }); |
28 | 28 |
|
29 | | -Promise.all(promises).then(writeFile); |
| 29 | +// new Promise(resolve => { |
| 30 | +// console.log('Parsing SID data'); |
| 31 | +// Promise.all(promises).then(writeFile).then(resolve); |
| 32 | +// }); |
| 33 | + |
| 34 | +module.exports = { |
| 35 | + promises: promises, |
| 36 | + writeFile: writeFile |
| 37 | +}; |
30 | 38 |
|
31 | 39 | // Callback functions |
32 | 40 | function parseFile (fileContent, airportName) { |
33 | 41 | // Splits each block (may contain SID, STAR, Final...) |
34 | | - var temp = fileContent.split('\r\n\r\n'); |
| 42 | + let temp = fileContent.split('\r\n\r\n'); |
35 | 43 | temp.shift(); |
36 | 44 | fileContent = []; // Empties fileContent for SID filters |
37 | 45 |
|
38 | 46 | // Filters SID blocks and pushes to fileContent |
39 | | - temp.forEach(function (block) { |
| 47 | + temp.forEach(block => { |
40 | 48 | if (block.indexOf('SID') === 0) fileContent.push(block); |
41 | 49 | }); |
42 | 50 |
|
43 | 51 | if (fileContent.length === 0) return; |
44 | 52 |
|
45 | 53 | SID[airportName] = []; |
46 | 54 |
|
47 | | - for (var blocks = 0; blocks < fileContent.length; blocks++) { |
| 55 | + for (let blocks = 0; blocks < fileContent.length; blocks++) { |
48 | 56 | // Splits each SID block by line (SID line) |
49 | 57 | fileContent[blocks] = fileContent[blocks].split('\r\n'); |
50 | 58 |
|
51 | | - var obj = { |
| 59 | + let obj = { |
52 | 60 | name: undefined, |
53 | 61 | runway: undefined, |
54 | 62 | waypoints: [] |
55 | 63 | }; |
56 | 64 |
|
57 | | - for (var lines = 0; lines < fileContent[blocks].length; lines++) { |
| 65 | + for (let lines = 0; lines < fileContent[blocks].length; lines++) { |
58 | 66 | // Splits each SID line by element |
59 | 67 | fileContent[blocks][lines] = fileContent[blocks][lines].split(','); |
60 | 68 |
|
61 | | - var potentialWaypoint = fileContent[blocks][lines][1]; |
| 69 | + const potentialWaypoint = fileContent[blocks][lines][1]; |
62 | 70 | if (lines > 0 && (waypoints[potentialWaypoint] || navaids[potentialWaypoint])) { |
63 | 71 | obj.waypoints.push(fileContent[blocks][lines][1].trim()); |
64 | | - |
65 | | - // SID[airportName][SID[airportName].length - 1].waypoints.push({ |
66 | | - // fix: fileContent[blocks][lines][1], |
67 | | - // altRes: 0 ? undefined : fileContent[blocks][lines][13], |
68 | | - // spdRes: 0 ? undefined : fileContent[blocks][lines][11] |
69 | | - // }); |
70 | 72 | } |
71 | 73 | } |
72 | 74 |
|
73 | | - var descriptor = fileContent[blocks][0]; |
74 | | - var name = String(descriptor[1]).trim(); |
75 | | - var runway = String(descriptor[2]).trim(); |
| 75 | + const descriptor = fileContent[blocks][0]; |
| 76 | + const name = String(descriptor[1]).trim(); |
| 77 | + const runway = String(descriptor[2]).trim(); |
76 | 78 |
|
77 | 79 | if (name) obj.name = name; |
78 | 80 | if (RWY_REGEXP.test(runway)) obj.runway = runway; |
|
0 commit comments