From 9a6175de0f76a9aa05f23c16da6bf7069fa22b2e Mon Sep 17 00:00:00 2001 From: James Pogran Date: Tue, 11 Jun 2024 15:05:59 -0400 Subject: [PATCH] Download hcl textmate grammer from syntax repo --- build/downloader.ts | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/build/downloader.ts b/build/downloader.ts index c56bdca3c2..1fe845868d 100644 --- a/build/downloader.ts +++ b/build/downloader.ts @@ -112,7 +112,7 @@ async function downloadSyntax(info: ExtensionInfo) { const release = `v${info.syntaxVersion}`; const productName = info.name.replace('-preview', ''); - const fileName = `${productName}.tmGrammar.json`; + let fileName = `${productName}.tmGrammar.json`; const cwd = path.resolve(__dirname); const buildDir = path.basename(cwd); @@ -129,17 +129,36 @@ async function downloadSyntax(info: ExtensionInfo) { fs.mkdirSync(installPath); - const url = `https://github.com/hashicorp/syntax/releases/download/${release}/${fileName}`; + let url = `https://github.com/hashicorp/syntax/releases/download/${release}/${fileName}`; if (process.env.downloader_log === 'true') { console.log(`Downloading: ${url}`); } // const content = await got({ url }).text(); // fs.writeFileSync(fpath, content); - const buffer = await fileFromUrl(url); + let buffer = await fileFromUrl(url); fs.writeFileSync(fpath, buffer); if (process.env.downloader_log === 'true') { console.log(`Download completed: ${fpath}`); } + + fileName = `hcl.tmGrammar.json`; + const hpath = path.join(installPath, fileName); + if (fs.existsSync(hpath)) { + if (process.env.downloader_log === 'true') { + console.log(`Syntax path exists at ${hpath}. Exiting`); + } + return; + } + + url = `https://github.com/hashicorp/syntax/releases/download/${release}/${fileName}`; + if (process.env.downloader_log === 'true') { + console.log(`Downloading: ${url}`); + } + buffer = await fileFromUrl(url); + fs.writeFileSync(hpath, buffer); + if (process.env.downloader_log === 'true') { + console.log(`Download completed: ${fpath}`); + } } async function run(platform: string, architecture: string) {