Skip to content

Commit 690b7bc

Browse files
feat(install): introduce a unified package installation command (dxatscale#1420)
This PR introduces a unified package install command, that allows to use a single command to install any spowerscripts artifact. This reduces complexity to while scripting pipelines to understand the type of package and install it in one go. The change also deprecates other commands BREAKING CHANGE: deprecates existing individual package installation commands
1 parent 077009f commit 690b7bc

File tree

9 files changed

+176
-10
lines changed

9 files changed

+176
-10
lines changed

packages/sfpowerscripts-cli/messages/install_data_package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"commandDescription": "Installs a SFDMU-based data package consisting of csvfiles and export.json to a target org",
2+
"commandDescription": "(DEPRECATED) Installs a SFDMU-based data package consisting of csvfiles and export.json to a target org",
33
"packageFlagDescription": "Name of the package to be installed",
44
"targetOrgFlagDescription": "Alias/User Name of the target environment",
55
"artifactDirectoryFlagDescription": "The directory where the artifact is located",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"commandDescription": "Installs a sfpowerscripts artifact to an org",
3+
"packageFlagDescription": "Name of the package to be installed",
4+
"targetOrgFlagDescription": "Alias/User Name of the target environment",
5+
"apexCompileOnlyPackageFlagDescription": "(unlocked) package installation triggers a compilation of apex, flag to trigger compilation of package only",
6+
"artifactDirectoryFlagDescription": "The directory where the artifact is located",
7+
"securityTypeFlagDescription": "(unlocked) Select the security access for the package installation",
8+
"optimizedeployment": "(source) Optimize deployment by triggering test classes that are in the package, rather than using the whole tests in the org",
9+
"skiptesting": "(source) Skips running test when deploying to a sandbox",
10+
"upgradeTypeFlagDescription": "(unlocked)the upgrade type for the package installation",
11+
"waitTimeFlagDescription": "wait time for command to finish in minutes",
12+
"publishWaitTimeFlagDescription": "(unlocked) number of minutes to wait for subscriber package version ID to become available in the target org",
13+
"skipIfAlreadyInstalled": "Skip the installation if the package is already installed in the org"
14+
}

packages/sfpowerscripts-cli/messages/install_source_package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"commandDescription": "Installs a sfpowerscripts source package to the target org",
2+
"commandDescription": "(DEPRECATED) Installs a sfpowerscripts source package to the target org",
33
"packageFlagDescription": "Name of the package to be installed",
44
"targetOrgFlagDescription": "Alias/User Name of the target environment",
55
"artifactDirectoryFlagDescription": "The directory where the artifact is located",

packages/sfpowerscripts-cli/messages/install_unlocked_package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"commandDescription": "Installs an unlocked package using sfpowerscripts metadata",
2+
"commandDescription": "(DEPRECATED) Installs an unlocked package using sfpowerscripts metadata",
33
"packageFlagDescription": "Name of the package to be installed",
44
"targetOrgFlagDescription": "Alias/User Name of the target environment",
55
"packageInstalledFromFlagDescription": "automatically retrieve the version ID of the package to be installed, from the build artifact",

packages/sfpowerscripts-cli/src/InstallPackageCommand.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ export default abstract class InstallPackageCommand extends SfpowerscriptsComman
3434
description: messages.getMessage('artifactDirectoryFlagDescription'),
3535
default: 'artifacts',
3636
}),
37-
skiponmissingartifact: Flags.boolean({
38-
char: 's',
39-
description: messages.getMessage('skipOnMissingArtifactFlagDescription'),
40-
}),
4137
};
4238

4339
protected artifact: Artifact;

