-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
68 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as vscode from "vscode"; | ||
import * as cp from "child_process"; | ||
import * as fs from "fs"; | ||
import * as os from "os"; | ||
import * as path from "path"; | ||
import { getViashVersion } from "./getViashVersion"; | ||
|
||
const versionCachedDir = path.join(os.homedir(), ".viash", "releases"); | ||
|
||
export function getViashSchemaFile( | ||
version: string | undefined = undefined | ||
): string | undefined { | ||
if (!version) { | ||
version = getViashVersion(); | ||
} | ||
const schemaPath = path.join(versionCachedDir, version, "schema.json"); | ||
|
||
if (!fs.existsSync(schemaPath)) { | ||
try { | ||
fs.mkdirSync(path.dirname(schemaPath), { recursive: true }); // Ensure directory exists | ||
|
||
const { status, stderr } = cp.spawnSync( | ||
"viash", | ||
["export", "json_schema", "--format", "json", "--output", schemaPath], | ||
{ cwd: vscode.workspace.workspaceFolders?.[0].uri.fsPath } | ||
); | ||
if (status) { | ||
vscode.window.showErrorMessage(`Error getting Viash schema: ${stderr}`); | ||
return undefined; | ||
} | ||
console.log(`Schema file created at: ${schemaPath}`); | ||
} catch (error) { | ||
vscode.window.showErrorMessage(`Error getting Viash schema: ${error}`); | ||
return undefined; | ||
} | ||
} | ||
|
||
return schemaPath; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import * as vscode from "vscode"; | ||
import * as cp from "child_process"; | ||
|
||
export function getViashVersion(): string { | ||
try { | ||
const { stdout } = cp.spawnSync("viash", ["--version"], { | ||
cwd: vscode.workspace.workspaceFolders?.[0].uri.fsPath, | ||
}); | ||
// stdout format: 'viash <version> (c) <year> <author>' | ||
return stdout.toString().trim().split(" ")[1]; | ||
} catch (error) { | ||
vscode.window.showErrorMessage(`Error getting Viash version: ${error}`); | ||
return "unknown"; | ||
} | ||
} |