Skip to content

Commit 8209848

Browse files
committed
feat: report commands, restructuring
1 parent d45b343 commit 8209848

24 files changed

+1248
-78
lines changed
File renamed without changes.

config/migrate-products.json

Lines changed: 488 additions & 0 deletions
Large diffs are not rendered by default.

messages/data-seeding.generate.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@ Number of minutes to wait for command to complete.
3535
# flags.async.summary
3636

3737
Run the command asynchronously.
38+
39+
# report.suggestion
40+
41+
- Check the status with: sf data-seeding generate report -i %s
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# summary
2+
3+
View the status of a data-seeding generate job
4+
5+
# description
6+
7+
View the status of a data-seeding generate job that has already been initiated or completed
8+
9+
# examples
10+
11+
- Display the status of a specific data seeding job
12+
<%= config.bin %> <%= command.id %> --job-id="[XXXX-YYYY-ZZZZ-AAAA]"
13+
14+
- Display the status of a the most recent data seeding job
15+
<%= config.bin %> <%= command.id %> --use-most-recent
16+
17+
# flags.job-id.summary
18+
19+
ID of a specific `data-seeding generate` job.
20+
21+
# flags.use-most-recent.summary
22+
23+
View status of most recent `data-seeding generate` job.

messages/data-seeding.migrate.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# summary
2+
3+
Migrates data from one org to another
4+
5+
# description
6+
7+
Migrates selected data based on a configuration file from a source org and into a target org
8+
9+
# examples
10+
11+
- Migrate data using a specific configuration file and org aliases
12+
13+
$ <%= config.bin %> <%= command.id %> -s sourceOrg -t targetOrg -f "/config/data-seed.json"
14+
15+
- Migrate data using default configuration file and usernames for each org
16+
17+
$ <%= config.bin %> <%= command.id %> --source-org="source@org.com" --target-org="target@org.com" --config-file="/config/data-seed.json"
18+
19+
20+
# flags.target-org.summary
21+
22+
Username or alias of the Target org where data will be migrated to.
23+
24+
# flags.source-org.summary
25+
26+
Username or alias of the Source org where data will be migrated from.
27+
28+
# flags.config-file.summary
29+
30+
Path to data migration JSON configuration file.
31+
32+
# flags.async.summary
33+
34+
Run the command asynchronously.
35+
36+
# flags.wait.summary
37+
38+
Number of minutes to wait for command to complete.
39+
40+
# report.suggestion
41+
42+
- Check the status with: sf data-seeding migrate report -i %s
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# summary
22

3-
View the status of a data seeding job
3+
View the status of a data-seeding migrate job
44

55
# description
66

7-
View the status of a data seeding job that has already been initiated or completed
7+
View the status of a data-seeding migrate job that has already been initiated or completed
88

99
# examples
1010

@@ -13,10 +13,11 @@ View the status of a data seeding job that has already been initiated or complet
1313

1414
- Display the status of a the most recent data seeding job
1515
<%= config.bin %> <%= command.id %> --use-most-recent
16+
1617
# flags.job-id.summary
1718

18-
ID of a specific data seeding job.
19+
ID of a specific `data-seeding migrate` job.
1920

2021
# flags.use-most-recent.summary
2122

22-
View status of most recent data seeding job.
23+
View status of most recent `data-seeding migrate` job.

package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"eslint-plugin-sf-plugin": "^1.20.5",
2424
"oclif": "^4.14.19",
2525
"ts-node": "^10.9.2",
26+
"tsx": "^4.19.0",
2627
"typescript": "^5.5.4"
2728
},
2829
"engines": {
@@ -58,7 +59,15 @@
5859
],
5960
"topics": {
6061
"data-seeding": {
61-
"description": "Migrate real data, generate fake data using GenAI, or deploy data files to target orgs"
62+
"description": "Migrate real data, generate fake data using GenAI, or deploy data files to target orgs",
63+
"subtopics": {
64+
"generate": {
65+
"description": "description for data-seeding.generate"
66+
},
67+
"migrate": {
68+
"description": "description for data-seeding.migrate"
69+
}
70+
}
6271
}
6372
},
6473
"flexibleTaxonomy": true
@@ -201,4 +210,4 @@
201210
},
202211
"exports": "./lib/index.js",
203212
"type": "module"
204-
}
213+
}

