Skip to content
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

Refactor "create template commands" to reduce code duplication #1246

Merged
merged 31 commits into from
Apr 17, 2019

Conversation

allileong
Copy link
Contributor

@allileong allileong commented Apr 8, 2019

What does this PR do?

  • Refactors our "create template commands" to reduce code duplication.
  • Moves the LWC create command from salesforcedx-vscode-lwc to saleforcedx-vscode-core

What issues does this PR fix or reference?

W-5988755

}).execute(cancellationToken);

execution.processExitSubject.subscribe(async data => {
this.logMetric(execution.command.logName, startTime);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the logging for the directory type (default or custom) is missing. I think it had to do with me making this branch before I added that in 😛 . Check out one of the command files in a more recent version of develop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@brpowell
Copy link
Contributor

brpowell commented Apr 8, 2019

@allileong The forceLightningLwcCreate command should be updated to use the baseTemplateCommand now as well. That one is sneaky because it's in the lwc package. Besides that and the logging comment I left it looks good to me!

@codecov
Copy link

codecov bot commented Apr 8, 2019

Codecov Report

Merging #1246 into develop will increase coverage by 1.83%.
The diff coverage is 83.17%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1246      +/-   ##
===========================================
+ Coverage    70.99%   72.83%   +1.83%     
===========================================
  Files          198      201       +3     
  Lines         7471     7332     -139     
  Branches       786      761      -25     
===========================================
+ Hits          5304     5340      +36     
+ Misses        2010     1834     -176     
- Partials       157      158       +1
Impacted Files Coverage Δ
.../salesforcedx-vscode-core/src/commands/commands.ts 72.8% <ø> (-3.76%) ⬇️
...re/src/commands/templates/metadataTypeConstants.ts 100% <100%> (ø)
...orcedx-vscode-core/src/commands/templates/index.ts 100% <100%> (ø)
...core/src/commands/templates/baseTemplateCommand.ts 64.7% <64.7%> (ø)
.../src/commands/templates/forceLightningAppCreate.ts 86.66% <86.66%> (ø)
...ommands/templates/forceLightningInterfaceCreate.ts 86.66% <86.66%> (ø)
...e/src/commands/templates/forceApexTriggerCreate.ts 86.66% <86.66%> (ø)
.../src/commands/templates/forceLightningLwcCreate.ts 86.66% <86.66%> (ø)
...c/commands/templates/forceVisualforcePageCreate.ts 86.66% <86.66%> (ø)
...ore/src/commands/templates/forceApexClassCreate.ts 86.66% <86.66%> (ø)
... and 16 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3102ef9...2d886b2. Read the comment docs.

@@ -30,74 +30,6 @@ import { taskViewService } from '../statuses';
import { telemetryService } from '../telemetry';
import { getRootWorkspacePath, hasRootWorkspace } from '../util';

export class LightningFilePathExistsChecker
Copy link
Contributor Author

@allileong allileong Apr 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consolidated the 2 LightningFilePathExistsCheckers (one was here and the other was in the salesforcedx-vscode-lwc extension) and the FilePathExistsChecker from this file, and moved it to the baseTemplateCommand.ts file.

return inputs;
} else {
const overwrite = await notificationService.showWarningMessage(
nls.localize('warning_prompt_file_overwrite', this.metadataLabel),
Copy link
Contributor Author

@allileong allileong Apr 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screen Shot 2019-04-09 at 4 52 39 PM

The new warning message includes the metadata type of the entity that the user is choosing to overwrite. The new string added to the end of the i18n.ts file with names ending in `*_message_name` represent the different metadata names that could replace 'Aura Bundle' in the screenshot above.

fileNameGatherer,
outputDirGatherer
),
new ForceLightningAppCreateExecutor(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the exception of this line, each of the forceLightning*Create() methods are exactly the same. This may be a place to further reduce code duplication in the future.

@@ -308,217 +304,6 @@ describe('Command Utilities', () => {
});
});

describe('LightningFilePathExistsChecker', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests were moved to the baseTemplateCommand.test.ts file.

});
});

describe('FilePathExistsChecker for Aura bundle', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests from this line to the end of the file were moved from commands.test.ts. With more time, I would have assessed whether we should be keeping these tests and whether or not more tests need to be added.

@allileong
Copy link
Contributor Author

Hey @brpowell @lcampos, these code changes are ready for review. With more time, I would have liked to:

  • Spend more time seeing if the tests in the baseTemplateCommand.test.ts file that are validating the FilePathExistsChecker should be updated (test cases added or removed) since the checker itself has been modified. The current tests have been around since before this refactor
  • Manually test the create commands more

@jonnyhork
Copy link
Contributor

@lcampos This PR would fix the issues related to W-6017178 in Theia. I was wondering if there is anything I can do to help this get merged? I know you guys are a bit short staffed. Thanks!

@lcampos
Copy link
Contributor

lcampos commented Apr 16, 2019

@jonnyhork I've made some updates to the PR and functionality wise it's ready, I just want to add a couple more tests and will then get it merged. I'm thinking this will be merged later today or early tomorrow.

@jonnyhork
Copy link
Contributor

Great, thanks!

nls.localize('force_lightning_app_create_text')
);
expect(lightningAppCreate.getDefaultDirectory()).to.equal('aura');
expect(lightningAppCreate.getFileExtension()).to.equal('.app');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're checking defaultDirectory and fileExtension, we might as well check the sourcePathStrategy for the commands too. For the bundles we want to make sure they're using BundlePathStrategy, o/w DefaultPathStrategy.

Copy link
Contributor

@brpowell brpowell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just had a comment about checking source path strategy as part of the tests.

@lcampos lcampos merged commit 2a7d578 into develop Apr 17, 2019
@lcampos lcampos deleted the aleong/templateRefactor branch April 17, 2019 01:17
@lcampos
Copy link
Contributor

lcampos commented Apr 17, 2019

fyi @jonnyhork this is now in develop branch. I'll work on PR #1259 next.

@forcedotcom forcedotcom deleted a comment from jonnyhork Apr 17, 2019
@salesforce-cla
Copy link

salesforce-cla bot commented Apr 7, 2021

Thanks for the contribution! Unfortunately we can't verify the commit author(s): Allison Leong <a***@s***.com>. One possible solution is to add that email to your GitHub account. Alternatively you can change your commits to another email and force push the change. After getting your commits associated with your GitHub account, refresh the status of this Pull Request.

@salesforce-cla
Copy link

salesforce-cla bot commented May 5, 2021

Thanks for the contribution! Unfortunately we can't verify the commit author(s): Allison Leong <a***@s***.com> Luis Campos <l***@s***.com>. One possible solution is to add that email to your GitHub account. Alternatively you can change your commits to another email and force push the change. After getting your commits associated with your GitHub account, refresh the status of this Pull Request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants