Skip to content

Commit

Permalink
fix: pkg create and delete commands
Browse files Browse the repository at this point in the history
  • Loading branch information
peternhale committed Jun 27, 2022
1 parent 7389687 commit c71ca30
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 43 deletions.
4 changes: 2 additions & 2 deletions messages/package_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ Don’t prompt before deleting the package.

Deleted packages can’t be recovered.

Do you want to continue? (y\nn)
Do you want to continue? (y\n)

# promptUndelete

This will undelete the package, which may result in unintended consequences for customers. Proceed with caution.

Do you want to continue? (y\nn)
Do you want to continue? (y\n)

# promptDeleteDeny

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^1.9.2",
"@oclif/plugin-version": "^1.0.4",
"@salesforce/command": "^5.1.3",
"@salesforce/core": "^3.21.1",
"@oclif/core": "^1.9.5",
"@oclif/plugin-version": "^1.1.0",
"@salesforce/command": "^5.2.0",
"@salesforce/core": "^3.22.0",
"@salesforce/kit": "^1.5.42",
"@salesforce/packaging": "^0.0.3",
"@salesforce/packaging": "0.0.5-test-04",
"tslib": "^2"
},
"devDependencies": {
Expand Down
39 changes: 36 additions & 3 deletions src/commands/force/package/beta/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
import { Messages, SfdxPropertyKeys } from '@salesforce/core';
import {
applyErrorAction,
createPackage,
massageErrorMessage,
PackageCreateOptions,
PackageType,
} from '@salesforce/packaging';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_create');
Expand Down Expand Up @@ -60,8 +67,34 @@ export class PackageCreateCommand extends SfdxCommand {
}),
};

public async run(): Promise<unknown> {
process.exitCode = 1;
return Promise.resolve('Not yet implemented');
public async run(): Promise<{ Id: string }> {
const options: PackageCreateOptions = {
description: (this.flags.description || '') as string,
errorNotificationUsername: this.flags.errornotificationusername as string,
name: this.flags.name as string,
noNamespace: this.flags.nonamespace as boolean,
orgDependent: this.flags.orgdependent as boolean,
packageType: this.flags.packagetype as PackageType,
path: this.flags.path as string,
};
const result: { Id: string } = await createPackage(
this.hubOrg,
this.hubOrg.getConnection(),
this.project,
options
).catch((err) => {
// TODO: until package2 is GA, wrap perm-based errors w/ 'contact sfdc' action (REMOVE once package2 is GA'd)
err = massageErrorMessage(err);
throw applyErrorAction(err);
});
if (!this.flags.json) {
this.display(result);
}
return result;
}

private display(result: { Id: string }): void {
this.ux.styledHeader('Ids');
this.ux.table([{ name: 'Package Id', value: result.Id }], { name: { header: 'NAME' }, value: { header: 'VALUE' } });
}
}
39 changes: 36 additions & 3 deletions src/commands/force/package/beta/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
import { Messages, SfdxPropertyKeys } from '@salesforce/core';
import { applyErrorAction, deletePackage, massageErrorMessage, PackageSaveResult } from '@salesforce/packaging';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_delete');
Expand Down Expand Up @@ -38,8 +39,40 @@ export class PackageDeleteCommand extends SfdxCommand {
}),
};

