ndc-suez
Version:
Generate standard ndc UI
77 lines • 4.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ndcExport = 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 ndcExport(options) {
const dataLabelArray = {};
const resultCommentArray = {};
return (_tree, _context) => {
// export
const exportTemplateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files/export'), [
(0, schematics_1.applyTemplates)({
classify: core_1.strings.classify,
name: options.name,
dataLabels: dataLabelArray,
resultComments: resultCommentArray,
}),
(0, schematics_1.move)((0, core_1.normalize)(`${core_1.strings.classify(options.name)}`))
]);
return (0, schematics_1.chain)([
(tree, _context) => {
return new Promise((resolve, reject) => {
const workbook = new ExcelJS.Workbook();
const header = ['ContractTitle', 'ContractNumber', 'Variant', 'Simulation', 'Author', 'Date', 'Version', 'ReportType', 'CaseNumber',
'Title', 'Warning', 'Warning1', 'Warning2', 'Warning3', 'Warning4', ''];
const filePaths = options.filename;
for (const [index, filePath] of filePaths.entries()) {
console.log('Process: ' + filePath);
const buffer = tree.read(filePath);
if (!buffer) {
return reject(new Error(`File ${filePath} not found`));
}
workbook.xlsx.load(buffer).then(() => {
// const worksheet = workbook.getWorksheet(1);
const worksheets = workbook.worksheets;
for (const worksheet of worksheets) {
worksheet.eachRow((row, _rowNumber) => {
var _a;
const firstCell = row.getCell(1);
const cleanValue = firstCell.value ? firstCell.value.toString()
.replace('&=Tpl.', '').replace('.Label', '') : '';
if (!header.includes(cleanValue)) {
if (cleanValue.endsWith('_lbl') || cleanValue.endsWith('_Box')) {
dataLabelArray[cleanValue] = 'string';
}
else {
dataLabelArray[cleanValue] = 'ReType';
}
}
if (cleanValue == '') {
const variable = row.getCell('I');
const value = (_a = variable.value) === null || _a === void 0 ? void 0 : _a.toString().replace('&=Tpl.', '').replace('.Comment', '');
if (value && value != 'CComment' && !dataLabelArray.hasOwnProperty(value)) {
resultCommentArray[value] = 'ReType';
}
}
/*if(firstCell.font && firstCell.font.bold && !header.includes(cleanValue)) {
console.log(cleanValue);
}*/
});
}
if (index == filePaths.length - 1) {
// @ts-ignore
resolve(tree);
}
}).catch(error => reject(error));
}
});
},
(0, schematics_1.mergeWith)(exportTemplateSource, schematics_1.MergeStrategy.Overwrite)
]);
};
}
exports.ndcExport = ndcExport;
//# sourceMappingURL=index.js.map