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

[WIP] James/create project #197

Merged
merged 11 commits into from
Nov 14, 2017
Merged

[WIP] James/create project #197

merged 11 commits into from
Nov 14, 2017

Conversation

Sweetman
Copy link
Contributor

What does this PR do?

Add command to create a new DX project

What issues does this PR fix or reference?

@W-4284294@

"activationEvents": ["workspaceContains:sfdx-project.json"],
"activationEvents": [
"workspaceContains:sfdx-project.json,",
"onCommand:sfdx.force.project.create"
Copy link
Contributor Author

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:

  1. 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.
  2. 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"
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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(
Copy link
Contributor Author

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({
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

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.

The new command's text looks good. I didn't review anything else.

@codecov
Copy link

codecov bot commented Oct 30, 2017

Codecov Report

Merging #197 into develop will decrease coverage by 0.19%.
The diff coverage is 67.64%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
...ages/salesforcedx-vscode-core/src/messages/i18n.ts 100% <ø> (ø) ⬆️
packages/salesforcedx-vscode-core/src/index.ts 100% <100%> (ø) ⬆️
...ges/salesforcedx-vscode-core/src/commands/index.ts 100% <100%> (ø) ⬆️
.../salesforcedx-vscode-core/src/commands/commands.ts 83.66% <33.33%> (-1.01%) ⬇️
...edx-vscode-core/src/commands/forceProjectCreate.ts 64.15% <64.15%> (ø)
...esforcedx-vscode-core/src/scratch-org-decorator.ts 87.5% <75%> (-2.98%) ⬇️
...s/salesforcedx-apex-debugger/src/commands/index.ts 41.66% <0%> (-1.82%) ⬇️
...ges/salesforcedx-vscode-apex-debugger/src/index.ts 25.74% <0%> (+0.49%) ⬆️

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 ceccbb0...3f52dc4. Read the comment docs.

console.log('SFDX CLI Extension Activated');

// Context
vscode.commands.executeCommand('setContext', 'sfdx:project_opened', true);
const sfdxProjectOpened = await vscode.workspace.findFiles(
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

@Sweetman Sweetman changed the title James/create project [WIP] James/create project Oct 31, 2017
projectName: string;
}

export class SelectProjectName implements ParametersGatherer<ProjectName> {
Copy link
Contributor Author

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.

@Sweetman Sweetman changed the title [WIP] James/create project James/create project Nov 1, 2017
@@ -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',
Copy link
Contributor Author

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.

Copy link
Contributor

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.

@Sweetman Sweetman changed the title James/create project [WIP] James/create project Nov 2, 2017
canSelectFiles: false,
canSelectFolders: true,
canSelectMany: false,
openLabel: 'Create Project'
Copy link
Contributor

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');
Copy link
Contributor

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(
Copy link
Contributor

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 () => {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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 .

Copy link
Contributor

@GaryFNC GaryFNC Nov 9, 2017

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)

@kaplanjosh
Copy link

kaplanjosh commented Nov 7, 2017 via email

@Sweetman
Copy link
Contributor Author

Sweetman commented Nov 8, 2017

@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

@DatGuyJonathan
Copy link
Contributor

LGTM. Let's rebase and verify appveyor build is good.

@Sweetman Sweetman force-pushed the james/createProject branch 2 times, most recently from 8405a16 to 2ce7983 Compare November 13, 2017 19:26
@Sweetman Sweetman merged commit 23cfb4f into develop Nov 14, 2017
@Sweetman Sweetman deleted the james/createProject branch November 14, 2017 00:32
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.

None yet

5 participants