This commit is contained in:
@@ -5,7 +5,15 @@ import color from 'chalk';
|
||||
// VARS =========
|
||||
const STOCK_WARN_AMOUNT = 5;
|
||||
|
||||
const data = fs.readFileSync('data/products.csv', 'utf-8');
|
||||
let data = '';
|
||||
|
||||
try {
|
||||
data = fs.readFileSync('data/products.csv', 'utf-8');
|
||||
} catch (error) {
|
||||
console.log(color.red(error));
|
||||
// Beendet den Prozess erfolgreich (Code 0)
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const products = data.split('\n');
|
||||
const headerAr = products.shift().split(/\s*,\s*/); // => [ 'Code', 'Short Description', 'Tagline', 'Quantity', 'Price' ]
|
||||
@@ -60,9 +68,7 @@ const writeHtmlDocument = (content = '') => {
|
||||
|
||||
const listItems = products
|
||||
.filter((row) => row !== '') // leere String Einträge rausfiltern
|
||||
.map((row) => {
|
||||
return recordToHtml(row);
|
||||
});
|
||||
.map(recordToHtml); // Funktionsreferenz
|
||||
|
||||
const htmlList = `<ul class="list-group">${listItems.join('')}</ul>`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user