Skip to content

Commit dea0998

Browse files
committed
fix: resolve yarn.lock merge conflict with upstream main
2 parents 10eebfe + 2816fb5 commit dea0998

12 files changed

Lines changed: 1847 additions & 1282 deletions

File tree

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
---
2+
name: add-template-generator
3+
description: Add a new template generator command to the CLI
4+
---
5+
6+
Use this workflow whenever exposing a generator from salesforcedx-templates to CLI users.
7+
8+
# Add Template Generator Command Workflow
9+
10+
This workflow guides you through adding a new template generator command that exposes a template from `salesforcedx-templates` to the Salesforce CLI.
11+
12+
## Prerequisites
13+
14+
- Template generator already exists in `salesforcedx-templates` repository
15+
- You know the metadata type name and any subtemplates
16+
- You have the repo cloned and dependencies installed
17+
18+
## Step 1: Bootstrap the Command
19+
20+
// turbo
21+
Run the command generator to create the initial command structure:
22+
23+
```bash
24+
sf dev generate command -n template:generate:{metadataType}:{optionalSubTemplate} --no-unit
25+
```
26+
27+
**Notes:**
28+
29+
- Replace `{metadataType}` with your metadata type (e.g., `flexipage`, `apex`)
30+
- Only add `{optionalSubTemplate}` if you need nested generators (e.g., `digital-experience:site`)
31+
- This creates the command file, updates oclif metadata, and adds NUTs
32+
33+
## Step 2: Update package.json Topics
34+
35+
Open `package.json` and locate the `oclif.topics` section. Under `template > generate`, add a description for your new subtopic:
36+
37+
```json
38+
{
39+
"oclif": {
40+
"topics": {
41+
"template": {
42+
"subtopics": {
43+
"generate": {
44+
"subtopics": {
45+
"{metadataType}": {
46+
"description": "Commands for generating {metadataType} metadata"
47+
}
48+
}
49+
}
50+
}
51+
}
52+
}
53+
}
54+
}
55+
```
56+
57+
## Step 3: Set Command State (Optional)
58+
59+
If your command is not GA-ready, add a state to the command class:
60+
61+
```typescript
62+
public static readonly state = 'beta'; // or 'preview'
63+
```
64+
65+
**State options:**
66+
67+
- `beta`: Shows beta warning to users
68+
- `preview`: Shows preview warning to users
69+
- No state: Command is GA (requires backwards compatibility)
70+
71+
If you want to hide the command from docs and autocomplete:
72+
73+
```typescript
74+
public static readonly hidden = true;
75+
```
76+
77+
**Note:** Hidden commands won't be included in release notes.
78+
79+
## Step 4: Verify File Path
80+
81+
Ensure your command file follows the correct path convention:
82+
83+
- **Single top-level generator**: `src/commands/template/generate/{metadataType}/index.ts`
84+
- **Nested generator**: `src/commands/template/generate/{metadataType}/{subTemplate}.ts`
85+
86+
## Step 5: Define CLI Flags
87+
88+
Before 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.
89+
90+
**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.
91+
92+
### Agent instructions for adding flags
93+
94+
1. Tell user to run `sf dev generate flag` from plugin root.
95+
2. **Flow order:** (1) select command, (2) type (string/boolean/etc.), (3) name (kebab-case), (4) summary, (5) short name (optional), (6) required?, (7) multiple?
96+
3. List flags to add with suggested name, type, summary from generator interface.
97+
4. After user completes: (a) add mappings to options object if command passes opts to `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.
98+
99+
### Running the flag generator
100+
101+
```bash
102+
sf dev generate flag
103+
```
104+
105+
This will:
106+
107+
- Add the flag to your command's `flags` object
108+
- Generate TypeScript types
109+
- Add entries to the `messages.md` file
110+
111+
**Common flags to consider:**
112+
113+
- `--name` / `-n`: Name of the generated item (usually required)
114+
- `--output-dir` / `-d`: Output directory (default: '.')
115+
- `--template` / `-t`: Template type selection (if multiple templates)
116+
- `--api-version`: API version override
117+
118+
## Step 6: Review Message Files
119+
120+
Check `messages/{metadataType}.md` (merge from `template.generate.{metadataType}.md` if generator created a separate file) and ensure:
121+
122+
- Summary is clear and concise
123+
- Description provides helpful context
124+
- Flag descriptions are detailed and explain constraints
125+
- Examples are practical and cover common use cases
126+
127+
**Optional:** Add links to developer.salesforce.com docs in descriptions if helpful.
128+
129+
## Step 7: Implement the run() Method
130+
131+
Update the `run()` method to call `runGenerator`:
132+
133+
```typescript
134+
import { runGenerator } from '../../utils/templateCommand.js';
135+
136+
public async run(): Promise<CreateOutput> {
137+
const { flags } = await this.parse(CommandClass);
138+
139+
// Add any pre-processing or validation here
140+
141+
return runGenerator({
142+
templateType: TemplateType.{YourMetadataType},
143+
opts: flags,
144+
ux: new Ux({ jsonEnabled: this.jsonEnabled() }),
145+
});
146+
}
147+
```
148+
149+
## Step 8: Write/Update NUTs
150+
151+
Review the auto-generated NUTs in `test/commands/template/generate/{metadataType}/`. Add tests to validate:
152+
153+
- Required flags work correctly
154+
- Optional flags are respected
155+
- Correct files are created in the right locations
156+
- Flag combinations work as expected
157+
158+
Most template generators don't require scratch org connections.
159+
160+
## Step 9: Test Locally
161+
162+
// turbo
163+
Build and link the plugin:
164+
165+
```bash
166+
yarn build
167+
sf plugins link .
168+
```
169+
170+
Test your command:
171+
172+
```bash
173+
sf template generate {metadataType} --name TestExample --output-dir ./test-output
174+
```
175+
176+
Verify the generated files are correct.
177+
178+
## Step 10: Run Tests
179+
180+
// turbo
181+
Run the NUTs to ensure everything works:
182+
183+
```bash
184+
yarn test
185+
```
186+
187+
## Local Development with salesforcedx-templates
188+
189+
If you're also working on the template in `salesforcedx-templates`:
190+
191+
1. Ensure you're using yarn 1
192+
2. Update `package.json` to reference your local `salesforcedx-templates`:
193+
```json
194+
"dependencies": {
195+
"salesforcedx-templates": "file:../path/to/salesforcedx-templates"
196+
}
197+
```
198+
3. After template changes: `yarn build` in salesforcedx-templates
199+
4. Then: `yarn install --force && yarn build` in plugin-templates
200+
201+
## Troubleshooting
202+
203+
If your command does not appear:
204+
205+
- confirm file path matches convention
206+
- run yarn build
207+
- ensure oclif topics updated
208+
- relink plugin:
209+
210+
sf plugins unlink @salesforce/plugin-templates
211+
sf plugins link .
212+
213+
## Final Validation Checklist
214+
215+
Before opening PR ensure:
216+
217+
- command runs locally
218+
- files generate correctly
219+
- flags validated
220+
- messages documented
221+
- NUTs pass
222+
- topics updated

.claude/skills/concise/SKILL.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
name: concise
3+
description: when creating/modifying md files in skills/rules for AI
4+
disable-model-invocation: false
5+
---
6+
7+
# Concise
8+
9+
We want to save tokens and preserve context window size.
10+
11+
- use fragments/bullets, not full sentences
12+
- remove as many words as possible without altering meaning
13+
- cut repetition
14+
- prefer shorter words that mean the same thing

0 commit comments

Comments
 (0)