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

Move code around #44

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"commands": [
{
"command": "salesforcedx-vscode-offline-app.onboardingWizard",
"title": "%extension.command.title%",
"category": "%extension.command.category%"
"title": "%extension.commands.config-wizard.title%",
"category": "%extension.commands.config-wizard.category%"
}
]
},
Expand Down
4 changes: 2 additions & 2 deletions package.nls.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extension.command.title": "Configuration Wizard",
"extension.command.category": "Offline Starter Kit",
"extension.commands.config-wizard.title": "Configuration Wizard",
"extension.commands.config-wizard.category": "Offline Starter Kit",
"extension.displayName": "Salesforce Mobile Extensions for Visual Studio Code",
"extension.description": "Tools to help developers create their Salesforce Mobile experiences in a VSCode development environment."
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { commands, window, l10n } from 'vscode';
import { OrgUtils } from '../utils/orgUtils';
import { OrgUtils } from '../../utils/orgUtils';

export class AuthorizeCommand {
static async authorizeToOrg(): Promise<boolean> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { ProgressLocation, Uri, window, l10n } from 'vscode';
import { CommonUtils } from '@salesforce/lwc-dev-mobile-core/lib/common/CommonUtils';
import { InstructionsWebviewProvider } from '../webviews';
import { InstructionsWebviewProvider } from '../../webviews';

export class BriefcaseCommand {
static readonly OPEN_ORG_BRIEFCASE_PAGE_CMD =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { Uri, WebviewPanel, commands, l10n, window } from 'vscode';
import * as process from 'process';
import { CommonUtils } from '@salesforce/lwc-dev-mobile-core/lib/common/CommonUtils';
import { InstructionsWebviewProvider } from '../webviews';
import { InstructionsWebviewProvider } from '../../webviews';

export type ProjectManagementChoiceAction = (panel?: WebviewPanel) => void;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/

import { window, QuickPickItem, QuickPickItemKind, l10n } from 'vscode';
import { Field, OrgUtils } from '../utils/orgUtils';
import { UIUtils } from '../utils/uiUtils';
import { UEMBuilder } from '../utils/uemBuilder';
import { Field, OrgUtils } from '../../utils/orgUtils';
import { UIUtils } from '../../utils/uiUtils';
import { UEMBuilder } from '../../utils/uemBuilder';

export class LandingPageCommand {
public static readonly GLOBAL_ACTIONS_CARD_LABEL = l10n.t('Global Actions');
Expand Down
94 changes: 94 additions & 0 deletions src/commands/wizard/onboardingWizard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved most of the code from extension.ts to here

* 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';

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.copyDefaultTemplate(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) {
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
);
}
}
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
*/

import { QuickPickItem, Uri, l10n } from 'vscode';
import { UIUtils } from '../utils/uiUtils';
import { UIUtils } from '../../utils/uiUtils';
import { workspace } from 'vscode';
import * as path from 'path';
import * as fs from 'fs';
import { InstructionsWebviewProvider } from '../webviews';
import { InstructionsWebviewProvider } from '../../webviews';

export interface TemplateQuickPickItem extends QuickPickItem {
filenamePrefix: string;
Expand Down
83 changes: 3 additions & 80 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,88 +8,11 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
import { TemplateChooserCommand } from './commands/templateChooserCommand';
import { BriefcaseCommand } from './commands/briefcaseCommand';
import { DeployToOrgCommand } from './commands/deployToOrgCommand';
import { ConfigureProjectCommand } from './commands/configureProjectCommand';
import { AuthorizeCommand } from './commands/authorizeCommand';
import { InstructionsWebviewProvider } from './webviews';

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.copyDefaultTemplate(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();
});
}
import * as onboardingWizard from './commands/wizard/onboardingWizard';

export function activate(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);
}
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
);
}
}
}
);
onboardingWizard.registerCommand(context);
onboardingWizard.onActivate(context);
}

// This method is called when your extension is deactivated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import * as assert from 'assert';
import * as sinon from 'sinon';
import { commands, window } from 'vscode';
import { afterEach } from 'mocha';
import { AuthorizeCommand } from '../../../commands/authorizeCommand';
import { OrgUtils } from '../../../utils/orgUtils';
import { AuthorizeCommand } from '../../../../commands/wizard/authorizeCommand';
import { OrgUtils } from '../../../../utils/orgUtils';

suite('Authorize Org Command Test Suite', () => {
afterEach(function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import * as assert from 'assert';
import * as sinon from 'sinon';
import { afterEach, beforeEach } from 'mocha';
import { BriefcaseCommand } from '../../../commands/briefcaseCommand';
import { BriefcaseCommand } from '../../../../commands/wizard/briefcaseCommand';
import { Uri, l10n, window, Progress, CancellationToken } from 'vscode';
import { CommonUtils } from '@salesforce/lwc-dev-mobile-core/lib/common/CommonUtils';
import { InstructionsWebviewProvider } from '../../../webviews';
import { InstructionsWebviewProvider } from '../../../../webviews';

suite('Briefcase Command Test Suite', () => {
beforeEach(function () {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import {
ConfigureProjectCommand,
DefaultProjectConfigurationProcessor,
ProjectConfigurationProcessor
} from '../../../commands/configureProjectCommand';
} from '../../../../commands/wizard/configureProjectCommand';
import {
TempProjectDirManager,
createPlatformAbsolutePath
} from '../../TestHelper';
} from '../../../TestHelper';

suite('Configure Project Command Test Suite', () => {
beforeEach(function () {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as assert from 'assert';
import * as sinon from 'sinon';
import { afterEach } from 'mocha';
import { Uri, commands, window, workspace } from 'vscode';
import { DeployToOrgCommand } from '../../../commands/deployToOrgCommand';
import { DeployToOrgCommand } from '../../../../commands/wizard/deployToOrgCommand';

suite('Deploy To Org Command Test Suite', () => {
afterEach(function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import * as assert from 'assert';
import * as sinon from 'sinon';
import * as vscode from 'vscode';
import { OrgUtils, SObject } from '../../../utils/orgUtils';
import { OrgUtils, SObject } from '../../../../utils/orgUtils';
import { SinonStub } from 'sinon';
import { afterEach, beforeEach } from 'mocha';
import { UIUtils } from '../../../utils/uiUtils';
import { UEMBuilder } from '../../../utils/uemBuilder';
import { UIUtils } from '../../../../utils/uiUtils';
import { UEMBuilder } from '../../../../utils/uemBuilder';
import { QuickPickItem } from 'vscode';
import { LandingPageCommand } from '../../../commands/landingPageCommand';
import { LandingPageCommand } from '../../../../commands/wizard/landingPageCommand';

suite('Landing Page Command Test Suite', () => {
let originalShowQuickPickFunction: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import * as path from 'path';
import { workspace, Uri } from 'vscode';
import { SinonStub } from 'sinon';
import { afterEach, beforeEach } from 'mocha';
import { UIUtils } from '../../../utils/uiUtils';
import { UIUtils } from '../../../../utils/uiUtils';
import {
TemplateChooserCommand,
TemplateQuickPickItem
} from '../../../commands/templateChooserCommand';
} from '../../../../commands/wizard/templateChooserCommand';

suite('Template Chooser Command Test Suite', () => {
beforeEach(function () {});
Expand Down