From 2a7197a6dffc491ec58e54e9bde565ebc5d7f171 Mon Sep 17 00:00:00 2001 From: Nils Andresen Date: Tue, 11 Oct 2022 14:03:31 +0200 Subject: [PATCH 1/2] (#730) added a new script task Which calls "npm ci", if node_modules does not exist. By calling this before the "watch" task, the workflow of clone, start VSCode, hit F5 will "simply work". --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1f63997b..d3036d49 100644 --- a/package.json +++ b/package.json @@ -619,9 +619,10 @@ "scripts": { "vscode:prepublish": "npm run compile", "compile": "tsc -p ./", - "watch": "tsc -watch -p ./", + "watch": "npm run ensureCi && tsc -watch -p ./", "test": "npm run compile && node ./out/test/runTest.js", - "depcheck": "depcheck" + "depcheck": "depcheck", + "ensureCi": "node -e \"const fs=require('fs'); if (fs.existsSync('./node_modules/')) { process.exit(123); }\" && npm ci" }, "dependencies": { "adm-zip": "^0.5.9", From 1bd5707dba9488a6fecca38f6611c0c192caba00 Mon Sep 17 00:00:00 2001 From: Nils Andresen Date: Tue, 11 Oct 2022 11:55:08 +0200 Subject: [PATCH 2/2] (#728) update omnisharp on every update of cake.bakery --- src/bakery/cakeBakery.ts | 76 +++++++++++++++++++++++++++------ src/bakery/cakeBakeryCommand.ts | 24 +++++------ src/cakeMain.ts | 30 +------------ 3 files changed, 75 insertions(+), 55 deletions(-) diff --git a/src/bakery/cakeBakery.ts b/src/bakery/cakeBakery.ts index 01c88a5a..6c572d9a 100644 --- a/src/bakery/cakeBakery.ts +++ b/src/bakery/cakeBakery.ts @@ -1,12 +1,15 @@ var request = require('request'); var AdmZip = require('adm-zip'); +import * as vscode from 'vscode'; import * as path from 'path'; import * as fs from 'fs'; +import * as os from 'os'; import { window } from 'vscode'; import { CAKE_BAKERY_PACKAGE_URL, DEFAULT_RESPONSE_TIMEOUT } from '../constants'; +import { logger } from '../shared' export class CakeBakery { private extensionPath : string; @@ -17,35 +20,33 @@ export class CakeBakery { public getTargetPath(): string { return path.join( - this.extensionPath, - 'Cake.Bakery/tools/Cake.Bakery.dll' + this.getInstallationPath(), + 'tools/Cake.Bakery.dll' ); } - public getNupkgDestinationPath(): string { + public getInstallationPath(): string { return path.join( this.extensionPath, 'Cake.Bakery' ); } - public getToolFolderPath(): string { - return path.join( - this.extensionPath); - } - public downloadAndExtract(): Thenable { + const installationPath = this.getInstallationPath(); + const extensionPath = this.extensionPath; return new Promise((resolve, reject) => { // Download the NuGet Package - let vm = this; try { - if (!fs.existsSync(vm.getToolFolderPath())) { - fs.mkdirSync(vm.getToolFolderPath()); + if (!fs.existsSync(extensionPath)) { + fs.mkdirSync(extensionPath); } } catch (error) { window.showErrorMessage('Unable to create directory'); } + logger.logInfo("Downloading Cake.Bakery to " + extensionPath) + var data: any[] = [], dataLen = 0; @@ -66,12 +67,61 @@ export class CakeBakery { } var zip = new AdmZip(buf); - zip.extractAllTo(vm.getNupkgDestinationPath()); + zip.extractAllTo(installationPath); + logger.logInfo("Cake.Bakery successfully installed to: " + installationPath) resolve(true); }) .on('error', function(e: any) { - reject(`Failed to download Cake Bakery from NuGet: ${e}`); + const err = `Failed to download Cake Bakery from NuGet: ${e}`; + logger.logError(err); + reject(err); }); }); } + + public updateOmnisharpSettings() : Thenable { + return new Promise((resolve, reject) => { + logger.logInfo("Updating Cake.Bakery path in omnisharp."); + try { + const omnisharpUserFolderPath = this.getOmnisharpUserFolderPath(); + if (!fs.existsSync(omnisharpUserFolderPath)) { + fs.mkdirSync(omnisharpUserFolderPath); + } + + const targetPath = this.getTargetPath(); + const omnisharpCakeConfigFile = this.getOmnisharpCakeConfigFile(); + if (fs.existsSync(omnisharpCakeConfigFile)) { + // Read in file + //import omnisharpCakeConfig from omnisharpCakeConfigFile; + var omnisharpCakeConfig = JSON.parse(fs.readFileSync(omnisharpCakeConfigFile, 'utf-8')) + logger.logInfo(`existing bakery-path: ${omnisharpCakeConfig.cake.bakeryPath}`); + omnisharpCakeConfig.cake.bakeryPath = targetPath; + logger.logInfo(`new bakery-path: ${omnisharpCakeConfig.cake.bakeryPath}`); + fs.writeFileSync(omnisharpCakeConfigFile, JSON.stringify(omnisharpCakeConfig, null, 2)); + + // lets force a restart of the Omnisharp server to use new config + vscode.commands.executeCommand('o.restart'); + } else { + // create file + var newOmnisharpCakeConfig = { cake: { bakeryPath: targetPath }}; + fs.writeFileSync(omnisharpCakeConfigFile, JSON.stringify(newOmnisharpCakeConfig)); + } + logger.logInfo("Omnisharp setting successfully updated.") + resolve(); + } catch (e) { + const err = `Failed to update Omnisharp settings: ${e}`; + logger.logError(err); + reject(err); + } + }); + } + + + private getOmnisharpUserFolderPath() : string { + return path.join(os.homedir(), ".omnisharp"); + } + + private getOmnisharpCakeConfigFile() : string { + return path.join(this.getOmnisharpUserFolderPath(), "omnisharp.json"); + } } diff --git a/src/bakery/cakeBakeryCommand.ts b/src/bakery/cakeBakeryCommand.ts index 7eb9e383..c836c047 100644 --- a/src/bakery/cakeBakeryCommand.ts +++ b/src/bakery/cakeBakeryCommand.ts @@ -1,35 +1,33 @@ -import { commands, window, workspace } from 'vscode'; +import { commands, window } from 'vscode'; import * as fs from 'fs'; import { CakeBakery } from './cakeBakery'; +import { logger } from '../shared' export async function updateCakeBakeryCommand(extensionPath: string) { - // Make sure that we're in the correct place. - if (workspace.rootPath === undefined) { - window.showErrorMessage('You have not yet opened a folder.'); - return; - } - // Install Cake Bakery - var result = await installCakeDebug(extensionPath); + var result = await forceInstallBakery(extensionPath); if (result) { commands.executeCommand('o.restart'); window.showInformationMessage( - 'Intellisense support for Cake files was installed.' + 'Intellisense support (Cake.Bakery) for Cake files was installed.' ); } else { window.showErrorMessage( - 'Error downloading intellisense support for Cake files.' + 'Error downloading intellisense support (Cake.Bakery) for Cake files.' ); } } -export async function installCakeDebug(extensionPath: string): Promise { +export async function forceInstallBakery(extensionPath: string): Promise { let bakery = new CakeBakery(extensionPath); - var targetPath = bakery.getNupkgDestinationPath(); + var targetPath = bakery.getInstallationPath(); + logger.logInfo("Force-updating Cake.Bakery in " + targetPath); if (fs.existsSync(targetPath)) { fs.rmdirSync(targetPath, {recursive: true}); } - return await bakery.downloadAndExtract(); + const success = await bakery.downloadAndExtract(); + await bakery.updateOmnisharpSettings(); + return success; } diff --git a/src/cakeMain.ts b/src/cakeMain.ts index f05612cc..52f44930 100644 --- a/src/cakeMain.ts +++ b/src/cakeMain.ts @@ -105,41 +105,13 @@ export function activate(context: vscode.ExtensionContext): void { onConfigurationChanged(context, null as unknown as vscode.ConfigurationChangeEvent); } -function getOmnisharpUserFolderPath() : string { - return path.join(os.homedir(), ".omnisharp"); -} - -function getOmnisharpCakeConfigFile() : string { - return path.join(getOmnisharpUserFolderPath(), "omnisharp.json"); -} - async function _registerCakeBakery(context: vscode.ExtensionContext) { let bakery = new CakeBakery(context.extensionPath); var targetPath = bakery.getTargetPath(); if (!fs.existsSync(targetPath)) { await bakery.downloadAndExtract(); - - if (!fs.existsSync(getOmnisharpUserFolderPath())) { - fs.mkdirSync(getOmnisharpUserFolderPath()); - } - - if (fs.existsSync(getOmnisharpCakeConfigFile())) { - // Read in file - //import omnisharpCakeConfig from getOmnisharpCakeConfigFile(); - var omnisharpCakeConfig = JSON.parse(fs.readFileSync(getOmnisharpCakeConfigFile(), 'utf-8')) - logger.logInfo(`existing bakery-path: ${omnisharpCakeConfig.cake.bakeryPath}`); - omnisharpCakeConfig.cake.bakeryPath = targetPath; - logger.logInfo(`new bakery-path: ${omnisharpCakeConfig.cake.bakeryPath}`); - fs.writeFileSync(getOmnisharpCakeConfigFile(), JSON.stringify(omnisharpCakeConfig)); - - // lets force a restart of the Omnisharp server to use new config - vscode.commands.executeCommand('o.restart'); - } else { - // create file - var newOmnisharpCakeConfig = { cake: { bakeryPath: targetPath }}; - fs.writeFileSync(getOmnisharpCakeConfigFile(), JSON.stringify(newOmnisharpCakeConfig)); - } + await bakery.updateOmnisharpSettings(); } else { logger.logToOutput("Cake.Bakery has already been installed, skipping automated download and extraction."); }