'use strict' ; import * as path from 'path' ; import * as vscode from 'vscode' ; import { Uri } from 'vscode' ; import { Logger } from './util/logger' ; import { Constants } from './constants' ; import { AppManager } from './appManager' ; import { ICommand , IConfig } from './spgo' ; import { ErrorHelper } from './util/errorHelper' ; import { WorkspaceHelper } from './util/workspaceHelper' ; import { SaveFileCommand } from './command/saveFileCommand' ; import { CopySPUrlCommand } from './command/copySPUrlCommand' ; import { DeleteFileCommand } from './command/deleteFileCommand' ; import { PublishFileCommand } from './command/publishFileCommand' ; import { CheckOutFileCommand } from './command/checkOutFileCommand' ; import { RetrieveFolderCommand } from './command/retrieveFolderCommand' ; import { DiscardCheckOutCommand } from './command/discardCheckOutCommand' ; import { GetServerVersionCommand } from './command/getServerVersionCommand' ; import { PublishWorkspaceCommand } from './command/publishWorkspaceCommand' ; import { ResetCredentialsCommand } from './command/resetCredentialsCommand' ; import { PopulateWorkspaceCommand } from './command/populateWorkspaceCommand' ; import { ConfigureWorkspaceCommand } from './command/configureWorkspaceCommand' ; import { CompareFileWithServerCommand } from './command/compareFileWithServerCommand' ; import { GetCurrentFileInformationCommand } from './command/getCurrentFileInformationCommand' ; export function activate ( context ) { vscode . window . spgo = new AppManager ( context . workspaceState ) ; Logger . outputMessage ( 'SPGo enabled.' , vscode . window . spgo . outputChannel ) ; context . subscriptions . push ( vscode . commands . registerCommand ( 'spgo.checkOutFile' , ( selectedResource ? ) => { selectedResource = selectedResource || WorkspaceHelper . getActiveFile ( ) ; const command = new CheckOutFileCommand ( ) ; command . execute ( selectedResource ) ; } ) ) ; context . subscriptions . push ( vscode . commands . registerCommand ( 'spgo.compareFileWithServer' , ( selectedResource ? ) => { selectedResource = selectedResource || WorkspaceHelper . getActiveFile ( ) ; const command = new CompareFileWithServerCommand ( ) ; command . execute ( selectedResource ) ; } ) ) ; context . subscriptions . push ( vscode . commands . registerCommand ( 'spgo.configureWorkspace' , ( ) => { const selectedResource = WorkspaceHelper . getActiveFile ( ) ; const command = new ConfigureWorkspaceCommand ( ) ; command . execute ( selectedResource ) ; } ) ) ; context . subscriptions . push ( vscode . commands . registerCommand ( 'spgo.copyRelativeUrl' , ( selectedResource ? ) => { selectedResource = selectedResource || WorkspaceHelper . getActiveFile ( ) ; const command = new CopySPUrlCommand ( ) ; command . execute ( selectedResource , false ) ; } ) ) ; context . subscriptions . push ( vscode . commands . registerCommand ( 'spgo.copyAbsoluteUrl' , ( selectedResource ? ) => { selectedResource = selectedResource || WorkspaceHelper . getActiveFile ( ) ; const command = new CopySPUrlCommand ( ) ; command . execute ( selectedResource , true ) ; } ) ) ; context . subscriptions . push ( vscode . commands . registerCommand ( 'spgo.deleteFile' , ( selectedResource ? ) => { selectedResource = selectedResource || WorkspaceHelper . getActiveFile ( ) ; const command = new DeleteFileCommand ( ) ; command . execute ( selectedResource ) ; } ) ) ; context . subscriptions . push ( vscode . commands . registerCommand ( 'spgo.discardCheckOut' , ( selectedResource ? ) => { selectedResource = selectedResource || WorkspaceHelper . getActiveFile ( ) ; const command = new DiscardCheckOutCommand ( ) ; command . execute ( selectedResource ) ; } ) ) ; context . subscriptions . push ( vscode . commands . registerCommand ( 'spgo.getServerVersion' , ( selectedResource ? ) => { selectedResource = selectedResource || WorkspaceHelper . getActiveFile ( ) ; const command = new GetServerVersionCommand ( ) ; command . execute ( selectedResource ) ; } ) ) ; context . subscriptions . push ( vscode . commands . registerCommand ( 'spgo.populateWorkspace' , ( ) => { const command = new PopulateWorkspaceCommand ( ) ; command . execute ( null ) ; } ) ) ; context . subscriptions . push ( vscode . commands . registerCommand ( 'spgo.publishWorkspace' , ( ) => { const command = new PublishWorkspaceCommand ( ) ; command . execute ( null ) ; } ) ) ; context . subscriptions . push ( vscode . commands . registerCommand ( 'spgo.publishMajor' , ( selectedResource ? ) => { selectedResource = selectedResource || WorkspaceHelper . getActiveFile ( ) ; const command = new PublishFileCommand ( ) ; command . execute ( selectedResource , Constants . PUBLISHING_MAJOR ) ; } ) ) ; context . subscriptions . push ( vscode . commands . registerCommand ( 'spgo.publishMinor' , ( selectedResource ? ) => { selectedResource = selectedResource || WorkspaceHelper . getActiveFile ( ) ; const command = new PublishFileCommand ( ) ; command . execute ( selectedResource , Constants . PUBLISHING_MINOR ) ; } ) ) ; context . subscriptions . push ( vscode . commands . registerCommand ( 'spgo.reloadConfiguration' , ( ) => { WorkspaceHelper . getActiveWorkspaceUri ( ) . then ( ( activeWorkspace ) => vscode . window . spgo . initialize ( activeWorkspace ) ) . then ( ( ) => Logger . updateStatusBar ( 'Configuration file reloaded' , 5 ) ) . catch ( err => ErrorHelper . handleError ( err ) ) ; } ) ) ; context . subscriptions . push ( vscode . commands . registerCommand ( 'spgo.resetCredentials' , ( ) => { const command = new ResetCredentialsCommand ( ) ; command . execute ( null ) ; } ) ) ; context . subscriptions . push ( vscode . commands . registerCommand ( 'spgo.retrieveFolder' , ( ) => { const command = new RetrieveFolderCommand ( ) ; command . execute ( null ) ; } ) ) ; context . subscriptions . push ( vscode . workspace . onDidSaveTextDocument ( ( textDocument ) => { vscode . window . spgo . initialize ( textDocument . uri ) . then ( ( config ) => { if ( config ) { if ( textDocument . fileName . includes ( config . sourceRoot ) && Constants . PUBLISHING_NONE != config . publishingScope ) { if ( Constants . PUBLISHING_MAJOR == config . publishingScope || Constants . PUBLISHING_MINOR == config . publishingScope ) { const command = new PublishFileCommand ( ) ; command . execute ( textDocument . uri , config . publishingScope ) ; } else { const command = new SaveFileCommand ( ) ; command . execute ( textDocument . uri ) ; } } else if ( textDocument . fileName . endsWith ( path . sep + Constants . CONFIG_FILE_NAME ) ) { vscode . window . spgo . reloadConfiguration ( textDocument . uri ) ; } } } ) ; } ) ) ; context . subscriptions . push ( vscode . workspace . onDidOpenTextDocument ( ( textDocument ) => { const selectedResource = textDocument . uri . scheme !== 'output' ? textDocument . uri : WorkspaceHelper . getActiveFile ( ) ; if ( selectedResource . fsPath !== path . sep ) { const command = new GetCurrentFileInformationCommand ( ) ; command . execute ( selectedResource ) ; } } ) ) ; } export function deactivate ( ) { Logger . outputMessage ( 'SPGo deactivated.' , vscode . window . spgo . outputChannel ) ; }