import { PathsCommand } from './pathsCommand' ; import { MavensMateChannel } from '../../vscode/mavensMateChannel' ; import { handleCompileResponse } from '../handlers/compileResponseHandler' ; import * as vscode from 'vscode' ; import Promise = require ( 'bluebird' ) ; let languagesToCompileOnSave = new Set < string > ( [ 'apex' , 'visualforce' , 'xml' , 'javascript' ] ) ; class CompileFile extends PathsCommand { static create ( label ? ) { if ( ! label ) { label = 'Compile File' ; } return new CompileFile ( label ) ; } constructor ( label ) { super ( label , 'compile-metadata' ) ; } protected confirmPath ( ) { let uriToOpen = vscode . Uri . file ( this . filePath ) ; let confirmPromise = vscode . workspace . openTextDocument ( uriToOpen ) . then ( ( textDocument ) => { if ( ! languagesToCompileOnSave . has ( textDocument . languageId ) ) { return Promise . reject ( `Can not compile this file: ${ this . filePath }` ) ; } else if ( this . filePath . includes ( 'apex-scripts' ) ) { return Promise . reject ( `Local Apex Scripts can't be compiled. You can run them with Run Apex Script` ) ; } else if ( this . filePath . includes ( 'resource-bundles' ) ) { return Promise . reject ( `Files inside Resource Bundles cannot be compiled. Use Deploy Resource Bundle instead` ) ; } else { return super . confirmPath ( ) ; } } ) ; return confirmPromise ; } onSuccess ( response ) { return super . onSuccess ( response ) . then ( ( ) => handleCompileResponse ( response ) ) ; } } export = CompileFile ;