import * as fse from 'fs-extra' ; import * as os from 'os' ; import * as path from 'path' ; export async function gulp_installAzureAccount ( ) { return gulp_installVSCodeExtension ( 'ms-vscode' , 'azure-account' ) ; } export async function gulp_installResourceGroups ( ) { return gulp_installVSCodeExtension ( 'ms-azuretools' , 'vscode-azureresourcegroups' ) ; } export async function gulp_installVSCodeExtension ( publisherId , extensionName , useInsiders = false ) { const extensionId = `${ publisherId }.${ extensionName }` ; const vsCodeDir = useInsiders ? '.vscode-insiders' : '.vscode' ; const extensionsPath = path . join ( os . homedir ( ) , vsCodeDir , 'extensions' ) ; let existingExtensions = [ ] ; if ( await fse . pathExists ( extensionsPath ) ) { existingExtensions = await fse . readdir ( extensionsPath ) ; } if ( ! existingExtensions . some ( ( e ) => e . includes ( extensionId ) ) ) { console . log ( `"Installing" test extension with id "${ extensionId }".` ) ; const version = '0.0.1' ; const extensionPath = path . join ( extensionsPath , `${ extensionId }-${ version }` ) ; const packageJsonPath = path . join ( extensionPath , 'package.json' ) ; const packageJson = { name : extensionName , displayName : "" , publisher : publisherId , description : "" , version : version , engines : { vscode : "^1.31.0" } , activationEvents : [ ] , main : "./extension" , contributes : { } } ; await fse . ensureFile ( packageJsonPath ) ; await fse . writeJSON ( packageJsonPath , packageJson ) ; const extensionJsPath = path . join ( extensionPath , 'extension.js' ) ; const extensionJs = `exports.activate = function activate() { };exports.deactivate = function deactivate() { };` ; await fse . ensureFile ( extensionJsPath ) ; await fse . writeFile ( extensionJsPath , extensionJs ) ; } else { console . log ( `Extension with id "${ extensionId }" already installed.` ) ; return Promise . resolve ( ) ; } }