Skip to content

Commit

Permalink
Download syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
jpogran committed Mar 21, 2022
1 parent 0cf5caf commit c109dc2
Show file tree
Hide file tree
Showing 5 changed files with 533 additions and 885 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
bin/
out/
node_modules/
syntaxes/
*.vsix
.DS_Store
.vscode-test
Expand Down
40 changes: 36 additions & 4 deletions build/downloader.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import got from 'got';
import * as fs from 'fs';
import * as path from 'path';
import * as releases from '@hashicorp/js-releases';
Expand Down Expand Up @@ -36,22 +37,26 @@ function getArch(arch: string) {
}

interface ExtensionInfo {
name: string;
extensionVersion: string;
languageServerVersion: string;
preview: false;
syntaxVersion: string;
}

function getExtensionInfo(): ExtensionInfo {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pjson = require('../package.json');
return {
name: pjson.name,
extensionVersion: pjson.version,
languageServerVersion: pjson.langServer.version,
syntaxVersion: pjson.syntax.version,
preview: pjson.preview,
};
}

async function run(platform: string, architecture: string) {
async function downloadLanguageServer(platform: string, architecture: string, extInfo: ExtensionInfo) {
const cwd = path.resolve(__dirname);

const buildDir = path.basename(cwd);
Expand All @@ -64,9 +69,6 @@ async function run(platform: string, architecture: string) {

fs.mkdirSync(installPath);

const extInfo = getExtensionInfo();
console.log(extInfo);

// userAgent = `Terraform-VSCode/${extensionVersion} VSCode/${vscodeVersion}`;
const ciBuild = process.env.CI;
const runnerLocation = ciBuild ? `CLI-Downloader GitHub-Actions` : `CLI-Downloader`;
Expand Down Expand Up @@ -94,6 +96,36 @@ async function run(platform: string, architecture: string) {
});
}

async function downloadSyntax(info: ExtensionInfo) {
const release = `v${info.syntaxVersion}`;

const fileName = `${info.name}.tmGrammar.json`;
const url = `https://github.com/hashicorp/syntax/releases/download/${release}/${fileName}`;
console.log(`Downloading: ${url}`);

const cwd = path.resolve(__dirname);
const buildDir = path.basename(cwd);
const repoDir = cwd.replace(buildDir, '');
const installPath = path.join(repoDir, 'syntaxes');

const fpath = path.join(installPath, fileName);
if (fs.existsSync(installPath)) {
fs.rmSync(installPath, { recursive: true, force: true });
}
fs.mkdirSync(installPath);

const content = await got({ url }).text();
fs.writeFileSync(fpath, content);
console.log(`Download completed: ${fpath}`);
}

async function run(platform: string, architecture: string) {
const extInfo = getExtensionInfo();
console.log(extInfo);
await downloadLanguageServer(platform, architecture, extInfo);
await downloadSyntax(extInfo);
}

let os = process.platform.toString();
let arch = process.arch;

Expand Down
Loading

0 comments on commit c109dc2

Please sign in to comment.