src/commands/data-seeding/generate.ts renamed to src/commands/data-seeding/generate/index.ts

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
99
import { Messages, PollingClient, SfError, StatusResult } from '@salesforce/core';
1010
import { Duration } from '@salesforce/kit';
11-
import { initiateDataSeed, pollSeedStatus, PollSeedResponse } from '../../utils/api.js';
12-
import { getSeedGenerateMso, getSeedGenerateStage as getStage } from '../../utils/mso.js';
13-
import { DataSeedingGenerateResult } from '../../utils/types.js';
14-
import { GenerateRequestCache } from '../../utils/cache.js';
11+
import { initiateDataSeed, pollSeedStatus, PollSeedResponse } from '../../../utils/api.js';
12+
import { getSeedGenerateMso, getSeedGenerateStage as getStage } from '../../../utils/mso.js';
13+
import { DataSeedingGenerateResult } from '../../../utils/types.js';
14+
import { GenerateRequestCache } from '../../../utils/cache.js';
1515

1616
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
1717
const messages = Messages.loadMessages('@salesforce/plugin-data-seeding', 'data-seeding.generate');
18+
1819
export default class DataSeedingGenerate extends SfCommand<DataSeedingGenerateResult> {
1920
public static readonly summary = messages.getMessage('summary');
2021
public static readonly description = messages.getMessage('description');
@@ -56,27 +57,27 @@ export default class DataSeedingGenerate extends SfCommand<DataSeedingGenerateRe
5657
const { flags } = await this.parse(DataSeedingGenerate);
5758
const { async, 'config-file': configFile, 'source-org': sourceOrg, 'target-org': targetOrg, wait } = flags;
5859

59-
const { request_id: jobId } = await initiateDataSeed(configFile);
60+
const { request_id: jobId } = await initiateDataSeed(configFile, 'data-generation');
61+
62+
const reportMessage = messages.getMessage('report.suggestion', [jobId]);
6063

6164
if (!jobId) throw new Error('Failed to receive job id');
6265

66+
const baseData = { jobId, sourceOrg, targetOrg };
67+
6368
await (await GenerateRequestCache.create()).createCacheEntry(jobId);
6469

6570
const buildResponse = (response: PollSeedResponse): DataSeedingGenerateResult => ({
6671
dataSeedingJob: 'generate',
67-
jobId,
6872
startTime: response?.execution_start_time,
6973
endTime: response?.execution_end_time,
70-
sourceOrg,
71-
targetOrg,
7274
status: response.status,
75+
...baseData,
7376
});
7477

75-
// TODO: Cache the jobId so that it can be used by the `--use-most-recent` flag
76-
7778
if (wait && !async) {
7879
const mso = getSeedGenerateMso({ jsonEnabled: this.jsonEnabled() });
79-
mso.updateData({ jobId, sourceOrg, targetOrg });
80+
mso.updateData(baseData);
8081

8182
const options: PollingClient.Options = {
8283
poll: async (): Promise<StatusResult> => {
@@ -114,13 +115,12 @@ export default class DataSeedingGenerate extends SfCommand<DataSeedingGenerateRe
114115

115116
if (err.message.includes('The client has timed out')) {
116117
mso.updateData({ status: 'Client Timeout' });
117-
err.actions = [
118-
'- Increase the value of the "--wait" flag',
119-
`- Check the status with: sf data-seeding report -i ${jobId}`,
120-
];
118+
err.actions = [ reportMessage ];
119+
mso.stop('current');
120+
} else {
121+
mso.error();
121122
}
122123

123-
mso.stop();
124124
throw err;
125125
}
126126
} else {
@@ -133,15 +133,13 @@ export default class DataSeedingGenerate extends SfCommand<DataSeedingGenerateRe
133133
});
134134

135135
mso.goto(getStage(response.step), {
136-
jobId,
137-
sourceOrg,
138-
targetOrg,
136+
...baseData,
139137
startTime: response.execution_start_time,
140138
status: 'Initiated',
141139
});
142140

143-
mso.stop();
144-
this.log(`- Check the status with: sf data-seeding report -i ${jobId}`);
141+
mso.stop('current');
142+
this.log(reportMessage);
145143

146144
return buildResponse(response);
147145
}

