Generate config options (i.e. path) for Beautifier's Executables

This commit is contained in:
Glavin Wiechert 2017-05-29 01:34:12 -03:00
parent bc21afd424
commit fcc32d3fab
8 changed files with 276 additions and 31 deletions

View File

@ -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 |
| --- | --- | --- | ---- |

View File

@ -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

View File

@ -409,4 +409,4 @@
"lint": "coffeelint src/ spec/",
"code-docs": "codo && open docs/code/index.html"
}
}
}

View File

@ -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');

View File

@ -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

View File

@ -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'
}
}
]

View File

@ -3,7 +3,7 @@ module.exports = {
title: 'General'
type: 'object'
collapsed: true
order: -1
order: -2
description: 'General options for Atom Beautify'
properties:
_analyticsUserId :

View File

@ -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."
}
}
}
}
}
}