import * as fse from 'fs-extra' ; import * as os from 'os' ; import * as path from 'path' ; import { Progress } from 'vscode' ; import { IActionContext } from 'vscode-azureextensionui' ; import { gitignoreFileName , hostFileName , localSettingsFileName , workerRuntimeKey } from '../../../constants' ; import { IHostJsonV1 , IHostJsonV2 } from '../../../funcConfig/host' ; import { ILocalSettingsJson } from '../../../funcConfig/local.settings' ; import { FuncVersion } from '../../../FuncVersion' ; import { bundleFeedUtils } from '../../../utils/bundleFeedUtils' ; import { confirmOverwriteFile , writeFormattedJson } from "../../../utils/fs" ; import { nonNullProp } from '../../../utils/nonNull' ; import { getRootFunctionsWorkerRuntime } from '../../../vsCodeConfig/settings' ; import { IProjectWizardContext } from '../IProjectWizardContext' ; import { ProjectCreateStepBase } from './ProjectCreateStepBase' ; export class ScriptProjectCreateStep extends ProjectCreateStepBase { protected funcignore : string [ ] = [ '.git*' , '.vscode' , 'local.settings.json' , 'test' ] ; protected gitignore : string = '' ; protected localSettingsJson : ILocalSettingsJson = { IsEncrypted : false , Values : { AzureWebJobsStorage : '' } } ; public async executeCore ( context , _progress ) { const version = nonNullProp ( context , 'version' ) ; const hostJsonPath = path . join ( context . projectPath , hostFileName ) ; if ( await confirmOverwriteFile ( context , hostJsonPath ) ) { const hostJson = version === FuncVersion . v1 ? { } : await this . getHostContent ( context ) ; await writeFormattedJson ( hostJsonPath , hostJson ) ; } const localSettingsJsonPath = path . join ( context . projectPath , localSettingsFileName ) ; if ( await confirmOverwriteFile ( context , localSettingsJsonPath ) ) { const functionsWorkerRuntime = getRootFunctionsWorkerRuntime ( context . language ) ; if ( functionsWorkerRuntime ) { this . localSettingsJson . Values ! [ workerRuntimeKey ] = functionsWorkerRuntime ; } await writeFormattedJson ( localSettingsJsonPath , this . localSettingsJson ) ; } const gitignorePath = path . join ( context . projectPath , gitignoreFileName ) ; if ( await confirmOverwriteFile ( context , gitignorePath ) ) { await fse . writeFile ( gitignorePath , this . gitignore . concat ( `
# Azure Functions artifacts
bin
obj
appsettings.json
local.settings.json

# Azurite artifacts
__blobstorage__
__queuestorage__
__azurite_db*__.json` ) ) ; } const funcIgnorePath = path . join ( context . projectPath , '.funcignore' ) ; if ( await confirmOverwriteFile ( context , funcIgnorePath ) ) { await fse . writeFile ( funcIgnorePath , this . funcignore . sort ( ) . join ( os . EOL ) ) ; } } protected async getHostContent ( context ) { const hostJson = { version : '2.0' , logging : { applicationInsights : { samplingSettings : { isEnabled : true , excludedTypes : 'Request' } } } } ; await bundleFeedUtils . addDefaultBundle ( context , hostJson ) ; return hostJson ; } }