-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (30 loc) · 1.12 KB
/
index.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
#!/usr/bin/env node
const fs = require('fs');
const program = require('commander');
const {parseData, processData} = require('./data-processing');
// Commander.js program configuration
program.version('0.0.1')
.arguments('<inputFile> <outputFile>') // Require file names as cmd arguments
.action((inputFile, outputFile) => {
if (!inputFile || !outputFile) {
throw new Error('Input and output files are required');
}
let inputFileContent;
try {
inputFileContent = fs.readFileSync(inputFile, 'UTF-8');
} catch (error) {
console.error('Could not open input file, check its path');
throw error;
}
// Parse data
const data = parseData(inputFileContent);
// Process data
const result = processData(data);
// Format result for output
const formattedResult = result
.map(item => `${item.text}: ${item.modulus}`) // ES6 template literals
.join('\n');
// Write output to file
fs.writeFileSync(outputFile, formattedResult);
})
.parse(process.argv);