Skip to content

Commit 9e9bcd4

Browse files
authored
Merge pull request #332 from salesforcecli/cd/parking-orbit
fix: parking orbit plugin-org
2 parents 87a8e08 + 7c2d778 commit 9e9bcd4

28 files changed

+3881
-1583
lines changed

.mocharc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"require": "ts-node/register,source-map-support/register",
33
"watch-extensions": "ts",
4+
"watch-files": ["src", "test"],
45
"recursive": true,
56
"reporter": "spec",
67
"timeout": 5000

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: 15 additions & 16 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.2",
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.2.0",
11+
"@salesforce/core": "^3.22.0",
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-
"@salesforce/cli-plugins-testkit": "^1.5.3",
19-
"@salesforce/dev-config": "^3.0.0",
20-
"@salesforce/dev-scripts": "^2.0.0",
18+
"@oclif/plugin-command-snapshot": "^3.1.3",
19+
"@salesforce/cli-plugins-testkit": "^2.3.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,12 @@
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+
"test:watch": "mocha --watch \"./test/**/*.test.ts\"",
116+
"version": "oclif readme"
118117
},
119118
"publishConfig": {
120119
"access": "public"

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

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@ import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
1111
import { Duration } from '@salesforce/kit';
1212
import {
1313
AuthFields,
14-
Aliases,
14+
StateAggregator,
1515
Config,
1616
Lifecycle,
1717
Messages,
1818
Org,
1919
OrgTypes,
20+
OrgConfigProperties,
2021
ResultEvent,
2122
SandboxEvents,
2223
SandboxProcessObject,
2324
SandboxRequest,
2425
SandboxUserAuthResponse,
25-
SfdxError,
26+
SfError,
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'), '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 stateAggregator = await StateAggregator.getInstance();
211+
stateAggregator.aliases.set(this.flags.setalias, results.sandboxRes.authUserName);
212+
const result = await stateAggregator.aliases.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(OrgConfigProperties.TARGET_ORG, 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 stateAggregator = await StateAggregator.getInstance();
238+
stateAggregator.aliases.set(this.flags.setalias, this.sandboxAuth.authUserName);
239+
const result = await stateAggregator.aliases.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(OrgConfigProperties.TARGET_ORG, 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 stateAggregator = await StateAggregator.getInstance();
266265
if (this.flags.setalias) {
267-
await aliases.updateValue(this.flags.setalias, username);
266+
stateAggregator.aliases.set(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 = stateAggregator.aliases.get(username) || username;
277+
const result = config.set(OrgConfigProperties.TARGET_ORG, 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+
OrgConfigProperties,
18+
StateAggregator,
1919
SandboxEvents,
2020
SandboxRequest,
2121
StatusEvent,
@@ -83,21 +83,20 @@ export class OrgCloneCommand extends SfdxCommand {
8383
this.ux.log(sandboxReadyForUse);
8484
this.ux.styledHeader('Sandbox Org Cloning Status');
8585
this.ux.table(data, {
86-
columns: [
87-
{ key: 'key', label: 'Name' },
88-
{ key: 'value', label: 'Value' },
89-
],
86+
key: { header: 'Name' },
87+
value: { header: 'Value' },
9088
});
9189

9290
if (results?.sandboxRes?.authUserName) {
9391
if (this.flags.setalias) {
94-
const alias = await Aliases.create({});
95-
const result = alias.set(this.flags.setalias, results.sandboxRes.authUserName);
92+
const stateAggregator = await StateAggregator.getInstance();
93+
stateAggregator.aliases.set(this.flags.setalias, results.sandboxRes.authUserName);
94+
const result = stateAggregator.aliases.getAll();
9695
this.logger.debug('Set Alias: %s result: %s', this.flags.setalias, result);
9796
}
9897
if (this.flags.setdefaultusername) {
9998
const globalConfig: Config = this.configAggregator.getGlobalConfig();
100-
globalConfig.set(Config.DEFAULT_USERNAME, results.sandboxRes.authUserName);
99+
globalConfig.set(OrgConfigProperties.TARGET_ORG, results.sandboxRes.authUserName);
101100
const result = await globalConfig.write();
102101
this.logger.debug('Set defaultUsername: %s result: %s', this.flags.setdefaultusername, result);
103102
}
@@ -110,10 +109,9 @@ export class OrgCloneCommand extends SfdxCommand {
110109
const wait = this.flags.wait as Duration;
111110
return this.org.cloneSandbox(sandboxReq, srcSandboxName, { wait });
112111
} else {
113-
throw SfdxError.create(
114-
new SfdxErrorConfig('@salesforce/plugin-org', 'clone', 'commandOrganizationTypeNotSupport', [
115-
OrgTypes.Sandbox,
116-
]).addAction('commandOrganizationTypeNotSupportAction', [OrgTypes.Sandbox])
112+
throw new SfError(
113+
messages.getMessage('commandOrganizationTypeNotSupport', [OrgTypes.Sandbox]),
114+
messages.getMessage('commandOrganizationTypeNotSupportAction', [OrgTypes.Sandbox])
117115
);
118116
}
119117
}
@@ -146,10 +144,9 @@ export class OrgCloneCommand extends SfdxCommand {
146144
delete sandboxReq[OrgCloneCommand.SANDBOXDEF_SRC_SANDBOXNAME];
147145
} else {
148146
// error - we need SourceSandboxName to know which sandbox to clone from
149-
throw SfdxError.create(
150-
new SfdxErrorConfig('@salesforce/plugin-org', 'clone', 'missingSourceSandboxName', [
151-
OrgCloneCommand.SANDBOXDEF_SRC_SANDBOXNAME,
152-
]).addAction('missingSourceSandboxNameAction', [OrgCloneCommand.SANDBOXDEF_SRC_SANDBOXNAME])
147+
throw new SfError(
148+
messages.getMessage('missingSourceSandboxName', [OrgCloneCommand.SANDBOXDEF_SRC_SANDBOXNAME]),
149+
messages.getMessage('missingSourceSandboxNameAction', [OrgCloneCommand.SANDBOXDEF_SRC_SANDBOXNAME])
153150
);
154151
}
155152
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)