-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
59 lines (48 loc) · 1.63 KB
/
app.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
var commander = require('commander');
var fs = require('fs');
var xlsxParse = require('excel');
var ArrayStream = require('arraystream');
var chalk = require('chalk');
var utils = require('./lib/utils');
var months = require('./lib/months');
var streams = require('./lib/streams');
// Parse cli arguments
commander
.version('0.0.1')
.usage('node app.js --in [input file] --out [output file]')
.option('-i, --in <path>', 'An input file')
.option('-o, --out <path>', 'An output file')
.parse(process.argv);
// Set input/output paths
var inputfile = commander.in;
var outputfile = commander.out;
if (inputfile === undefined) {
utils.displayError('--in file was not specified.');
}
if (!fs.existsSync(inputfile)) {
utils.displayError('--in file does not exist.');
}
if (outputfile === undefined) {
utils.displayError('--out file was not specified.');
}
// Create file write stream with output path
streams.createFileOutStream(__dirname + '/output/' + outputfile);
// Kick off the parsing process...
xlsxParse(commander.in, function xlsxParseCallback (err, data) {
if (err) {
utils.displayError('Could not parse xlsx file - ' + err);
}
// Remove the first line of data containing the column headings
data.shift();
// Setup stream event handlers
streams.fileout.on('finish', function () {
console.log(chalk.green('\n--- Finished ---\n'));
});
console.log(chalk.green('--- Processing Events ---\n'));
ArrayStream.create(data)
.pipe(streams.createEvent)
.pipe(streams.eventToMonth)
.pipe(streams.dataTransform)
.pipe(streams.stringify)
.pipe(streams.fileout);
});