From a3502a4ab4d1dde5f59c87f18cdbe2fa3ac30abc Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Fri, 12 Nov 2021 16:07:30 +0100 Subject: [PATCH 1/2] make dev command read enabledApiProposals-property and fetch files accordingly --- index.js | 32 +++++++++++++++++++------------- index.ts | 34 +++++++++++++++++++++------------- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/index.js b/index.js index 8039173..9399a13 100755 --- a/index.js +++ b/index.js @@ -23,25 +23,28 @@ else if (argv._[0]) { } function handleDev(gitTagOrBranch) { if (gitTagOrBranch === void 0) { gitTagOrBranch = 'main'; } - var url = "https://raw.githubusercontent.com/microsoft/vscode/" + gitTagOrBranch + "/src/vscode-dts/vscode.proposed.d.ts"; - var legacyUrl = "https://raw.githubusercontent.com/microsoft/vscode/" + gitTagOrBranch + "/src/vs/vscode.proposed.d.ts"; - var outPath = path_1["default"].resolve(process.cwd(), './vscode.proposed.d.ts'); - console.log("Downloading vscode.proposed.d.ts\nTo: " + outPath + "\nFrom: " + url); - download(url, outPath)["catch"](function () { return download(legacyUrl, outPath); }).then(function () { - if (!isProposedApiEnabled()) { - console.log("Please set " + toRedString("\"enableProposedApi\": true") + " in package.json."); - } - console.log('Read more about proposed API at: https://code.visualstudio.com/api/advanced-topics/using-proposed-api'); - }); + var proposalNames = getEnabledApiProposals(); + if (proposalNames.length === 0) { + console.error("No proposals in the \"enabledApiProposals\"-property of package.json found."); + return; + } + for (var _i = 0, proposalNames_1 = proposalNames; _i < proposalNames_1.length; _i++) { + var name_1 = proposalNames_1[_i]; + var url = "https://raw.githubusercontent.com/microsoft/vscode/" + gitTagOrBranch + "/src/vscode-dts/vscode.proposed." + name_1 + ".d.ts"; + var outPath = path_1["default"].resolve(process.cwd(), "./vscode.proposed." + name_1 + ".d.ts"); + console.log("Downloading vscode.proposed." + toGreenString(name_1) + ".d.ts\nTo: " + outPath + "\nFrom: " + url); + download(url, outPath)["catch"](function (err) { return console.error(err); }); + } + console.log('Read more about proposed API at: https://code.visualstudio.com/api/advanced-topics/using-proposed-api'); } -function isProposedApiEnabled() { +function getEnabledApiProposals() { try { var packageJsonPath = path_1["default"].resolve(process.cwd(), './package.json'); var packageJson = JSON.parse(fs_1["default"].readFileSync(packageJsonPath, 'utf-8')); - return !!packageJson.enableProposedApi; + return Array.isArray(packageJson.enabledApiProposals) ? packageJson.enabledApiProposals : []; } catch (_a) { - return false; + return []; } } function handleDefaultDownload(gitTagOrBranch, force) { @@ -144,3 +147,6 @@ function removeNodeModulesTypes() { function toRedString(s) { return "\u001B[31m" + s + "\u001B[0m"; } +function toGreenString(s) { + return "\u001B[32m" + s + "\u001B[0m"; +} diff --git a/index.ts b/index.ts index 76d25ae..f91e7b7 100755 --- a/index.ts +++ b/index.ts @@ -20,26 +20,30 @@ if (argv._.length === 0 || argv['h'] || argv['help']) { function handleDev(gitTagOrBranch: string = 'main') { - const url = `https://raw.githubusercontent.com/microsoft/vscode/${gitTagOrBranch}/src/vscode-dts/vscode.proposed.d.ts` - const legacyUrl = `https://raw.githubusercontent.com/microsoft/vscode/${gitTagOrBranch}/src/vs/vscode.proposed.d.ts` - const outPath = path.resolve(process.cwd(), './vscode.proposed.d.ts') - console.log(`Downloading vscode.proposed.d.ts\nTo: ${outPath}\nFrom: ${url}`) + const proposalNames = getEnabledApiProposals(); + if (proposalNames.length === 0) { + console.error(`No proposals in the "enabledApiProposals"-property of package.json found.`) + return; + } - download(url, outPath).catch(() => download(legacyUrl, outPath)).then(() => { - if (!isProposedApiEnabled()) { - console.log(`Please set ${toRedString(`"enableProposedApi": true`)} in package.json.`) - } - console.log('Read more about proposed API at: https://code.visualstudio.com/api/advanced-topics/using-proposed-api') - }) + for (const name of proposalNames) { + const url = `https://raw.githubusercontent.com/microsoft/vscode/${gitTagOrBranch}/src/vscode-dts/vscode.proposed.${name}.d.ts` + const outPath = path.resolve(process.cwd(), `./vscode.proposed.${name}.d.ts`) + console.log(`Downloading vscode.proposed.${toGreenString(name)}.d.ts\nTo: ${outPath}\nFrom: ${url}`) + + download(url, outPath).catch(err => console.error(err)) + } + + console.log('Read more about proposed API at: https://code.visualstudio.com/api/advanced-topics/using-proposed-api') } -function isProposedApiEnabled() { +function getEnabledApiProposals(): string[] { try { const packageJsonPath = path.resolve(process.cwd(), './package.json') const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')) - return !!packageJson.enableProposedApi + return Array.isArray(packageJson.enabledApiProposals) ? packageJson.enabledApiProposals : [] } catch { - return false + return [] } } @@ -147,3 +151,7 @@ function removeNodeModulesTypes() { function toRedString(s: string) { return `\x1b[31m${s}\x1b[0m` } + +function toGreenString(s: string) { + return `\x1b[32m${s}\x1b[0m` +} From e77161fc3307bfe273b88fece27747af11365123 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Fri, 12 Nov 2021 16:11:17 +0100 Subject: [PATCH 2/2] update help message and readme --- README.md | 8 ++++---- index.js | 6 +++--- index.ts | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f482169..1b5bf7e 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@ CLI utility for downloading vscode.d.ts and vscode.proposed.d.ts ```bash ~ > npx vscode-dts -vscode-dts: CLI utility for downloading vscode.d.ts and vscode.proposed.d.ts +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 dev Download vscode.proposed.d.ts from git tag/branch of microsoft/vscode + - npx vscode-dts dev Download vscode.proposaled..d.ts files + - npx vscode-dts dev Download vscode.proposaled..d.ts files from git tag/branch of microsoft/vscode - npx vscode-dts Download vscode.d.ts from git tag/branch of microsoft/vscode - npx vscode-dts -f Download vscode.d.ts and remove conflicting types in node_modules/@types/vscode - npx vscode-dts Print Help @@ -34,4 +34,4 @@ provided by the bot. You will only need to do this once across all repos using o 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 +contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. diff --git a/index.js b/index.js index 9399a13..68fce39 100755 --- a/index.js +++ b/index.js @@ -67,11 +67,11 @@ function handleDefaultDownload(gitTagOrBranch, force) { } function getHelpMessage() { return [ - 'vscode-dts: CLI utility for downloading vscode.d.ts and vscode.proposed.d.ts', + '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 dev Download vscode.proposed.d.ts from git tag/branch of microsoft/vscode', + ' - npx vscode-dts dev Download vscode.proposaled..d.ts files', + ' - npx vscode-dts dev Download vscode.proposaled..d.ts files from git tag/branch of microsoft/vscode', ' - npx vscode-dts Download vscode.d.ts from git tag/branch of microsoft/vscode', ' - npx vscode-dts -f Download vscode.d.ts and remove conflicting types in node_modules/@types/vscode', ' - npx vscode-dts Print Help', diff --git a/index.ts b/index.ts index f91e7b7..a08b2a2 100755 --- a/index.ts +++ b/index.ts @@ -69,11 +69,11 @@ function handleDefaultDownload(gitTagOrBranch: string, force?: boolean) { function getHelpMessage() { return [ - 'vscode-dts: CLI utility for downloading vscode.d.ts and vscode.proposed.d.ts', + '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 dev Download vscode.proposed.d.ts from git tag/branch of microsoft/vscode', + ' - npx vscode-dts dev Download vscode.proposaled..d.ts files', + ' - npx vscode-dts dev Download vscode.proposaled..d.ts files from git tag/branch of microsoft/vscode', ' - npx vscode-dts Download vscode.d.ts from git tag/branch of microsoft/vscode', ' - npx vscode-dts -f Download vscode.d.ts and remove conflicting types in node_modules/@types/vscode', ' - npx vscode-dts Print Help',