-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdl-ext.ts
More file actions
31 lines (27 loc) · 1.39 KB
/
dl-ext.ts
File metadata and controls
31 lines (27 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
export const getLocalDirectory = () => {
const __filename = fileURLToPath(import.meta.url);
return dirname(__filename);
};
const downloadResource = async (url: string, targetDir: string, filename: string) => {
const target = resolve(targetDir, filename);
if (existsSync(target)) {
console.log(`Skipping download because ${target} already exists.`);
} else {
const result = mkdirSync(targetDir, { recursive: true });
if (result) {
console.log(`Created target directory: ${targetDir}`);
}
console.log(`Downloading ${url} to ${target}`);
const resp = await fetch(url);
const buffer = await resp.arrayBuffer();
writeFileSync(target, Buffer.from(buffer));
}
};
// Source: https://gist.github.com/wanglf/7acc591890dc0d8ceff1e7ec9af32a55?permalink_comment_id=4151555#gistcomment-4151555
// https://marketplace.visualstudio.com/_apis/public/gallery/publishers/${publisher}/vsextensions/${extension}/${version}/vspackage
// not yet used
await downloadResource('https://marketplace.visualstudio.com/_apis/public/gallery/publishers/TypeFox/vsextensions/open-collaboration-tools/0.3.0/vspackage',
resolve(getLocalDirectory(), './extensions/'), 'open-collaboration-tools.vsix');