diff --git a/README.md b/README.md index 29f7ebd..93ef52c 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,37 @@ - -# Contributing - -This project welcomes contributions and suggestions. Most contributions require you to agree to a -Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us -the rights to use your contribution. For details, visit https://cla.microsoft.com. - -When you submit a pull request, a CLA-bot will automatically determine whether you need to provide -a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions -provided by the bot. You will only need to do this once across all repos using our CLA. - -This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). -For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or -contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. +# vscode-dts + +CLI utility for downloading vscode.d.ts and vscode.proposed.d.ts + +## Usage + +```bash + ~ > npx vscode-dts +vscode-dts: CLI utility for downloading vscode.d.ts and vscode.proposed.d.ts + +Usage: + - npx vscode-dts dev Download vscode.proposed.d.ts + - npx vscode-dts Download vscode.d.ts from git tag of microsoft/vscode + - npx vscode-dts Download vscode.d.ts from git branch of microsoft/vscode + - npx vscode-dts Print Help + - npx vscode-dts -h Print Help + - npx vscode-dts --help Print Help + ~ > +``` + +## License + +[MIT](LICENSE) + +## Contributing + +This project welcomes contributions and suggestions. Most contributions require you to agree to a +Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us +the rights to use your contribution. For details, visit https://cla.microsoft.com. + +When you submit a pull request, a CLA-bot will automatically determine whether you need to provide +a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions +provided by the bot. You will only need to do this once across all repos using our CLA. + +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). +For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or +contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. \ No newline at end of file diff --git a/index.js b/index.js new file mode 100755 index 0000000..efac8f0 --- /dev/null +++ b/index.js @@ -0,0 +1,57 @@ +#!/usr/bin/env node + +const https = require('https') +const fs = require('fs') +const path = require('path') +const os = require('os') + +const PROPOSED_DTS_URL = 'https://raw.githubusercontent.com/microsoft/vscode/master/src/vs/vscode.proposed.d.ts' + +const realArgs = process.argv.slice(2) + +if (realArgs.length === 0 || realArgs[0] === '-h' || realArgs[0] === '--help') { + console.log(printHelp()) +} else if (realArgs[0] === 'dev') { + const outPath = path.resolve(process.cwd(), './vscode.proposed.d.ts') + console.log(`Downloading vscode.proposed.d.ts to ${outPath}`) + download(PROPOSED_DTS_URL, outPath).then(() => { + console.log('Please set "enableProposedApi": true in package.json.') + console.log('Read more about proposed API at: https://code.visualstudio.com/api/advanced-topics/using-proposed-api') + }) +} else if (realArgs[0]) { + const url = `https://raw.githubusercontent.com/microsoft/vscode/${realArgs[0]}/src/vs/vscode.d.ts` + const outPath = path.resolve(process.cwd(), './vscode.d.ts') + console.log(`Downloading vscode.d.ts to ${outPath} from ${url}`) + download(url, outPath) +} + +function printHelp() { + return [ + 'vscode-dts: CLI utility for downloading vscode.d.ts and vscode.proposed.d.ts', + '', + 'Usage:', + ' - npx vscode-dts dev Download vscode.proposed.d.ts', + ' - npx vscode-dts Download vscode.d.ts from git tag of microsoft/vscode', + ' - npx vscode-dts Download vscode.d.ts from git branch of microsoft/vscode', + ' - npx vscode-dts Print Help', + ' - npx vscode-dts -h Print Help', + ' - npx vscode-dts --help Print Help' + ].join(os.EOL) +} + +function download(url, outPath) { + return new Promise((resolve, reject) => { + const outStream = fs.createWriteStream(outPath) + outStream.on('close', () => { + resolve() + }) + + https.get(url, res => { + if (res.statusCode !== 200) { + reject(`Failed to get ${url}`) + } + + res.pipe(outStream) + }) + }) +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..0cad130 --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "name": "vscode-dts", + "version": "0.1.0", + "description": "CLI utility for downloading vscode.d.ts and vscode.proposed.d.ts", + "bin": "index.js", + "author": { + "name": "Microsoft Corporation" + }, + "license": "MIT", + "devDependencies": { + "@types/node": "^12.0.2" + } +} diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..362134b --- /dev/null +++ b/yarn.lock @@ -0,0 +1,8 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@types/node@^12.0.2": + version "12.0.2" + resolved "https://registry.yarnpkg.com/@types/node/-/node-12.0.2.tgz#3452a24edf9fea138b48fad4a0a028a683da1e40" + integrity sha512-5tabW/i+9mhrfEOUcLDu2xBPsHJ+X5Orqy9FKpale3SjDA17j5AEpYq5vfy3oAeAHGcvANRCO3NV3d2D6q3NiA==