Last active
June 17, 2020 02:14
-
-
Save ssut/54d573e87013ff0330f6e9e9ed14625c to your computer and use it in GitHub Desktop.
download vscode extensions from settings sync's cloudSettings file
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
const fs = require('fs'); | |
const { promisify } = require('util'); | |
const child = require('child_process'); | |
const statAsync = promisify(fs.stat); | |
const unlinkAsync = promisify(fs.unlink); | |
const UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36'; | |
async function main() { | |
try { | |
fs.mkdirSync('ext-downloads'); | |
} catch {} | |
const extensions = require('./extensions.json'); | |
let downloaded = 0; | |
for (const extension of extensions) { | |
const [ publisher ] = extension.metadata.publisherId.split('.', 1); | |
const destination = `ext-downloads/${extension.name}-${extension.version}.vsix`; | |
try { | |
if ((await statAsync(destination)).size > 0) { | |
console.info('SKIP'); | |
downloaded += 1; | |
continue; | |
} else { | |
await unlinkAsync(destination); | |
} | |
} catch {} | |
const url = `https://${publisher}.gallery.vsassets.io/_apis/public/gallery/publisher/${publisher}/extension/${extension.name}/${extension.version}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage`; | |
const downloader = child.spawn('wget', [ | |
'--no-dns-cache', | |
'--retry-on-http-error=429', | |
'-t=10', | |
'--waitretry=5', | |
'-U', | |
UA, | |
'-O', | |
destination, | |
url, | |
]); | |
downloader.stdout.pipe(process.stdout); | |
downloader.stderr.pipe(process.stderr); | |
await new Promise((resolve) => { | |
downloader.on('exit', resolve); | |
}); | |
try { | |
if ((await statAsync(destination)).size === 0) { | |
throw new Error(); | |
} | |
console.info('OK'); | |
downloaded += 1; | |
} catch { | |
await unlinkAsync(destination).catch(() => {}); | |
console.info('ERROR'); | |
} | |
} | |
console.info(downloaded, '/', extensions.length); | |
} | |
main(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment