|
4 | 4 | *--------------------------------------------------------------------------------------------*/
|
5 | 5 | 'use strict';
|
6 | 6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 |
| -exports.watchTask = exports.compileTask = void 0; |
| 7 | +exports.watchApiProposalNames = exports.compileApiProposalNames = exports.watchTask = exports.compileTask = void 0; |
8 | 8 | const es = require("event-stream");
|
9 | 9 | const fs = require("fs");
|
10 | 10 | const gulp = require("gulp");
|
@@ -175,3 +175,65 @@ class MonacoGenerator {
|
175 | 175 | }
|
176 | 176 | }
|
177 | 177 | }
|
| 178 | +function apiProposalNamesGenerator() { |
| 179 | + const stream = es.through(); |
| 180 | + const pattern = /vscode\.proposed\.([a-zA-Z]+)\.d\.ts/; |
| 181 | + const dtsFolder = path.join(REPO_SRC_FOLDER, 'vscode-dts'); |
| 182 | + const generateFile = () => { |
| 183 | + try { |
| 184 | + const t1 = Date.now(); |
| 185 | + const proposalNames = []; |
| 186 | + for (let file of fs.readdirSync(dtsFolder)) { |
| 187 | + const match = pattern.exec(file); |
| 188 | + if (match) { |
| 189 | + proposalNames.push([match[1], `https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/${file}`]); |
| 190 | + } |
| 191 | + } |
| 192 | + const source = [ |
| 193 | + '/*---------------------------------------------------------------------------------------------', |
| 194 | + ' * Copyright (c) Microsoft Corporation. All rights reserved.', |
| 195 | + ' * Licensed under the MIT License. See License.txt in the project root for license information.', |
| 196 | + ' *--------------------------------------------------------------------------------------------*/', |
| 197 | + '', |
| 198 | + '// THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY.', |
| 199 | + '', |
| 200 | + 'export const allApiProposals = Object.freeze({', |
| 201 | + `${proposalNames.map(t => `\t${t[0]}: '${t[1]}'`).join(',\n')}`, |
| 202 | + '});', |
| 203 | + 'export type ApiProposalName = keyof typeof allApiProposals;', |
| 204 | + '', |
| 205 | + ].join('\n'); |
| 206 | + const outFile = path.join(dtsFolder, '../vs/workbench/services/extensions/common/extensionsApiProposals.ts'); |
| 207 | + if (fs.readFileSync(outFile).toString() !== source) { |
| 208 | + fs.writeFileSync(outFile, source); |
| 209 | + console.log(`Generated 'extensionsApiProposals.ts' in ${Date.now() - t1}ms`); |
| 210 | + } |
| 211 | + } |
| 212 | + catch (err) { |
| 213 | + stream.emit('error', err); |
| 214 | + } |
| 215 | + }; |
| 216 | + let handle; |
| 217 | + stream.on('data', () => { |
| 218 | + clearTimeout(handle); |
| 219 | + handle = setTimeout(generateFile, 250); |
| 220 | + }); |
| 221 | + return stream; |
| 222 | +} |
| 223 | +function compileApiProposalNames() { |
| 224 | + return function () { |
| 225 | + const srcPipe = gulp.src('src/vscode-dts/**', { base: 'src' }); |
| 226 | + const proposals = apiProposalNamesGenerator(); |
| 227 | + return srcPipe.pipe(proposals); |
| 228 | + }; |
| 229 | +} |
| 230 | +exports.compileApiProposalNames = compileApiProposalNames; |
| 231 | +function watchApiProposalNames() { |
| 232 | + return function () { |
| 233 | + const watchSrc = watch('src/vscode-dts/**', { base: 'src', readDelay: 200 }); |
| 234 | + const proposals = apiProposalNamesGenerator(); |
| 235 | + proposals.write(undefined); // send something to trigger initial generate |
| 236 | + return watchSrc.pipe(proposals); |
| 237 | + }; |
| 238 | +} |
| 239 | +exports.watchApiProposalNames = watchApiProposalNames; |
0 commit comments