"use strict" ; import * as vscode from "vscode" ; import * as utils from "./utils" ; import * as path from "path" ; import { TelemetryContext } from "./telemetry" ; import { ScaffoldType , PlatformType } from "./constants" ; import { RemoteExtension } from "./Models/RemoteExtension" ; import { IoTWorkbenchProjectBase , OpenScenario } from "./Models/IoTWorkbenchProjectBase" ; import { ProjectHostType } from "./Models/Interfaces/ProjectHostType" ; import { configExternalCMakeProjectToIoTContainerProject } from "./utils" ; import { TypeNotSupportedError } from "./common/Error/SystemErrors/TypeNotSupportedError" ; import { OperationCanceledError } from "./common/Error/OperationCanceledError" ; import { WorkspaceNotOpenError } from "./common/Error/OperationFailedErrors/WorkspaceNotOpenError" ; const importLazy = require ( "import-lazy" ) ; const ioTWorkspaceProjectModule = importLazy ( ( ) => require ( "./Models/IoTWorkspaceProject" ) ) ( ) ; const ioTContainerizedProjectModule = importLazy ( ( ) => require ( "./Models/IoTContainerizedProject" ) ) ( ) ; export class ProjectEnvironmentConfiger { async configureCmakeProjectEnvironment ( context , channel , telemetryContext ) { RemoteExtension . ensureLocalBeforeRunCommand ( "configure CMake project environment" , context ) ; const scaffoldType = ScaffoldType . Local ; const projectRootPath = utils . getProjectDeviceRootPath ( ) ; if ( ! projectRootPath ) { throw new WorkspaceNotOpenError ( "configure project environment" ) ; } await vscode . window . withProgress ( { title : "CMake Project development container configuration" , location : vscode . ProgressLocation . Window } , async ( ) => { await ProjectEnvironmentConfiger . configureProjectEnvironmentAsPlatform ( context , channel , telemetryContext , PlatformType . EmbeddedLinux , projectRootPath , scaffoldType ) ; const message = `Successfully configured development container for CMake project.` ; utils . channelShowAndAppendLine ( channel , message ) ; vscode . window . showInformationMessage ( message ) ; } ) ; return ; } static async configureProjectEnvironmentAsPlatform ( context , channel , telemetryContext , platform , projectFileRootPath , scaffoldType ) { let project ; if ( platform === PlatformType . Arduino ) { const projectHostType = await IoTWorkbenchProjectBase . getProjectType ( scaffoldType , projectFileRootPath ) ; if ( projectHostType !== ProjectHostType . Workspace ) { const message = `This is not an iot workbench Arduino project. You cannot configure it as Arduino platform.` ; vscode . window . showWarningMessage ( message ) ; throw new OperationCanceledError ( message ) ; } const projectRootPath = path . join ( projectFileRootPath , ".." ) ; project = new ioTWorkspaceProjectModule . IoTWorkspaceProject ( context , channel , telemetryContext , projectRootPath ) ; if ( ! project ) { await utils . properlyOpenIoTWorkspaceProject ( telemetryContext ) ; } } else if ( platform === PlatformType . EmbeddedLinux ) { await configExternalCMakeProjectToIoTContainerProject ( scaffoldType ) ; await RemoteExtension . checkRemoteExtension ( "configure project environment" ) ; project = new ioTContainerizedProjectModule . IoTContainerizedProject ( context , channel , telemetryContext , projectFileRootPath ) ; } else { throw new TypeNotSupportedError ( "platform" , `${ platform }` ) ; } await project . load ( scaffoldType ) ; await project . configureProjectEnvironmentCore ( projectFileRootPath , scaffoldType ) ; await project . openProject ( scaffoldType , false , OpenScenario . configureProject ) ; } }