@copado/copado-cli
Version:
Copado Developer CLI
69 lines • 2.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SfdxFileSystem = void 0;
const core_1 = require("@salesforce/core");
const core_2 = require("@oclif/core");
core_1.Messages.importMessagesDirectory(__dirname);
const messages = core_1.Messages.loadMessages('@copado/copado-cli', 'copado_auth');
const logSymbols = require('log-symbols');
/**
* Main class for sfdx filesystem API. Here are all method related to sfdx file handling.
* @export
* @class SfdxFileSystem
*/
class SfdxFileSystem {
/**
* "targetusername" parameter and "defaultusername" parameter can be either a username or alias.
* This method converts alias in username and check if username exists.
* @param targetUsName
*/
static async getUserName(targetUsName) {
const userNames = await core_1.AuthInfo.listAllAuthorizations().then(auth => {
return auth === null || auth === void 0 ? void 0 : auth.map(authfile => authfile.username);
});
const stateAggregator = await core_1.StateAggregator.getInstance();
const userName = stateAggregator.aliases.resolveUsername(targetUsName);
if (!userName && !userNames.includes(targetUsName)) {
throw new core_1.SfError(messages.getMessage('noUserNameFound'));
}
return userName ? userName : targetUsName;
}
/**
* Returns info stored in local files regarding the "username"
* @param targetUser
*/
static async getUserInfo(targetUser) {
return await core_1.AuthInfo.create({
username: targetUser
});
}
/**
* Gets "defaultusername" property from config file: sfdx-config.json
*/
static async getDefaultUserName() {
return await core_1.ConfigAggregator.create().then(defaultConfig => defaultConfig.getPropertyValue('target-org')) || await core_1.ConfigAggregator.create().then(defaultConfig => defaultConfig.getPropertyValue('defaultusername'));
}
/**
* Check if current Org is an Scratch Org
* @param devHubUsername
*/
static async isScratchOrg(devHubUsername) {
// If authinfo does not contain "devHubUsername" it is not a ScratchOrg
if (!devHubUsername) {
core_2.ux.action.stop(logSymbols.error);
throw new core_1.SfError(messages.getMessage('noScratchOrg'));
}
}
/**
* Check if scratch org is expired
* @param expDate
*/
static async isExpired(expDate) {
const now = new Date();
const today = new Date(now.getFullYear(), now.getMonth(), now.getDay());
if (today > new Date(expDate))
throw new core_1.SfError(messages.getMessage('scratchOrgExpired'));
}
}
exports.SfdxFileSystem = SfdxFileSystem;
//# sourceMappingURL=sfdxfilesystem.js.map