From ccb27f8c6a526866484a4f785ca0cc8e77d699a0 Mon Sep 17 00:00:00 2001 From: Christopher Wallace Date: Wed, 30 Nov 2022 11:02:14 -0500 Subject: [PATCH] Added ability to slowly import objects --- package.json | 2 +- src/helpers/env.ts | 1 + src/helpers/sdf.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 902d768..9243411 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ssync", - "version": "0.0.17", + "version": "0.0.18", "description": "Sync a NetSuite environment with a local repository.", "main": "./dist/app.js", "scripts": { diff --git a/src/helpers/env.ts b/src/helpers/env.ts index 9f96a01..de8083b 100644 --- a/src/helpers/env.ts +++ b/src/helpers/env.ts @@ -15,5 +15,6 @@ export default cleanEnv(process.env, { NSENV: str(), GITURL: str(), EXCLUDED: str(), + SLOW: str(), WORKSPACE: str(), }); diff --git a/src/helpers/sdf.ts b/src/helpers/sdf.ts index 9b63dca..e7a45a7 100644 --- a/src/helpers/sdf.ts +++ b/src/helpers/sdf.ts @@ -84,6 +84,7 @@ const importObjects = async () => { CustomObjects.forEach(async (custObject: CustomObject) => { if (ephermeralCustomizations.includes(custObject.type)) return; if (custObject.objects[0] === undefined) return; + console.log(`Attempting to import all ${custObject.type} ...`) const collectOutput = await runCommand(CLICommand.ImportObjects, `--scriptid ALL ` + @@ -105,6 +106,46 @@ const importObjects = async () => { }); }; +const importObjectsSlowly = async () => { + // Ephermeral data customizations should not be supported at this time. + const ephermeralCustomizations = env.EXCLUDED.split(','); + const slowlyImportCustomizations = env.SLOW.split(','); + + CustomObjects.forEach(async (custObject: CustomObject) => { + if (ephermeralCustomizations.includes(custObject.type)) return; + if (custObject.objects[0] === undefined) return; + if (!slowlyImportCustomizations.includes(custObject.type)) return; + console.log(`Attempting to import slow ${custObject.type} ...`) + + // List all objects + custObject.objects = (await runCommand(CLICommand.ListObjects, `--type ${custObject.type}`)) + .stdout + .replace(`\x1B[2K\x1B[1G`, ``) + .split('\n') + .filter(entry => entry.startsWith(custObject.type)) + .map(x => x.split(":")[1]); + + // Import all collected objects + const collectOutput = await runCommand(CLICommand.ImportObjects, + `--scriptid ${custObject.objects.join(" ")} ` + + `--type ${custObject.type} ` + + `--destinationfolder ${custObject.destination} ` + + `--excludefiles` + ); + + if (collectOutput.includes(`The following objects failed with reason "Import custom objects failed.":`)) { + custObject.error = true; + console.error(`Failed to import: ${custObject.type}`); + }; + }); + + CustomObjects.forEach(custObject => { + if (custObject.error) { + console.log(`Failed to import: ${custObject.type}`); + } + }); +}; + export default async function runSdf() { changeDir(); saveNetSuiteToken(); @@ -115,4 +156,5 @@ export default async function runSdf() { importFiles(); await listObjects(); await importObjects(); + await importObjectsSlowly(); }