packages/sfpowerscripts-cli/src/commands/package/data/install.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Messages } from '@salesforce/core';
22
import InstallPackageCommand from '../../../InstallPackageCommand';
33
import { PackageInstallationStatus } from '@dxatscale/sfpowerscripts.core/lib/package/packageInstallers/PackageInstallationResult';
4-
import { ConsoleLogger } from '@dxatscale/sfp-logger';
4+
import SFPLogger, { ConsoleLogger, LoggerLevel } from '@dxatscale/sfp-logger';
55
import SfpPackageInstaller from '@dxatscale/sfpowerscripts.core/lib/package/SfpPackageInstaller';
66
import { SfpPackageInstallationOptions } from '@dxatscale/sfpowerscripts.core/lib/package/packageInstallers/InstallPackage';
77
import { Flags } from '@oclif/core';
@@ -20,6 +20,8 @@ export default class InstallDataPackage extends InstallPackageCommand {
2020

2121
public static examples = [`$ sfp package:data:install -n mypackage -u <org>`];
2222

23+
public static deprecated:boolean = true;
24+
2325
public static flags = {
2426
package: Flags.string({
2527
char: 'n',
@@ -45,6 +47,9 @@ export default class InstallDataPackage extends InstallPackageCommand {
4547
public async install() {
4648
try {
4749

50+
SFPLogger.log(`This command is now deprecated, please proceed to use sfp package:install instead`,LoggerLevel.WARN)
51+
52+
4853
const skipIfAlreadyInstalled = this.flags.skipifalreadyinstalled;
4954
let options: SfpPackageInstallationOptions = {
5055
skipIfPackageInstalled: skipIfAlreadyInstalled
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import { Messages } from '@salesforce/core';
2+
import InstallPackageCommand from '../../InstallPackageCommand';
3+
import { PackageInstallationStatus } from '@dxatscale/sfpowerscripts.core/lib/package/packageInstallers/PackageInstallationResult';
4+
import SFPLogger, { COLOR_HEADER, COLOR_KEY_MESSAGE, ConsoleLogger, LoggerLevel } from '@dxatscale/sfp-logger';
5+
import { SfpPackageInstallationOptions } from '@dxatscale/sfpowerscripts.core/lib/package/packageInstallers/InstallPackage';
6+
import SfpPackageInstaller from '@dxatscale/sfpowerscripts.core/lib/package/SfpPackageInstaller';
7+
import { Flags } from '@oclif/core';
8+
import { loglevel, requiredUserNameFlag } from '../../flags/sfdxflags';
9+
import { PackageType } from '@dxatscale/sfpowerscripts.core/lib/package/SfpPackage';
10+
11+
12+
Messages.importMessagesDirectory(__dirname);
13+
const messages = Messages.loadMessages('@dxatscale/sfpowerscripts', 'install_package');
14+
15+
export default class Install extends InstallPackageCommand {
16+
public static description = messages.getMessage('commandDescription');
17+
18+
public static examples = [`$ sfp package:install -n packagename -u sandboxalias -i`];
19+
20+
public static flags = {
21+
package: Flags.string({
22+
char: 'n',
23+
description: messages.getMessage('packageFlagDescription'),
24+
}),
25+
targetorg: requiredUserNameFlag,
26+
apexcompileonlypackage: Flags.boolean({
27+
char: 'a',
28+
description: messages.getMessage('apexCompileOnlyPackageFlagDescription'),
29+
}),
30+
artifactdir: Flags.directory({
31+
description: messages.getMessage('artifactDirectoryFlagDescription'),
32+
default: 'artifacts',
33+
}),
34+
securitytype: Flags.string({
35+
description: messages.getMessage('securityTypeFlagDescription'),
36+
options: ['full', 'none'],
37+
default: 'none',
38+
}),
39+
skipifalreadyinstalled: Flags.boolean({
40+
char: 'f',
41+
description: messages.getMessage('skipIfAlreadyInstalled'),
42+
}),
43+
upgradetype: Flags.string({
44+
description: messages.getMessage('upgradeTypeFlagDescription'),
45+
options: ['delete-only', 'deprecate-only', 'mixed-mode'],
46+
default: 'mixed-mode',
47+
}),
48+
optimizedeployment: Flags.boolean({
49+
char: 'o',
50+
description: messages.getMessage('optimizedeployment'),
51+
default: false,
52+
required: false,
53+
}),
54+
skiptesting: Flags.boolean({
55+
char: 't',
56+
description: messages.getMessage('skiptesting'),
57+
default: false,
58+
required: false,
59+
}),
60+
waittime: Flags.string({
61+
description: messages.getMessage('waitTimeFlagDescription'),
62+
default: '120',
63+
}),
64+
publishwaittime: Flags.string({
65+
description: messages.getMessage('publishWaitTimeFlagDescription'),
66+
default: '10',
67+
}),
68+
loglevel
69+
};
70+
71+
protected static requiresUsername = true;
72+
protected static requiresDevhubUsername = false;
73+
74+
public async install() {
75+
try {
76+
const installationkey = this.flags.installationkey;
77+
const apexcompileonlypackage = this.flags.apexcompileonlypackage;
78+
const security_type = this.flags.securitytype;
79+
const upgrade_type = this.flags.upgradetype;
80+
const waitTime = this.flags.waittime;
81+
const publishWaitTime = this.flags.publishwaittime;
82+
const skipIfAlreadyInstalled = this.flags.skipifalreadyinstalled;
83+
const optimizeDeployment: boolean = this.flags.optimizedeployment;
84+
const skipTesting: boolean = this.flags.skiptesting;
85+
86+
87+
SFPLogger.log(COLOR_HEADER(`command: ${COLOR_KEY_MESSAGE(`install`)}`));
88+
SFPLogger.log(COLOR_HEADER(`Package Name: ${this.sfpPackage.packageName}`));
89+
SFPLogger.log(COLOR_HEADER(`Package Type: ${this.sfpPackage.packageType}`));
90+
SFPLogger.log(COLOR_HEADER(`Skip Packages If Already Installed: ${this.flags.skipifalreadyinstalled?`true`:`false`}`));
91+
SFPLogger.log(COLOR_HEADER(`Artifact Directory: ${this.flags.artifactdir}`));
92+
SFPLogger.log(COLOR_HEADER(`Target Environment: ${this.flags.targetorg}`));
93+
94+
95+
if(this.sfpPackage.packageType == PackageType.Unlocked)
96+
{
97+
98+
SFPLogger.log(COLOR_HEADER(`Security Type: ${this.flags.securitytype}`));
99+
SFPLogger.log(COLOR_HEADER(`Upgrade Type: ${this.flags.upgradetype}`));
100+
SFPLogger.log(COLOR_HEADER(`Apex Compile Mode: ${ apexcompileonlypackage ? `package` : `all`}`));
101+
}
102+
else if(this.sfpPackage.packageType == PackageType.Source)
103+
{
104+
SFPLogger.log(COLOR_HEADER(`Optimize Deployment: ${this.flags.optimizedeployment}`));
105+
SFPLogger.log(COLOR_HEADER(`Skip Testing: ${this.flags.skiptesting}`));
106+
}
107+
108+
109+
SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);
110+
111+
112+
let options: SfpPackageInstallationOptions = {
113+
installationkey: installationkey,
114+
apexcompile: apexcompileonlypackage ? `package` : `all`,
115+
securitytype: security_type,
116+
optimizeDeployment: optimizeDeployment,
117+
skipTesting: skipTesting,
118+
upgradetype: upgrade_type,
119+
waitTime: waitTime,
120+
publishWaitTime: publishWaitTime,
121+
disableArtifactCommit: false,
122+
skipIfPackageInstalled: skipIfAlreadyInstalled,
123+
apiVersion: this.sfpPackage.apiVersion
124+
};
125+
126+
let result = await SfpPackageInstaller.installPackage(
127+
new ConsoleLogger(),
128+
this.sfpPackage,
129+
this.sfpOrg,
130+
options
131+
);
132+
133+
if (result.result === PackageInstallationStatus.Failed) {
134+
throw new Error(result.message);
135+
}
136+
} catch (err) {
137+
console.log(err);
138+
process.exitCode = 1;
139+
}
140+
}
141+
}

packages/sfpowerscripts-cli/src/commands/package/source/install.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Messages } from '@salesforce/core';
22
import InstallPackageCommand from '../../../InstallPackageCommand';
33
import * as fs from 'fs-extra';
44
import { PackageInstallationStatus } from '@dxatscale/sfpowerscripts.core/lib/package/packageInstallers/PackageInstallationResult';
5-
import { ConsoleLogger } from '@dxatscale/sfp-logger';
5+
import SFPLogger, { ConsoleLogger, LoggerLevel } from '@dxatscale/sfp-logger';
66
import { DeploymentType } from '@dxatscale/sfpowerscripts.core/lib/deployers/DeploymentExecutor';
77
import { SfpPackageInstallationOptions } from '@dxatscale/sfpowerscripts.core/lib/package/packageInstallers/InstallPackage';
88
import SfpPackageInstaller from '@dxatscale/sfpowerscripts.core/lib/package/SfpPackageInstaller';
@@ -21,6 +21,8 @@ export default class InstallSourcePackage extends InstallPackageCommand {
2121

2222
public static examples = [`$ sfp package:source:install -n mypackage -u <org>`];
2323

24+
public static deprecated:boolean = true;
25+
2426
public static flags = {
2527
package: Flags.string({
2628
char: 'n',
@@ -63,6 +65,9 @@ export default class InstallSourcePackage extends InstallPackageCommand {
6365

6466
public async install(): Promise<any> {
6567

68+
SFPLogger.log(`This command is now deprecated, please proceed to use sfp package:install instead`,LoggerLevel.WARN)
69+
70+
6671
const sfdx_package: string = this.flags.package;
6772
const optimizeDeployment: boolean = this.flags.optimizedeployment;
6873
const skipTesting: boolean = this.flags.skiptesting;

packages/sfpowerscripts-cli/src/commands/package/unlocked/install.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Messages } from '@salesforce/core';
22
import InstallPackageCommand from '../../../InstallPackageCommand';
33
import { PackageInstallationStatus } from '@dxatscale/sfpowerscripts.core/lib/package/packageInstallers/PackageInstallationResult';
4-
import { ConsoleLogger } from '@dxatscale/sfp-logger';
4+
import SFPLogger, { ConsoleLogger, LoggerLevel } from '@dxatscale/sfp-logger';
55
import { SfpPackageInstallationOptions } from '@dxatscale/sfpowerscripts.core/lib/package/packageInstallers/InstallPackage';
66
import SfpPackageInstaller from '@dxatscale/sfpowerscripts.core/lib/package/SfpPackageInstaller';
77
import { Flags } from '@oclif/core';
@@ -20,6 +20,8 @@ export default class InstallUnlockedPackage extends InstallPackageCommand {
2020

2121
public static examples = [`$ sfp package:unlocked:install -n packagename -u sandboxalias -i`];
2222

23+
public static deprecated:boolean = true;
24+
2325
public static flags = {
2426
package: Flags.string({
2527
char: 'n',
@@ -72,6 +74,9 @@ export default class InstallUnlockedPackage extends InstallPackageCommand {
7274
protected static requiresDevhubUsername = false;
7375

7476
public async install() {
77+
78+
SFPLogger.log(`This command is now deprecated, please proceed to use sfp package:install instead`,LoggerLevel.WARN)
79+
7580
try {
7681
const installationkey = this.flags.installationkey;
7782
const apexcompileonlypackage = this.flags.apexcompileonlypackage;

0 commit comments

Comments
 (0)