-
Notifications
You must be signed in to change notification settings - Fork 16
W-22415490 feat: add generation of top level graphqlrc.yml file for generating react uiBundles #936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| */ | ||
|
|
||
| import path from 'node:path'; | ||
| import fs from 'node:fs/promises'; | ||
| import { Flags, SfCommand, Ux } from '@salesforce/sf-plugins-core'; | ||
| import { CreateOutput, UIBundleOptions, TemplateType } from '@salesforce/templates'; | ||
| import { Messages, SfProject } from '@salesforce/core'; | ||
|
|
@@ -15,6 +16,7 @@ Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); | |
| const messages = Messages.loadMessages('@salesforce/plugin-templates', 'ui-bundle.generate'); | ||
|
|
||
| export const UI_BUNDLES_DIR = 'uiBundles'; | ||
| const GRAPHQLRC_FILENAME = '.graphqlrc.yml'; | ||
|
|
||
| export default class UiBundleGenerate extends SfCommand<CreateOutput> { | ||
| public static readonly summary = messages.getMessage('summary'); | ||
|
|
@@ -62,6 +64,43 @@ export default class UiBundleGenerate extends SfCommand<CreateOutput> { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new `.graphqlrc.yml` at the sfdx project root so the GraphQL LSP extension | ||
| * can auto-discover it. The file at the project root references `schema.graphql` as a | ||
| * sibling and uses a recursive glob for documents so nested ui-bundle src trees are picked up. | ||
| * | ||
| * Returns the new file path on success, or undefined when not running inside an sfdx project, | ||
| * when the bundle's `.graphqlrc.yml` was not generated, or when a `.graphqlrc.yml` already | ||
| * exists at the project root. | ||
| */ | ||
| private static async createGraphqlrcAtProjectRoot(bundleSourcePath: string): Promise<string | undefined> { | ||
| let projectRoot: string; | ||
| try { | ||
| const project = await SfProject.resolve(); | ||
| projectRoot = project.getPath(); | ||
| } catch { | ||
| return undefined; | ||
| } | ||
|
|
||
| try { | ||
| await fs.access(bundleSourcePath); | ||
| } catch { | ||
| return undefined; | ||
| } | ||
|
|
||
| const targetPath = path.join(projectRoot, GRAPHQLRC_FILENAME); | ||
| try { | ||
| await fs.access(targetPath); | ||
| return undefined; | ||
| } catch { | ||
| // target does not exist — proceed | ||
| } | ||
|
|
||
| const content = "schema: 'schema.graphql'\ndocuments: './**/src/**/*.{graphql,js,ts,jsx,tsx}'\n"; | ||
| await fs.writeFile(targetPath, content); | ||
| return targetPath; | ||
| } | ||
|
|
||
| public async run(): Promise<CreateOutput> { | ||
| const { flags } = await this.parse(UiBundleGenerate); | ||
|
|
||
|
|
@@ -75,11 +114,30 @@ export default class UiBundleGenerate extends SfCommand<CreateOutput> { | |
| apiversion: flags['api-version'], | ||
| }; | ||
|
|
||
| return runGenerator({ | ||
| const ux = new Ux({ jsonEnabled: this.jsonEnabled() }); | ||
|
|
||
| const result = await runGenerator({ | ||
| templateType: TemplateType.UIBundle, | ||
| opts: flagsAsOptions, | ||
| ux: new Ux({ jsonEnabled: this.jsonEnabled() }), | ||
| ux, | ||
| templates: getCustomTemplates(this.configAggregator), | ||
| }); | ||
|
|
||
| if (flags.template === 'reactbasic') { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in theory, this should be part of all UIBundles, in fact, maybe all of the sfdx projects. the issue is that in lwc ones, we don't pull the schema down. Note: i would feel more comfortable if we add it for the ones we know and pull the schema.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had a question regarding the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, IIUC regarding the graphql schema file, I thought that the graphql.schema pulling happens outside of scope of running the sf cli commands
|
||
| const bundleSourcePath = path.join(result.outputDir, flags.name, GRAPHQLRC_FILENAME); | ||
| const newPath = await UiBundleGenerate.createGraphqlrcAtProjectRoot(bundleSourcePath); | ||
| if (newPath) { | ||
| const targetRelative = path.relative(process.cwd(), newPath); | ||
| const createLine = ` create ${targetRelative}`; | ||
| ux.log(createLine); | ||
| return { | ||
| ...result, | ||
| created: [...result.created, targetRelative], | ||
| rawOutput: `${result.rawOutput.replace(/\n$/, '')}\n${createLine}\n`, | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where's the origin of these "CustomTemplates"? what's the difference between adding it here (
flags.templatebelow), versus in thereactbasic"customTemplate"?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jodarove I'm not familiar with that construct, so here is claude's analysis of it: