Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
// Make folder
const overrideFolder = overrideSettings.configfolder;
if (!readFolder) {
readFolder = "ETCopyData";
}
this.rootFolderRaw = readFolder;
this.rootFolderFull = this.rootFolderRaw;
if (overrideFolder) {
if (readFolder.indexOf(overrideFolder) !== 0) {
this.rootFolderFull = overrideFolder + "/" + readFolder;
}
}
fs.mkdirp(this.rootFolderFull)
.then(() => {
let path: string = "";
path = this.rootFolderFull;
// VERBOSE: Create sub-folders based on time so files do not override
// path += `/${Util.getWallTime(true)}`;
fs.mkdirp(path)
.then(() => {
this.rootFolderFull = path;
resolve(this.rootFolderFull);
});
});
});
}
.then(() => {
let path: string = "";
path = this.rootFolderFull;
// VERBOSE: Create sub-folders based on time so files do not override
// path += `/${Util.getWallTime(true)}`;
fs.mkdirp(path)
.then(() => {
this.rootFolderFull = path;
resolve(this.rootFolderFull);
});
});
});
}
if (purge) {
this.ux.log(`Removing all files inside of ${outDir}`);
try {
await purgeFolder(outDir);
} catch (e) {
this.ux.error(e);
this.exit(1);
return;
}
}
}
} catch (e) { }
await fs.mkdirp(outDir);
if (hasChanges) {
await spawnPromise('sfdx', ['force:source:convert', '-d', outDir], { shell: true, cwd: tmpProject });
}
if (hasDeletions) {
await fsPromise.copyFile(`${tempDeleteProjConverted}/package.xml`, `${outDir}/destructiveChangesPost.xml`);
if (!hasChanges) {
await fsPromise.writeFile(
`${outDir}/package.xml`,
''
);
}
}
} catch (e) {
this.ux.error(e);
this.exit(1);
private async mkTempDir() {
const tempDir = await new Promise((resolve, reject) => {
tmp.dir((err, path) => {
if (err) {
reject(err);
}
resolve(path);
});
});
await fs.mkdirp(tempDir);
return tempDir;
}
for (const path of changed) {
const metadataPaths = await resolveMetadata(path, targetRef);
if (!metadataPaths) {
this.ux.warn(`Could not resolve metadata for ${path}`);
continue;
}
for (let mdPath of metadataPaths) {
if (isAbsolute(mdPath)) {
mdPath = relative(this.projectPath, mdPath);
}
const newPath = join(tempDir, mdPath);
await fs.mkdirp(dirname(newPath));
await copyFileFromRef(mdPath, targetRef, newPath);
}
}
return tempDir;
}
let fetchedCountPerObject = {};
am.on('dumpProgress', status => {
fetchedCount = status.fetchedCount;
fetchedCountPerObject = status.fetchedCountPerObject;
const perObjectCount = Object.keys(fetchedCountPerObject).map(object => `${object}: ${fetchedCountPerObject[object]}`).join(', ');
const message = `fetched count: ${fetchedCount}, ${perObjectCount}`;
this.ux.setSpinnerStatus(message);
});
this.ux.startSpinner('dumping records');
const csvs = await am.dumpAsCSVData(config.targets);
this.ux.stopSpinner();
this.ux.log(`fetched count: ${fetchedCount}`);
try {
await fs.stat(config.outputDir);
} catch (e) {
await fs.mkdirp(config.outputDir);
}
const results = await Promise.all(
config.targets.map(async ({ object }, i) => {
const csv = csvs[i];
const count = fetchedCountPerObject[object] || 0;
const filename = `${object}.csv`;
const filepath = path.join(config.outputDir, filename);
const bom = this.flags.excludebom ? '' : '\ufeff';
await writeFile(filepath, bom + csv, 'utf8');
return { filepath, count };
})
);
this.ux.log();
this.ux.table(
results,
{