Skip to content

Commit

Permalink
feat(dependency:install): add release def filter v2 (#108)
Browse files Browse the repository at this point in the history
* feat(dependency:install): add release def filter

* fix(fht): fht/ft not being applied for post deployment (#101)

* fix(fht): fht/ft not being applied for post deployment

* chore: remove unecessary workingDirectory attribute on fht yml file path

* Revert "chore: remove unecessary workingDirectory attribute on fht yml file path"

This reverts commit a82cd0a.

* chore: set default value for working directory

* fix: release parameter and display header info

* fix: release parameter and display header info

* chore: refactor command log

* chore: remove unecessary var

* chore: refact command logger constructor

* refactor(logger): refactor methods to better naming

* refactor(logger): refactor methods to better naming

* refactor(logger): refactor methods to better naming

* chore: rename commandLogger to CommandHeaderDisplayer

* refactor(logger): add default contructor value

---------

Co-authored-by: Alan Jaouen <[email protected]>
  • Loading branch information
dieffrei and alanjaouen authored Aug 6, 2024
1 parent 6138447 commit 644f700
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 15 deletions.
7 changes: 4 additions & 3 deletions messages/dependency_install.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"commandDescription":"Install all the external dependencies of a given project",
"installationkeysFlagDescription":"Installation key for key-protected packages (format is packagename:key --> core:key nCino:key vlocity:key to allow some packages without installation key)"
}
"commandDescription":"Install all the external dependencies of a given project",
"configFileFlagDescription":"Path to the config file which determines which external dependency are being installed based on packages in release config",
"installationkeysFlagDescription":"Installation key for key-protected packages (format is packagename:key --> core:key nCino:key vlocity:key to allow some packages without installation key)"
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
},
"scripts": {
"prepare": "husky",
"watch": "npm run compile -- --watch",
"build": "npm run clean && npm run compile",
"docs": "oclif readme --no-aliases --multi --dir=docs --repository-prefix https://github.com/flxbl-io/sfp",
"manifest": "oclif manifest",
Expand Down
46 changes: 34 additions & 12 deletions src/commands/dependency/install.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import SfpCommand from '../../SfpCommand';
import { Messages } from '@salesforce/core';
import {Messages} from '@salesforce/core';
import ExternalPackage2DependencyResolver from '../../core/package/dependencies/ExternalPackage2DependencyResolver';
import ProjectConfig from '../../core/project/ProjectConfig';
import SFPLogger, { COLOR_KEY_MESSAGE, ConsoleLogger, LoggerLevel } from '@flxbl-io/sfp-logger';
import SFPLogger, {COLOR_KEY_MESSAGE, ConsoleLogger, VoidLogger} from '@flxbl-io/sfp-logger';
import ExternalDependencyDisplayer from '../../core/display/ExternalDependencyDisplayer';
import InstallUnlockedPackageCollection from '../../core/package/packageInstallers/InstallUnlockedPackageCollection';
import SFPOrg from '../../core/org/SFPOrg';
import { Flags } from '@oclif/core';
import { loglevel, targetdevhubusername, requiredUserNameFlag } from '../../flags/sfdxflags';
import {Flags} from '@oclif/core';
import {loglevel, requiredUserNameFlag, targetdevhubusername} from '../../flags/sfdxflags';
import ReleaseConfigLoader from '../../impl/release/ReleaseConfigLoader';
import CommandHeaderDisplayer from "../../core/display/CommandHeaderDisplayer";

// Initialize Messages with the current plugin directory
Messages.importMessagesDirectory(__dirname);
Expand All @@ -30,32 +32,52 @@ export default class Install extends SfpCommand {
required: false,
description: messages.getMessage('installationkeysFlagDescription'),
}),
releaseconfig: Flags.string({
char: 'r',
required: false,
description: messages.getMessage('configFileFlagDescription'),
}),
loglevel
};

private displayReleaseInfo(releaseConfigPath: string, hasInstallationKeys: boolean, userName: string) {
const logger: CommandHeaderDisplayer = new CommandHeaderDisplayer()
.headerLine()
.headerAttribute('command', 'dependency install')
.headerAttribute('target-org', `${userName}`)
.headerAttributeIf(releaseConfigPath != null, 'release-config', `${releaseConfigPath}`)
.headerAttributeIf(hasInstallationKeys, 'Has Installation Keys', `${hasInstallationKeys}`)
.headerLine();
}


public async execute(): Promise<any> {
// this.org is guaranteed because requiresUsername=true, as opposed to supportsUsername
const username = this.org.getUsername();

this.displayReleaseInfo(this.flags.releaseconfig, !!this.flags.installationkeys, username);

//Resolve external package dependencies
let externalPackageResolver = new ExternalPackage2DependencyResolver(
this.hubOrg.getConnection(),
ProjectConfig.getSFDXProjectConfig(null),
this.flags.installationkeys
);
let externalPackage2s = await externalPackageResolver.resolveExternalPackage2DependenciesToVersions();

SFPLogger.log(
`Installing external package dependencies of this project in ${username}`,
LoggerLevel.INFO,
new ConsoleLogger()
);
//Display resolved dependenencies
let packages = null;
if (this.flags.releaseconfig) {
let releaseConfigLoader: ReleaseConfigLoader = new ReleaseConfigLoader(new ConsoleLogger(), this.flags.releaseconfig);
packages = releaseConfigLoader.getPackagesAsPerReleaseConfig();
}

let externalPackage2s = await externalPackageResolver.resolveExternalPackage2DependenciesToVersions(packages);

//Display resolved dependencies
let externalDependencyDisplayer = new ExternalDependencyDisplayer(externalPackage2s, new ConsoleLogger());
externalDependencyDisplayer.display();

let packageCollectionInstaller = new InstallUnlockedPackageCollection(
await SFPOrg.create({ aliasOrUsername: username }),
await SFPOrg.create({aliasOrUsername: username}),
new ConsoleLogger()
);
await packageCollectionInstaller.install(externalPackage2s, true, true);
Expand Down
28 changes: 28 additions & 0 deletions src/core/display/CommandHeaderDisplayer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import SFPLogger, {COLOR_HEADER, COLOR_KEY_MESSAGE, ConsoleLogger, Logger, LoggerLevel} from "@flxbl-io/sfp-logger";

export default class CommandHeaderDisplayer {

private loggerLevel: LoggerLevel;
private readonly logger: Logger;

constructor(logger: Logger = new ConsoleLogger()) {
this.logger = logger;
}

public headerLine(): CommandHeaderDisplayer {
SFPLogger.printHeaderLine('', COLOR_HEADER, this.loggerLevel, this.logger);
return this;
}

public headerAttribute(attribute, value?): CommandHeaderDisplayer {
SFPLogger.log(`${COLOR_HEADER(attribute)} : ${value}`, this.loggerLevel, this.logger);
return this;
}

public headerAttributeIf(condition: boolean, attribute, value?): CommandHeaderDisplayer {
if (condition) {
SFPLogger.log(`${COLOR_HEADER(attribute)} : ${value}`, this.loggerLevel, this.logger);
}
return this;
}
}

0 comments on commit 644f700

Please sign in to comment.