From 52f811c9eb18127dda9c7a02facee801ccd01484 Mon Sep 17 00:00:00 2001 From: Pine Wu Date: Sun, 22 Aug 2021 13:55:15 +0800 Subject: [PATCH] Do not prompt setting enableProposedApi if set. Fix #5 --- .prettierrc.json | 4 +++- index.js | 18 +++++++++++++++--- index.ts | 16 ++++++++++++++-- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/.prettierrc.json b/.prettierrc.json index 0a64884..f31fad4 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,5 +1,7 @@ { "printWidth": 120, "semi": false, - "singleQuote": true + "singleQuote": true, + "trailingComma": "none", + "arrowParens": "avoid" } \ No newline at end of file diff --git a/index.js b/index.js index 6f1acf1..fbb3099 100755 --- a/index.js +++ b/index.js @@ -28,10 +28,22 @@ function handleDev(gitTagOrBranch) { 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).then(function () { - console.log("Please set " + toRedString("\"enableProposedApi\": true") + " in package.json."); + 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'); }); } +function isProposedApiEnabled() { + 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; + } + catch (_a) { + return false; + } +} function handleDefaultDownload(gitTagOrBranch, force) { // handle master->main rename for old consumers if (gitTagOrBranch === 'master') { @@ -57,10 +69,10 @@ function getHelpMessage() { ' - 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 Download vscode.d.ts from git tag/branch of microsoft/vscode', - ' - npx vscode-dts -f Download vscode.d.ts and remove comflicing types in node_modules/@types/vscode', + ' - npx vscode-dts -f Download vscode.d.ts and remove conflicting types in node_modules/@types/vscode', ' - npx vscode-dts Print Help', ' - npx vscode-dts -h Print Help', - ' - npx vscode-dts --help Print Help' + ' - npx vscode-dts --help Print Help', ].join(os_1["default"].EOL); } function download(url, outPath) { diff --git a/index.ts b/index.ts index 4f0d33f..99d4982 100755 --- a/index.ts +++ b/index.ts @@ -26,15 +26,27 @@ function handleDev(gitTagOrBranch?: string) { console.log(`Downloading vscode.proposed.d.ts\nTo: ${outPath}\nFrom: ${url}`) download(url, outPath).then(() => { - console.log(`Please set ${toRedString(`"enableProposedApi": true`)} in package.json.`) + 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') }) } +function isProposedApiEnabled() { + try { + const packageJsonPath = path.resolve(process.cwd(), './package.json') + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')) + return !!packageJson.enableProposedApi + } catch { + return false + } +} + function handleDefaultDownload(gitTagOrBranch: string, force?: boolean) { // handle master->main rename for old consumers if (gitTagOrBranch === 'master') { - gitTagOrBranch = 'main'; + gitTagOrBranch = 'main' } const url = `https://raw.githubusercontent.com/microsoft/vscode/${gitTagOrBranch}/src/vs/vscode.d.ts`