Skip to content

Commit c29cfc2

Browse files
authored
feat: add analytics dashboard lwc templates (#325)
* feat: support aura/lwc component templates @W-9191596@ * feat: analytics dashboard lwc templates @W-9191596@ * fix: update to union type on LightningComponentOptions and also use a hard-coded list on the options flag config for --template to match for consistency.
1 parent 11e4255 commit c29cfc2

26 files changed

+434
-76
lines changed

packages/plugin-templates/messages/messages.json

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"MissingAuraFolder": "Lightning bundles must have a parent folder named 'aura'.",
6565
"MissingAppname": "Missing required flag:\n -n, --appname APPNAME name of the generated Lightning app\nSee more help with --help\n",
6666
"MissingComponentName": "Missing required flag:\n -n, --componentname COMPONENTNAME name of the generated Lightning component\nSee more help with --help\n",
67+
"MissingLightningComponentTemplate": "Template %s not available for component type %s.",
6768
"MissingLWCFolder": "Lightning bundles must have a parent folder named 'lwc'.",
6869
"MissingEventname": "Missing required flag:\n -n, --eventname EVENTNAME name of the generated Lightning event\nSee more help with --help\n",
6970
"MissingInterfacename": "Missing required flag:\n -n, --interfacename INTERFACENAME name of the generated Lightning interface\nSee more help with --help\n",

packages/plugin-templates/src/commands/force/lightning/component/create.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99

1010
import { flags } from '@salesforce/command';
1111
import LightningComponentGenerator from '@salesforce/templates/lib/generators/lightningComponentGenerator';
12-
import { CreateUtil } from '@salesforce/templates/lib/utils';
1312
import { AnyJson } from '@salesforce/ts-types';
1413
import { MessageUtil, TemplateCommand } from '../../../../utils';
1514

16-
const lightningComponentFileSuffix = /.cmp$/;
1715
const BUNDLE_TYPE = MessageUtil.get('Component');
1816

1917
export default class LightningComponent extends TemplateCommand {
@@ -53,11 +51,10 @@ export default class LightningComponent extends TemplateCommand {
5351
char: 't',
5452
description: MessageUtil.get('TemplateFlagDescription'),
5553
longDescription: MessageUtil.get('TemplateFlagLongDescription'),
56-
default: 'DefaultLightningCmp',
57-
options: CreateUtil.getCommandTemplatesForFiletype(
58-
lightningComponentFileSuffix,
59-
'lightningcomponent'
60-
)
54+
default: 'default',
55+
// Note: keep this list here and LightningComponentOptions#template in-sync with the
56+
// templates/lightningcomponents/[aura|lwc]/* folders
57+
options: ['default', 'analyticsDashboard', 'analyticsDashboardWithStep']
6158
}),
6259
outputdir: flags.string({
6360
char: 'd',

packages/plugin-templates/test/commands/force/lightning/component/create.test.ts

+180-4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,31 @@ describe('Lightning component creation tests:', () => {
5959
);
6060
}
6161
);
62+
63+
test
64+
.withOrg()
65+
.withProject()
66+
.stdout()
67+
.command([
68+
'force:lightning:component:create',
69+
'--componentname',
70+
'foo',
71+
'--outputdir',
72+
'aura',
73+
'--template',
74+
'default'
75+
])
76+
.it(
77+
'should create lightning aura component files from default template in the aura output directory',
78+
ctx => {
79+
assert.file(AuraLightningTestFormatter.fileformatter('foo', 'foo'));
80+
assert.file(path.join('aura', 'foo', 'foo.cmp-meta.xml'));
81+
assert.fileContent(
82+
path.join('aura', 'foo', 'foo.cmp-meta.xml'),
83+
'<AuraDefinitionBundle xmlns="http://soap.sforce.com/2006/04/metadata">'
84+
);
85+
}
86+
);
6287
});
6388

