Skip to content

Commit cb631c9

Browse files
committed
fix: parking orbit plugin-org
1 parent 0e970e7 commit cb631c9

File tree

15 files changed

+3760
-1473
lines changed

15 files changed

+3760
-1473
lines changed

bin/dev

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env node
2+
3+
const oclif = require('@oclif/core');
4+
5+
const path = require('path');
6+
const project = path.join(__dirname, '..', 'tsconfig.json');
7+
8+
// In dev mode -> use ts-node and dev plugins
9+
process.env.NODE_ENV = 'development';
10+
11+
require('ts-node').register({ project });
12+
13+
// In dev mode, always show stack traces
14+
oclif.settings.debug = true;
15+
16+
// Start the CLI
17+
oclif.run().then(oclif.flush).catch(oclif.Errors.handle);

bin/dev.cmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
3+
node "%~dp0\dev" %*

bin/run

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
22

3-
require('@oclif/command').run()
4-
.catch(require('@oclif/errors/handle'))
3+
const oclif = require('@oclif/core');
4+
5+
oclif.run().then(require('@oclif/core/flush')).catch(require('@oclif/core/handle'));

bin/run.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
@echo off
22

3-
node "%~dp0\run" %*
3+
node "%~dp0\run" %*

package.json

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
{
22
"name": "@salesforce/plugin-org",
3-
"description": "A template repository for sfdx plugins",
4-
"version": "1.13.0",
3+
"description": "Commands to interact with Salesforce orgs",
4+
"version": "2.0.0",
55
"author": "Salesforce",
6+
"main": "lib/index.js",
67
"bugs": "https://github.com/forcedotcom/cli/issues",
78
"dependencies": {
8-
"@oclif/config": "^1.18.1",
9-
"@salesforce/command": "^4.2.2",
10-
"@salesforce/core": "^2.36.3",
9+
"@oclif/core": "^1.7.0",
10+
"@salesforce/command": "^5.1.0",
11+
"@salesforce/core": "^3.18.2",
1112
"@salesforce/kit": "^1.5.17",
1213
"open": "8.4.0",
1314
"tslib": "^2"
1415
},
1516
"devDependencies": {
1617
"@oclif/dev-cli": "^1",
17-
"@oclif/plugin-command-snapshot": "^2.2.2",
18+
"@oclif/plugin-command-snapshot": "^3.1.3",
1819
"@salesforce/cli-plugins-testkit": "^1.5.3",
19-
"@salesforce/dev-config": "^3.0.0",
20-
"@salesforce/dev-scripts": "^2.0.0",
20+
"@salesforce/dev-config": "^3.0.1",
21+
"@salesforce/dev-scripts": "^2.0.2",
2122
"@salesforce/plugin-command-reference": "^1.3.0",
2223
"@salesforce/prettier-config": "^0.0.2",
2324
"@salesforce/ts-sinon": "1.3.21",
@@ -37,10 +38,10 @@
3738
"eslint-plugin-jsdoc": "^35.1.2",
3839
"eslint-plugin-prettier": "^3.1.3",
3940
"husky": "^7.0.4",
40-
"lint-staged": "^11.0.0",
4141
"mocha": "^9.1.3",
4242
"moment": "^2.29.1",
4343
"nyc": "^15.1.0",
44+
"oclif": "^3.0.1",
4445
"prettier": "^2.4.1",
4546
"pretty-quick": "^3.1.0",
4647
"shelljs": "^0.8.5",
@@ -49,9 +50,6 @@
4950
"ts-node": "^10.0.0",
5051
"typescript": "^4.4.4"
5152
},
52-
"resolutions": {
53-
"@salesforce/core": "^2.37.1"
54-
},
5553
"config": {
5654
"commitizen": {
5755
"path": "cz-conventional-changelog"
@@ -110,11 +108,11 @@
110108
"prepare": "sf-install",
111109
"pretest": "sf-compile-test",
112110
"test": "sf-test",
113-
"test:command-reference": "./bin/run commandreference:generate --erroronwarnings",
114-
"test:deprecation-policy": "./bin/run snapshot:compare",
111+
"test:command-reference": "./bin/dev commandreference:generate --erroronwarnings",
112+
"test:deprecation-policy": "./bin/dev snapshot:compare",
115113
"test:nuts": "nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 600000 --parallel",
116114
"test:nuts:sandbox": "nyc mocha \"**/*.sandboxNut.ts\" --slow 450000 --timeout 7200000",
117-
"version": "oclif-dev readme"
115+
"version": "oclif readme"
118116
},
119117
"publishConfig": {
120118
"access": "public"

src/commands/force/org/beta/create.ts

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
1111
import { Duration } from '@salesforce/kit';
1212
import {
1313
AuthFields,
14-
Aliases,
14+
GlobalInfo,
1515
Config,
1616
Lifecycle,
1717
Messages,
@@ -22,7 +22,8 @@ import {
2222
SandboxProcessObject,
2323
SandboxRequest,
2424
SandboxUserAuthResponse,
25-
SfdxError,
25+
SfError,
26+
SfdxPropertyKeys,
2627
StatusEvent,
2728
ScratchOrgRequest,
2829
ScratchOrgInfo,
@@ -114,10 +115,10 @@ export class Create extends SfdxCommand {
114115

115116
private validateSandboxFlags(): void {
116117
if (!this.flags.targetusername) {
117-
throw SfdxError.create('@salesforce/plugin-org', 'create', 'requiresUsername');
118+
throw new SfError(messages.getMessage('requiresUsername'));
118119
}
119120
if (this.flags.retry !== 0) {
120-
throw SfdxError.create('@salesforce/plugin-org', 'create', 'retryIsNotValidForSandboxes');
121+
throw new SfError(messages.getMessage('retryIsNotValidForSandboxes'));
121122
}
122123

123124
if (this.flags.clientid) {
@@ -169,7 +170,7 @@ export class Create extends SfdxCommand {
169170
this.ux.warn(`No SandboxName defined, generating new SandboxName: ${sandboxReq.SandboxName}`);
170171
}
171172
if (!sandboxReq.LicenseType) {
172-
throw SfdxError.create('@salesforce/plugin-org', 'create', 'missingLicenseType');
173+
throw new SfError(messages.getMessage('missingLicenseType'));
173174
}
174175
return sandboxReq;
175176
}
@@ -201,21 +202,19 @@ export class Create extends SfdxCommand {
201202
this.ux.log(sandboxReadyForUse);
202203
this.ux.styledHeader('Sandbox Org Creation Status');
203204
this.ux.table(data, {
204-
columns: [
205-
{ key: 'key', label: 'Name' },
206-
{ key: 'value', label: 'Value' },
207-
],
205+
key: { header: 'Name' },
206+
value: { header: 'Value' },
208207
});
209208
if (results.sandboxRes?.authUserName) {
210209
if (this.flags.setalias) {
211-
const alias = await Aliases.create(Aliases.getDefaultOptions());
212-
alias.set(this.flags.setalias, results.sandboxRes.authUserName);
213-
const result = await alias.write();
210+
const globalInfo = await GlobalInfo.getInstance();
211+
globalInfo.aliases.set(this.flags.setalias, results.sandboxRes.authUserName);
212+
const result = await globalInfo.write();
214213
this.logger.debug('Set Alias: %s result: %s', this.flags.setalias, result);
215214
}
216215
if (this.flags.setdefaultusername) {
217216
const globalConfig: Config = this.configAggregator.getGlobalConfig();
218-
globalConfig.set(Config.DEFAULT_USERNAME, results.sandboxRes.authUserName);
217+
globalConfig.set(SfdxPropertyKeys.DEFAULT_USERNAME, results.sandboxRes.authUserName);
219218
const result = await globalConfig.write();
220219
this.logger.debug('Set defaultUsername: %s result: %s', this.flags.setdefaultusername, result);
221220
}
@@ -231,18 +230,18 @@ export class Create extends SfdxCommand {
231230
return prodOrg.createSandbox(sandboxReq, { wait });
232231
} catch (e) {
233232
// guaranteed to be SfdxError from core;
234-
const err = e as SfdxError;
233+
const err = e as SfError;
235234
if (err?.message.includes('The org cannot be found')) {
236235
// there was most likely an issue with DNS when auth'ing to the new sandbox, but it was created.
237236
if (this.flags.setalias && this.sandboxAuth) {
238-
const alias = await Aliases.create(Aliases.getDefaultOptions());
239-
alias.set(this.flags.setalias, this.sandboxAuth.authUserName);
240-
const result = await alias.write();
237+
const globalInfo = await GlobalInfo.getInstance();
238+
globalInfo.aliases.set(this.flags.setalias, this.sandboxAuth.authUserName);
239+
const result = await globalInfo.write();
241240
this.logger.debug('Set Alias: %s result: %s', this.flags.setalias, result);
242241
}
243242
if (this.flags.setdefaultusername && this.sandboxAuth) {
244243
const globalConfig: Config = this.configAggregator.getGlobalConfig();
245-
globalConfig.set(Config.DEFAULT_USERNAME, this.sandboxAuth.authUserName);
244+
globalConfig.set(SfdxPropertyKeys.DEFAULT_USERNAME, this.sandboxAuth.authUserName);
246245
const result = await globalConfig.write();
247246
this.logger.debug('Set defaultUsername: %s result: %s', this.flags.setdefaultusername, result);
248247
}
@@ -262,9 +261,9 @@ export class Create extends SfdxCommand {
262261
}
263262

264263
private async setAliasAndDefaultUsername(username: string): Promise<void> {
265-
const aliases = await Aliases.create(Aliases.getDefaultOptions());
264+
const globalInfo = await GlobalInfo.getInstance();
266265
if (this.flags.setalias) {
267-
await aliases.updateValue(this.flags.setalias, username);
266+
globalInfo.aliases.update(this.flags.setalias, username);
268267
this.logger.debug('Set Alias: %s result: %s', this.flags.setalias);
269268
}
270269
if (this.flags.setdefaultusername) {
@@ -274,20 +273,20 @@ export class Create extends SfdxCommand {
274273
} catch {
275274
config = await Config.create({ isGlobal: true });
276275
}
277-
const value = aliases.getKeysByValue(username)[0] || username;
278-
const result = config.set(Config.DEFAULT_USERNAME, value);
276+
const value = globalInfo.aliases.get(username) || username;
277+
const result = config.set(SfdxPropertyKeys.DEFAULT_USERNAME, value);
279278
await config.write();
280279
this.logger.debug('Set defaultUsername: %s result: %s', this.flags.setdefaultusername, result);
281280
}
282281
}
283282
private async createScratchOrg(): Promise<ScratchOrgProcessObject> {
284283
this.logger.debug('OK, will do scratch org creation');
285284
if (!this.hubOrg) {
286-
throw SfdxError.create('@salesforce/plugin-org', 'create', 'RequiresDevhubUsernameError');
285+
throw new SfError(messages.getMessage('RequiresDevhubUsernameError'));
287286
}
288287
// Ensure we have an org config input source.
289288
if (!this.flags.definitionfile && Object.keys(this.varargs).length === 0) {
290-
throw new SfdxError(messages.getMessage('noConfig'));
289+
throw new SfError(messages.getMessage('noConfig'));
291290
}
292291

293292
this.logger.debug('validation complete');

src/commands/force/org/clone.ts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import { EOL } from 'os';
99
import * as fs from 'fs';
1010
import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
1111
import {
12-
SfdxError,
13-
SfdxErrorConfig,
12+
SfError,
1413
Config,
1514
Lifecycle,
1615
Messages,
1716
OrgTypes,
18-
Aliases,
17+
SfdxPropertyKeys,
18+
GlobalInfo,
1919
SandboxEvents,
2020
SandboxRequest,
2121
StatusEvent,
@@ -82,21 +82,20 @@ export class OrgCloneCommand extends SfdxCommand {
8282
this.ux.log(sandboxReadyForUse);
8383
this.ux.styledHeader('Sandbox Org Cloning Status');
8484
this.ux.table(data, {
85-
columns: [
86-
{ key: 'key', label: 'Name' },
87-
{ key: 'value', label: 'Value' },
88-
],
85+
key: { header: 'Name' },
86+
value: { header: 'Value' },
8987
});
9088

9189
if (results?.sandboxRes?.authUserName) {
9290
if (this.flags.setalias) {
93-
const alias = await Aliases.create({});
94-
const result = alias.set(this.flags.setalias, results.sandboxRes.authUserName);
91+
const globalInfo = await GlobalInfo.create();
92+
globalInfo.aliases.set(this.flags.setalias, results.sandboxRes.authUserName);
93+
const result = globalInfo.aliases.getAll();
9594
this.logger.debug('Set Alias: %s result: %s', this.flags.setalias, result);
9695
}
9796
if (this.flags.setdefaultusername) {
9897
const globalConfig: Config = this.configAggregator.getGlobalConfig();
99-
globalConfig.set(Config.DEFAULT_USERNAME, results.sandboxRes.authUserName);
98+
globalConfig.set(SfdxPropertyKeys.DEFAULT_USERNAME, results.sandboxRes.authUserName);
10099
const result = await globalConfig.write();
101100
this.logger.debug('Set defaultUsername: %s result: %s', this.flags.setdefaultusername, result);
102101
}
@@ -109,10 +108,9 @@ export class OrgCloneCommand extends SfdxCommand {
109108
const wait = this.flags.wait as Duration;
110109
return this.org.cloneSandbox(sandboxReq, srcSandboxName, { wait });
111110
} else {
112-
throw SfdxError.create(
113-
new SfdxErrorConfig('@salesforce/plugin-org', 'clone', 'commandOrganizationTypeNotSupport', [
114-
OrgTypes.Sandbox,
115-
]).addAction('commandOrganizationTypeNotSupportAction', [OrgTypes.Sandbox])
111+
throw new SfError(
112+
messages.getMessage('commandOrganizationTypeNotSupport', [OrgTypes.Sandbox]),
113+
messages.getMessage('commandOrganizationTypeNotSupportAction', [OrgTypes.Sandbox])
116114
);
117115
}
118116
}
@@ -145,10 +143,9 @@ export class OrgCloneCommand extends SfdxCommand {
145143
delete sandboxReq[OrgCloneCommand.SANDBOXDEF_SRC_SANDBOXNAME];
146144
} else {
147145
// error - we need SourceSandboxName to know which sandbox to clone from
148-
throw SfdxError.create(
149-
new SfdxErrorConfig('@salesforce/plugin-org', 'clone', 'missingSourceSandboxName', [
150-
OrgCloneCommand.SANDBOXDEF_SRC_SANDBOXNAME,
151-
]).addAction('missingSourceSandboxNameAction', [OrgCloneCommand.SANDBOXDEF_SRC_SANDBOXNAME])
146+
throw new SfError(
147+
messages.getMessage('missingSourceSandboxName', [OrgCloneCommand.SANDBOXDEF_SRC_SANDBOXNAME]),
148+
messages.getMessage('missingSourceSandboxNameAction', [OrgCloneCommand.SANDBOXDEF_SRC_SANDBOXNAME])
152149
);
153150
}
154151
return { sandboxReq, srcSandboxName };

src/commands/force/org/display.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import * as os from 'os';
99
import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
10-
import { AuthInfo, Messages, sfdc, SfdxError } from '@salesforce/core';
10+
import { AuthInfo, Messages, sfdc, SfError } from '@salesforce/core';
1111
import { camelCaseToTitleCase } from '@salesforce/kit';
1212

1313
import { OrgDisplayReturn, ScratchOrgFields } from '../../../shared/orgTypes';
@@ -71,12 +71,6 @@ export class OrgDisplayCommand extends SfdxCommand {
7171

7272
private print(result: OrgDisplayReturn): void {
7373
this.ux.log('');
74-
const columns = {
75-
columns: [
76-
{ key: 'key', label: 'KEY' },
77-
{ key: 'value', label: 'VALUE' },
78-
],
79-
};
8074
const tableRows = Object.keys(result)
8175
.filter((key) => result[key] !== undefined && result[key] !== null) // some values won't exist
8276
.sort() // this command always alphabetizes the table rows
@@ -86,7 +80,10 @@ export class OrgDisplayCommand extends SfdxCommand {
8680
}));
8781

8882
this.ux.styledHeader('Org Description');
89-
this.ux.table(tableRows, columns);
83+
this.ux.table(tableRows, {
84+
key: { header: 'KEY' },
85+
value: { header: 'VALUE' },
86+
});
9087
}
9188

9289
private async getScratchOrgInformation(orgId: string): Promise<ScratchOrgFields> {
@@ -106,7 +103,7 @@ export class OrgDisplayCommand extends SfdxCommand {
106103
createdDate: result.CreatedDate,
107104
};
108105
}
109-
throw new SfdxError(
106+
throw new SfError(
110107
messages.getMessage('noScratchOrgInfoError', [sfdc.trimTo15(orgId), hubOrg.getUsername()]),
111108
'NoScratchInfo',
112109
[messages.getMessage('noScratchOrgInfoAction')]

0 commit comments

Comments
 (0)