From 2769eb9b71a735e2105ebea0281f363099db75f1 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Wed, 8 Sep 2021 10:29:34 +0200 Subject: [PATCH] Fix beta startup + main release script to reset the id --- .github/workflows/release.yml | 3 +++ package.json | 2 +- scripts/beta-release.js | 3 ++- scripts/main-release.js | 7 ++++++ src/extension.ts | 16 +++++-------- src/helpers/Extension.ts | 42 +++++++++++++++++++++++++---------- 6 files changed, 49 insertions(+), 24 deletions(-) create mode 100644 scripts/main-release.js diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 61e3f61e..374b90da 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,6 +19,9 @@ jobs: - name: Install the dependencies run: npm i + + - name: Prepare MAIN release + run: node scripts/main-release.js - name: Publish run: npx vsce publish -p ${{ secrets.VSCE_PAT }} diff --git a/package.json b/package.json index 08eb1da5..e8cc77d7 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "vscode-front-matter", + "name": "vscode-front-matter-beta", "displayName": "Front Matter", "description": "An essential Visual Studio Code extension when you want to manage the markdown pages of your static site like: Hugo, Jekyll, Hexo, NextJs, Gatsby, and many more...", "icon": "assets/frontmatter-teal-128x128.png", diff --git a/scripts/beta-release.js b/scripts/beta-release.js index 82714a46..d426ddae 100644 --- a/scripts/beta-release.js +++ b/scripts/beta-release.js @@ -3,9 +3,10 @@ const path = require('path'); const packageJson = require('../package.json'); const version = packageJson.version.split('.'); + packageJson.version = `${version[0]}.${version[1]}.${process.argv[process.argv.length-1].substr(0, 7)}`; packageJson.preview = true; -packageJson.name = `${packageJson.name}-beta`; +packageJson.name = "vscode-front-matter-beta"; packageJson.displayName = `${packageJson.displayName} BETA`; packageJson.description = `BETA Version of Front Matter. ${packageJson.description}`; packageJson.icon = "assets/frontmatter-beta.png"; diff --git a/scripts/main-release.js b/scripts/main-release.js new file mode 100644 index 00000000..23866cbe --- /dev/null +++ b/scripts/main-release.js @@ -0,0 +1,7 @@ +const fs = require('fs'); +const path = require('path'); + +const packageJson = require('../package.json'); +packageJson.name = "vscode-front-matter"; + +fs.writeFileSync(path.join(path.resolve('.'), 'package.json'), JSON.stringify(packageJson, null, 2)); \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index b534d77f..7d256475 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -21,19 +21,15 @@ let collection: vscode.DiagnosticCollection; const mdSelector: vscode.DocumentSelector = { language: 'markdown', scheme: 'file' }; -export async function activate({ subscriptions, extensionUri, extensionPath, globalState, globalStorageUri }: vscode.ExtensionContext) { - - // Check if Front Matter is extension is installed - if (basename(globalStorageUri.fsPath) === EXTENSION_BETA_ID) { - const mainVersion = vscode.extensions.getExtension(EXTENSION_ID); +export async function activate(context: vscode.ExtensionContext) { + const { subscriptions, extensionUri, extensionPath } = context; - if (mainVersion) { - Notifications.error(`Front Matter BETA cannot be used while the main version is installed. Please ensure that you have only over version installed.`); - return undefined; - } + const extension = Extension.getInstance(context); + + if (!extension.checkIfExtensionCanRun()) { + return undefined; } - const extension = Extension.getInstance(globalState, extensionUri); extension.migrateSettings() collection = vscode.languages.createDiagnosticCollection('frontMatter'); diff --git a/src/helpers/Extension.ts b/src/helpers/Extension.ts index 655a93bd..30e09e97 100644 --- a/src/helpers/Extension.ts +++ b/src/helpers/Extension.ts @@ -1,23 +1,24 @@ import { basename } from "path"; -import { Memento, extensions, Uri } from "vscode"; +import { extensions, Uri, ExtensionContext } from "vscode"; import { Folders, WORKSPACE_PLACEHOLDER } from "../commands/Folders"; import { SETTINGS_CONTENT_FOLDERS, SETTINGS_CONTENT_PAGE_FOLDERS } from "../constants"; -import { EXTENSION_ID, EXTENSION_STATE_VERSION } from "../constants/Extension"; +import { EXTENSION_BETA_ID, EXTENSION_ID, EXTENSION_STATE_VERSION } from "../constants/Extension"; +import { Notifications } from "./Notifications"; import { SettingsHelper } from "./SettingsHelper"; export class Extension { private static instance: Extension; - private constructor(private globalState: Memento, private extPath: Uri) {} + private constructor(private ctx: ExtensionContext) {} /** * Creates the singleton instance for the panel * @param extPath */ - public static getInstance(globalState?: Memento, extPath?: Uri): Extension { - if (!Extension.instance && globalState && extPath) { - Extension.instance = new Extension(globalState, extPath); + public static getInstance(ctx?: ExtensionContext): Extension { + if (!Extension.instance && ctx) { + Extension.instance = new Extension(ctx); } return Extension.instance; @@ -27,9 +28,9 @@ export class Extension { * Get the current version information for the extension */ public getVersion(): { usedVersion: string | undefined, installedVersion: string } { - const frontMatter = extensions.getExtension(EXTENSION_ID)!; + const frontMatter = extensions.getExtension(this.isBetaVersion() ? EXTENSION_BETA_ID : EXTENSION_ID)!; const installedVersion = frontMatter.packageJSON.version; - const usedVersion = this.globalState.get(EXTENSION_STATE_VERSION); + const usedVersion = this.ctx.globalState.get(EXTENSION_STATE_VERSION); if (!usedVersion) { this.setVersion(installedVersion); @@ -45,14 +46,14 @@ export class Extension { * Set the current version information for the extension */ public setVersion(installedVersion: string): void { - this.globalState.update(EXTENSION_STATE_VERSION, installedVersion); + this.ctx.globalState.update(EXTENSION_STATE_VERSION, installedVersion); } /** * Get the path to the extension */ public get extensionPath(): Uri { - return this.extPath; + return this.ctx.extensionUri; } /** @@ -75,10 +76,27 @@ export class Extension { } public async setState(propKey: string, propValue: string): Promise { - await this.globalState.update(propKey, propValue); + await this.ctx.globalState.update(propKey, propValue); } public async getState(propKey: string): Promise { - return await this.globalState.get(propKey); + return await this.ctx.globalState.get(propKey); + } + + public isBetaVersion() { + return basename(this.ctx.globalStorageUri.fsPath) === EXTENSION_BETA_ID; + } + + public checkIfExtensionCanRun() { + if (this.isBetaVersion()) { + const mainVersionInstalled = extensions.getExtension(EXTENSION_ID); + + if (mainVersionInstalled) { + Notifications.error(`Front Matter BETA cannot be used while the main version is installed. Please ensure that you have only over version installed.`); + return false; + } + } + + return true; } } \ No newline at end of file