Skip to content

Commit 108c060

Browse files
committed
feat: support generating a manifest from an org with include and exclude metadata lists
1 parent 508254d commit 108c060

File tree

7 files changed

+69
-13
lines changed

7 files changed

+69
-13
lines changed

command-snapshot.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@
239239
"flagChars": ["c", "d", "m", "n", "p", "t"],
240240
"flags": [
241241
"api-version",
242+
"exclude-metadata",
242243
"flags-dir",
243244
"from-org",
244245
"include-packages",

messages/manifest.generate.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Use --name to specify a custom name for the generated manifest if the pre-define
1919

2020
To include multiple metadata components, either set multiple --metadata <name> flags or a single --metadata flag with multiple names separated by spaces. Enclose names that contain spaces in one set of double quotes. The same syntax applies to --include-packages and --source-dir.
2121

22+
To build a manifest from the metadata in an org use the --from-org flag optionally combining it with the --metadata flag to only include certain metadata types, or the --exclude-metadata flag to exclude certain metadata types. When building a manifest from an org, the command makes many API calls concurrently to discover the metadata that exists in the org. To limit the number of concurrent requests use the `SF_LIST_METADATA_BATCH_SIZE` environment variable and set it to a size that works best for your org and environment. If you are experiencing timeouts and/or inconsistent manifest contents then setting this environment variable should improve accuracy. However, the command will take longer to run since it sends fewer requests at a time.
23+
2224
# examples
2325

2426
- Create a manifest for deploying or retrieving all Apex classes and custom objects:
@@ -37,10 +39,22 @@ To include multiple metadata components, either set multiple --metadata <name> f
3739

3840
$ <%= config.bin %> <%= command.id %> --from-org [email protected] --include-packages unlocked
3941

42+
- Create a manifest from specific metadata types in an org:
43+
44+
$ <%= config.bin %> <%= command.id %> --from-org [email protected] --metadata ApexClass,CustomObject,CustomLabels
45+
46+
- Create a manifest from all metadata components in an org excluding specific metadata types:
47+
48+
$ <%= config.bin %> <%= command.id %> --from-org [email protected] --exclude-metadata StandardValueSet
49+
4050
# flags.include-packages.summary
4151

4252
Package types (managed, unlocked) whose metadata is included in the manifest; by default, metadata in managed and unlocked packages is excluded. Metadata in unmanaged packages is always included.
4353

54+
# flags.exclude-metadata.summary
55+
56+
Metadata types (types only; not names) to exclude when building a manifest from an org.
57+
4458
# flags.from-org.summary
4559

4660
Username or alias of the org that contains the metadata components from which to build a manifest.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@salesforce/kit": "^3.2.3",
1313
"@salesforce/plugin-info": "^3.4.23",
1414
"@salesforce/sf-plugins-core": "^12.0.11",
15-
"@salesforce/source-deploy-retrieve": "^12.10.2",
15+
"@salesforce/source-deploy-retrieve": "12.10.4-dev-17431548.0",
1616
"@salesforce/source-tracking": "^7.1.17",
1717
"@salesforce/ts-types": "^2.0.12",
1818
"ansis": "^3.3.2",

src/commands/project/generate/manifest.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export type ManifestGenerateCommandResult = {
3838
path: string;
3939
};
4040

41-
const xorFlags = ['metadata', 'source-dir', 'from-org'];
41+
const atLeastOneOfFlags = ['metadata', 'source-dir', 'from-org'];
4242

4343
export class ManifestGenerate extends SfCommand<ManifestGenerateCommandResult> {
4444
public static readonly summary = messages.getMessage('summary');
@@ -53,14 +53,14 @@ export class ManifestGenerate extends SfCommand<ManifestGenerateCommandResult> {
5353
metadata: arrayWithDeprecation({
5454
char: 'm',
5555
summary: messages.getMessage('flags.metadata.summary'),
56-
exactlyOne: xorFlags,
56+
exclusive: ['source-dir'],
5757
}),
5858
'source-dir': arrayWithDeprecation({
5959
char: 'p',
6060
aliases: ['sourcepath'],
6161
deprecateAliases: true,
6262
summary: messages.getMessage('flags.source-dir.summary'),
63-
exactlyOne: xorFlags,
63+
exclusive: ['metadata'],
6464
}),
6565
name: Flags.string({
6666
char: 'n',
@@ -85,11 +85,18 @@ export class ManifestGenerate extends SfCommand<ManifestGenerateCommandResult> {
8585
char: 'c',
8686
dependsOn: ['from-org'],
8787
}),
88+
'exclude-metadata': Flags.string({
89+
multiple: true,
90+
delimiter: ',',
91+
summary: messages.getMessage('flags.exclude-metadata.summary'),
92+
dependsOn: ['from-org'],
93+
exclusive: ['metadata'],
94+
}),
8895
'from-org': Flags.custom({
8996
summary: messages.getMessage('flags.from-org.summary'),
90-
exactlyOne: xorFlags,
9197
aliases: ['fromorg'],
9298
deprecateAliases: true,
99+
exclusive: ['source-dir'],
93100
parse: async (input: string | undefined) => (input ? Org.create({ aliasOrUsername: input }) : undefined),
94101
})(),
95102
'output-dir': Flags.string({
@@ -102,6 +109,12 @@ export class ManifestGenerate extends SfCommand<ManifestGenerateCommandResult> {
102109

103110
public async run(): Promise<ManifestGenerateCommandResult> {
104111
const { flags } = await this.parse(ManifestGenerate);
112+
113+
// We need at least one of these flags (but could be more than 1): 'metadata', 'source-dir', 'from-org'
114+
if (!Object.keys(flags).some((f) => atLeastOneOfFlags.includes(f))) {
115+
throw Error(`provided flags must include at least one of: ${atLeastOneOfFlags.toString()}`);
116+
}
117+
105118
// convert the manifesttype into one of the "official" manifest names
106119
// if no manifesttype flag passed, use the manifestname?flag
107120
// if no manifestname flag, default to 'package.xml'
@@ -114,12 +127,14 @@ export class ManifestGenerate extends SfCommand<ManifestGenerateCommandResult> {
114127
const componentSet = await ComponentSetBuilder.build({
115128
apiversion: flags['api-version'] ?? (await getSourceApiVersion()),
116129
sourcepath: flags['source-dir'],
117-
metadata: flags.metadata
118-
? {
119-
metadataEntries: flags.metadata,
120-
directoryPaths: await getPackageDirs(),
121-
}
122-
: undefined,
130+
metadata:
131+
flags.metadata ?? flags['exclude-metadata']
132+
? {
133+
metadataEntries: flags.metadata ?? [],
134+
directoryPaths: await getPackageDirs(),
135+
excludedEntries: flags['exclude-metadata'],
136+
}
137+
: undefined,
123138
org: flags['from-org']
124139
? {
125140
username: flags['from-org'].getUsername() as string,

test/tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
"extends": "@salesforce/dev-config/tsconfig-test-strict-esm",
33
"include": ["./**/*.ts"],
44
"compilerOptions": {
5-
"skipLibCheck": true
5+
"skipLibCheck": true,
6+
"baseUrl": "..",
7+
"paths": {
8+
"@salesforce/source-deploy-retrieve": ["node_modules/@salesforce/source-deploy-retrieve"]
9+
}
610
}
711
}

tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
"outDir": "lib",
55
"rootDir": "src",
66
"skipLibCheck": true,
7-
"baseUrl": "."
7+
"baseUrl": ".",
8+
"paths": {
9+
"@salesforce/source-deploy-retrieve": ["node_modules/@salesforce/source-deploy-retrieve"]
10+
}
811
},
912
"include": ["./src/**/*.ts"]
1013
}

yarn.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,25 @@
16711671
cli-progress "^3.12.0"
16721672
terminal-link "^3.0.0"
16731673

1674+
"@salesforce/[email protected]":
1675+
version "12.10.4-dev-17431548.0"
1676+
resolved "https://registry.yarnpkg.com/@salesforce/source-deploy-retrieve/-/source-deploy-retrieve-12.10.4-dev-17431548.0.tgz#3d1214fa7b69c9e4eaf68912cad198d55208b15c"
1677+
integrity sha512-tAvqDNp3Oa0QDGhs1rJCOJQYvRO7pfKxzWutjVN2g7fbxn/ej5U5ZX6hKfCp411+NmI7MsN5wUpjQOs185h0mA==
1678+
dependencies:
1679+
"@salesforce/core" "^8.8.0"
1680+
"@salesforce/kit" "^3.2.2"
1681+
"@salesforce/ts-types" "^2.0.12"
1682+
fast-levenshtein "^3.0.0"
1683+
fast-xml-parser "^4.5.0"
1684+
got "^11.8.6"
1685+
graceful-fs "^4.2.11"
1686+
ignore "^5.3.2"
1687+
isbinaryfile "^5.0.2"
1688+
jszip "^3.10.1"
1689+
mime "2.6.0"
1690+
minimatch "^9.0.5"
1691+
proxy-agent "^6.4.0"
1692+
16741693
"@salesforce/source-deploy-retrieve@^12.10.2", "@salesforce/source-deploy-retrieve@^12.7.4":
16751694
version "12.10.2"
16761695
resolved "https://registry.yarnpkg.com/@salesforce/source-deploy-retrieve/-/source-deploy-retrieve-12.10.2.tgz#c3737f3751f84cb4754b666edd83c014c91b87bb"

0 commit comments

Comments
 (0)