generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: working on source:manifest:generate * fix: manifest:create command working * chore: manifest:create NUTs * chore: update NUTs * chore: unique flag descriptions * chore: update messages * fix: bump SDR to 4.0.2 (#169) * fix: bump SDR to 4.0.2 * chore: disable sfdx NUTs * chore: disable sfdx executible in generateNut * chore(release): 1.0.7 [ci skip] * chore: code review I - onto apiversion * chore: apiversion flag * chore: learn about flags.builtin * fix: working on source:manifest:generate * fix: manifest:create command working * chore: manifest:create NUTs * chore: update NUTs * chore: unique flag descriptions * chore: update messages * chore: code review I - onto apiversion * chore: apiversion flag * chore: learn about flags.builtin Co-authored-by: SF-CLI-BOT <[email protected]>
- Loading branch information
1 parent
12f1301
commit cdad337
Showing
8 changed files
with
255 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"description": "create a project manifest that lists the metadata components you want to deploy or retrieve \n Create a manifest from a list of metadata components (--metadata) or from one or more local directories that contain source files (--sourcepath). You can specify either of these parameters, not both.\n\nUse --manifesttype to specify the type of manifest you want to create. The resulting manifest files have specific names, such as the standard package.xml or destructiveChanges.xml to delete metadata. Valid values for this parameter, and their respective file names, are:\n\n package : package.xml (default)\n pre : destructiveChangesPre.xml\n post : destructiveChangesPost.xml\n destroy : destructiveChanges.xml\n\nSee https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_deploy_deleting_files.htm for information about these destructive manifest files. \n\nUse --manifestname to specify a custom name for the generated manifest if the pre-defined ones don’t suit your needs. You can specify either --manifesttype or --manifestname, but not both.\n", | ||
"examples": [ | ||
"$ sfdx force:source:manifest:create -m ApexClass", | ||
"$ sfdx force:source:manifest:create -m ApexClass:MyApexClass --manifesttype destroy", | ||
"$ sfdx force:source:manifest:create --sourcepath force-app --manifestname myNewManifest" | ||
], | ||
"flags": { | ||
"manifesttype": "type of manifest to create; the type determines the name of the created file", | ||
"manifestname": "name of a custom manifest file to create", | ||
"outputdir": "directory to save the created manifest", | ||
"sourcepath": "comma-separated list of paths to the local source files to include in the manifest", | ||
"metadata": "comma-separated list of names of metadata components to include in the manifest" | ||
}, | ||
"success": "successfully wrote %s", | ||
"successOutputDir": "successfully wrote %s to %s" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Copyright (c) 2020, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import * as os from 'os'; | ||
import { join } from 'path'; | ||
import { flags, FlagsConfig } from '@salesforce/command'; | ||
import { fs } from '@salesforce/core'; | ||
import { Messages } from '@salesforce/core'; | ||
import { SourceCommand } from '../../../../sourceCommand'; | ||
import { ComponentSetBuilder } from '../../../../componentSetBuilder'; | ||
|
||
Messages.importMessagesDirectory(__dirname); | ||
const messages = Messages.loadMessages('@salesforce/plugin-source', 'create'); | ||
|
||
const manifestTypes: Record<string, string> = { | ||
pre: 'destructiveChangesPre.xml', | ||
post: 'destructiveChangesPost.xml', | ||
destroy: 'destructiveChanges.xml', | ||
package: 'package.xml', | ||
}; | ||
|
||
interface CreateCommandResult { | ||
name: string; | ||
path: string; | ||
} | ||
|
||
export class create extends SourceCommand { | ||
public static readonly description = messages.getMessage('description'); | ||
public static readonly examples = messages.getMessage('examples').split(os.EOL); | ||
public static readonly requiresProject = true; | ||
public static readonly flagsConfig: FlagsConfig = { | ||
apiversion: flags.builtin({}), | ||
metadata: flags.array({ | ||
char: 'm', | ||
description: messages.getMessage('flags.metadata'), | ||
exclusive: ['sourcepath'], | ||
}), | ||
sourcepath: flags.array({ | ||
char: 'p', | ||
description: messages.getMessage('flags.sourcepath'), | ||
exclusive: ['metadata'], | ||
}), | ||
manifestname: flags.string({ | ||
char: 'n', | ||
description: messages.getMessage('flags.manifestname'), | ||
exclusive: ['manifesttype'], | ||
}), | ||
manifesttype: flags.enum({ | ||
description: messages.getMessage('flags.manifesttype'), | ||
options: Object.keys(manifestTypes), | ||
char: 't', | ||
}), | ||
outputdir: flags.string({ | ||
char: 'o', | ||
description: messages.getMessage('flags.outputdir'), | ||
}), | ||
}; | ||
protected xorFlags = ['metadata', 'sourcepath']; | ||
private manifestName: string; | ||
private outputDir: string; | ||
private outputPath: string; | ||
|
||
public async run(): Promise<CreateCommandResult> { | ||
await this.createManifest(); | ||
this.resolveSuccess(); | ||
return this.formatResult(); | ||
} | ||
|
||
protected async createManifest(): Promise<void> { | ||
this.validateFlags(); | ||
// convert the manifesttype into one of the "official" manifest names | ||
// if no manifesttype flag passed, use the manifestname flag | ||
// if no manifestname flag, default to 'package.xml' | ||
this.manifestName = | ||
manifestTypes[this.getFlag<string>('manifesttype')] || this.getFlag<string>('manifestname') || 'package.xml'; | ||
this.outputDir = this.getFlag<string>('outputdir'); | ||
|
||
const componentSet = await ComponentSetBuilder.build({ | ||
apiversion: this.getFlag('apiversion'), | ||
sourcepath: this.getFlag<string[]>('sourcepath'), | ||
metadata: this.flags.metadata && { | ||
metadataEntries: this.getFlag<string[]>('metadata'), | ||
directoryPaths: this.getPackageDirs(), | ||
}, | ||
}); | ||
|
||
// add the .xml suffix if the user just provided a file name | ||
this.manifestName = this.manifestName.endsWith('.xml') ? this.manifestName : this.manifestName + '.xml'; | ||
|
||
if (this.outputDir) { | ||
fs.mkdirSync(this.outputDir, { recursive: true }); | ||
this.outputPath = join(this.outputDir, this.manifestName); | ||
} else { | ||
this.outputPath = this.manifestName; | ||
} | ||
|
||
return fs.writeFile(this.outputPath, componentSet.getPackageXml()); | ||
} | ||
|
||
// noop this method because any errors will be reported by the createManifest method | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
protected resolveSuccess(): void {} | ||
|
||
protected formatResult(): CreateCommandResult { | ||
if (!this.isJsonOutput()) { | ||
if (this.outputDir) { | ||
this.ux.log(messages.getMessage('successOutputDir', [this.manifestName, this.outputDir])); | ||
} else { | ||
this.ux.log(messages.getMessage('success', [this.manifestName])); | ||
} | ||
} | ||
return { path: this.outputPath, name: this.manifestName }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright (c) 2021, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import { join } from 'path'; | ||
import { expect } from '@salesforce/command/lib/test'; | ||
import { TestSession } from '@salesforce/cli-plugins-testkit'; | ||
import { execCmd } from '@salesforce/cli-plugins-testkit'; | ||
import { fs } from '@salesforce/core'; | ||
import { Dictionary } from '@salesforce/ts-types'; | ||
|
||
const apexManifest = | ||
'<?xml version="1.0" encoding="UTF-8"?>\n' + | ||
'<Package xmlns="http://soap.sforce.com/2006/04/metadata">\n' + | ||
' <types>\n' + | ||
' <members>GeocodingService</members>\n' + | ||
' <members>GeocodingServiceTest</members>\n' + | ||
' <members>PagedResult</members>\n' + | ||
' <members>PropertyController</members>\n' + | ||
' <members>SampleDataController</members>\n' + | ||
' <members>TestPropertyController</members>\n' + | ||
' <members>TestSampleDataController</members>\n' + | ||
' <name>ApexClass</name>\n' + | ||
' </types>\n' + | ||
' <version>51.0</version>\n' + | ||
'</Package>'; | ||
|
||
describe('force:source:manifest:create', () => { | ||
let session: TestSession; | ||
|
||
before(async () => { | ||
session = await TestSession.create({ | ||
project: { | ||
gitClone: 'https://github.com/trailheadapps/dreamhouse-lwc.git', | ||
}, | ||
}); | ||
}); | ||
|
||
after(async () => { | ||
await session?.clean(); | ||
}); | ||
|
||
it('should produce a manifest (package.xml) for ApexClass', () => { | ||
const result = execCmd<Dictionary>('force:source:manifest:create --metadata ApexClass --json', { | ||
ensureExitCode: 0, | ||
}).jsonOutput.result; | ||
expect(result).to.be.ok; | ||
expect(result).to.include({ path: 'package.xml', name: 'package.xml' }); | ||
}); | ||
|
||
it('should produce a manifest (destructiveChanges.xml) for ApexClass in a new directory', () => { | ||
const output = join('abc', 'def'); | ||
const outputFile = join(output, 'destructiveChanges.xml'); | ||
const result = execCmd<Dictionary>( | ||
`force:source:manifest:create --metadata ApexClass --manifesttype destroy --outputdir ${output} --apiversion=51.0 --json`, | ||
{ | ||
ensureExitCode: 0, | ||
} | ||
).jsonOutput.result; | ||
expect(result).to.be.ok; | ||
expect(result).to.include({ path: `${outputFile}`, name: 'destructiveChanges.xml' }); | ||
const file = fs.readFileSync(join(session.project.dir, outputFile), 'utf-8'); | ||
expect(file).to.include(apexManifest); | ||
}); | ||
|
||
it('should produce a custom manifest (myNewManifest.xml) for a sourcepath', () => { | ||
const output = join('abc', 'def'); | ||
const outputFile = join(output, 'myNewManifest.xml'); | ||
const result = execCmd<Dictionary>( | ||
`force:source:manifest:create --metadata ApexClass --manifestname myNewManifest --outputdir ${output} --json`, | ||
{ | ||
ensureExitCode: 0, | ||
} | ||
).jsonOutput.result; | ||
expect(result).to.be.ok; | ||
expect(result).to.include({ path: `${outputFile}`, name: 'myNewManifest.xml' }); | ||
}); | ||
|
||
it('should produce a manifest in a directory with stdout output', () => { | ||
const output = join('abc', 'def'); | ||
const result = execCmd<Dictionary>(`force:source:manifest:create --metadata ApexClass --outputdir ${output}`, { | ||
ensureExitCode: 0, | ||
}).shellOutput; | ||
expect(result).to.include(`successfully wrote package.xml to ${output}`); | ||
}); | ||
|
||
it('should produce a manifest with stdout output', () => { | ||
const result = execCmd<Dictionary>('force:source:manifest:create --metadata ApexClass', { | ||
ensureExitCode: 0, | ||
}).shellOutput; | ||
expect(result).to.include('successfully wrote package.xml'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters