From fcc32d3fab19432b28d3d69663729b326529d73f Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Mon, 29 May 2017 01:34:12 -0300 Subject: [PATCH] Generate config options (i.e. path) for Beautifier's Executables --- docs/index.coffee | 39 ++++---- docs/options.md | 132 ++++++++++++++++++++++++++++ package.json | 2 +- script/build-options.js | 53 ++++++++++- src/beautifiers/executable.coffee | 9 +- src/beautifiers/php-cs-fixer.coffee | 4 - src/config.coffee | 2 +- src/options.json | 66 ++++++++++++++ 8 files changed, 276 insertions(+), 31 deletions(-) diff --git a/docs/index.coffee b/docs/index.coffee index 61b4dbe..afbba77 100755 --- a/docs/index.coffee +++ b/docs/index.coffee @@ -82,25 +82,28 @@ Handlebars.registerHelper('example-config', (key, option, options) -> Handlebars.registerHelper('language-beautifiers-support', (languageOptions, options) -> - rows = _.map(languageOptions, (val, k) -> - name = val.title - defaultBeautifier = _.get(val, "properties.default_beautifier.default") - beautifiers = _.map(val.beautifiers, (b) -> - beautifier = beautifiersMap[b] - isDefault = b is defaultBeautifier - if beautifier.link - r = "[`#{b}`](#{beautifier.link})" - else - r = "`#{b}`" - if isDefault - r += " (Default)" - return r - ) - grammars = _.map(val.grammars, (b) -> "`#{b}`") - extensions = _.map(val.extensions, (b) -> "`.#{b}`") + rows = _.chain(languageOptions) + .filter((val, k) -> k isnt "executables") + .map((val, k) -> + name = val.title + defaultBeautifier = _.get(val, "properties.default_beautifier.default") + beautifiers = _.map(val.beautifiers, (b) -> + beautifier = beautifiersMap[b] + isDefault = b is defaultBeautifier + if beautifier.link + r = "[`#{b}`](#{beautifier.link})" + else + r = "`#{b}`" + if isDefault + r += " (Default)" + return r + ) + grammars = _.map(val.grammars, (b) -> "`#{b}`") + extensions = _.map(val.extensions, (b) -> "`.#{b}`") - return "| #{name} | #{grammars.join(', ')} |#{extensions.join(', ')} | #{beautifiers.join(', ')} |" - ) + return "| #{name} | #{grammars.join(', ')} |#{extensions.join(', ')} | #{beautifiers.join(', ')} |" + ) + .value() results = """ | Language | Grammars | File Extensions | Supported Beautifiers | | --- | --- | --- | ---- | diff --git a/docs/options.md b/docs/options.md index 84d5fba..2187766 100644 --- a/docs/options.md +++ b/docs/options.md @@ -131,6 +131,75 @@ Supported options for each language. --- +#### [Executables](#executables) + +**Description**: + +Configure executables used by beautifiers. + +##### [PHP](#php) + +**Namespace**: `` + +**Key**: `php` + +**Type**: `object` + +**Supported Beautifiers**: [`PHP-CS-Fixer`](#php-cs-fixer) + +**Description**: + +Options for PHP executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*PHP*" and change it to your desired configuration. + +##### [PHP-CS-Fixer](#php-cs-fixer) + +**Namespace**: `` + +**Key**: `php_cs_fixer` + +**Type**: `object` + +**Supported Beautifiers**: [`PHP-CS-Fixer`](#php-cs-fixer) + +**Description**: + +Options for PHP-CS-Fixer executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*PHP-CS-Fixer*" and change it to your desired configuration. + +##### [PHPCBF](#phpcbf) + +**Namespace**: `` + +**Key**: `phpcbf` + +**Type**: `object` + +**Supported Beautifiers**: [`PHPCBF`](#phpcbf) + +**Description**: + +Options for PHPCBF executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*PHPCBF*" and change it to your desired configuration. + #### [Apex](#apex) **Supported Beautifiers**: [`Uncrustify`](#uncrustify) @@ -17618,6 +17687,48 @@ Allow risky rules to be applied (PHP-CS-Fixer 2 only) (Supported by PHP-CS-Fixer } ``` +##### [PHP](#php) + +**Namespace**: `` + +**Key**: `php` + +**Type**: `object` + +**Supported Beautifiers**: [`PHP-CS-Fixer`](#php-cs-fixer) + +**Description**: + +Options for PHP executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*PHP*" and change it to your desired configuration. + +##### [PHP-CS-Fixer](#php-cs-fixer) + +**Namespace**: `` + +**Key**: `php_cs_fixer` + +**Type**: `object` + +**Supported Beautifiers**: [`PHP-CS-Fixer`](#php-cs-fixer) + +**Description**: + +Options for PHP-CS-Fixer executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*PHP-CS-Fixer*" and change it to your desired configuration. + ### PHPCBF @@ -17699,6 +17810,27 @@ Standard name Squiz, PSR2, PSR1, PHPCS, PEAR, Zend, MySource... or path to CS ru } ``` +##### [PHPCBF](#phpcbf) + +**Namespace**: `` + +**Key**: `phpcbf` + +**Type**: `object` + +**Supported Beautifiers**: [`PHPCBF`](#phpcbf) + +**Description**: + +Options for PHPCBF executable. + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*PHPCBF*" and change it to your desired configuration. + ### Perltidy diff --git a/package.json b/package.json index 5234181..96a69e1 100644 --- a/package.json +++ b/package.json @@ -409,4 +409,4 @@ "lint": "coffeelint src/ spec/", "code-docs": "codo && open docs/code/index.html" } -} +} \ No newline at end of file diff --git a/script/build-options.js b/script/build-options.js index 4d1fabf..40b253b 100644 --- a/script/build-options.js +++ b/script/build-options.js @@ -172,6 +172,54 @@ buildOptionsForBeautifiers = function(beautifiers, allLanguages) { return flatOptions; }; +buildOptionsForExecutables = function(beautifiers) { + executables = _.chain(beautifiers) + .map((beautifier) => { + const executables = beautifier.executables || []; + executables.forEach((executable) => executable.beautifiers = [beautifier.name]); + return executables; + }) + .flatten() + .value(); + + const properties = {} + _.forEach(executables, (executable) => { + const { name, cmd, beautifiers } = executable; + const sanitizedCmd = cmd.split('-').join('_'); + const key = sanitizedCmd; + const option = { + key: key, + title: name, + type: "object", + collapsed: true, + description: `Options for ${name} executable.`, + beautifiers, + properties: { + path: { + key: "path", + title: "Executable Path", + type: "string", + default: "", + description: `Absolute path to the "${cmd}" executable.`, + } + } + } + properties[key] = option; + }); + + const options = { + executables: { + title: 'Executables', + type: 'object', + collapsed: true, + order: -1, + description: 'Configure executables used by beautifiers.', + properties + } + } + return options +}; + buildOptionsForBeautifiers = function(beautifiers, allLanguages) { var beautifier, beautifierName, defaultBeautifier, f, fallback, field, fields, fn, g, group, i, j, k, l, laOp, lang, langName, langOptions, languageName, languages, len, len1, len2, len3, len4, len5, m, n, name, name1, namespace, namespaceDest, namespaceSrc, o, op, optionDef, optionName, options, optionsDest, optionsSrc, p, q, ref, ref1, ref10, ref11, ref12, ref13, ref14, ref15, ref16, ref17, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9, unsupportedOptions; langOptions = {}; @@ -374,10 +422,11 @@ beautifier = new Beautifiers(); console.log('Building options for beautifiers'); beautifierOptions = buildOptionsForBeautifiers(beautifier.beautifiers, beautifier.languages.languages); +executableOptions = buildOptionsForExecutables(beautifier.beautifiers) console.log('Done building options for beautifiers'); - -optionsStr = JSON.stringify(beautifierOptions, null, 2); +combinedOptions = Object.assign({}, beautifierOptions, executableOptions) +optionsStr = JSON.stringify(combinedOptions, null, 2); outputFilename = path.resolve(__dirname, '../src/options.json'); diff --git a/src/beautifiers/executable.coffee b/src/beautifiers/executable.coffee index ae8ef9b..cfce18d 100644 --- a/src/beautifiers/executable.coffee +++ b/src/beautifiers/executable.coffee @@ -23,16 +23,15 @@ module.exports = class Executable @installation = options.installation if options.version? versionOptions = options.version - @versionArgs = versionOptions.args - @versionParse = versionOptions.parse - @versionsSupported = versionOptions.supported + @versionArgs = versionOptions.args or @versionArgs + @versionParse = versionOptions.parse or @versionParse + @versionsSupported = versionOptions.supported or @versionsSupported @setupLogger() init: () -> Promise.all([ @loadVersion() - ]) - .then(() => @) + ]).then(() => @) ### Logger instance diff --git a/src/beautifiers/php-cs-fixer.coffee b/src/beautifiers/php-cs-fixer.coffee index d2129df..d013edd 100644 --- a/src/beautifiers/php-cs-fixer.coffee +++ b/src/beautifiers/php-cs-fixer.coffee @@ -17,9 +17,7 @@ module.exports = class PHPCSFixer extends Beautifier homepage: "http://php.net/" installation: "http://php.net/manual/en/install.php" version: { - args: ['--version'] parse: (text) -> text.match(/PHP (.*) \(cli\)/)[1] - supported: '>= 0.0.0' } } { @@ -28,9 +26,7 @@ module.exports = class PHPCSFixer extends Beautifier homepage: "https://github.com/FriendsOfPHP/PHP-CS-Fixer" installation: "https://github.com/FriendsOfPHP/PHP-CS-Fixer#installation" version: { - args: ['--version'] parse: (text) -> text.match(/version (.*) by/)[1] + ".0" - supported: '>= 0.0.0' } } ] diff --git a/src/config.coffee b/src/config.coffee index 2b00226..3ab01d3 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -3,7 +3,7 @@ module.exports = { title: 'General' type: 'object' collapsed: true - order: -1 + order: -2 description: 'General options for Atom Beautify' properties: _analyticsUserId : diff --git a/src/options.json b/src/options.json index d207c82..9e667a7 100644 --- a/src/options.json +++ b/src/options.json @@ -9122,5 +9122,71 @@ "description": "Automatically beautify YAML files on save" } } + }, + "executables": { + "title": "Executables", + "type": "object", + "collapsed": true, + "order": -1, + "description": "Configure executables used by beautifiers.", + "properties": { + "php": { + "key": "php", + "title": "PHP", + "type": "object", + "collapsed": true, + "description": "Options for PHP executable.", + "beautifiers": [ + "PHP-CS-Fixer" + ], + "properties": { + "path": { + "key": "path", + "title": "Executable Path", + "type": "string", + "default": "", + "description": "Absolute path to the \"php\" executable." + } + } + }, + "php_cs_fixer": { + "key": "php_cs_fixer", + "title": "PHP-CS-Fixer", + "type": "object", + "collapsed": true, + "description": "Options for PHP-CS-Fixer executable.", + "beautifiers": [ + "PHP-CS-Fixer" + ], + "properties": { + "path": { + "key": "path", + "title": "Executable Path", + "type": "string", + "default": "", + "description": "Absolute path to the \"php-cs-fixer\" executable." + } + } + }, + "phpcbf": { + "key": "phpcbf", + "title": "PHPCBF", + "type": "object", + "collapsed": true, + "description": "Options for PHPCBF executable.", + "beautifiers": [ + "PHPCBF" + ], + "properties": { + "path": { + "key": "path", + "title": "Executable Path", + "type": "string", + "default": "", + "description": "Absolute path to the \"phpcbf\" executable." + } + } + } + } } } \ No newline at end of file