sfdx-hardis
Version:
Swiss-army-knife Toolbox for Salesforce. Allows you to define a complete CD/CD Pipeline. Orchestrate base commands and assist users with interactive wizards
69 lines (65 loc) • 3.37 kB
JavaScript
/* jscpd:ignore-start */
import { SfCommand, Flags, requiredOrgFlagWithDeprecations } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
import c from 'chalk';
import { isCI, uxLog } from '../../../../common/utils/index.js';
import { importData, selectDataWorkspace } from '../../../../common/utils/dataUtils.js';
import { promptOrgUsernameDefault } from '../../../../common/utils/orgUtils.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('sfdx-hardis', 'org');
export default class DataImport extends SfCommand {
static title = 'Import data';
static description = `Import/Load data in an org using a [SFDX Data Loader](https://help.sfdmu.com/) Project
If you need to run this command in a production org, you need to either:
- Define **sfdmuCanModify** in your .sfdx-hardis.yml config file. (Example: \`sfdmuCanModify: prod-instance.my.salesforce.com\`)
- Define an environment variable SFDMU_CAN_MODIFY. (Example: \`SFDMU_CAN_MODIFY=prod-instance.my.salesforce.com\`)
See article:
[](https://nicolas.vuillamy.fr/how-to-detect-bad-words-in-salesforce-records-using-sfdx-data-loader-and-sfdx-hardis-171db40a9bac)
`;
static examples = ['$ sf hardis:org:data:import'];
static flags = {
path: Flags.string({
char: 'p',
description: 'Path to the sfdmu workspace folder',
}),
debug: Flags.boolean({
char: 'd',
default: false,
description: messages.getMessage('debugMode'),
}),
websocket: Flags.string({
description: messages.getMessage('websocket'),
}),
skipauth: Flags.boolean({
description: 'Skip authentication check when a default username is required',
}),
'target-org': requiredOrgFlagWithDeprecations,
};
// Set this to true if your command requires a project workspace; 'requiresProject' is false by default
static requiresProject = false;
// List required plugins, their presence will be tested before running the command
static requiresSfdxPlugins = ['sfdmu'];
/* jscpd:ignore-end */
async run() {
const { flags } = await this.parse(DataImport);
let sfdmuPath = flags.path || null;
// Identify sfdmu workspace if not defined
if (sfdmuPath == null) {
sfdmuPath = await selectDataWorkspace({ selectDataLabel: 'Please select a data workspace to IMPORT' });
}
// Select org that where records will be imported
let orgUsername = flags['target-org'].getUsername();
if (!isCI) {
orgUsername = await promptOrgUsernameDefault(this, orgUsername || '', { devHub: false, setDefault: false });
}
// Export data from org
await importData(sfdmuPath || '', this, {
targetUsername: orgUsername,
});
// Output message
const message = `Successfully import data from sfdmu project ${c.green(sfdmuPath)} into org ${c.green(orgUsername)}`;
uxLog(this, c.cyan(message));
return { outputString: message };
}
}
//# sourceMappingURL=import.js.map