Fix Docker Executable with optional Executable, PHP-CS-Fixer

This commit is contained in:
Glavin Wiechert 2018-05-14 13:21:14 -03:00
parent 7b3bc35048
commit a62ca65a23
2 changed files with 27 additions and 11 deletions

View File

@ -49,6 +49,7 @@ class Executable
.then(() => @)
.catch((error) =>
if not @.required
@verbose("Not required")
@
else
Promise.reject(error)
@ -366,6 +367,7 @@ class HybridExecutable extends Executable
constructor: (options) ->
super(options)
@verbose("HybridExecutable Options", options)
if options.docker?
@dockerOptions = Object.assign({}, @dockerOptions, options.docker)
@docker = @constructor.dockerExecutable()
@ -389,6 +391,17 @@ class HybridExecutable extends Executable
super()
.catch((error) =>
return Promise.reject(error) if not @docker?
return @
)
.then(() =>
shouldTryWithDocker = not @isInstalled and @docker?
@verbose("Executable shouldTryWithDocker", shouldTryWithDocker, @isInstalled, @docker?)
if shouldTryWithDocker
return @initDocker()
return @
)
initDocker: () ->
@docker.init()
.then(=> @runImage(@versionArgs, @versionRunOptions))
.then((text) => @saveVersion(text))
@ -398,9 +411,12 @@ class HybridExecutable extends Executable
@debug(dockerError)
Promise.reject(error)
)
)
run: (args, options = {}) ->
@verbose("Running HybridExecutable")
@verbose("installedWithDocker", @installedWithDocker)
@verbose("docker", @docker)
@verbose("docker.isInstalled", @docker and @docker.isInstalled)
if @installedWithDocker and @docker and @docker.isInstalled
return @runImage(args, options)
super(args, options)
@ -430,7 +446,7 @@ class HybridExecutable extends Executable
image,
newArgs
],
options
Object.assign({}, options, { cmd: undefined })
)
)

View File

@ -105,7 +105,7 @@ module.exports = class PHPCSFixer extends Beautifier
isPhpScript = (finalPhpCsFixerPath.indexOf(".phar") isnt -1) or (finalPhpCsFixerPath.indexOf(".php") isnt -1)
@verbose('isPhpScript', isPhpScript)
if finalPhpCsFixerPath and isPhpScript
if not phpCsFixer.isInstalled and finalPhpCsFixerPath and isPhpScript
php.run([finalPhpCsFixerPath, phpCsFixerOptions, tempFile], runOptions)
.then(=>
@readFile(tempFile)