ndc-suez
Version:
Generate standard ndc UI
95 lines • 4.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ndcMatlab = void 0;
const schematics_1 = require("@angular-devkit/schematics");
const fs = require("fs-extra");
const ExcelJS = require("exceljs");
const core_1 = require("@angular-devkit/core");
// import {normalize, strings} from "@angular-devkit/core";
function ndcMatlab(options) {
const successfullCopies = [];
const errorCopies = [];
const successTemplateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files/success'), [
(0, schematics_1.applyTemplates)({
success: successfullCopies
}),
(0, schematics_1.move)((0, core_1.normalize)(`${options.destinationPath}`))
]);
const errorTemplateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files/error'), [
(0, schematics_1.applyTemplates)({
error: errorCopies
}),
(0, schematics_1.move)((0, core_1.normalize)(`${options.destinationPath}`))
]);
return (0, schematics_1.chain)([
(tree, _context) => {
// Ensure source exists
if (!fs.existsSync(options.sourcePath)) {
throw new Error(`Source path does not exist: ${options.sourcePath}`);
}
// Create destination directory if it doesn't exist
if (!fs.existsSync(options.destinationPath)) {
fs.mkdirSync(options.destinationPath, { recursive: true });
}
// Copy Init.m
fs.copyFileSync(`${options.sourcePath}/common/Init.m`, `${options.destinationPath}/Init.m`);
return new Promise(async (resolve, reject) => {
const workbook = new ExcelJS.Workbook();
const buffer = tree.read(options.spec);
if (!buffer) {
return reject(new Error(`Spec file ${options.spec} not found`));
}
await workbook.xlsx.load(buffer);
const worksheet = workbook.getWorksheet('scripts');
worksheet?.eachRow((row, rowNumber) => {
if (rowNumber > 1) {
const firstCell = row.getCell(1);
const noteFolder = firstCell.value;
if (!noteFolder) {
throw new Error(`Cannot detect note folder, see first cell value of script tab in spec`);
}
const script = row.getCell(2);
let scriptName = script?.value?.toString();
if (scriptName) {
const version = row.getCell(3)?.value?.toString();
scriptName = scriptName + '.m';
const destinationPath = `${options.destinationPath}/${scriptName}`;
const normPath = `${options.sourcePath}/${noteFolder}/${version}/${scriptName}`;
if (fs.existsSync(normPath)) {
fs.copyFileSync(normPath, destinationPath);
successfullCopies.push({
Name: scriptName, Version: version
});
// @ts-ignore
resolve(tree);
}
else {
const commonPath = `${options.sourcePath}/common/${version}/${scriptName}`;
if (fs.existsSync(commonPath)) {
fs.copyFileSync(commonPath, destinationPath);
successfullCopies.push({
Name: scriptName, Version: version
});
// @ts-ignore
resolve(tree);
}
else {
errorCopies.push({
Name: scriptName, Version: version
});
// throw new Error(`${scriptName} not found`);
}
}
}
}
});
});
// copyFilesRecursively(options.sourcePath, options.destinationPath);
// return tree;
},
(0, schematics_1.mergeWith)(successTemplateSource, schematics_1.MergeStrategy.Overwrite),
(0, schematics_1.mergeWith)(errorTemplateSource, schematics_1.MergeStrategy.Overwrite)
]);
}
exports.ndcMatlab = ndcMatlab;
//# sourceMappingURL=index.js.map