/**
* Generates the AstFolder corresponding to a given path and to its potential AstFolder parent
* @param {string} path // The path of the AstFolder
* @param {Language} language
* @returns AstFolderInterface
*/
private generateAstFolder(path: string, language: Language): AstFolderInterface { // ----------------------- +2.6 Complexity index (+0.6 atomic, +2 recursivity)
let astFolder: AstFolderInterface = { // --------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
path: platformPath(path), // ----------------------------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
astFiles: [] // ------------------------------------------------------------------------------------ +0.1 Complexity index (+0.1 atomic)
};
let initService; // ------------------------------------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
switch (language) { // --------------------------------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
case Language.JS: // ------------------------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
case Language.TS: // ------------------------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
case Language.JSX: // ------------------------------------------------------------------------------ +0.3 Complexity index (+0.3 atomic)
case Language.TSX: // ------------------------------------------------------------------------------ +0.3 Complexity index (+0.3 atomic)
initService = new AstFileGenerationService(); // ----------------------------------------------- +0.4 Complexity index (+0.4 atomic)
break
case Language.JAVA: // ----------------------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
initService = new AstFileGenerationJavaService(); // ------------------------------------------- +0.4 Complexity index (+0.4 atomic)
break
default: // ---------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
initService = new AstFileGenerationService(); // ----------------------------------------------- +0.4 Complexity index (+0.4 atomic)
}
const filesOrDirs = fs.readdirSync(path); // ----------------------------------------------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
let currentFile = undefined; // ------------------------------------------------------------------------ +0.3 Complexity index (+0.3 atomic)
try {
filesOrDirs.forEach((elementName: string) => { // -------------------------------------------------- +2.5 Complexity index (+0.5 atomic, +2 structural)
const pathElement = path + elementName; // ----------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
currentFile = pathElement; // ------------------------------------------------------------------ +0.3 Complexity index (+0.3 atomic)
if (!Options.isIgnored(pathElement)) { // ------------------------------------------------------ +3.4 Complexity index (+0.4 atomic, +1 nesting, +2 structural)
if (fs.statSync(pathElement).isDirectory() && !LIMIT_GENERATIONS) { // --------------------- +6.3 Complexity index (+0.8 atomic, +1.5 nesting, +4 structural)
astFolder.children = astFolder.children ?? []; // -------------------------------------- +0.6 Complexity index (+0.6 atomic)
astFolder.children.push(this.generateAstFolder(`${pathElement}/`, language)); // ------- +2.7 Complexity index (+0.7 atomic, +2 structural)
} else if (this.isFileToGenerate(pathElement, language)) { // ------------------------------ +2.5 Complexity index (+0.5 atomic, +2 structural)
astFolder.astFiles.push(initService.generate(pathElement, astFolder)); // -------------- +2.7 Complexity index (+0.7 atomic, +2 structural)
}
}
});
} catch (e) { // --------------------------------------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
const [err, lines] = e.message.split('!!!'); // ---------------------------------------------------- +1.7 Complexity index (+0.7 atomic, +1 structural)
if (lines) { // ------------------------------------------------------------------------------------ +1.7 Complexity index (+0.2 atomic, +0.5 nesting, +1 structural)
console.log(`Error in file: ${currentFile}\nAt line ${lines}`); // ----------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
}
const error = new Error(err); // ------------------------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
error.stack = e.stack; // -------------------------------------------------------------------------- +0.5 Complexity index (+0.5 atomic)
throw error; // ------------------------------------------------------------------------------------ +0.1 Complexity index (+0.1 atomic)
}
return astFolder; // ----------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
}
|