Enable PHP-CS-Fixer Path option except Windows

This commit is contained in:
onigra 2017-02-11 20:37:21 +09:00
parent cdb52a873d
commit 87ed01e7be
1 changed files with 41 additions and 40 deletions

View File

@ -19,21 +19,22 @@ module.exports = class PHPCSFixer extends Beautifier
configFile = if context? and context.filePath? then @findFile(path.dirname(context.filePath), '.php_cs')
if @isWindows
# Find php-cs-fixer.phar script
@Promise.all([
@which(options.cs_fixer_path) if options.cs_fixer_path
@which('php-cs-fixer')
]).then((paths) =>
@debug('php-cs-fixer paths', paths)
_ = require 'lodash'
# Get first valid, absolute path
phpCSFixerPath = _.find(paths, (p) -> p and path.isAbsolute(p) )
@verbose('phpCSFixerPath', phpCSFixerPath)
@debug('phpCSFixerPath', phpCSFixerPath, paths)
# Check if PHP-CS-Fixer path was found
if phpCSFixerPath?
# Found PHP-CS-Fixer path
# Find php-cs-fixer.phar script
@Promise.all([
@which(options.cs_fixer_path) if options.cs_fixer_path
@which('php-cs-fixer')
]).then((paths) =>
@debug('php-cs-fixer paths', paths)
_ = require 'lodash'
# Get first valid, absolute path
phpCSFixerPath = _.find(paths, (p) -> p and path.isAbsolute(p) )
@verbose('phpCSFixerPath', phpCSFixerPath)
@debug('phpCSFixerPath', phpCSFixerPath, paths)
# Check if PHP-CS-Fixer path was found
if phpCSFixerPath?
# Found PHP-CS-Fixer path
if @isWindows
@run("php", [
phpCSFixerPath
"fix"
@ -51,30 +52,30 @@ module.exports = class PHPCSFixer extends Beautifier
@readFile(tempFile)
)
else
@verbose('php-cs-fixer not found!')
# Could not find PHP-CS-Fixer path
@Promise.reject(@commandNotFoundError(
'php-cs-fixer'
{
link: "https://github.com/FriendsOfPHP/PHP-CS-Fixer"
program: "php-cs-fixer.phar"
pathOption: "PHP - CS Fixer Path"
@run(phpCSFixerPath, [
"fix"
"--level=#{options.level}" if options.level
"--fixers=#{options.fixers}" if options.fixers
"--config-file=#{configFile}" if configFile
tempFile = @tempFile("temp", text)
], {
ignoreReturnCode: true
help: {
link: "https://github.com/FriendsOfPHP/PHP-CS-Fixer"
}
})
)
)
else
@run("php-cs-fixer", [
"fix"
"--level=#{options.level}" if options.level
"--fixers=#{options.fixers}" if options.fixers
"--config-file=#{configFile}" if configFile
tempFile = @tempFile("temp", text)
], {
ignoreReturnCode: true
help: {
link: "https://github.com/FriendsOfPHP/PHP-CS-Fixer"
}
})
.then(=>
@readFile(tempFile)
.then(=>
@readFile(tempFile)
)
else
@verbose('php-cs-fixer not found!')
# Could not find PHP-CS-Fixer path
@Promise.reject(@commandNotFoundError(
'php-cs-fixer'
{
link: "https://github.com/FriendsOfPHP/PHP-CS-Fixer"
program: "php-cs-fixer.phar"
pathOption: "PHP - CS Fixer Path"
})
)
)