|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | +const path = require('path'); |
| 6 | +const fs = require('fs'); |
| 7 | +const https = require('https'); |
| 8 | + |
| 9 | +const pickKeys = [ |
| 10 | + 'extensionTips', 'extensionImportantTips', 'keymapExtensionTips', |
| 11 | + 'configBasedExtensionTips', 'extensionKeywords', 'extensionAllowedBadgeProviders', |
| 12 | + 'extensionAllowedBadgeProvidersRegex', 'extensionAllowedProposedApi', |
| 13 | + 'extensionEnabledApiProposals', 'extensionKind', 'languageExtensionTips' |
| 14 | +]; |
| 15 | + |
| 16 | +async function start() { |
| 17 | + const releasePath = path.join(__dirname, '../product-release.json'); |
| 18 | + if (!fs.existsSync(releasePath)) { |
| 19 | + console.error('product-release.json is not exists, please copy product.json from VSCode Desktop Stable'); |
| 20 | + return; |
| 21 | + } |
| 22 | + const branchProduct = JSON.parse(fs.readFileSync(path.join(__dirname, '../product.json')).toString()); |
| 23 | + const releaseProduct = JSON.parse(fs.readFileSync(releasePath).toString()); |
| 24 | + const tmpProductPath = path.join(__dirname, '../product-tmp.json'); |
| 25 | + for (let key of pickKeys) { |
| 26 | + branchProduct[key] = releaseProduct[key]; |
| 27 | + } |
| 28 | + fs.writeFileSync(tmpProductPath, JSON.stringify(branchProduct, null, 4)); |
| 29 | + |
| 30 | + if (keysDiff(branchProduct, releaseProduct)) { |
| 31 | + // allow-any-unicode-next-line |
| 32 | + console.log('📦 check if you need these keys or not'); |
| 33 | + } |
| 34 | + await checkProductExtensions(branchProduct); |
| 35 | + // allow-any-unicode-next-line |
| 36 | + console.log('📦 you can copy product-tmp.json file to product.json file and resolve logs above by yourself'); |
| 37 | + // allow-any-unicode-next-line |
| 38 | + console.log('✅ done'); |
| 39 | +} |
| 40 | + |
| 41 | +const AllowMissKeys = [ |
| 42 | + 'win32SetupExeBasename', |
| 43 | + 'darwinCredits', |
| 44 | + 'darwinExecutable', |
| 45 | + 'downloadUrl', |
| 46 | + 'updateUrl', |
| 47 | + 'webEndpointUrl', |
| 48 | + 'webEndpointUrlTemplate', |
| 49 | + 'quality', |
| 50 | + 'exeBasedExtensionTips', |
| 51 | + 'webExtensionTips', |
| 52 | + 'remoteExtensionTips', |
| 53 | + 'crashReporter', |
| 54 | + 'appCenter', |
| 55 | + 'enableTelemetry', |
| 56 | + 'aiConfig', |
| 57 | + 'msftInternalDomains', |
| 58 | + 'sendASmile', |
| 59 | + 'documentationUrl', |
| 60 | + 'releaseNotesUrl', |
| 61 | + 'keyboardShortcutsUrlMac', |
| 62 | + 'keyboardShortcutsUrlLinux', |
| 63 | + 'keyboardShortcutsUrlWin', |
| 64 | + 'introductoryVideosUrl', |
| 65 | + 'tipsAndTricksUrl', |
| 66 | + 'newsletterSignupUrl', |
| 67 | + 'twitterUrl', |
| 68 | + 'requestFeatureUrl', |
| 69 | + 'reportMarketplaceIssueUrl', |
| 70 | + 'privacyStatementUrl', |
| 71 | + 'showTelemetryOptOut', |
| 72 | + 'npsSurveyUrl', |
| 73 | + 'cesSurveyUrl', |
| 74 | + 'checksumFailMoreInfoUrl', |
| 75 | + 'electronRepository', |
| 76 | + 'settingsSearchUrl', |
| 77 | + 'surveys', |
| 78 | + 'tasConfig', |
| 79 | + 'experimentsUrl', |
| 80 | + 'extensionSyncedKeys', |
| 81 | + 'extensionVirtualWorkspacesSupport', |
| 82 | + 'auth', |
| 83 | + 'configurationSync.store', |
| 84 | + 'commit', |
| 85 | + 'date', |
| 86 | + 'checksums', |
| 87 | + 'settingsSearchBuildId', |
| 88 | + 'darwinUniversalAssetId', |
| 89 | +]; |
| 90 | + |
| 91 | +function keysDiff(branch, release) { |
| 92 | + const toMap = (ret, e) => { |
| 93 | + ret[e] = true; |
| 94 | + return ret; |
| 95 | + }; |
| 96 | + const map1 = Object.keys(branch).reduce(toMap, {}); |
| 97 | + const map2 = Object.keys(release).reduce(toMap, {}); |
| 98 | + let changed = false; |
| 99 | + for (let key in branch) { |
| 100 | + if (!!!map2[key]) { |
| 101 | + changed = true; |
| 102 | + // allow-any-unicode-next-line |
| 103 | + console.log(`🟠 Remove key: ${key}`); |
| 104 | + } |
| 105 | + } |
| 106 | + for (let key in release) { |
| 107 | + if (!!!map1[key] && !AllowMissKeys.includes(key)) { |
| 108 | + changed = true; |
| 109 | + // allow-any-unicode-next-line |
| 110 | + console.log(`🟠 Add key: ${key}`); |
| 111 | + } |
| 112 | + } |
| 113 | + return changed; |
| 114 | +} |
| 115 | + |
| 116 | +async function checkProductExtensions(product) { |
| 117 | + const uniqueExtIds = new Set(); |
| 118 | + // Allow extension that downloaded from ms marketplace by users to use proposed api |
| 119 | + // uniqueExtIds.push(...product.extensionAllowedProposedApi); |
| 120 | + |
| 121 | + // Check recommand extension tips |
| 122 | + for (let key in product.configBasedExtensionTips) { |
| 123 | + Object.keys(product.configBasedExtensionTips[key].recommendations ?? {}).forEach(id => uniqueExtIds.add(id)); |
| 124 | + } |
| 125 | + Object.keys(product.extensionImportantTips).forEach(id => uniqueExtIds.add(id)); |
| 126 | + Object.keys(product.extensionTips).forEach(id => uniqueExtIds.add(id)); |
| 127 | + Object.keys(product.extensionEnabledApiProposals).forEach(id => uniqueExtIds.add(id)); |
| 128 | + product.keymapExtensionTips.forEach(id => uniqueExtIds.add(id)); |
| 129 | + product.languageExtensionTips.forEach(id => uniqueExtIds.add(id)); |
| 130 | + |
| 131 | + // Check if extensions exists in openvsx |
| 132 | + for (let id of uniqueExtIds) { |
| 133 | + const openvsxUrl = `https://open-vsx.org/api/${id.replace(/\./g, '/')}`; |
| 134 | + const ok = await urlExists(openvsxUrl); |
| 135 | + if (!ok) { |
| 136 | + // allow-any-unicode-next-line |
| 137 | + console.error(`🔴 Extension not exists: ${id}`); |
| 138 | + } |
| 139 | + } |
| 140 | +} |
| 141 | + |
| 142 | +async function urlExists(url) { |
| 143 | + return new Promise((resolve, reject) => { |
| 144 | + https.get(url, res => { |
| 145 | + resolve(res.statusCode === 200); |
| 146 | + }).on('error', error => { |
| 147 | + reject(error); |
| 148 | + }); |
| 149 | + }); |
| 150 | +} |
| 151 | + |
| 152 | +start().then().catch(console.error); |
0 commit comments