add-template-generator
Add a new template generator command to the CLI
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Add a new template generator command to the CLI
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
| name | add-template-generator |
| description | Add a new template generator command to the CLI |
Use this workflow whenever exposing a generator from salesforcedx-templates to CLI users.
This workflow guides you through adding a new template generator command that exposes a template from salesforcedx-templates to the Salesforce CLI.
salesforcedx-templates repository// turbo Run the command generator to create the initial command structure:
sf dev generate command -n template:generate:{metadataType}:{optionalSubTemplate} --no-unit
Notes:
{metadataType} with your metadata type (e.g., flexipage, apex){optionalSubTemplate} if you need nested generators (e.g., digital-experience:site)Open package.json and locate the oclif.topics section. Under template > generate, add a description for your new subtopic:
{
"oclif": {
"topics": {
"template": {
"subtopics": {
"generate": {
"subtopics": {
"{metadataType}": {
"description": "Commands for generating {metadataType} metadata"
}
}
}
}
}
}
}
}
If your command is not GA-ready, add a state to the command class:
public static readonly state = 'beta'; // or 'preview'
State options:
beta: Shows beta warning to userspreview: Shows preview warning to usersIf you want to hide the command from docs and autocomplete:
public static readonly hidden = true;
Note: Hidden commands won't be included in release notes.
Ensure your command file follows the correct path convention:
src/commands/template/generate/{metadataType}/index.tssrc/commands/template/generate/{metadataType}/{subTemplate}.tsBefore defining flags, inspect the generator TypeScript interface in salesforcedx-templates. The interface is the source of truth for flag structure. If it is unavailable, request it instead of guessing.
Important: Do NOT add flags manually. The sf dev generate flag command is interactive and requires the user to run it themselves—the agent cannot respond to its prompts. When adding flags, instruct the user to run the command and provide guidance for the interactive flow.
sf dev generate flag from plugin root.runGenerator; (b) if generator created messages/template.generate.{metadataType}.md instead of updating the existing file, merge those entries into messages/{metadataType}.md and delete the generated file.sf dev generate flag
This will:
flags objectmessages.md fileCommon flags to consider:
--name / -n: Name of the generated item (usually required)--output-dir / -d: Output directory (default: '.')--template / -t: Template type selection (if multiple templates)--api-version: API version overrideCheck messages/{metadataType}.md (merge from template.generate.{metadataType}.md if generator created a separate file) and ensure:
Optional: Add links to developer.salesforce.com docs in descriptions if helpful.
Update the run() method to call runGenerator:
import { runGenerator } from '../../utils/templateCommand.js';
public async run(): Promise<CreateOutput> {
const { flags } = await this.parse(CommandClass);
// Add any pre-processing or validation here
return runGenerator({
templateType: TemplateType.{YourMetadataType},
opts: flags,
ux: new Ux({ jsonEnabled: this.jsonEnabled() }),
});
}
Review the auto-generated NUTs in test/commands/template/generate/{metadataType}/. Add tests to validate:
Most template generators don't require scratch org connections.
// turbo Build and link the plugin:
yarn build
sf plugins link .
Test your command:
sf template generate {metadataType} --name TestExample --output-dir ./test-output
Verify the generated files are correct.
// turbo Run the NUTs to ensure everything works:
yarn test
If you're also working on the template in salesforcedx-templates:
package.json to reference your local salesforcedx-templates:
"dependencies": {
"salesforcedx-templates": "file:../path/to/salesforcedx-templates"
}
yarn build in salesforcedx-templatesyarn install --force && yarn build in plugin-templatesIf your command does not appear:
confirm file path matches convention
run yarn build
ensure oclif topics updated
relink plugin:
sf plugins unlink @salesforce/plugin-templates sf plugins link .
Before opening PR ensure: