From ce52413ecc70fb9de39c286471269b06415d5b54 Mon Sep 17 00:00:00 2001 From: Meisam Seyed Aliroteh Date: Wed, 18 Oct 2023 11:53:53 -0700 Subject: [PATCH 1/2] move code around --- package.json | 4 +- package.nls.json | 4 +- src/commands/{ => wizard}/authorizeCommand.ts | 2 +- src/commands/{ => wizard}/briefcaseCommand.ts | 2 +- .../{ => wizard}/configureProjectCommand.ts | 2 +- .../{ => wizard}/deployToOrgCommand.ts | 0 .../{ => wizard}/landingPageCommand.ts | 6 +- src/commands/wizard/onboardingWizard.ts | 93 +++++++++++++++++++ .../{ => wizard}/templateChooserCommand.ts | 4 +- src/extension.ts | 83 +---------------- .../authorizeToOrgCommand.test.ts | 4 +- .../{ => wizard}/briefcaseCommand.test.ts | 4 +- .../configureProjectCommand.test.ts | 4 +- .../{ => wizard}/deployToOrgCommand.test.ts | 2 +- .../{ => wizard}/landingPageCommand.test.ts | 8 +- .../templateChooserCommand.test.ts | 4 +- 16 files changed, 121 insertions(+), 105 deletions(-) rename src/commands/{ => wizard}/authorizeCommand.ts (96%) rename src/commands/{ => wizard}/briefcaseCommand.ts (96%) rename src/commands/{ => wizard}/configureProjectCommand.ts (99%) rename src/commands/{ => wizard}/deployToOrgCommand.ts (100%) rename src/commands/{ => wizard}/landingPageCommand.ts (98%) create mode 100644 src/commands/wizard/onboardingWizard.ts rename src/commands/{ => wizard}/templateChooserCommand.ts (97%) rename src/test/suite/commands/{ => wizard}/authorizeToOrgCommand.test.ts (94%) rename src/test/suite/commands/{ => wizard}/briefcaseCommand.test.ts (95%) rename src/test/suite/commands/{ => wizard}/configureProjectCommand.test.ts (99%) rename src/test/suite/commands/{ => wizard}/deployToOrgCommand.test.ts (96%) rename src/test/suite/commands/{ => wizard}/landingPageCommand.test.ts (95%) rename src/test/suite/commands/{ => wizard}/templateChooserCommand.test.ts (96%) diff --git a/package.json b/package.json index 3bfaac0a..23689e5a 100644 --- a/package.json +++ b/package.json @@ -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%" } ] }, diff --git a/package.nls.json b/package.nls.json index 86ac1d17..4ed2ed3d 100644 --- a/package.nls.json +++ b/package.nls.json @@ -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." } diff --git a/src/commands/authorizeCommand.ts b/src/commands/wizard/authorizeCommand.ts similarity index 96% rename from src/commands/authorizeCommand.ts rename to src/commands/wizard/authorizeCommand.ts index 33d43190..bcf7a4d4 100644 --- a/src/commands/authorizeCommand.ts +++ b/src/commands/wizard/authorizeCommand.ts @@ -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 { diff --git a/src/commands/briefcaseCommand.ts b/src/commands/wizard/briefcaseCommand.ts similarity index 96% rename from src/commands/briefcaseCommand.ts rename to src/commands/wizard/briefcaseCommand.ts index 59d9ce42..f4028fb6 100644 --- a/src/commands/briefcaseCommand.ts +++ b/src/commands/wizard/briefcaseCommand.ts @@ -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 = diff --git a/src/commands/configureProjectCommand.ts b/src/commands/wizard/configureProjectCommand.ts similarity index 99% rename from src/commands/configureProjectCommand.ts rename to src/commands/wizard/configureProjectCommand.ts index a26783a1..86ee0ea5 100644 --- a/src/commands/configureProjectCommand.ts +++ b/src/commands/wizard/configureProjectCommand.ts @@ -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; diff --git a/src/commands/deployToOrgCommand.ts b/src/commands/wizard/deployToOrgCommand.ts similarity index 100% rename from src/commands/deployToOrgCommand.ts rename to src/commands/wizard/deployToOrgCommand.ts diff --git a/src/commands/landingPageCommand.ts b/src/commands/wizard/landingPageCommand.ts similarity index 98% rename from src/commands/landingPageCommand.ts rename to src/commands/wizard/landingPageCommand.ts index 83197a27..2561a2fd 100644 --- a/src/commands/landingPageCommand.ts +++ b/src/commands/wizard/landingPageCommand.ts @@ -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'); diff --git a/src/commands/wizard/onboardingWizard.ts b/src/commands/wizard/onboardingWizard.ts new file mode 100644 index 00000000..70e79e87 --- /dev/null +++ b/src/commands/wizard/onboardingWizard.ts @@ -0,0 +1,93 @@ +/* + * 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 { + 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 + ); + } + } + } + ); +} \ No newline at end of file diff --git a/src/commands/templateChooserCommand.ts b/src/commands/wizard/templateChooserCommand.ts similarity index 97% rename from src/commands/templateChooserCommand.ts rename to src/commands/wizard/templateChooserCommand.ts index e19399b3..4b6789aa 100644 --- a/src/commands/templateChooserCommand.ts +++ b/src/commands/wizard/templateChooserCommand.ts @@ -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; diff --git a/src/extension.ts b/src/extension.ts index 00b96284..0980bc88 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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 { - 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 diff --git a/src/test/suite/commands/authorizeToOrgCommand.test.ts b/src/test/suite/commands/wizard/authorizeToOrgCommand.test.ts similarity index 94% rename from src/test/suite/commands/authorizeToOrgCommand.test.ts rename to src/test/suite/commands/wizard/authorizeToOrgCommand.test.ts index 341f2851..023c0868 100644 --- a/src/test/suite/commands/authorizeToOrgCommand.test.ts +++ b/src/test/suite/commands/wizard/authorizeToOrgCommand.test.ts @@ -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 () { diff --git a/src/test/suite/commands/briefcaseCommand.test.ts b/src/test/suite/commands/wizard/briefcaseCommand.test.ts similarity index 95% rename from src/test/suite/commands/briefcaseCommand.test.ts rename to src/test/suite/commands/wizard/briefcaseCommand.test.ts index 0f1a286d..1114fc49 100644 --- a/src/test/suite/commands/briefcaseCommand.test.ts +++ b/src/test/suite/commands/wizard/briefcaseCommand.test.ts @@ -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 () {}); diff --git a/src/test/suite/commands/configureProjectCommand.test.ts b/src/test/suite/commands/wizard/configureProjectCommand.test.ts similarity index 99% rename from src/test/suite/commands/configureProjectCommand.test.ts rename to src/test/suite/commands/wizard/configureProjectCommand.test.ts index 2fe0272c..fa243938 100644 --- a/src/test/suite/commands/configureProjectCommand.test.ts +++ b/src/test/suite/commands/wizard/configureProjectCommand.test.ts @@ -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 () {}); diff --git a/src/test/suite/commands/deployToOrgCommand.test.ts b/src/test/suite/commands/wizard/deployToOrgCommand.test.ts similarity index 96% rename from src/test/suite/commands/deployToOrgCommand.test.ts rename to src/test/suite/commands/wizard/deployToOrgCommand.test.ts index c0a91dbf..52636180 100644 --- a/src/test/suite/commands/deployToOrgCommand.test.ts +++ b/src/test/suite/commands/wizard/deployToOrgCommand.test.ts @@ -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 () { diff --git a/src/test/suite/commands/landingPageCommand.test.ts b/src/test/suite/commands/wizard/landingPageCommand.test.ts similarity index 95% rename from src/test/suite/commands/landingPageCommand.test.ts rename to src/test/suite/commands/wizard/landingPageCommand.test.ts index 088bf1ce..8ac5df4a 100644 --- a/src/test/suite/commands/landingPageCommand.test.ts +++ b/src/test/suite/commands/wizard/landingPageCommand.test.ts @@ -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: ( diff --git a/src/test/suite/commands/templateChooserCommand.test.ts b/src/test/suite/commands/wizard/templateChooserCommand.test.ts similarity index 96% rename from src/test/suite/commands/templateChooserCommand.test.ts rename to src/test/suite/commands/wizard/templateChooserCommand.test.ts index 199d647a..12cb516d 100644 --- a/src/test/suite/commands/templateChooserCommand.test.ts +++ b/src/test/suite/commands/wizard/templateChooserCommand.test.ts @@ -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 () {}); From 64aad2db090603db276704c302db319a14951744 Mon Sep 17 00:00:00 2001 From: Meisam Seyed Aliroteh Date: Wed, 18 Oct 2023 11:58:18 -0700 Subject: [PATCH 2/2] fix prettier error --- src/commands/wizard/onboardingWizard.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/commands/wizard/onboardingWizard.ts b/src/commands/wizard/onboardingWizard.ts index 70e79e87..7c2d88b2 100644 --- a/src/commands/wizard/onboardingWizard.ts +++ b/src/commands/wizard/onboardingWizard.ts @@ -14,7 +14,8 @@ import { AuthorizeCommand } from './authorizeCommand'; import { InstructionsWebviewProvider } from '../../webviews'; const wizardCommand = 'salesforcedx-vscode-offline-app.onboardingWizard'; -const onboardingWizardStateKey = 'salesforcedx-vscode-offline-app.onboardingWizard.projectCreationState'; +const onboardingWizardStateKey = + 'salesforcedx-vscode-offline-app.onboardingWizard.projectCreationState'; enum OnboardingWizardState { projectConfigured @@ -90,4 +91,4 @@ export function registerCommand(context: vscode.ExtensionContext) { } } ); -} \ No newline at end of file +}