Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/commands/template/generate/ui-bundle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ const messages = Messages.loadMessages('@salesforce/plugin-templates', 'ui-bundl
export const UI_BUNDLES_DIR = 'uiBundles';
const GRAPHQLRC_FILENAME = '.graphqlrc.yml';

// Templates that scaffold GraphQL tooling (a bundle-level .graphqlrc.yml plus a codegen config) and
// therefore need a project-root .graphqlrc.yml so the GraphQL LSP and lint tooling can auto-discover
// the schema across every ui-bundle in the project.
const TEMPLATES_WITH_GRAPHQL = new Set(['reactbasic', 'angularbasic']);

export default class UiBundleGenerate extends SfCommand<CreateOutput> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');
Expand Down Expand Up @@ -132,7 +137,7 @@ export default class UiBundleGenerate extends SfCommand<CreateOutput> {
templates: getCustomTemplates(this.configAggregator),
});

if (flags.template === 'reactbasic') {
if (TEMPLATES_WITH_GRAPHQL.has(flags.template)) {
const bundleSourcePath = path.join(result.outputDir, flags.name, GRAPHQLRC_FILENAME);
const newPath = await UiBundleGenerate.createGraphqlrcAtProjectRoot(bundleSourcePath);
if (newPath) {
Expand Down
44 changes: 40 additions & 4 deletions test/commands/template/generate/ui-bundle/index.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,53 @@ describe('template generate ui-bundle:', () => {
});

describe('Check UI bundle creation with angularbasic template', () => {
it('should create Angular UI bundle with all required files', () => {
afterEach(() => {
const rootGraphqlrc = path.join(projectDir, '.graphqlrc.yml');
if (fs.existsSync(rootGraphqlrc)) {
fs.unlinkSync(rootGraphqlrc);
}
});

it('should create Angular UI bundle with all required files and create .graphqlrc.yml at the project root', () => {
const outputDir = path.join(projectDir, 'force-app', 'main', 'default', UI_BUNDLES_DIR);
execCmd(`template generate ui-bundle --name MyAngularApp --template angularbasic --output-dir "${outputDir}"`, {
ensureExitCode: 0,
});
const firstResult = execCmd(
`template generate ui-bundle --name MyAngularApp --template angularbasic --output-dir "${outputDir}"`,
{
ensureExitCode: 0,
}
);
assert.file([
path.join(outputDir, 'MyAngularApp', 'MyAngularApp.uibundle-meta.xml'),
path.join(outputDir, 'MyAngularApp', 'src', 'index.html'),
path.join(outputDir, 'MyAngularApp', 'ui-bundle.json'),
path.join(outputDir, 'MyAngularApp', 'package.json'),
]);

const rootGraphqlrc = path.join(projectDir, '.graphqlrc.yml');
assert.file(rootGraphqlrc);
assert.fileContent(rootGraphqlrc, "schema: 'schema.graphql'");
assert.fileContent(rootGraphqlrc, "documents: './**/src/**/*.{graphql,js,ts,jsx,tsx}'");
expect(firstResult.shellOutput.stdout).to.contain('create .graphqlrc.yml');

const contentBefore = fs.readFileSync(rootGraphqlrc, 'utf8');
const mtimeBefore = fs.statSync(rootGraphqlrc).mtimeMs;

const secondResult = execCmd(
`template generate ui-bundle --name MyAngularApp2 --template angularbasic --output-dir "${outputDir}"`,
{
ensureExitCode: 0,
}
);
assert.file([
path.join(outputDir, 'MyAngularApp2', 'MyAngularApp2.uibundle-meta.xml'),
path.join(outputDir, 'MyAngularApp2', 'package.json'),
]);
expect(secondResult.shellOutput.stdout).to.not.contain('create .graphqlrc.yml');

const contentAfter = fs.readFileSync(rootGraphqlrc, 'utf8');
const mtimeAfter = fs.statSync(rootGraphqlrc).mtimeMs;
expect(contentAfter).to.equal(contentBefore);
expect(mtimeAfter).to.equal(mtimeBefore);
});
});

Expand Down
Loading