Skip to content

Commit

Permalink
Fix for landing page template copying.
Browse files Browse the repository at this point in the history
Was only copying the json file, so wasnt actually getting deployed to org. I was testing by just manually copying into local build so this slipped past.
  • Loading branch information
dbreese committed Jun 14, 2023
1 parent 1e23875 commit 2bced89
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 40 deletions.
58 changes: 36 additions & 22 deletions src/commands/templateChooserCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as path from 'path';
import * as fs from 'fs';

export interface TemplateQuickPickItem extends QuickPickItem {
filename: string;
filenamePrefix: string;
}

/**
Expand All @@ -22,36 +22,38 @@ export interface TemplateQuickPickItem extends QuickPickItem {
export class TemplateChooserCommand {
static readonly STATIC_RESOURCES_PATH =
'/force-app/main/default/staticresources';
static readonly LANDING_PAGE_FILENAME = 'landing_page.json';
static readonly LANDING_PAGE_FILENAME_PREFIX = 'landing_page';
static readonly JSON_FILE_EXTENSION = '.json';
static readonly METADATA_FILE_EXTENSION = '.resource-meta.xml';

static readonly TEMPLATE_LIST_ITEMS: TemplateQuickPickItem[] = [
{
label: l10n.t('Default'),
detail: l10n.t(
'Recently viewed Contacts, Accounts, and Opportunities.'
),
filename: 'landing_page_default.json'
filenamePrefix: 'landing_page_default'
},
{
label: l10n.t('Case Management'),
detail: l10n.t(
'New Case action and the 5 most recent Cases, Accounts, and Contacts.'
),
filename: 'landing_page_case_management.json'
filenamePrefix: 'landing_page_case_management'
},
{
label: l10n.t('Healthcare'),
detail: l10n.t(
'Global quick actions with BarcodeScanner, new Visitor, and more.'
),
filename: 'landing_page_healthcare.json'
filenamePrefix: 'landing_page_healthcare'
},
{
label: l10n.t('Retail Execution'),
detail: l10n.t(
'Global quick actions with new Opportunity, new Lead, and more.'
),
filename: 'landing_page_retail_execution.json'
filenamePrefix: 'landing_page_retail_execution'
}
];

Expand All @@ -70,31 +72,43 @@ export class TemplateChooserCommand {
return Promise.resolve();
}

await TemplateChooserCommand.copySelectedFile(
(selectedItem as TemplateQuickPickItem).filename
await TemplateChooserCommand.copySelectedFiles(
(selectedItem as TemplateQuickPickItem).filenamePrefix
);
}

/**
* This will copy the given template filename over to the staticresources/landing_page.json location.
* @param fileName name of the template file to copy.
* This will copy the given template files over to the staticresources/landing_page.* locations, including
* the .json and .resource-meta.xml file.
* @param fileNamePrefix filename prefix of the template file to copy.
*/
static async copySelectedFile(fileName: string): Promise<boolean> {
static async copySelectedFiles(fileNamePrefix: string): Promise<boolean> {
const workspaceFolders = workspace.workspaceFolders;
if (workspaceFolders && workspaceFolders.length > 0) {
const rootPath = workspaceFolders[0].uri.fsPath;
const sourcePath = path.join(
rootPath,
TemplateChooserCommand.STATIC_RESOURCES_PATH,
fileName
);
const destinationPath = path.join(
rootPath,
TemplateChooserCommand.STATIC_RESOURCES_PATH,
TemplateChooserCommand.LANDING_PAGE_FILENAME
);

fs.copyFileSync(sourcePath, destinationPath);
// copy both the json and metadata files.
for (const fileExtension of [
TemplateChooserCommand.JSON_FILE_EXTENSION,
TemplateChooserCommand.METADATA_FILE_EXTENSION
]) {
const fileName = `${fileNamePrefix}${fileExtension}`;
const destinationFileName = `${TemplateChooserCommand.LANDING_PAGE_FILENAME_PREFIX}${fileExtension}`;
console.log(`Copying ${fileName} to ${destinationFileName}`);

const sourcePath = path.join(
rootPath,
TemplateChooserCommand.STATIC_RESOURCES_PATH,
fileName
);
const destinationPath = path.join(
rootPath,
TemplateChooserCommand.STATIC_RESOURCES_PATH,
destinationFileName
);

fs.copyFileSync(sourcePath, destinationPath);
}
return Promise.resolve(true);
}
return Promise.reject('Could not determine workspace folder.');
Expand Down
42 changes: 24 additions & 18 deletions src/test/suite/commands/templateChooserCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ suite('Template Chooser Command Test Suite', () => {
label: 'Case Management',
description: 'This is the description',
detail: 'Contains a new case quick action, along with the 5 most recent cases, accounts, and contacts.',
filename: 'somefile.json'
filenamePrefix: 'somefile'
};

showQuickPickStub.onCall(0).returns(chosenItem);
Expand All @@ -51,23 +51,29 @@ suite('Template Chooser Command Test Suite', () => {
// execute our command
await TemplateChooserCommand.chooseTemplate();

// ensure copy was performed
const expectedSourcePath = path.join(
testPath,
TemplateChooserCommand.STATIC_RESOURCES_PATH,
'somefile.json'
);
const expectedDestinationPath = path.join(
testPath,
TemplateChooserCommand.STATIC_RESOURCES_PATH,
TemplateChooserCommand.LANDING_PAGE_FILENAME
);
assert.ok(
copyFileSyncStub.calledWith(
expectedSourcePath,
expectedDestinationPath
)
);
// ensure copy was performed for both json and metadata files
for (const fileExtension of [
TemplateChooserCommand.JSON_FILE_EXTENSION,
TemplateChooserCommand.METADATA_FILE_EXTENSION
]) {
const expectedSourcePath = path.join(
testPath,
TemplateChooserCommand.STATIC_RESOURCES_PATH,
`somefile${fileExtension}`
);
const expectedDestinationPath = path.join(
testPath,
TemplateChooserCommand.STATIC_RESOURCES_PATH,
`${TemplateChooserCommand.LANDING_PAGE_FILENAME_PREFIX}${fileExtension}`
);
assert.ok(
copyFileSyncStub.calledWith(
expectedSourcePath,
expectedDestinationPath
),
`Should attempt to copy ${expectedSourcePath} to ${expectedDestinationPath}`
);
}
});

test('Nothing is selected', async () => {
Expand Down

0 comments on commit 2bced89

Please sign in to comment.