Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions editors/vscode/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/semi": "warn",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off"
},
"ignorePatterns": [
"out",
"dist",
"**/*.d.ts"
]
}
5 changes: 3 additions & 2 deletions editors/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
],
"main": "./dist/extension.js",
"scripts": {
"vscode:prepublish": "npm run package",
"vscode:prepublish": "npm run build",
"build": "npm run check-types && npm run lint && node esbuild.js --production",
"compile": "npm run check-types && npm run lint && node esbuild.js",
"watch": "npm run check-types && npm run lint && node esbuild.js --watch",
"package": "npm run check-types && npm run lint && node esbuild.js --production",
"package": "vsce package",
"check-types": "tsc --noEmit",
"lint": "eslint src --ext ts",
"test": "npm run compile && node ./dist/test/runTest.js"
Expand Down
73 changes: 55 additions & 18 deletions editors/vscode/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ import * as path from 'path';
import * as https from 'https';
import * as os from 'os';
import { IncomingMessage } from 'http';
import { exec } from 'child_process';
import { promisify } from 'util';

const execAsync = promisify(exec);

const BINARY_NAME = 'naviscope';
const REPO_OWNER = 'biuld';
const REPO_NAME = 'naviscope';
// Update this version when bundling a new version of the extension
const EXPECTED_VERSION = '0.1.0';

export async function bootstrap(context: vscode.ExtensionContext): Promise<string | undefined> {
const naviscopeHome = path.join(os.homedir(), '.naviscope');
Expand All @@ -23,31 +29,63 @@ export async function bootstrap(context: vscode.ExtensionContext): Promise<strin
}

const binaryPath = path.join(binDir, BINARY_NAME);
let shouldDownload = false;

if (fs.existsSync(binaryPath)) {
return binaryPath;
const isCompatible = await checkVersion(binaryPath);
if (!isCompatible) {
const selection = await vscode.window.showWarningMessage(
`Naviscope binary version mismatch. Expected v${EXPECTED_VERSION}. Update now?`,
'Update',
'Skip'
);
if (selection === 'Update') {
shouldDownload = true;
}
}
} else {
const selection = await vscode.window.showInformationMessage(
`Naviscope binary is required. Download automatically to ${binDir}?`,
'Download',
'Cancel'
);
if (selection === 'Download') {
shouldDownload = true;
} else {
return undefined;
}
}

const selection = await vscode.window.showInformationMessage(
`Naviscope binary is required. Download automatically to ${binDir}?`,
'Download',
'Cancel'
);
if (shouldDownload) {
try {
if (fs.existsSync(binaryPath)) {
fs.unlinkSync(binaryPath);
}
await downloadBinary(binaryPath);
vscode.window.showInformationMessage(`Naviscope installed successfully!`);
} catch (error) {
vscode.window.showErrorMessage(`Failed to download Naviscope: ${error}`);
if (fs.existsSync(binaryPath)) {
fs.unlinkSync(binaryPath);
}
return undefined;
}
}

if (selection !== 'Download') {
return undefined;
if (fs.existsSync(binaryPath)) {
return binaryPath;
}
return undefined;
}

async function checkVersion(binaryPath: string): Promise<boolean> {
try {
await downloadBinary(binaryPath);
vscode.window.showInformationMessage(`Naviscope installed successfully!`);
return binaryPath;
} catch (error) {
vscode.window.showErrorMessage(`Failed to download Naviscope: ${error}`);
if (fs.existsSync(binaryPath)) {
fs.unlinkSync(binaryPath);
}
return undefined;
const { stdout } = await execAsync(`"${binaryPath}" --version`);
// Expected output: "naviscope 0.1.0"
return stdout.includes(EXPECTED_VERSION);
} catch (e) {
console.warn('Failed to check version:', e);
return false;
}
}

Expand Down Expand Up @@ -112,7 +150,6 @@ function getPlatformIdentifier(): string | null {
if (arch === 'arm64') {
return 'macos-aarch64';
}
// Intel Mac is not supported
}
return null;
}
Loading