6489
describe('Check lightning aura components creation without -meta.xml file', () => {
@@ -112,12 +137,12 @@ describe('Lightning component creation tests:', () => {
112137
.it(
113138
'should create lightning web component files in the lwc output directory with the internal flag for disabling -meta.xml files',
114139
ctx => {
115-
assert.file(
116-
path.join('lwc', 'internallwctest', 'internallwctest.html')
117-
);
118140
assert.noFile(
119141
path.join('lwc', 'internallwctest', 'internallwctest.js-meta.xml')
120142
);
143+
assert.file(
144+
path.join('lwc', 'internallwctest', 'internallwctest.html')
145+
);
121146
assert.file(
122147
path.join('lwc', 'internallwctest', 'internallwctest.js')
123148
);
@@ -144,9 +169,119 @@ describe('Lightning component creation tests:', () => {
144169
'lwc'
145170
])
146171
.it(
147-
'should create lightning web component files in the lwc output directory with the internal flag for disabling -meta.xml files',
172+
'should create lightning web component files in the lwc output directory',
148173
ctx => {
149174
assert.file(path.join('lwc', 'foo', 'foo.js-meta.xml'));
175+
assert.file(path.join('lwc', 'foo', 'foo.html'));
176+
assert.file(path.join('lwc', 'foo', 'foo.js'));
177+
assert.fileContent(
178+
path.join('lwc', 'foo', 'foo.js'),
179+
'export default class Foo extends LightningElement {}'
180+
);
181+
}
182+
);
183+
184+
test
185+
.withOrg()
186+
.withProject()
187+
.stdout()
188+
.command([
189+
'force:lightning:component:create',
190+
'--componentname',
191+
'foo',
192+
'--outputdir',
193+
'lwc',
194+
'--type',
195+
'lwc',
196+
'--template',
197+
'default'
198+
])
199+
.it(
200+
'should create lightning web component files from default template in the lwc output directory',
201+
ctx => {
202+
assert.file(path.join('lwc', 'foo', 'foo.js-meta.xml'));
203+
assert.file(path.join('lwc', 'foo', 'foo.html'));
204+
assert.file(path.join('lwc', 'foo', 'foo.js'));
205+
assert.fileContent(
206+
path.join('lwc', 'foo', 'foo.js'),
207+
'export default class Foo extends LightningElement {}'
208+
);
209+
}
210+
);
211+
});
212+
213+
describe('Check analytics dashboard lwc creation', () => {
214+
test
215+
.withOrg()
216+
.withProject()
217+
.stdout()
218+
.command([
219+
'force:lightning:component:create',
220+
'--componentname',
221+
'foo',
222+
'--outputdir',
223+
'lwc',
224+
'--type',
225+
'lwc',
226+
'--template',
227+
'analyticsDashboard'
228+
])
229+
.it(
230+
'should create analyticsDashboard lwc files in the lwc output directory',
231+
ctx => {
232+
const jsFile = path.join('lwc', 'foo', 'foo.js');
233+
const metaFile = path.join('lwc', 'foo', 'foo.js-meta.xml');
234+
assert.file(metaFile);
235+
assert.file(path.join('lwc', 'foo', 'foo.html'));
236+
assert.file(jsFile);
237+
assert.fileContent(metaFile, '<target>analytics__Dashboard</target>');
238+
assert.fileContent(metaFile, 'targets="analytics__Dashboard"');
239+
assert.fileContent(metaFile, '<hasStep>false</hasStep>');
240+
assert.fileContent(
241+
jsFile,
242+
'export default class Foo extends LightningElement {'
243+
);
244+
assert.fileContent(jsFile, '@api getState;');
245+
assert.fileContent(jsFile, '@api setState;');
246+
}
247+
);
248+
test
249+
.withOrg()
250+
.withProject()
251+
.stdout()
252+
.command([
253+
'force:lightning:component:create',
254+
'--componentname',
255+
'foo',
256+
'--outputdir',
257+
'lwc',
258+
'--type',
259+
'lwc',
260+
'--template',
261+
'analyticsDashboardWithStep'
262+
])
263+
.it(
264+
'should create analyticsDashboardWithStep lwc files in the lwc output directory',
265+
ctx => {
266+
const jsFile = path.join('lwc', 'foo', 'foo.js');
267+
const metaFile = path.join('lwc', 'foo', 'foo.js-meta.xml');
268+
assert.file(metaFile);
269+
assert.file(path.join('lwc', 'foo', 'foo.html'));
270+
assert.file(jsFile);
271+
assert.fileContent(metaFile, '<target>analytics__Dashboard</target>');
272+
assert.fileContent(metaFile, 'targets="analytics__Dashboard"');
273+
assert.fileContent(metaFile, '<hasStep>true</hasStep>');
274+
assert.fileContent(
275+
jsFile,
276+
'export default class Foo extends LightningElement {'
277+
);
278+
assert.fileContent(jsFile, '@api getState;');
279+
assert.fileContent(jsFile, '@api setState;');
280+
assert.fileContent(jsFile, '@api results;');
281+
assert.fileContent(jsFile, '@api metadata;');
282+
assert.fileContent(jsFile, '@api selection;');
283+
assert.fileContent(jsFile, '@api setSelection;');
284+
assert.fileContent(jsFile, '@api selectMode;');
150285
}
151286
);
152287
});
@@ -184,5 +319,46 @@ describe('Lightning component creation tests:', () => {
184319
.it('should throw missing lwc parent folder error', ctx => {
185320
expect(ctx.stderr).to.contain(messages.getMessage('MissingLWCFolder'));
186321
});
322+
test
323+
.withOrg()
324+
.withProject()
325+
.stderr()
326+
.command([
327+
'force:lightning:component:create',
328+
'--outputdir',
329+
'lwc',
330+
'--componentname',
331+
'foo',
332+
'--type',
333+
'lwc',
334+
'--template',
335+
'foo'
336+
])
337+
.it('should throw invalid template error', ctx => {
338+
expect(ctx.stderr).to.contain(messages.getMessage('InvalidTemplate'));
339+
});
340+
test
341+
.withOrg()
342+
.withProject()
343+
.stderr()
344+
.command([
345+
'force:lightning:component:create',
346+
'--outputdir',
347+
'aura',
348+
'--componentname',
349+
'foo',
350+
'--type',
351+
'aura',
352+
'--template',
353+
'analyticsDashboard'
354+
])
355+
.it('should throw missing template error', ctx => {
356+
expect(ctx.stderr).to.contain(
357+
messages.getMessage('MissingLightningComponentTemplate', [
358+
'analyticsDashboard',
359+
'aura'
360+
])
361+
);
362+
});
187363
});
188364
});

0 commit comments

Comments
 (0)