UNPKG

@tangelo/tangelo-configuration-toolkit

Version:

Tangelo Configuration Toolkit is a command-line toolkit which offers support for developing a Tangelo configuration.

36 lines (29 loc) 2.18 kB
const fs = require('fs-extra'); const globby = require('globby'); module.exports = function getRepoconfig(repoPath) { return globby .sync('database/config/**/txd_document_types.sql', {cwd: repoPath, absolute: true}) .map(p => { const dtSqlInsert = fs.readFileSync(p).toString().match(/select(.*?)from(?=\s+dual)/s)[1]; const ntSqlInsert = fs.readFileSync(p.replace('txd_document_types', 'txd_node_types')).toString().match(/select(.*?)from(?=\s+dual)/s)[1]; const dtDisplayName = dtSqlInsert.match(/'([^']+)' display_name/)[1]; const ntName = ntSqlInsert.match(/'([^']+)' name/)[1]; const xpiDir = ntSqlInsert.match(/'([^']+)' xsl_prep_inc/)?.[1] ?? dtSqlInsert.match(/'([^']+)' xsl_xincludes/)[1]; const path_cmscustom = xpiDir.replace(/\/[^/]+$/, '').split(/\//); const path_dbconfig = p.replace(/.*\/database\/config\/(.*)\/[^/]+/, '$1').split(/[/\\]/); const dnRegex = [path_cmscustom[0].replace(/[_'"]/g, '.'), path_dbconfig[0].replace(/[_'"]/g, '.')].sort((a, b) => b.length - a.length).join('|'); /* Get customer name based on txd_document_types.display_name; if that match fails fallback to customername defined in path */ const customer_name = (dtDisplayName.match(RegExp(dnRegex, 'i')) || [path_cmscustom[0].split(/[\s_]/g).map(s => s[0].toUpperCase() + s.substring(1)).join(' ')])[0]; const customer_name_regex = RegExp(customer_name.replace(/(\W)/g, '\\$1?'), 'gi'); // match customer name; allow differences in special characters / match case insensitive return { customer_name, customer_abbr: ntName.split('_')[0], /* if display name matches the customer name; strip customer name from display name to get the project name; otherwise use the complete display name as projectname */ project_name: dtDisplayName.match(customer_name_regex) ? dtDisplayName.replace(customer_name_regex, '').trim() : dtDisplayName, project_abbr: ntName.split('_')[1], path_cmscustom, path_dbconfig, id_range: dtSqlInsert.match(/(\d+)\d{3} id/)[1] }; }); };