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
50 lines • 1.89 kB
JavaScript
import c from 'chalk';
import fs from 'fs-extra';
import * as path from 'path';
import * as os from 'os';
import { getConfig } from '../../config/index.js';
import { uxLog } from '../utils/index.js';
export class LocalTestProvider {
name = 'localtest';
description = 'Writes in a local file (just for tests, can not work in CI)';
poolStorageLocalFileName = null;
async initialize() {
await this.managePoolStorageLocalFileName();
return this.poolStorageLocalFileName !== null;
}
async getValue(key = null) {
await this.managePoolStorageLocalFileName(key);
if (fs.existsSync(this.poolStorageLocalFileName || '')) {
return fs.readJsonSync(this.poolStorageLocalFileName || '');
}
return {};
}
async setValue(key = null, value) {
await this.managePoolStorageLocalFileName(key);
await fs.writeFile(this.poolStorageLocalFileName || '', JSON.stringify(value, null, 2), 'utf8');
return true;
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async updateActiveScratchOrg(_scratchOrg, _keyValues) {
return null;
}
async managePoolStorageLocalFileName(key = null) {
if (this.poolStorageLocalFileName == null) {
if (key === null) {
const config = await getConfig('user');
const projectName = config.projectName || 'default';
key = `pool_${projectName}`;
}
this.poolStorageLocalFileName = path.join(os.homedir(), `poolStorage_${key}.json`);
uxLog(this, c.grey('Local test storage file: ' + this.poolStorageLocalFileName));
}
}
async userSetup() {
return true;
}
async userAuthenticate() {
// No authentication for testing local files
return true;
}
}
//# sourceMappingURL=localtest.js.map