Browse Source

Move "scripts-description" to toplevel

Fixes #6881
Mathias Brodala 7 years ago
parent
commit
80d0c2029b
3 changed files with 22 additions and 12 deletions
  1. 9 11
      doc/articles/scripts.md
  2. 4 0
      res/composer-schema.json
  3. 9 1
      src/Composer/Console/Application.php

+ 9 - 11
doc/articles/scripts.md

@@ -278,16 +278,14 @@ JSON array of commands.
 
 ## Custom descriptions.
 
-You can set custom script descriptions with the following extra in your composer.json:
-
- ```json
- {
-     "extra": {
-        "scripts-description": {
-            "test": "Run all tests!"
-        }
-     }
- }
- ```
+You can set custom script descriptions with the following in your `composer.json`:
+
+```json
+{
+    "scripts-description": {
+        "test": "Run all tests!"
+    }
+}
+```
 
 > **Note:** You can only set custom descriptions of custom commands.

+ 4 - 0
res/composer-schema.json

@@ -447,6 +447,10 @@
                 }
             }
         },
+        "scripts-description": {
+            "type": ["object"],
+            "description": "Descriptions for scripts listeners, shown in console help."
+        },
         "support": {
             "type": "object",
             "properties": {

+ 9 - 1
src/Composer/Console/Application.php

@@ -228,7 +228,15 @@ class Application extends BaseApplication
                             if ($this->has($script)) {
                                 $io->writeError('<warning>A script named '.$script.' would override a Composer command and has been skipped</warning>');
                             } else {
-                                $description = isset($composer['extra']['scripts-description'][$script]) ? $composer['extra']['scripts-description'][$script] : null;
+                                $description = null;
+
+                                if (isset($composer['scripts-description'][$script])) {
+                                    $description = $composer['scripts-description'][$script];
+                                } elseif (isset($composer['extra']['scripts-description'][$script])) {
+                                    $io->writeError('<warning>You are using "scripts-description" in "extra" which is deprecated. Move "scripts-description" to the topmost level next to "scripts" instead.</warning>');
+                                    $description = $composer['extra']['scripts-description'][$script];
+                                }
+
                                 $this->add(new Command\ScriptAliasCommand($script, $description));
                             }
                         }