Skip to content

Commit

Permalink
Added ability to slowly import objects
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherwxyz committed Nov 30, 2022
1 parent fea776d commit ccb27f8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
1 change: 1 addition & 0 deletions src/helpers/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export default cleanEnv(process.env, {
NSENV: str(),
GITURL: str(),
EXCLUDED: str(),
SLOW: str(),
WORKSPACE: str(),
});
42 changes: 42 additions & 0 deletions src/helpers/sdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ` +
Expand 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();
Expand All @@ -115,4 +156,5 @@ export default async function runSdf() {
importFiles();
await listObjects();
await importObjects();
await importObjectsSlowly();
}

0 comments on commit ccb27f8

Please sign in to comment.