forked from salesforce/salesforcedx-vscode-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathonboardingWizard.ts
More file actions
97 lines (89 loc) · 3.99 KB
/
onboardingWizard.ts
File metadata and controls
97 lines (89 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import * as vscode from 'vscode';
import { TemplateChooserCommand } from './templateChooserCommand';
import { BriefcaseCommand } from './briefcaseCommand';
import { DeployToOrgCommand } from './deployToOrgCommand';
import { ConfigureProjectCommand } from './configureProjectCommand';
import { AuthorizeCommand } from './authorizeCommand';
import { InstructionsWebviewProvider } from '../../webviews/instructions';
import { LwcGenerationCommand } from './lwcGenerationCommand';
export const wizardCommand = 'salesforcedx-vscode-offline-app.onboardingWizard';
const onboardingWizardStateKey =
'salesforcedx-vscode-offline-app.onboardingWizard.projectCreationState';
enum OnboardingWizardState {
projectConfigured
}
async function runPostProjectConfigurationSteps(
extensionUri: vscode.Uri
): Promise<void> {
return new Promise(async (resolve) => {
await AuthorizeCommand.authorizeToOrg();
await BriefcaseCommand.setupBriefcase(extensionUri);
await TemplateChooserCommand.chooseTemplate(extensionUri);
await LwcGenerationCommand.createSObjectLwcQuickActions(extensionUri);
await AuthorizeCommand.authorizeToOrg();
await DeployToOrgCommand.deployToOrg();
await InstructionsWebviewProvider.showDismissableInstructions(
extensionUri,
vscode.l10n.t('View in the Salesforce Mobile App'),
'resources/instructions/salesforcemobileapp.html'
);
return resolve();
});
}
export function onActivate(context: vscode.ExtensionContext) {
// If activation is coming as the result of the project being newly
// loaded into the workspace, pick up with the next step of the wizard.
const isPostProjectConfiguration =
context.globalState.get(onboardingWizardStateKey) ===
OnboardingWizardState.projectConfigured;
if (isPostProjectConfiguration) {
context.globalState.update(onboardingWizardStateKey, undefined);
vscode.commands.executeCommand(wizardCommand, true);
}
}
export function registerCommand(context: vscode.ExtensionContext) {
const disposable = vscode.commands.registerCommand(
wizardCommand,
async (fromPostProjectConfiguration: boolean = false) => {
if (fromPostProjectConfiguration) {
await runPostProjectConfigurationSteps(context.extensionUri);
} else {
const projectDir = await new ConfigureProjectCommand(
context.extensionUri
).configureProject();
if (!projectDir) {
// No directory selected. Do not continue.
return Promise.resolve();
} else if (
vscode.workspace.workspaceFolders &&
vscode.workspace.workspaceFolders.length > 0 &&
vscode.workspace.workspaceFolders[0].uri.fsPath ===
projectDir
) {
// Selected folder is already loaded into the workspace.
// Run the next steps directly, because the workspace will
// not reload in this case.
await runPostProjectConfigurationSteps(
context.extensionUri
);
} else {
// Different project folder from what's currently loaded
// into the workspace. The workspace will reload,
// and we need to set a breadcrumb to pick up with the
// next steps, after it does.
context.globalState.update(
onboardingWizardStateKey,
OnboardingWizardState.projectConfigured
);
}
}
}
);
context.subscriptions.push(disposable);
}