public async run(): Promise<unknown> {
process.exitCode = 1;
return Promise.resolve('Not yet implemented');
public async run(): Promise<PackageSaveResult> {
// user must acknowledge the warning prompt or use noprompt flag
const accepted = await this.prompt(
this.flags.noprompt,
messages.getMessage(this.flags.undelete ? 'promptUndelete' : 'promptDelete')
);
if (!accepted) {
throw messages.createError('promptDeleteDeny');
}

const result = await deletePackage(
this.flags.package,
this.project,
this.hubOrg.getConnection(),
!!this.flags.undelete
).catch((err) => {
// TODO: until package2 is GA, wrap perm-based errors w/ 'contact sfdc' action (REMOVE once package2 is GA'd)
err = massageErrorMessage(err);
throw applyErrorAction(err);
});
this.display(result);
return result;
}

private async prompt(noninteractive, message): Promise<boolean> {
const answer = noninteractive ? 'YES' : await this.ux.prompt(message);
// print a line of white space after the prompt is entered for separation
this.ux.log('');
return answer.toUpperCase() === 'YES' || answer.toUpperCase() === 'Y';
}

private display(result: PackageSaveResult): void {
const message = messages.getMessage(this.flags.undelete ? 'humanSuccessUndelete' : 'humanSuccess', [result.id]);
this.ux.log();
this.ux.log(message);
}
}
7 changes: 5 additions & 2 deletions src/commands/force/package/beta/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
import { Messages, SfdxPropertyKeys } from '@salesforce/core';
import { listPackages, getPackageAliasesFromId, PackagingSObjects } from '@salesforce/packaging';
import { listPackages, getPackageAliasesFromId, PackagingSObjects, applyErrorAction } from '@salesforce/packaging';
import * as chalk from 'chalk';
import { CliUx } from '@oclif/core';
import { QueryResult } from 'jsforce';
Expand Down Expand Up @@ -51,7 +51,10 @@ export class PackageListCommand extends SfdxCommand {

public async run(): Promise<Package2Result[]> {
this.logger = this.logger.child('package:list');
const queryResult = await listPackages(this.hubOrg.getConnection());
const queryResult = await listPackages(this.hubOrg.getConnection()).catch((err) => {
// TODO: until package2 is GA, wrap perm-based errors w/ 'contact sfdc' action (REMOVE once package2 is GA'd)
throw applyErrorAction(err);
});
this.mapRecordsToResults(queryResult);
if (!this.flags.json) {
this.displayResults();
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "@salesforce/dev-config/tsconfig",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src"
"rootDir": "src",
"skipLibCheck": true
},
"include": ["./src/**/*.ts"]
}
49 changes: 22 additions & 27 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -724,10 +724,10 @@
is-wsl "^2.1.1"
tslib "^2.3.1"

"@oclif/core@^1.0.8", "@oclif/core@^1.1.1", "@oclif/core@^1.2.1", "@oclif/core@^1.3.1", "@oclif/core@^1.3.4", "@oclif/core@^1.3.6", "@oclif/core@^1.6.4", "@oclif/core@^1.7.0", "@oclif/core@^1.9.2":
version "1.9.3"
resolved "https://registry.yarnpkg.com/@oclif/core/-/core-1.9.3.tgz#02666e467235ad5674a633c40cb5112f73dc66fd"
integrity sha512-npxWULRu+iW9AuUNoCH118MNI8cxYIkcWkknz3mCDumTo11FC+h3OY1cMtlclqZHfZcDHh4iaSkNMX/7se9GUQ==
"@oclif/core@^1.0.8", "@oclif/core@^1.1.1", "@oclif/core@^1.2.1", "@oclif/core@^1.3.1", "@oclif/core@^1.3.4", "@oclif/core@^1.3.6", "@oclif/core@^1.6.4", "@oclif/core@^1.7.0", "@oclif/core@^1.9.5":
version "1.9.5"
resolved "https://registry.yarnpkg.com/@oclif/core/-/core-1.9.5.tgz#4dd00f35fceb89906245da791b14bd503103771a"
integrity sha512-C605Cr4RhHTMXYApLxdVt/PL6IA5cguN6MPvsMjxkvBppk2Fvcsj05dtRdDqShskRpZzHtu65emG1tHy8TWPWQ==
dependencies:
"@oclif/linewrap" "^1.0.0"
"@oclif/screen" "^3.0.2"
Expand Down Expand Up @@ -889,7 +889,7 @@
fast-levenshtein "^3.0.0"
lodash "^4.17.21"

"@oclif/plugin-version@^1.0.4":
"@oclif/plugin-version@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@oclif/plugin-version/-/plugin-version-1.1.0.tgz#c88c32aa1b112b946e2f33ebd783a8e91a43763c"
integrity sha512-yyxRWPrd9WWVwv4Ljype5pYAGXR/+RIlfJP3J37uy9bBnMd+TaWbVEWG1wqb1pk1nVGLM18Ux/YvxxfaTPsUUw==
Expand Down Expand Up @@ -1077,7 +1077,7 @@
chalk "^2.4.2"
cli-ux "^4.9.3"

"@salesforce/command@^5.1.0", "@salesforce/command@^5.1.3":
"@salesforce/command@^5.1.0", "@salesforce/command@^5.2.0":
version "5.2.0"
resolved "https://registry.yarnpkg.com/@salesforce/command/-/command-5.2.0.tgz#908b2fe38a6147b04d0a2316e459a3775889e4b1"
integrity sha512-HDr3oZTMkCeytL+MWL9+FxodDDhUzc+TyZKf4v+dF0VKevA8NFr2Hw6GyXJzLq/p8BKETHTe6cnq5KeiNIOsPg==
Expand Down Expand Up @@ -1113,10 +1113,10 @@
semver "^7.3.5"
ts-retry-promise "^0.6.0"

"@salesforce/core@^3.15.5", "@salesforce/core@^3.20.1", "@salesforce/core@^3.21.0", "@salesforce/core@^3.21.1":
version "3.21.1"
resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-3.21.1.tgz#3e51454d6e5f5fbf523e0372378210b8cf85f60f"
integrity sha512-TdOhTeXrfUhRsqqwQKQsA410uBvHsRQiD66wtC0lmUGHRBNxUYEmK6+zbMvVLyPLo6Db4GOPuZ/3DV839fIVBg==
"@salesforce/core@^3.15.5", "@salesforce/core@^3.20.1", "@salesforce/core@^3.22.0":
version "3.22.0"
resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-3.22.0.tgz#869cab4e95b6a7b3d0b10f34e91d5fb7cb818ab0"
integrity sha512-jzDdANxtcZFM+VcRuJ1eEYw1hSRytMkUxYkGFTVDiNg8OZvzPNeM/FIL4ILSo0Kmeu4k0/Wt86+ZtlbrMXd1vg==
dependencies:
"@salesforce/bunyan" "^2.0.0"
"@salesforce/kit" "^1.5.41"
Expand All @@ -1133,7 +1133,7 @@
form-data "^4.0.0"
graceful-fs "^4.2.9"
js2xmlparser "^4.0.1"
jsforce "2.0.0-beta.10"
jsforce "2.0.0-beta.14"
jsonwebtoken "8.5.1"
mkdirp "1.0.4"
ts-retry-promise "^0.6.0"
Expand Down Expand Up @@ -1192,12 +1192,12 @@
shx "^0.3.3"
tslib "^2.2.0"

"@salesforce/packaging@^0.0.3":
version "0.0.3"
resolved "https://registry.yarnpkg.com/@salesforce/packaging/-/packaging-0.0.3.tgz#2b481721495e00972d31f37c0a3f362f7810c109"
integrity sha512-M1W/IkGWtPaD0SV8nbCXzc6pc4gQkjudFWVtrV0JoZsY8jrX2ck68AcndjKmmqDqvtCWxarnBAEtDD+gFRBTKg==
"@salesforce/packaging@0.0.5-test-04":
version "0.0.5-test-04"
resolved "http://localhost:4873/@salesforce%2fpackaging/-/packaging-0.0.5-test-04.tgz#2a526f2ac70adddc7c0169adce7d593cc110069d"
integrity sha512-FhqmGZ9xcUsE8XbGpF4rx97ee82Dv+VA+3f/uojfUjmLZ70qh5S6pvKe2PUrF5Wq2D7EDWVICOtTjHB5oL2Nmw==
dependencies:
"@salesforce/core" "^3.21.0"
"@salesforce/core" "^3.22.0"
"@salesforce/kit" "^1.5.42"
"@salesforce/schemas" "^1.2.0"
"@salesforce/ts-types" "^1.5.20"
Expand All @@ -1210,7 +1210,7 @@
debug "^4.3.4"
graceful-fs "^4.2.10"
js2xmlparser "^4.0.2"
jsforce "2.0.0-beta.10"
jsforce "2.0.0-beta.14"
mkdirp "1.0.4"
ts-retry-promise "^0.6.1"

Expand Down Expand Up @@ -1245,12 +1245,7 @@
resolved "https://registry.yarnpkg.com/@salesforce/prettier-config/-/prettier-config-0.0.2.tgz#ded39bf7cb75238edc9db6dd093649111350f8bc"
integrity sha512-KExM355BLbxCW6siGBV7oUOotXvvVp0tAWERgzUkM2FcMb9fWrjwXDrIHc8V0UdDlA3UXtFltDWgN+Yqi+BA/g==

"@salesforce/schemas@^1.0.1", "@salesforce/schemas@^1.1.0":
version "1.1.3"
resolved "https://registry.yarnpkg.com/@salesforce/schemas/-/schemas-1.1.3.tgz#fce83f55c7557d47b9c814d5d02978ad734300b3"
integrity sha512-XWohlOT2oQDqAJH00OXS3f2MGjkwZ6pr4emnnkHSQbg7UdGW0rvGpEnRKqBbDUfZ4K5YKSo9Gj216ZtaP3JLXg==

"@salesforce/schemas@^1.2.0":
"@salesforce/schemas@^1.0.1", "@salesforce/schemas@^1.1.0", "@salesforce/schemas@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@salesforce/schemas/-/schemas-1.2.0.tgz#3c7ed492e3ee5d9d9fb24a32b5c574893f6648db"
integrity sha512-76oYf/9Rsn6Yl+awrTQvLaQuRDNX7F3X9ksRiw53OCJdydIF05buX6XLzN0WDWpkCg/asw+lZMuAzbDVS0tBmg==
Expand Down Expand Up @@ -4932,10 +4927,10 @@ jsesc@^2.5.1:
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-2.5.2.tgz#80564d2e483dacf6e8ef209650a67df3f0c283a4"
integrity sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==

jsforce@2.0.0-beta.10:
version "2.0.0-beta.10"
resolved "https://registry.yarnpkg.com/jsforce/-/jsforce-2.0.0-beta.10.tgz#c33fee5dd01c96d121235cffb8fee1458a35423e"
integrity sha512-AFigJHQocj8t36Eu+9XffoKoC2FO4/uMDMg08TfTXgvIp53lzvnQJoQrhEnwnKReof4tO2d+7j+d1QyiOa2yGg==
jsforce@2.0.0-beta.14:
version "2.0.0-beta.14"
resolved "https://registry.yarnpkg.com/jsforce/-/jsforce-2.0.0-beta.14.tgz#237753bdabb7e80447b5b266eaefc4abf8b6c951"
integrity sha512-j66PaKroshB4VZbfKBAx9+lJy8etFfGG1hGFsI7ufwxvacXxLTAxZwOEZPkYPMigiHrPlEMtIwh5NqwBsIn9HA==
dependencies:
"@babel/runtime" "^7.12.5"
"@babel/runtime-corejs3" "^7.12.5"
Expand Down

0 comments on commit c71ca30

Please sign in to comment.