UNPKG

ndc-suez

Version:

Generate standard ndc UI

79 lines 4.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ndcReport = void 0; const schematics_1 = require("@angular-devkit/schematics"); // import * as fs from 'fs-extra'; const ExcelJS = require("exceljs"); const core_1 = require("@angular-devkit/core"); function ndcReport(options) { const dataLabelArray = {}; return (_tree, _context) => { // export const reportTemplateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files/report'), [ (0, schematics_1.applyTemplates)({ classify: core_1.strings.classify, name: options.name, dataLabels: dataLabelArray }), (0, schematics_1.move)((0, core_1.normalize)(`${core_1.strings.classify(options.name)}`)) ]); return (0, schematics_1.chain)([ (tree, _context) => { return new Promise(async (resolve, reject) => { const workbook = new ExcelJS.Workbook(); const header = ['ContractTitle', 'ContractNumber', 'Variant', 'Simulation', 'Author', 'Date', 'Version', 'ReportType', 'CaseNumber', 'Title', 'Warning', 'Warning1', 'Warning2', 'Warning3', 'Warning4', '&=variable_messages', '&=result_messages', 'UserText', 'MESSAGES', '']; const massBalanceIgnore = ['nom_affaire', 'n_affaire', 'variante', 'date', 'simulation', 'etabli_par', 'version_NDC', 'cas', '']; const filePaths = options.filename; for (const [index, filePath] of filePaths.entries()) { console.log('Process: ' + filePath); const buffer = tree.read(filePath); if (!buffer) { console.log('File ' + filePath + ' not found'); return reject(new Error(`File ${filePath} not found`)); } await workbook.xlsx.load(buffer).then(() => { // const worksheet = workbook.getWorksheet(1); const worksheets = workbook.worksheets; if (worksheets.map(x => x.name).includes('MassBalance')) { const dataSheet = workbook.getWorksheet('data'); dataSheet?.eachRow((row, _rowNumber) => { const secondCell = row.getCell(2); const cleanValue = secondCell.value ? secondCell.value.toString() : ''; if (!massBalanceIgnore.includes(cleanValue)) { dataLabelArray[cleanValue] = 'ReType'; } }); // @ts-ignore resolve(tree); } else // usual process for (const worksheet of worksheets) { worksheet.eachRow((row, _rowNumber) => { const firstCell = row.getCell(1); const cleanValue = firstCell.value ? firstCell.value.toString() .replace('&=Tpl.', '').replace('.Label', '') : ''; if (!header.includes(cleanValue)) { if (cleanValue.endsWith('_lbl')) { dataLabelArray[cleanValue] = 'string'; } else { dataLabelArray[cleanValue] = 'ReType'; } } }); } if (index == filePaths.length - 1) { // @ts-ignore resolve(tree); } }).catch(error => reject(error)); } }); }, (0, schematics_1.mergeWith)(reportTemplateSource, schematics_1.MergeStrategy.Overwrite) ]); }; } exports.ndcReport = ndcReport; //# sourceMappingURL=index.js.map