Drupal-console: [generate:composer] Composer.json Stand Alone

Created on 5 Dec 2015  路  12Comments  路  Source: hechoendrupal/drupal-console

Problem / Motivation

composer.json can only be generate in DrupalConsole if the user needs to generate a new module, using the generate:module. However, we need to be able generate composer.json on an existing module without need of generate a module. In addition we should provide more options on writing the composer.json. Right now, the generation of composer.json assume many things instead of asking. The generation of composer.json assume all these without asking:

  "keywords": ["Drupal"],
  "homepage": "http://drupal.org/project/test2_module",
  "minimum-stability": "dev",
  "support": {
    "issues": "http://drupal.org/project/issues/test2_module",
    "source": "http://cgit.drupalcode.org/test2_module"
  }

All these things needs to be ask before the generate the composer.json.

Solution

  • We need to be able generate composer.json
  • homepage, support, issues, irc, source, minimum-stability should not be assume because they might change base on where the user is been hosting or providing support.
  • We need to be able to add the Authors (maintainers of the project)
  • We need to be able to add search and add under required libraries from packagist.org
  • And the composer.json should looks something like this:
{
  "name": "drupal/mobile_detect",
  "description": "Mobile_Detect is a lightweight PHP class for detecting mobile devices.",
  "type": "drupal-module",
  "homepage": "http://drupal.org/project/mobile_detect",
  "authors": [
    {
      "name": "Matthew Donadio (mpdonadio)",
      "homepage": "https://www.drupal.org/u/mpdonadio",
      "role": "Maintainer"
    },
    {
      "name": "Darryl Norris (darol100)",
      "email": "[email protected]",
      "homepage": "https://www.drupal.org/u/darol100",
      "role": "Co-maintainer"
    }
  ],
  "support": {
    "issues": "http://drupal.org/project/mobile_detect",
    "irc": "irc://irc.freenode.org/drupal-contribute",
    "source": "http://cgit.drupalcode.org/mobile_detect"
  },
  "license": "GPL-2.0+",
  "minimum-stability": "dev",
  "require": {
    "mobiledetect/mobiledetectlib": "~2.8"
  }
}

novice

Most helpful comment

not my business, but ...
if we want so detailed composer.json generation ...
why not skip doing that with DC and
let the user do a simple & effective 芦_composer init_禄?

i doubt it worth the work to mimic exactly the behaviour of a _composer init_
that command already exists, we are not providing something now (in case of imitate it)

All 12 comments

I am going to be working on this, please @jmolivas let's discuss a bit for this before I start the implementation

not my business, but ...
if we want so detailed composer.json generation ...
why not skip doing that with DC and
let the user do a simple & effective 芦_composer init_禄?

i doubt it worth the work to mimic exactly the behaviour of a _composer init_
that command already exists, we are not providing something now (in case of imitate it)

I like the idea, What do you think @jmolivas ?

I was not aware of the composer init. 馃憤 for closing this issue and let user use composer instead.

the advantage of DC is because add values related to the module is been generated.

just to simplify...
what about passing the module info as arguments to 芦composer init禄?
https://getcomposer.org/doc/03-cli.md#init

i mean, DC can just call to _composer init_ with the appropiate arguments, and let _composer_ do the real job ...

This is a really simple generator it just collects information already ask on the module generation and pass to this template => https://github.com/hechoendrupal/DrupalConsole/blob/master/templates/module/composer.json.twig

{
  "name": "drupal/{{ machine_name }}",
  "type": "drupal-{{ type }}",
  "description": "{{ description }}",
  "keywords": ["Drupal"],
  "license": "GPL-2.0+",
  "homepage": "https://www.drupal.org/project/{{ machine_name }}",
  "minimum-stability": "dev",
  "support": {
    "issues": "https://www.drupal.org/project/issues/{{ machine_name }}",
    "source": "http://cgit.drupalcode.org/{{ machine_name }}"
  },
  "require": { }
}

For this command you only need ask for module name, read description from Drupal Core and pass it to the same Twig template.

What about the authors, license , require information ?

  • license is already added to the template as GPL-2.0+
  • require is added as empty
  • authors we are missing this one on the template

PR https://github.com/hechoendrupal/drupal-console/pull/3844
PR Translation https://github.com/hechoendrupal/drupal-console-en/pull/199

I have added composer.json generator. It includes all features mentioned above, I have replaced composer,json generation in generate:module command with ChainQueue. So, we will use the same approach to generate a composer.json file.

We can extend it if we need more information in composer json, but I think it would be enough as a starting point. In other case the process of entering of millions parameters in the command could be annoying.

Merged

Was this page helpful?
0 / 5 - 0 ratings