33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- 'use strict' ;
6+ import * as fs from 'fs' ;
7+ import * as path from 'path' ;
8+ import * as os from 'os' ;
9+ import * as rimraf from 'rimraf' ;
10+ import * as es from 'event-stream' ;
11+ import * as rename from 'gulp-rename' ;
12+ import * as vfs from 'vinyl-fs' ;
13+ import * as ext from './extensions' ;
14+ import * as fancyLog from 'fancy-log' ;
15+ import * as ansiColors from 'ansi-colors' ;
16+ import { Stream } from 'stream' ;
717
8- const fs = require ( 'fs' ) ;
9- const path = require ( 'path' ) ;
10- const os = require ( 'os' ) ;
1118const mkdirp = require ( 'mkdirp' ) ;
12- const rimraf = require ( 'rimraf' ) ;
13- const es = require ( 'event-stream' ) ;
14- const rename = require ( 'gulp-rename' ) ;
15- const vfs = require ( 'vinyl-fs' ) ;
16- const ext = require ( './extensions' ) ;
17- const fancyLog = require ( 'fancy-log' ) ;
18- const ansiColors = require ( 'ansi-colors' ) ;
19+
20+ interface IExtensionDefinition {
21+ name : string ;
22+ version : string ;
23+ repo : string ;
24+ metadata : {
25+ id : string ;
26+ publisherId : {
27+ publisherId : string ;
28+ publisherName : string ;
29+ displayName : string ;
30+ flags : string ;
31+ } ;
32+ publisherDisplayName : string ;
33+ }
34+ }
1935
2036const root = path . dirname ( path . dirname ( __dirname ) ) ;
2137const productjson = JSON . parse ( fs . readFileSync ( path . join ( __dirname , '../../product.json' ) , 'utf8' ) ) ;
22- const builtInExtensions = productjson . builtInExtensions ;
23- const webBuiltInExtensions = productjson . webBuiltInExtensions ;
38+ const builtInExtensions = < IExtensionDefinition [ ] > productjson . builtInExtensions ;
39+ const webBuiltInExtensions = < IExtensionDefinition [ ] > productjson . webBuiltInExtensions ;
2440const controlFilePath = path . join ( os . homedir ( ) , '.vscode-oss-dev' , 'extensions' , 'control.json' ) ;
2541const ENABLE_LOGGING = ! process . env [ 'VSCODE_BUILD_BUILTIN_EXTENSIONS_SILENCE_PLEASE' ] ;
2642
27- function log ( ) {
43+ function log ( ... messages : string [ ] ) : void {
2844 if ( ENABLE_LOGGING ) {
29- fancyLog . apply ( this , arguments ) ;
45+ fancyLog ( ... messages ) ;
3046 }
3147}
3248
33- function getExtensionPath ( extension ) {
49+ function getExtensionPath ( extension : IExtensionDefinition ) : string {
3450 return path . join ( root , '.build' , 'builtInExtensions' , extension . name ) ;
3551}
3652
37- function isUpToDate ( extension ) {
53+ function isUpToDate ( extension : IExtensionDefinition ) : boolean {
3854 const packagePath = path . join ( getExtensionPath ( extension ) , 'package.json' ) ;
3955
4056 if ( ! fs . existsSync ( packagePath ) ) {
@@ -51,7 +67,7 @@ function isUpToDate(extension) {
5167 }
5268}
5369
54- function syncMarketplaceExtension ( extension ) {
70+ function syncMarketplaceExtension ( extension : IExtensionDefinition ) : Stream {
5571 if ( isUpToDate ( extension ) ) {
5672 log ( ansiColors . blue ( '[marketplace]' ) , `${ extension . name } @${ extension . version } ` , ansiColors . green ( '✔︎' ) ) ;
5773 return es . readArray ( [ ] ) ;
@@ -65,7 +81,7 @@ function syncMarketplaceExtension(extension) {
6581 . on ( 'end' , ( ) => log ( ansiColors . blue ( '[marketplace]' ) , extension . name , ansiColors . green ( '✔︎' ) ) ) ;
6682}
6783
68- function syncExtension ( extension , controlState ) {
84+ function syncExtension ( extension : IExtensionDefinition , controlState : 'disabled' | 'marketplace' ) : Stream {
6985 switch ( controlState ) {
7086 case 'disabled' :
7187 log ( ansiColors . blue ( '[disabled]' ) , ansiColors . gray ( extension . name ) ) ;
@@ -89,25 +105,29 @@ function syncExtension(extension, controlState) {
89105 }
90106}
91107
92- function readControlFile ( ) {
108+ interface IControlFile {
109+ [ name : string ] : 'disabled' | 'marketplace' ;
110+ }
111+
112+ function readControlFile ( ) : IControlFile {
93113 try {
94114 return JSON . parse ( fs . readFileSync ( controlFilePath , 'utf8' ) ) ;
95115 } catch ( err ) {
96116 return { } ;
97117 }
98118}
99119
100- function writeControlFile ( control ) {
120+ function writeControlFile ( control : IControlFile ) : void {
101121 mkdirp . sync ( path . dirname ( controlFilePath ) ) ;
102122 fs . writeFileSync ( controlFilePath , JSON . stringify ( control , null , 2 ) ) ;
103123}
104124
105- exports . getBuiltInExtensions = function getBuiltInExtensions ( ) {
125+ export function getBuiltInExtensions ( ) : Promise < void > {
106126 log ( 'Syncronizing built-in extensions...' ) ;
107127 log ( `You can manage built-in extensions with the ${ ansiColors . cyan ( '--builtin' ) } flag` ) ;
108128
109129 const control = readControlFile ( ) ;
110- const streams = [ ] ;
130+ const streams : Stream [ ] = [ ] ;
111131
112132 for ( const extension of [ ...builtInExtensions , ...webBuiltInExtensions ] ) {
113133 let controlState = control [ extension . name ] || 'marketplace' ;
@@ -123,10 +143,10 @@ exports.getBuiltInExtensions = function getBuiltInExtensions() {
123143 . on ( 'error' , reject )
124144 . on ( 'end' , resolve ) ;
125145 } ) ;
126- } ;
146+ }
127147
128148if ( require . main === module ) {
129- exports . getBuiltInExtensions ( ) . then ( ( ) => process . exit ( 0 ) ) . catch ( err => {
149+ getBuiltInExtensions ( ) . then ( ( ) => process . exit ( 0 ) ) . catch ( err => {
130150 console . error ( err ) ;
131151 process . exit ( 1 ) ;
132152 } ) ;
0 commit comments