src/commands/data-seeding/report.ts renamed to src/commands/data-seeding/generate/report.ts

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

88
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
99
import { Messages, SfError } from '@salesforce/core';
10-
import { pollSeedStatus } from '../../utils/api.js';
11-
import { getSeedGenerateMso, getSeedGenerateStage as getStage } from '../../utils/mso.js';
12-
import { DataSeedingReportResult } from '../../utils/types.js';
13-
import { GenerateRequestCache } from '../../utils/cache.js';
10+
import { pollSeedStatus } from '../../../utils/api.js';
11+
import { getSeedGenerateMso, getSeedGenerateStage as getStage } from '../../../utils/mso.js';
12+
import { DataSeedingReportResult } from '../../../utils/types.js';
13+
import { GenerateRequestCache } from '../../../utils/cache.js';
1414

1515
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
16-
const messages = Messages.loadMessages('@salesforce/plugin-data-seeding', 'data-seeding.report');
16+
const messages = Messages.loadMessages('@salesforce/plugin-data-seeding', 'data-seeding.generate.report');
1717

1818
// TEMP failure (Querying Source Org): 9258aae5-e9b0-4c73-a340-962d299b71bd
1919
// TEMP failure (Populating Target Org): 0aab5c70-069d-48f5-aa0d-157f745c5dfe
2020

21-
export default class DataSeedingReport extends SfCommand<DataSeedingReportResult> {
21+
export default class DataSeedingGenerateReport extends SfCommand<DataSeedingReportResult> {
2222
public static readonly summary = messages.getMessage('summary');
2323
public static readonly description = messages.getMessage('description');
2424
public static readonly examples = messages.getMessages('examples');
@@ -37,35 +37,33 @@ export default class DataSeedingReport extends SfCommand<DataSeedingReportResult
3737
};
3838

3939
public async run(): Promise<DataSeedingReportResult> {
40-
const { flags } = await this.parse(DataSeedingReport);
40+
const { flags } = await this.parse(DataSeedingGenerateReport);
4141

4242
const jobId = flags['job-id'] ?? (await GenerateRequestCache.create()).resolveFromCache().jobId;
4343

4444
if (!jobId) throw new SfError('No job ID provided or found in cache');
4545

4646
const response = await pollSeedStatus(jobId);
4747

48+
const data = {
49+
jobId,
50+
startTime: response.execution_start_time,
51+
endTime: response.execution_end_time,
52+
status: response.status,
53+
};
54+
4855
const mso = getSeedGenerateMso({
4956
jsonEnabled: this.jsonEnabled(),
5057
showElapsedTime: false,
5158
showStageTime: false,
5259
});
5360

54-
mso.goto(getStage(response.step), {
55-
jobId,
56-
startTime: response.execution_start_time,
57-
endTime: response.execution_end_time,
58-
status: response.status,
59-
});
61+
mso.goto(getStage(response.step), data);
6062

6163
switch (response.status) {
62-
case 'Completed':
63-
mso.stop();
64+
case 'In Progress':
65+
mso.stop('current');
6466
break;
65-
// The 'current' status will be implemented in a future mso update
66-
// case 'In Progress':
67-
// mso.stop('current');
68-
// break;
6967
case 'Failed':
7068
mso.error();
7169
throw new SfError(`Failed on step: ${response.step}\nLog Text: ${response.log_text}`);
@@ -75,10 +73,7 @@ export default class DataSeedingReport extends SfCommand<DataSeedingReportResult
7573

7674
return {
7775
dataSeedingJob: 'generate',
78-
jobId,
79-
startTime: response.execution_start_time,
80-
endTime: response.execution_end_time,
81-
status: response.status,
76+
...data,
8277
};
8378
}
8479
}

0 commit comments

Comments
 (0)