UNPKG

sfdx-git-delta

Version:

Generate the sfdx content in source format and destructive change from two git commits

95 lines 3.86 kB
'use strict'; import { join } from 'node:path/posix'; import GitAdapter from '../adapter/GitAdapter.js'; import { getLatestSupportedVersion, isVersionSupported, } from '../metadata/metadataManager.js'; import { MessageService } from './MessageService.js'; import { GIT_FOLDER } from '../constant/gitConstants.js'; import { fileExists, pathExists, readFile, sanitizePath } from './fsUtils.js'; const TO = 'to'; const FROM = 'from'; const SOURCE_API_VERSION_ATTRIBUTE = 'sourceApiVersion'; const SFDX_PROJECT_FILE_NAME = 'sfdx-project.json'; export default class CLIHelper { work; config; gitAdapter; message; constructor(work) { this.work = work; this.config = work.config; this.gitAdapter = GitAdapter.getInstance(work.config); this.message = new MessageService(); } async _validateGitSha() { const errors = []; await Promise.all([FROM, TO].map(async (shaParameter) => { const shaValue = this.config[shaParameter]; try { const ref = await this.gitAdapter.parseRev(shaValue); this.config[shaParameter] = ref; } catch { errors.push(this.message.getMessage('error.ParameterIsNotGitSHA', [ shaParameter, shaValue, ])); } })); return errors; } async validateConfig() { this._sanitizeConfig(); await this._handleDefault(); const errors = []; const repoExists = await pathExists(join(this.config.repo, GIT_FOLDER)); if (!repoExists) { errors.push(this.message.getMessage('error.PathIsNotGit', [this.config.repo])); } const gitErrors = await this._validateGitSha(); errors.push(...gitErrors); if (errors.length > 0) { throw new Error(errors.join(', ')); } await this.gitAdapter.configureRepository(); } async _handleDefault() { await this._getApiVersion(); await this._apiVersionDefault(); } async _getApiVersion() { const isInputVersionSupported = isVersionSupported(this.config.apiVersion); if (!isInputVersionSupported) { const sfdxProjectPath = join(this.config.repo, SFDX_PROJECT_FILE_NAME); const exists = await fileExists(sfdxProjectPath); if (exists) { const sfdxProjectRaw = await readFile(sfdxProjectPath); const sfdxProject = JSON.parse(sfdxProjectRaw); this.config.apiVersion = parseInt(sfdxProject[SOURCE_API_VERSION_ATTRIBUTE]) || -1; } } } _apiVersionDefault() { const isInputVersionSupported = isVersionSupported(this.config.apiVersion); if (!isInputVersionSupported) { const latestAPIVersionSupported = getLatestSupportedVersion(); if (this.config.apiVersion !== undefined && this.config.apiVersion !== null) { this.work.warnings.push(new Error(this.message.getMessage('warning.ApiVersionNotSupported', [ `${latestAPIVersionSupported}`, ]))); } this.config.apiVersion = latestAPIVersionSupported; } } _sanitizeConfig() { this.config.repo = sanitizePath(this.config.repo); this.config.source = sanitizePath(this.config.source); this.config.output = sanitizePath(this.config.output); this.config.ignore = sanitizePath(this.config.ignore); this.config.ignoreDestructive = sanitizePath(this.config.ignoreDestructive); this.config.include = sanitizePath(this.config.include); this.config.includeDestructive = sanitizePath(this.config.includeDestructive); } } //# sourceMappingURL=cliHelper.js.map