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

New menu for selecting output directory for "create" commands #1187

Merged
merged 13 commits into from
Mar 28, 2019

Conversation

brpowell
Copy link
Contributor

What does this PR do?

Revises the menu for selecting an output directory for the create commands that generates templates. Users are now prompted with a list of default output options. If they want to choose a custom directory, they can select the last option of the menu to show a list of all directories in the project. For components that require their parent folder to be named something specific, it is automatically created whether the chosen output directory has that name or not.

What issues does this PR fix or reference?

W-5815448
#852 #998

@@ -92,7 +88,7 @@ const fileNameGatherer = new SelectFileName();
const lightningFilePathExistsChecker = new LightningFilePathExistsChecker();

export async function forceLightningAppCreate(explorerDir?: any) {
const outputDirGatherer = new SelectStrictDirPath(explorerDir, 'aura');
const outputDirGatherer = new SelectOutputDir('aura', true);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because aura bundles require the "aura" parent folder, we let the constructor know this requirement by specifying "true".

@@ -27,7 +27,11 @@ export default class SfdxPackageDirectories {
if (dirPath.startsWith(path.sep)) {
dirPath = dirPath.substring(1);
}
packageDirectoryPaths.push(dirPath);
if (packageDirectory.default) {
packageDirectoryPaths = [dirPath].concat(packageDirectoryPaths);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Slight modification to have the default package directory in a project be the first element of the list.

outputDirGatherer,
fileNameGatherer
fileNameGatherer,
outputDirGatherer
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switched the order of these gatherers to keep the experience consistent with the other create commands.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would expect this change to break Should create Lightning LWC on the scaffolding.test.ts I fixed a few days ago.

@brpowell
Copy link
Contributor Author

@lcampos @ntotten Should we add telemetry data to measure when default folders are chosen vs. custom? I did something similar for the SObject refresh by appending the source to the command execution event - would that be sufficient?

@codecov
Copy link

codecov bot commented Mar 24, 2019

Codecov Report

Merging #1187 into develop will decrease coverage by 0.01%.
The diff coverage is 46.73%.

Impacted file tree graph

@@            Coverage Diff             @@
##           develop   #1187      +/-   ##
==========================================
- Coverage    71.01%     71%   -0.02%     
==========================================
  Files          196     196              
  Lines         7379    7397      +18     
  Branches       780     781       +1     
==========================================
+ Hits          5240    5252      +12     
- Misses        1983    1989       +6     
  Partials       156     156
Impacted Files Coverage Δ
...vscode-lwc/src/commands/forceLightningLwcCreate.ts 0% <0%> (ø) ⬆️
...ode-core/src/sfdxProject/sfdxPackageDirectories.ts 94.59% <100%> (+0.3%) ⬆️
...re/src/commands/forceVisualforceComponentCreate.ts 42.85% <28.57%> (+0.43%) ⬆️
...ode-core/src/commands/forceLightningEventCreate.ts 42.85% <28.57%> (+0.43%) ⬆️
...core/src/commands/forceLightningInterfaceCreate.ts 42.85% <28.57%> (+0.43%) ⬆️
...scode-core/src/commands/forceLightningAppCreate.ts 42.85% <28.57%> (+0.43%) ⬆️
...core/src/commands/forceLightningComponentCreate.ts 42.85% <28.57%> (+0.43%) ⬆️
...vscode-core/src/commands/forceApexTriggerCreate.ts 47.22% <28.57%> (+0.16%) ⬆️
...de-core/src/commands/forceVisualforcePageCreate.ts 40% <33.33%> (-0.63%) ⬇️
...x-vscode-core/src/commands/forceApexClassCreate.ts 40% <33.33%> (-0.63%) ⬇️
... and 1 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 fb1ed41...aabd51f. Read the comment docs.

Copy link
Contributor

@sfsholden sfsholden left a comment

Choose a reason for hiding this comment

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

LGTM

this.globKeyWord = globKeyWord;
private typeDir: string;
private typeDirRequired: boolean | undefined;
public readonly defaultOutput = '/main/default';
Copy link
Contributor

@lcampos lcampos Mar 25, 2019

Choose a reason for hiding this comment

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

I think this (use of defaultOutput's value as it is) is going to break on Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yikes good catch

let relativePath = path.relative(srcPath, path.join(value, '/'));
relativePath = path.join(relativePath, '');
public getCustomOptions(rootPath: string): string[] {
return new glob.GlobSync(path.join(rootPath, '**/')).found.map(value => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is going to break on Windows, can you verify ?

Copy link
Contributor

Choose a reason for hiding this comment

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

@lcampos do we need a path utility in our core library maybe? This seems to be a common problem. Maybe if we prevented the use of require('path)` and used our own utility, it would cut down on these windows bugs?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, using path is the right way to address this since its a Nodejs module and it does a good job across platforms.

@@ -235,5 +235,6 @@ export const messages = {
error_no_default_username:
'No default org is set. Run "SFDX: Create a Default Scratch Org" or "SFDX: Authorize an Org" to set one.',
error_no_default_devhubusername:
'No default Dev Hub is set. Run "SFDX: Authorize a Dev Hub" to set one.'
'No default Dev Hub is set. Run "SFDX: Authorize a Dev Hub" to set one.',
custom_output_directory: 'Select a Custom Directory'
Copy link
Contributor

@lcampos lcampos Mar 25, 2019

Choose a reason for hiding this comment

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

if (rootPath) {
let packageDirs: string[] = [];
try {
packageDirs = await SfdxPackageDirectories.getPackageDirectoryPaths();
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool handling for multiple packages.

@@ -90,10 +86,7 @@ const fileNameGatherer = new SelectFileName();
const filePathExistsChecker = new FilePathExistsChecker(APEX_TRIGGER_EXTENSION);

export async function forceApexTriggerCreate(explorerDir?: any) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to keep the explorerDir parameter now that's not being used ? Same question applies to the other create commands being modified.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so? I wasn't really sure what it was being used for in the first place...

@lcampos
Copy link
Contributor

lcampos commented Mar 25, 2019

@brpowell I do think adding telemetry to see how the feature is used would help. I know we already have some to track the execution time. You can either add more details to that one or add a new log line, it's up to you.

@ntotten
Copy link
Contributor

ntotten commented Mar 25, 2019

@lcampos @ntotten Should we add telemetry data to measure when default folders are chosen vs. custom? I did something similar for the SObject refresh by appending the source to the command execution event - would that be sufficient?

We should track overall use and maybe the result folder is worth doing - although don't track the folder name because it might contain PII, just track default vs custom. I'm not sure what it will really tell us? I would be interested in perf numbers though on how long creates take so we can figure out if any of them are slow, but i think we can do that as separate work.

@ntotten
Copy link
Contributor

ntotten commented Mar 25, 2019

@brpowell Does the new aura extension that was just merged on friday also need this change applied to it? //cc @nrkruk @lcampos

@lcampos
Copy link
Contributor

lcampos commented Mar 25, 2019

@brpowell Does the new aura extension that was just merged on friday also need this change applied to it? //cc @nrkruk @lcampos

These changes already cover the create commands for aura and lwc.

@@ -56,7 +57,12 @@ class ForceApexClassCreateExecutor extends SfdxCommandletExecutor<
}).execute(cancellationToken);

execution.processExitSubject.subscribe(async data => {
this.logMetric(execution.command.logName, startTime);
const dirType = response.data.outputdir.endsWith(
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 template commands badly need to be refactored to avoid having so much duplicated code. I started doing so but stuck it in another branch to separate it from this work. I'll make a story for it.

@brpowell brpowell requested a review from lcampos March 26, 2019 18:56
Copy link
Contributor

@ruthemmanuelle ruthemmanuelle left a comment

Choose a reason for hiding this comment

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

Thanks for the ping and the screenshot, @lcampos . I added a commit that changed "Select" to "Choose" in order to be more in line with our style guidelines. We use "select" for things like checkboxes, and "choose" when the choice is from a broader set of possibilities. Cc: @brpowell

@brpowell brpowell merged commit e102ca8 into develop Mar 28, 2019
@brpowell brpowell deleted the bp/defaultTemplates branch March 28, 2019 16:05
ruthemmanuelle added a commit that referenced this pull request Apr 3, 2019
@lcampos or @brpowell - Please check this updated text for accuracy:
Add a menu for selecting an output directory for commands that create metadata from a template; create the `default` directory, if it doesn’t exist, when running these commands ([PR #1187](#1187), [Issue #852](#852), [Issue #998](#998))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants