add generated file api proposal names, add compile script that generates this file

This commit is contained in:
Johannes Rieken
2021-11-10 11:54:24 +01:00
parent d90dd1355b
commit da967b591e
5 changed files with 149 additions and 4 deletions

View File

@@ -211,3 +211,75 @@ class MonacoGenerator {
}
}
}
function apiProposalNamesGenerator() {
const stream = es.through();
const pattern = /vscode\.proposed\.([a-zA-Z]+)\.d\.ts/;
const dtsFolder = path.join(REPO_SRC_FOLDER, 'vscode-dts');
const generateFile = () => {
try {
const t1 = Date.now();
const proposalNames: string[] = [];
for (let file of fs.readdirSync(dtsFolder)) {
const match = pattern.exec(file);
if (match) {
proposalNames.push(match[1]);
}
}
const source = [
'/*---------------------------------------------------------------------------------------------',
' * Copyright (c) Microsoft Corporation. All rights reserved.',
' * Licensed under the MIT License. See License.txt in the project root for license information.',
' *--------------------------------------------------------------------------------------------*/',
'',
'// THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY.',
'',
'export const apiProposals = {',
`${proposalNames.map(name => `\t${name}: true`).join(',\n')}`,
'};',
'export type ApiProposalName = keyof typeof apiProposals;',
'',
].join('\n');
const outFile = path.join(dtsFolder, '../vs/workbench/services/extensions/common/extensionsApiProposals.ts');
if (fs.readFileSync(outFile).toString() !== source) {
fs.writeFileSync(outFile, source);
console.log(`Generated 'extensionsApiProposals.ts' in ${Date.now() - t1}ms`);
}
} catch (err) {
stream.emit('error', err);
}
};
let handle: NodeJS.Timeout;
stream.on('data', () => {
clearTimeout(handle);
handle = setTimeout(generateFile, 250);
});
return stream;
}
export function compileApiProposalNames(): () => NodeJS.ReadWriteStream {
return function () {
const srcPipe = gulp.src('src/vscode-dts/**', { base: 'src' });
const proposals = apiProposalNamesGenerator();
return srcPipe.pipe(proposals);
};
}
export function watchApiProposalNames(): () => NodeJS.ReadWriteStream {
return function () {
const watchSrc = watch('src/vscode-dts/**', { base: 'src', readDelay: 200 });
const proposals = apiProposalNamesGenerator();
proposals.write(undefined); // send something to trigger initial generate
return watchSrc.pipe(proposals);
};
}