|
| 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 | + |
| 6 | +'use strict'; |
| 7 | + |
| 8 | +import * as fs from 'fs'; |
| 9 | +import * as cp from 'child_process'; |
| 10 | +import * as path from 'path'; |
| 11 | + |
| 12 | +let tag = ''; |
| 13 | +try { |
| 14 | + tag = cp |
| 15 | + .execSync('git describe --tags `git rev-list --tags --max-count=1`') |
| 16 | + .toString() |
| 17 | + .trim(); |
| 18 | + |
| 19 | + const dtsUri = `https://raw.githubusercontent.com/microsoft/vscode/${tag}/src/vs/vscode.d.ts`; |
| 20 | + const outPath = path.resolve(process.cwd(), 'DefinitelyTyped/types/vscode/index.d.ts'); |
| 21 | + cp.execSync(`curl ${dtsUri} --output ${outPath}`); |
| 22 | + |
| 23 | + updateDTSFile(outPath, tag); |
| 24 | + |
| 25 | + console.log(`Done updating vscode.d.ts at ${outPath}`); |
| 26 | +} catch (err) { |
| 27 | + console.error(err); |
| 28 | + console.error('Failed to update types'); |
| 29 | + process.exit(1); |
| 30 | +} |
| 31 | + |
| 32 | +function updateDTSFile(outPath: string, tag: string) { |
| 33 | + const oldContent = fs.readFileSync(outPath, 'utf-8'); |
| 34 | + const newContent = getNewFileContent(oldContent, tag); |
| 35 | + |
| 36 | + fs.writeFileSync(outPath, newContent); |
| 37 | +} |
| 38 | + |
| 39 | +function getNewFileContent(content: string, tag: string) { |
| 40 | + const oldheader = [ |
| 41 | + `/*---------------------------------------------------------------------------------------------`, |
| 42 | + ` * Copyright (c) Microsoft Corporation. All rights reserved.`, |
| 43 | + ` * Licensed under the MIT License. See License.txt in the project root for license information.`, |
| 44 | + ` *--------------------------------------------------------------------------------------------*/` |
| 45 | + ].join('\n'); |
| 46 | + |
| 47 | + return getNewFileHeader(tag) + content.slice(oldheader.length); |
| 48 | +} |
| 49 | + |
| 50 | +function getNewFileHeader(tag: string) { |
| 51 | + const [major, minor] = tag.split('.'); |
| 52 | + const shorttag = `${major}.${minor}`; |
| 53 | + |
| 54 | + const header = [ |
| 55 | + `// Type definitions for Visual Studio Code ${shorttag}`, |
| 56 | + `// Project: https://github.com/microsoft/vscode`, |
| 57 | + `// Definitions by: Visual Studio Code Team, Microsoft <https://github.com/Microsoft>`, |
| 58 | + `// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped`, |
| 59 | + ``, |
| 60 | + `/*---------------------------------------------------------------------------------------------`, |
| 61 | + ` * Copyright (c) Microsoft Corporation. All rights reserved.`, |
| 62 | + ` * Licensed under the MIT License.`, |
| 63 | + ` * See https://github.com/Microsoft/vscode/blob/master/LICENSE.txt for license information.`, |
| 64 | + ` *--------------------------------------------------------------------------------------------*/`, |
| 65 | + ``, |
| 66 | + `/**`, |
| 67 | + ` * Type Definition for Visual Studio Code ${shorttag} Extension API`, |
| 68 | + ` * See https://code.visualstudio.com/api for more information`, |
| 69 | + ` */` |
| 70 | + ].join('\n'); |
| 71 | + |
| 72 | + return header; |
| 73 | +} |
0 commit comments