-
Notifications
You must be signed in to change notification settings - Fork 401
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
[WIP] James/create project #197
Conversation
"activationEvents": ["workspaceContains:sfdx-project.json"], | ||
"activationEvents": [ | ||
"workspaceContains:sfdx-project.json,", | ||
"onCommand:sfdx.force.project.create" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding an additional activation event for the extension to allow the create command to execute. Two scenarios arise from this:
- Project create command is ran but does not go execute (i.e. user cancels out of input), all other commands are still hidden because of their when clause.
- Project create command is ran and executes all the way through causing the host to refresh with the new folder and go through the extension loading again. Since the command creates sfdx project, sfdx-project.json will be present and the extension will activate, showing all the commands.
@@ -44,5 +44,6 @@ | |||
"SFDX: Execute Anonymous Apex with Currently Selected Text", | |||
"feature_previews_title": "Salesforce Feature Previews", | |||
"enable_refresh_description": | |||
"Enables refresh of SObject definitions from a scratch org" | |||
"Enables refresh of SObject definitions from a scratch org", | |||
"force_project_create_text": "SFDX: Create Project" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ruthemmanuelle please confirm that this text is ok.
@@ -117,6 +117,12 @@ export class SfdxWorkspaceChecker implements PreconditionChecker { | |||
} | |||
} | |||
|
|||
export class EmptyPreChecker implements PreconditionChecker { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Command does not require any preconditions to be ran (unlike the other commands which all needed an sfdx workspace).
|
||
execution.processExitSubject.subscribe(async data => { | ||
if (data != undefined && data.toString() === '0') { | ||
await vscode.commands.executeCommand( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will close and reopen vscode with the new project in the workspace.
public async gather(): Promise< | ||
CancelResponse | ContinueResponse<ProjectURI> | ||
> { | ||
const projectUri = await vscode.window.showOpenDialog({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opens native file picker with the settings I set. Only letting it select one folder. Hitting cancel will return undefined.
} | ||
} | ||
|
||
export class PathExistsChecker |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Globs for the directory path about to be created, should provide an override prompt if the path already exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new command's text looks good. I didn't review anything else.
Codecov Report
@@ Coverage Diff @@
## develop #197 +/- ##
==========================================
- Coverage 80.66% 80.46% -0.2%
==========================================
Files 110 111 +1
Lines 4453 4515 +62
Branches 727 740 +13
==========================================
+ Hits 3592 3633 +41
- Misses 706 726 +20
- Partials 155 156 +1
Continue to review full report at Codecov.
|
console.log('SFDX CLI Extension Activated'); | ||
|
||
// Context | ||
vscode.commands.executeCommand('setContext', 'sfdx:project_opened', true); | ||
const sfdxProjectOpened = await vscode.workspace.findFiles( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously always set to true because extension would only activate if sfdx-project.json was present. If the project create command is the activation reason, this may not be true.
import * as path from 'path'; | ||
import { StatusBarAlignment, StatusBarItem, window, workspace } from 'vscode'; | ||
|
||
const CONFIG_FILE = path.join(workspace.rootPath!, '.sfdx/sfdx-config.json'); | ||
const CONFIG_FILE = workspace.rootPath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the command can be activated without a workspace, the non-null assertion would cause an error. I set it to the top level sfdx-config.json. If this file does not exist, we will still be okay since displayDefaultUsername essentially ignores files that do not exist.
080c483
to
25a1618
Compare
projectName: string; | ||
} | ||
|
||
export class SelectProjectName implements ParametersGatherer<ProjectName> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these ParametersGatherers and Condition checker are currently only used in this class, I am leaving them here. If you would prefer to move them to commands.ts
, please comment and let me know.
@@ -46,6 +46,7 @@ export const messages = { | |||
'Enter desired directory (Press Enter to confirm or Esc to cancel)', | |||
parameter_gatherer_enter_username_name: 'Enter target username', | |||
parameter_gatherer_enter_alias_name: 'Enter a scratch org alias', | |||
parameter_gatherer_enter_project_name: 'Enter project name', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ruthemmanuelle these messages were also here when I last pinged you but forgot to @mention you here. Just wanted to double check that you were able to take a look at this file as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @Sweetman . I hadn't seen these other messages, but they look fine.
25a1618
to
52488f7
Compare
canSelectFiles: false, | ||
canSelectFolders: true, | ||
canSelectMany: false, | ||
openLabel: 'Create Project' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be externalized?
const CONFIG_FILE = path.join(workspace.rootPath!, '.sfdx/sfdx-config.json'); | ||
const CONFIG_FILE = workspace.rootPath | ||
? path.join(workspace.rootPath, '.sfdx/sfdx-config.json') | ||
: path.join(os.homedir(), '.sfdx/sfdx-config.json'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You changed a hardcoded path to not use "/" in another PR. Might as well do that again here.
inputs: ContinueResponse<ProjectNameAndPath> | CancelResponse | ||
): Promise<ContinueResponse<ProjectNameAndPath> | CancelResponse> { | ||
if (inputs.type === 'CONTINUE') { | ||
const listOfDirs = new glob.GlobSync( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would fs.existsSync() suffice?
expect(response.type).to.equal('CANCEL'); | ||
}); | ||
|
||
it('Should return cancel if user input is empty string', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try a string with just white spaces also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kaplanjosh @DatGuyJonathan Should we allow a user to enter just white space? If not, do we show them some form of info/error message? The CLI command works with just white space as a project name. I think we should prompt if they want to continue if the name is all whitespace but open to other ideas if y'all have any.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, so force-language-services allows it. It could be by-design that we don't trim the name; @GaryFNC can offer his thoughts on that. If anything is going to be fixed, it should go into force-language-services .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original discussion with Mike Miller, etc. was that any valid "folder" name was OK - so not much checking in force-language-services.... BUT, it shouldn't really allow empty input or just white spaces..... That should be caught in FLS, but it is a bit harder for a user to input that on the CLI command line, so didn't get noticed. We don't generally trim the names since spaces are allowed in folder names (although yet, it is odd and hard to read if the spaces all come at the end).
So, I would suggest catching it either in FLS and surfacing the error message and prevalidating in the vscode command if you want as well (like the long discussion we had on that issue with IDE2 and commands)
Why do we allow empty input for project name? If it's by mistake we should
fix that. If there's a reason, let's find out so we can discuss.
On Tue, Nov 7, 2017 at 12:57 PM Jonathan Widjaja ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In
packages/salesforcedx-vscode-core/test/commands/forceProjectCreate.test.ts
<#197 (comment)>
:
> + inputBoxSpy.onCall(1).returns('');
+ inputBoxSpy.onCall(2).returns(PROJECT_NAME);
+ });
+
+ after(() => {
+ inputBoxSpy.restore();
+ });
+
+ it('Should return cancel if project name is undefined', async () => {
+ const gatherer = new SelectProjectName();
+ const response = await gatherer.gather();
+ expect(inputBoxSpy.calledOnce).to.be.true;
+ expect(response.type).to.equal('CANCEL');
+ });
+
+ it('Should return cancel if user input is empty string', async () => {
I see, so force-language-services allows it. It could be by-design that we
don't trim the name; @GaryFNC <https://github.com/garyfnc> can offer his
thoughts on that. If anything is going to be fixed, it should go into
force-language-services .
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#197 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AE-dc7GjISyFAH-Vtg1t1zqFs2uZgGZXks5s0MRTgaJpZM4QMADG>
.
--
--
*Josh Kaplan* | Senior Director, Product Management | salesforce.com |
Phone: 415.836.3623
|
@kaplanjosh @DatGuyJonathan I spoke to Gary about allowing whitespace. He said that he spoke with Mike Miller and others about it a while back. The conclusion was that any legitimate folder name is ok. This varies from OS to OS which is why strong validation was not implemented. /cc @GaryFNC |
LGTM. Let's rebase and verify appveyor build is good. |
8405a16
to
2ce7983
Compare
2ce7983
to
3f52dc4
Compare
What does this PR do?
Add command to create a new DX project
What issues does this PR fix or reference?
@W-4284294@