From dbc404de92be6656ab60617cdb46e1fb455d8e6a Mon Sep 17 00:00:00 2001 From: Bernie White Date: Thu, 28 Nov 2024 13:20:28 +1000 Subject: [PATCH] Update extension name (#2638) --- .github/workflows/build.yaml | 2 +- docs/CHANGELOG-v3.md | 2 +- docs/updates/v3_0.md | 2 +- esbuild.mjs | 2 +- .../getStarted/01_configureOptions.md | 6 +- package-lock.json | 4 +- package.json | 6 +- src/code/extension.ts | 289 ------------------ src/{code => vscode-ps-rule}/README.md | 0 .../commands/configureSettings.ts | 0 .../commands/createOptionsFile.ts | 0 .../commands/createOrEditDocumentation.ts | 0 .../commands/openOptionsFile.ts | 0 .../commands/restore.ts | 0 .../commands/runAnalysisTask.ts | 0 .../commands/showTasks.ts | 0 .../commands/walkthroughCopySnippet.ts | 0 src/{code => vscode-ps-rule}/configuration.ts | 0 src/{code => vscode-ps-rule}/consts.ts | 0 src/{code => vscode-ps-rule}/docLens.ts | 0 src/vscode-ps-rule/extension.ts | 289 ++++++++++++++++++ src/{code => vscode-ps-rule}/logger.ts | 0 src/{code => vscode-ps-rule}/main.ts | 0 src/{code => vscode-ps-rule}/powershell.ts | 0 src/{code => vscode-ps-rule}/tasks.ts | 0 src/{code => vscode-ps-rule}/test/runTest.ts | 0 .../test/suite/configuration.test.ts | 0 .../test/suite/extension.test.ts | 0 .../test/suite/index.ts | 0 .../test/suite/tasks.test.ts | 0 src/{code => vscode-ps-rule}/utils.ts | 0 31 files changed, 301 insertions(+), 301 deletions(-) delete mode 100644 src/code/extension.ts rename src/{code => vscode-ps-rule}/README.md (100%) rename src/{code => vscode-ps-rule}/commands/configureSettings.ts (100%) rename src/{code => vscode-ps-rule}/commands/createOptionsFile.ts (100%) rename src/{code => vscode-ps-rule}/commands/createOrEditDocumentation.ts (100%) rename src/{code => vscode-ps-rule}/commands/openOptionsFile.ts (100%) rename src/{code => vscode-ps-rule}/commands/restore.ts (100%) rename src/{code => vscode-ps-rule}/commands/runAnalysisTask.ts (100%) rename src/{code => vscode-ps-rule}/commands/showTasks.ts (100%) rename src/{code => vscode-ps-rule}/commands/walkthroughCopySnippet.ts (100%) rename src/{code => vscode-ps-rule}/configuration.ts (100%) rename src/{code => vscode-ps-rule}/consts.ts (100%) rename src/{code => vscode-ps-rule}/docLens.ts (100%) create mode 100644 src/vscode-ps-rule/extension.ts rename src/{code => vscode-ps-rule}/logger.ts (100%) rename src/{code => vscode-ps-rule}/main.ts (100%) rename src/{code => vscode-ps-rule}/powershell.ts (100%) rename src/{code => vscode-ps-rule}/tasks.ts (100%) rename src/{code => vscode-ps-rule}/test/runTest.ts (100%) rename src/{code => vscode-ps-rule}/test/suite/configuration.test.ts (100%) rename src/{code => vscode-ps-rule}/test/suite/extension.test.ts (100%) rename src/{code => vscode-ps-rule}/test/suite/index.ts (100%) rename src/{code => vscode-ps-rule}/test/suite/tasks.test.ts (100%) rename src/{code => vscode-ps-rule}/utils.ts (100%) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index a2786d6607..c5ce8362bc 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -186,7 +186,7 @@ jobs: uses: actions/upload-artifact@v4 with: name: Extension - path: out/package/code-*.vsix + path: out/package/vscode-ps-rule-*.vsix retention-days: 3 if-no-files-found: error diff --git a/docs/CHANGELOG-v3.md b/docs/CHANGELOG-v3.md index acce3697e8..5f6871bcb9 100644 --- a/docs/CHANGELOG-v3.md +++ b/docs/CHANGELOG-v3.md @@ -30,7 +30,7 @@ See [upgrade notes][1] for helpful information when upgrading from previous vers What's changed since pre-release v3.0.0-B0315: - New features: - - VSCode extension set to use Microsoft verified name by @BernieWhite. + - VSCode extension set to use Microsoft verified publisher name by @BernieWhite. [#2636](https://github.com/microsoft/PSRule/issues/2636) - General improvements: - Expose format options to emitters by @BernieWhite. diff --git a/docs/updates/v3_0.md b/docs/updates/v3_0.md index 663f4b1125..e87128d9bd 100644 --- a/docs/updates/v3_0.md +++ b/docs/updates/v3_0.md @@ -9,7 +9,7 @@ version: 3.0 The Visual Studio Code (VSCode) extension for PSRule now lives side-by-side with core components of [PSRule on GitHub][1]. -As part of this change we are now publishing the extension as a **verified** Microsoft extension with the ID `ps-rule.code`. +As part of this change we are now publishing the extension as a **verified** Microsoft extension with the ID `ps-rule.vscode-ps-rule`. We hope this will not only help the community to log issues and get help on the correct repository, but also streamline how we deliver updates in the future. diff --git a/esbuild.mjs b/esbuild.mjs index 7c02ebe2e8..9740f141f1 100644 --- a/esbuild.mjs +++ b/esbuild.mjs @@ -15,7 +15,7 @@ console.warn("build extension"); async function main() { const ctx = await esbuild.context({ - entryPoints: ['src/code/main.ts'], + entryPoints: ['src/vscode-ps-rule/main.ts'], bundle: true, format: 'cjs', minify: production, diff --git a/media/walkthroughs/getStarted/01_configureOptions.md b/media/walkthroughs/getStarted/01_configureOptions.md index 35e74b71ea..16c2971d72 100644 --- a/media/walkthroughs/getStarted/01_configureOptions.md +++ b/media/walkthroughs/getStarted/01_configureOptions.md @@ -2,7 +2,7 @@ - First, type `requires` and press Tab or Enter to complete the suggestion. - Continue typing to replace `Module` with `PSRule` and press Tab or Enter to move to the version constraint. -- Replace `'>=1.0.0'` with the minimum version of PSRule you want to use, such as `'>=2.8.1'`. +- Replace `'>=1.0.0'` with the minimum version of PSRule you want to use, such as `'>=2.9.0'`. ## Configure additional modules @@ -13,8 +13,8 @@ For example: ```yaml requires: - PSRule: '>=2.8.1' - PSRule.Rules.Azure: '>=1.26.1' + PSRule: '>=2.9.0' + PSRule.Rules.Azure: '>=1.39.3' ``` ### Configure other options diff --git a/package-lock.json b/package-lock.json index 3fba68f715..5876f5cf6c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "code", + "name": "vscode-ps-rule", "version": "0.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "code", + "name": "vscode-ps-rule", "version": "0.0.1", "license": "SEE LICENSE IN LICENSE", "dependencies": { diff --git a/package.json b/package.json index 637410b5d5..4183842a2f 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "code", + "name": "vscode-ps-rule", "displayName": "PSRule", "version": "0.0.1", "publisher": "ps-rule", @@ -488,7 +488,7 @@ "zzz_lint": "eslint . --ext .ts,.tsx", "zzz_pretest": "npm run compile", "zzz_vscode:prepublish": "npm run -S esbuild-base -- --minify && dotnet publish ./src/PSRule.EditorServices/ --output server/", - "zzz_esbuild-base": "esbuild ./src/code/main.ts --bundle --outfile=out/dist/main.js --external:vscode --format=cjs --platform=node", + "zzz_esbuild-base": "esbuild ./src/vscode-ps-rule/main.ts --bundle --outfile=out/dist/main.js --external:vscode --format=cjs --platform=node", "zzz_esbuild": "npm run -S esbuild-base -- --sourcemap", "zzz_esbuild-watch": "npm run -S esbuild-base -- --sourcemap --watch", "zzz_build": "tsc -p ./ && dotnet build && node build.mjs", @@ -500,7 +500,7 @@ "build:esbuild": "node esbuild.mjs", "package": "npm run package:dotnet && npm run package:esbuild && npm run package:pack", "package:dotnet": "dotnet build ./src/PSRule.EditorServices/ --output server/", - "package:pack": "vsce package --dependencies --pre-release --no-git-tag-version --no-update-package-json --githubBranch main --out out/package/ --readme-path src/code/README.md --changelog-path docs/CHANGELOG-v3.md --baseImagesUrl https://raw.githubusercontent.com/microsoft/PSRule/refs/heads/main/", + "package:pack": "vsce package --dependencies --pre-release --no-git-tag-version --no-update-package-json --githubBranch main --out out/package/ --readme-path src/vscode-ps-rule/README.md --changelog-path docs/CHANGELOG-v3.md --baseImagesUrl https://raw.githubusercontent.com/microsoft/PSRule/refs/heads/main/", "package:esbuild": "node esbuild.mjs", "test": "npm run build:dotnet && npm run build:esbuild && vscode-test" }, diff --git a/src/code/extension.ts b/src/code/extension.ts deleted file mode 100644 index 30781fdb8a..0000000000 --- a/src/code/extension.ts +++ /dev/null @@ -1,289 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -'use strict'; - -import * as path from 'path'; -import * as vscode from 'vscode'; -import { logger } from './logger'; -import { PSRuleTaskProvider } from './tasks'; -import { ConfigurationManager } from './configuration'; -import { pwsh } from './powershell'; -import { DocumentationLensProvider } from './docLens'; -import { createOptionsFile } from './commands/createOptionsFile'; -import { openOptionsFile } from './commands/openOptionsFile'; -import { walkthroughCopySnippet } from './commands/walkthroughCopySnippet'; -import { configureSettings } from './commands/configureSettings'; -import { runAnalysisTask } from './commands/runAnalysisTask'; -import { showTasks } from './commands/showTasks'; -import { PSRuleLanguageServer, getLanguageServer } from './utils'; -import { restore } from './commands/restore'; - -export let taskManager: PSRuleTaskProvider | undefined; -export let docLensProvider: DocumentationLensProvider | undefined; - -export interface ExtensionInfo { - id: string; - version: string; - channel: string; - path: string; - disable: boolean; -} - -export class ExtensionManager implements vscode.Disposable { - private _info!: ExtensionInfo; - private _context!: vscode.ExtensionContext; - private _server!: PSRuleLanguageServer | undefined; - - constructor() { } - - /** - * Information about the extension. - */ - public get info(): Promise { - const parent = this; - return new Promise((resolve, reject) => { - const interval = setInterval(() => { - if (parent._info) { - clearInterval(interval); - resolve(parent._info); - } - }, 100); - }); - } - - public get isTrusted(): boolean { - return vscode.workspace.isTrusted; - } - - /** - * A task provider if the workspace is trusted, otherwise returns undefined. - */ - public get tasks(): PSRuleTaskProvider | undefined { - return taskManager; - } - - public get server(): PSRuleLanguageServer | undefined { - return this._server; - } - - public activate(context: vscode.ExtensionContext) { - this._context = context; - this._info = this.checkExtension(context); - if (!this._info.disable) { - this.activateFeatures(); - } - } - - public dispose(): void { - if (docLensProvider) { - docLensProvider.dispose(); - } - if (taskManager) { - taskManager.dispose(); - } - if (pwsh) { - pwsh.dispose(); - } - if (logger) { - logger.dispose(); - } - } - - private async activateFeatures(): Promise { - await this.switchMode(); - if (this._context) { - this._context.subscriptions.push( - vscode.workspace.onDidGrantWorkspaceTrust(() => { - this.switchMode(); - }) - ); - this._context.subscriptions.push( - vscode.commands.registerCommand('PSRule.openOptionsFile', (path: string) => { - openOptionsFile(path); - }) - ); - this._context.subscriptions.push( - vscode.commands.registerCommand('PSRule.createOptionsFile', (path: string) => { - createOptionsFile(path); - }) - ); - this._context.subscriptions.push( - vscode.commands.registerCommand('PSRule.configureSettings', () => { - configureSettings(); - }) - ); - this._context.subscriptions.push( - vscode.commands.registerCommand('PSRule.walkthroughCopySnippet', (args: { snippet: string }) => { - walkthroughCopySnippet(args.snippet); - }) - ); - this._context.subscriptions.push( - vscode.commands.registerCommand('PSRule.runAnalysisTask', () => { - runAnalysisTask(); - }) - ); - this._context.subscriptions.push( - vscode.commands.registerCommand('PSRule.showTasks', () => { - showTasks(); - }) - ); - this._context.subscriptions.push( - vscode.commands.registerCommand('PSRule.restore', () => { - restore(); - }) - ); - } - } - - private async switchMode(): Promise { - ConfigurationManager.configure(this._context); - - if (!docLensProvider) { - docLensProvider = new DocumentationLensProvider(logger, this._context); - docLensProvider.register(); - } - - if (this.isTrusted) { - this.setContextVariables(); - } - - if (this.isTrusted) { - pwsh.configure(this._info); - } - - if (this.isTrusted) { - taskManager = new PSRuleTaskProvider(logger, this._context); - taskManager.register(); - } - - if (this.isTrusted) { - this._server = await getLanguageServer(this._context); - } - } - - private setContextVariables(): void { - vscode.commands.executeCommand('setContext', 'PSRule.workspaceTrusted', this.isTrusted); - } - - /** - * Check channel and version of the extension activated. - * @param context An extension context. - */ - private checkExtension(context: vscode.ExtensionContext): ExtensionInfo { - const extensionVersionKey = 'ps-rule-extension-version'; - - // Get channel - let extensionId = 'ps-rule.code'; - let isMainstreamInstalled = vscode.extensions.getExtension(extensionId) !== undefined; - - if (path.basename(context.globalStorageUri.fsPath) === 'ps-rule.code-dev') { - extensionId = 'ps-rule.code-dev'; - } - - // Get current version - const extension = vscode.extensions.getExtension(extensionId)!; - const extensionVersion: string = extension.packageJSON.version; - const extensionChannel: string = extension.packageJSON.channel; - - logger.verbose(`Running extension channel: ${extensionChannel}`); - logger.verbose(`Running extension version: ${extensionVersion}`); - - // Get last version - const lastVersion = context.globalState.get(extensionVersionKey); - - // Save the extension version - context.globalState.update(extensionVersionKey, extensionVersion); - - // Determine if the channel upgrade message is shown - const showChannelUpgrade: boolean = vscode.workspace - .getConfiguration('PSRule.notifications') - .get('showChannelUpgrade', true); - - const showExtension = 'Show Extension'; - if (extensionChannel === 'dev' && showChannelUpgrade) { - const showReleaseNotes = 'Show Release Notes'; - const alwaysIgnore = 'Always Ignore'; - - vscode.window - .showInformationMessage( - `You are running the ${extensionChannel} version of PSRule.`, - showReleaseNotes, - showExtension, - alwaysIgnore - ) - .then((choice) => { - if (choice === showReleaseNotes) { - vscode.commands.executeCommand( - 'markdown.showPreview', - vscode.Uri.file(path.resolve(__dirname, '../../CHANGELOG.md')) - ); - } - if (choice === showExtension) { - vscode.commands.executeCommand( - 'workbench.extensions.search', - 'ps-rule.code' - ); - } - if (choice === alwaysIgnore) { - vscode.workspace - .getConfiguration('PSRule.notifications') - .update('showChannelUpgrade', false, vscode.ConfigurationTarget.Global); - } - }); - } - if (extensionChannel === 'stable' && extensionVersion != lastVersion && showChannelUpgrade) { - const showReleaseNotes = 'Show Release Notes'; - const alwaysIgnore = 'Always Ignore'; - - vscode.window - .showInformationMessage( - `Welcome to v${extensionVersion} of PSRule.`, - showReleaseNotes, - alwaysIgnore - ) - .then((choice) => { - if (choice === showReleaseNotes) { - vscode.commands.executeCommand( - 'markdown.showPreview', - vscode.Uri.file(path.resolve(__dirname, '../../CHANGELOG.md')) - ); - } - if (choice === alwaysIgnore) { - vscode.workspace - .getConfiguration('PSRule.notifications') - .update('showChannelUpgrade', false, vscode.ConfigurationTarget.Global); - } - }); - } - - let disable = false; - if (extensionChannel === 'dev' && isMainstreamInstalled) { - disable = true; - vscode.window - .showWarningMessage( - `You may experience issues running the ${extensionChannel} version of PSRule, side-by-side with the stable version. Please uninstall one of ${extensionChannel} or stable version and reload Visual Studio Code for the best experience.`, - showExtension, - ) - .then((choice) => { - if (choice === showExtension) { - vscode.commands.executeCommand( - 'workbench.extensions.search', - 'PSRule' - ); - } - }); - } - - const result: ExtensionInfo = { - id: extensionId, - version: extensionVersion, - channel: extensionChannel, - path: context.extensionPath, - disable: disable, - }; - return result; - } -} - -export const ext: ExtensionManager = new ExtensionManager(); diff --git a/src/code/README.md b/src/vscode-ps-rule/README.md similarity index 100% rename from src/code/README.md rename to src/vscode-ps-rule/README.md diff --git a/src/code/commands/configureSettings.ts b/src/vscode-ps-rule/commands/configureSettings.ts similarity index 100% rename from src/code/commands/configureSettings.ts rename to src/vscode-ps-rule/commands/configureSettings.ts diff --git a/src/code/commands/createOptionsFile.ts b/src/vscode-ps-rule/commands/createOptionsFile.ts similarity index 100% rename from src/code/commands/createOptionsFile.ts rename to src/vscode-ps-rule/commands/createOptionsFile.ts diff --git a/src/code/commands/createOrEditDocumentation.ts b/src/vscode-ps-rule/commands/createOrEditDocumentation.ts similarity index 100% rename from src/code/commands/createOrEditDocumentation.ts rename to src/vscode-ps-rule/commands/createOrEditDocumentation.ts diff --git a/src/code/commands/openOptionsFile.ts b/src/vscode-ps-rule/commands/openOptionsFile.ts similarity index 100% rename from src/code/commands/openOptionsFile.ts rename to src/vscode-ps-rule/commands/openOptionsFile.ts diff --git a/src/code/commands/restore.ts b/src/vscode-ps-rule/commands/restore.ts similarity index 100% rename from src/code/commands/restore.ts rename to src/vscode-ps-rule/commands/restore.ts diff --git a/src/code/commands/runAnalysisTask.ts b/src/vscode-ps-rule/commands/runAnalysisTask.ts similarity index 100% rename from src/code/commands/runAnalysisTask.ts rename to src/vscode-ps-rule/commands/runAnalysisTask.ts diff --git a/src/code/commands/showTasks.ts b/src/vscode-ps-rule/commands/showTasks.ts similarity index 100% rename from src/code/commands/showTasks.ts rename to src/vscode-ps-rule/commands/showTasks.ts diff --git a/src/code/commands/walkthroughCopySnippet.ts b/src/vscode-ps-rule/commands/walkthroughCopySnippet.ts similarity index 100% rename from src/code/commands/walkthroughCopySnippet.ts rename to src/vscode-ps-rule/commands/walkthroughCopySnippet.ts diff --git a/src/code/configuration.ts b/src/vscode-ps-rule/configuration.ts similarity index 100% rename from src/code/configuration.ts rename to src/vscode-ps-rule/configuration.ts diff --git a/src/code/consts.ts b/src/vscode-ps-rule/consts.ts similarity index 100% rename from src/code/consts.ts rename to src/vscode-ps-rule/consts.ts diff --git a/src/code/docLens.ts b/src/vscode-ps-rule/docLens.ts similarity index 100% rename from src/code/docLens.ts rename to src/vscode-ps-rule/docLens.ts diff --git a/src/vscode-ps-rule/extension.ts b/src/vscode-ps-rule/extension.ts new file mode 100644 index 0000000000..545a595cc0 --- /dev/null +++ b/src/vscode-ps-rule/extension.ts @@ -0,0 +1,289 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +'use strict'; + +import * as path from 'path'; +import * as vscode from 'vscode'; +import { logger } from './logger'; +import { PSRuleTaskProvider } from './tasks'; +import { ConfigurationManager } from './configuration'; +import { pwsh } from './powershell'; +import { DocumentationLensProvider } from './docLens'; +import { createOptionsFile } from './commands/createOptionsFile'; +import { openOptionsFile } from './commands/openOptionsFile'; +import { walkthroughCopySnippet } from './commands/walkthroughCopySnippet'; +import { configureSettings } from './commands/configureSettings'; +import { runAnalysisTask } from './commands/runAnalysisTask'; +import { showTasks } from './commands/showTasks'; +import { PSRuleLanguageServer, getLanguageServer } from './utils'; +import { restore } from './commands/restore'; + +export let taskManager: PSRuleTaskProvider | undefined; +export let docLensProvider: DocumentationLensProvider | undefined; + +export interface ExtensionInfo { + id: string; + version: string; + channel: string; + path: string; + disable: boolean; +} + +export class ExtensionManager implements vscode.Disposable { + private _info!: ExtensionInfo; + private _context!: vscode.ExtensionContext; + private _server!: PSRuleLanguageServer | undefined; + + constructor() { } + + /** + * Information about the extension. + */ + public get info(): Promise { + const parent = this; + return new Promise((resolve, reject) => { + const interval = setInterval(() => { + if (parent._info) { + clearInterval(interval); + resolve(parent._info); + } + }, 100); + }); + } + + public get isTrusted(): boolean { + return vscode.workspace.isTrusted; + } + + /** + * A task provider if the workspace is trusted, otherwise returns undefined. + */ + public get tasks(): PSRuleTaskProvider | undefined { + return taskManager; + } + + public get server(): PSRuleLanguageServer | undefined { + return this._server; + } + + public activate(context: vscode.ExtensionContext) { + this._context = context; + this._info = this.checkExtension(context); + if (!this._info.disable) { + this.activateFeatures(); + } + } + + public dispose(): void { + if (docLensProvider) { + docLensProvider.dispose(); + } + if (taskManager) { + taskManager.dispose(); + } + if (pwsh) { + pwsh.dispose(); + } + if (logger) { + logger.dispose(); + } + } + + private async activateFeatures(): Promise { + await this.switchMode(); + if (this._context) { + this._context.subscriptions.push( + vscode.workspace.onDidGrantWorkspaceTrust(() => { + this.switchMode(); + }) + ); + this._context.subscriptions.push( + vscode.commands.registerCommand('PSRule.openOptionsFile', (path: string) => { + openOptionsFile(path); + }) + ); + this._context.subscriptions.push( + vscode.commands.registerCommand('PSRule.createOptionsFile', (path: string) => { + createOptionsFile(path); + }) + ); + this._context.subscriptions.push( + vscode.commands.registerCommand('PSRule.configureSettings', () => { + configureSettings(); + }) + ); + this._context.subscriptions.push( + vscode.commands.registerCommand('PSRule.walkthroughCopySnippet', (args: { snippet: string }) => { + walkthroughCopySnippet(args.snippet); + }) + ); + this._context.subscriptions.push( + vscode.commands.registerCommand('PSRule.runAnalysisTask', () => { + runAnalysisTask(); + }) + ); + this._context.subscriptions.push( + vscode.commands.registerCommand('PSRule.showTasks', () => { + showTasks(); + }) + ); + this._context.subscriptions.push( + vscode.commands.registerCommand('PSRule.restore', () => { + restore(); + }) + ); + } + } + + private async switchMode(): Promise { + ConfigurationManager.configure(this._context); + + if (!docLensProvider) { + docLensProvider = new DocumentationLensProvider(logger, this._context); + docLensProvider.register(); + } + + if (this.isTrusted) { + this.setContextVariables(); + } + + if (this.isTrusted) { + pwsh.configure(this._info); + } + + if (this.isTrusted) { + taskManager = new PSRuleTaskProvider(logger, this._context); + taskManager.register(); + } + + if (this.isTrusted) { + this._server = await getLanguageServer(this._context); + } + } + + private setContextVariables(): void { + vscode.commands.executeCommand('setContext', 'PSRule.workspaceTrusted', this.isTrusted); + } + + /** + * Check channel and version of the extension activated. + * @param context An extension context. + */ + private checkExtension(context: vscode.ExtensionContext): ExtensionInfo { + const extensionVersionKey = 'ps-rule-extension-version'; + + // Get channel + let extensionId = 'ps-rule.vscode-ps-rule'; + let isMainstreamInstalled = vscode.extensions.getExtension(extensionId) !== undefined; + + if (path.basename(context.globalStorageUri.fsPath) === 'ps-rule.vscode-ps-rule-dev') { + extensionId = 'ps-rule.vscode-ps-rule-dev'; + } + + // Get current version + const extension = vscode.extensions.getExtension(extensionId)!; + const extensionVersion: string = extension.packageJSON.version; + const extensionChannel: string = extension.packageJSON.channel; + + logger.verbose(`Running extension channel: ${extensionChannel}`); + logger.verbose(`Running extension version: ${extensionVersion}`); + + // Get last version + const lastVersion = context.globalState.get(extensionVersionKey); + + // Save the extension version + context.globalState.update(extensionVersionKey, extensionVersion); + + // Determine if the channel upgrade message is shown + const showChannelUpgrade: boolean = vscode.workspace + .getConfiguration('PSRule.notifications') + .get('showChannelUpgrade', true); + + const showExtension = 'Show Extension'; + if (extensionChannel === 'dev' && showChannelUpgrade) { + const showReleaseNotes = 'Show Release Notes'; + const alwaysIgnore = 'Always Ignore'; + + vscode.window + .showInformationMessage( + `You are running the ${extensionChannel} version of PSRule.`, + showReleaseNotes, + showExtension, + alwaysIgnore + ) + .then((choice) => { + if (choice === showReleaseNotes) { + vscode.commands.executeCommand( + 'markdown.showPreview', + vscode.Uri.file(path.resolve(__dirname, '../../CHANGELOG.md')) + ); + } + if (choice === showExtension) { + vscode.commands.executeCommand( + 'workbench.extensions.search', + 'ps-rule.vscode-ps-rule' + ); + } + if (choice === alwaysIgnore) { + vscode.workspace + .getConfiguration('PSRule.notifications') + .update('showChannelUpgrade', false, vscode.ConfigurationTarget.Global); + } + }); + } + if (extensionChannel === 'stable' && extensionVersion != lastVersion && showChannelUpgrade) { + const showReleaseNotes = 'Show Release Notes'; + const alwaysIgnore = 'Always Ignore'; + + vscode.window + .showInformationMessage( + `Welcome to v${extensionVersion} of PSRule.`, + showReleaseNotes, + alwaysIgnore + ) + .then((choice) => { + if (choice === showReleaseNotes) { + vscode.commands.executeCommand( + 'markdown.showPreview', + vscode.Uri.file(path.resolve(__dirname, '../../CHANGELOG.md')) + ); + } + if (choice === alwaysIgnore) { + vscode.workspace + .getConfiguration('PSRule.notifications') + .update('showChannelUpgrade', false, vscode.ConfigurationTarget.Global); + } + }); + } + + let disable = false; + if (extensionChannel === 'dev' && isMainstreamInstalled) { + disable = true; + vscode.window + .showWarningMessage( + `You may experience issues running the ${extensionChannel} version of PSRule, side-by-side with the stable version. Please uninstall one of ${extensionChannel} or stable version and reload Visual Studio Code for the best experience.`, + showExtension, + ) + .then((choice) => { + if (choice === showExtension) { + vscode.commands.executeCommand( + 'workbench.extensions.search', + 'PSRule' + ); + } + }); + } + + const result: ExtensionInfo = { + id: extensionId, + version: extensionVersion, + channel: extensionChannel, + path: context.extensionPath, + disable: disable, + }; + return result; + } +} + +export const ext: ExtensionManager = new ExtensionManager(); diff --git a/src/code/logger.ts b/src/vscode-ps-rule/logger.ts similarity index 100% rename from src/code/logger.ts rename to src/vscode-ps-rule/logger.ts diff --git a/src/code/main.ts b/src/vscode-ps-rule/main.ts similarity index 100% rename from src/code/main.ts rename to src/vscode-ps-rule/main.ts diff --git a/src/code/powershell.ts b/src/vscode-ps-rule/powershell.ts similarity index 100% rename from src/code/powershell.ts rename to src/vscode-ps-rule/powershell.ts diff --git a/src/code/tasks.ts b/src/vscode-ps-rule/tasks.ts similarity index 100% rename from src/code/tasks.ts rename to src/vscode-ps-rule/tasks.ts diff --git a/src/code/test/runTest.ts b/src/vscode-ps-rule/test/runTest.ts similarity index 100% rename from src/code/test/runTest.ts rename to src/vscode-ps-rule/test/runTest.ts diff --git a/src/code/test/suite/configuration.test.ts b/src/vscode-ps-rule/test/suite/configuration.test.ts similarity index 100% rename from src/code/test/suite/configuration.test.ts rename to src/vscode-ps-rule/test/suite/configuration.test.ts diff --git a/src/code/test/suite/extension.test.ts b/src/vscode-ps-rule/test/suite/extension.test.ts similarity index 100% rename from src/code/test/suite/extension.test.ts rename to src/vscode-ps-rule/test/suite/extension.test.ts diff --git a/src/code/test/suite/index.ts b/src/vscode-ps-rule/test/suite/index.ts similarity index 100% rename from src/code/test/suite/index.ts rename to src/vscode-ps-rule/test/suite/index.ts diff --git a/src/code/test/suite/tasks.test.ts b/src/vscode-ps-rule/test/suite/tasks.test.ts similarity index 100% rename from src/code/test/suite/tasks.test.ts rename to src/vscode-ps-rule/test/suite/tasks.test.ts diff --git a/src/code/utils.ts b/src/vscode-ps-rule/utils.ts similarity index 100% rename from src/code/utils.ts rename to src/vscode-ps-rule/utils.ts