Fix beta startup + main release script to reset the id

This commit is contained in:
Elio Struyf
2021-09-08 10:29:34 +02:00
parent aa97051437
commit 2769eb9b71
6 changed files with 49 additions and 24 deletions

View File

@@ -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 }}

View File

@@ -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",

View File

@@ -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";

7
scripts/main-release.js Normal file
View File

@@ -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));

View File

@@ -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');

View File

@@ -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<string>(EXTENSION_STATE_VERSION);
const usedVersion = this.ctx.globalState.get<string>(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<void> {
await this.globalState.update(propKey, propValue);
await this.ctx.globalState.update(propKey, propValue);
}
public async getState<T>(propKey: string): Promise<T | undefined> {
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;
}
}