From 2ad0a7fa4c9ef840b74e56020c3015c25c4190e0 Mon Sep 17 00:00:00 2001 From: mit-27 Date: Thu, 25 Jul 2024 04:31:47 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Update=20connectorUpdate=20scrip?= =?UTF-8?q?t=20and=20fix=20doc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/open-source/contributors/build.mdx | 2 +- packages/api/scripts/connectorUpdate.js | 35 ++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/docs/open-source/contributors/build.mdx b/docs/open-source/contributors/build.mdx index af4259a2e..bf1965984 100644 --- a/docs/open-source/contributors/build.mdx +++ b/docs/open-source/contributors/build.mdx @@ -180,7 +180,7 @@ For the sake of this guide, let's map the common object `contact` under `crm` ca docker build -t validate_connectors -f ./packages/api/Dockerfile.validate-connectors . ``` ```bash - docker run -v $(pwd):/app/ -e VERTICAL=crm -e OBJECT_TYPE=contact validate_connectors + docker run -v "$(pwd):/app/" -e VERTICAL=crm -e OBJECT_TYPE=contact validate_connectors ``` The script will automatically scan the `/crm/contact/services` folder and detect any new service folder so all dependencies and imports are updated across the codebase. diff --git a/packages/api/scripts/connectorUpdate.js b/packages/api/scripts/connectorUpdate.js index 437928172..b8eb6f582 100755 --- a/packages/api/scripts/connectorUpdate.js +++ b/packages/api/scripts/connectorUpdate.js @@ -231,7 +231,7 @@ function updateArrayInFile(filePath, arrayName, newArray) { updateFileContents(filePath, newContents); } -function updateModuleFile(moduleFile, newServiceDirs) { +function updateModuleFileForService(moduleFile, newServiceDirs) { let moduleFileContent = fs.readFileSync(moduleFile, 'utf8'); // Generate and insert new service imports @@ -258,6 +258,34 @@ function updateModuleFile(moduleFile, newServiceDirs) { fs.writeFileSync(moduleFile, moduleFileContent); } +function updateModuleFileForMapper(moduleFile, newServiceDirs, objectType) { + let moduleFileContent = fs.readFileSync(moduleFile, 'utf8'); + objectType = objectType.charAt(0).toUpperCase() + objectType.slice(1); + + // Generate and insert new service imports + newServiceDirs.forEach((serviceName) => { + const mapperClass = + serviceName.charAt(0).toUpperCase() + serviceName.slice(1) + objectType + 'Mapper'; + const importStatement = `import { ${mapperClass} } from './services/${serviceName}/mappers';\n`; + if (!moduleFileContent.includes(importStatement)) { + moduleFileContent = importStatement + moduleFileContent; + } + + // Add new service to the providers array if not already present + const providerRegex = /providers: \[\n([\s\S]*?)\n \],/; + const match = moduleFileContent.match(providerRegex); + if (match && !match[1].includes(mapperClass)) { + const updatedProviders = match[1] + `\n ${mapperClass},\n`; + moduleFileContent = moduleFileContent.replace( + providerRegex, + `providers: [\n${updatedProviders} ],`, + ); + } + }); + + fs.writeFileSync(moduleFile, moduleFileContent); +} + function updateEnumFile(enumFilePath, newServiceDirs, vertical) { let fileContent = fs.readFileSync(enumFilePath, 'utf8'); const base = vertical.substring(0, 1).toUpperCase() + vertical.substring(1); @@ -328,7 +356,7 @@ function updateInitSQLFile(initSQLFile, newServiceDirs, vertical) { let newLines = newServiceDirs .map((serviceName) => { const columnName = `${vertical.toLowerCase()}_${serviceName.toLowerCase()}`; - return ` ${columnName} boolean NOT NULL,\n`; + return ` ${columnName} boolean NULL,\n`; }) .join(''); @@ -439,7 +467,8 @@ function updateObjectTypes(baseDir, objectType, vertical) { `../src/${vertical}/${objectType.toLowerCase()}/${objectType.toLowerCase()}.module.ts`, ); - updateModuleFile(moduleFile, newServiceDirs, servicesDir); + updateModuleFileForService(moduleFile, newServiceDirs); + updateModuleFileForMapper(moduleFile, newServiceDirs, objectType) // Path to the mappings file // const mappingsFile = path.join(