[NPMCLI-25] Local mgnl cli configuration should be used automatically Created: 14/Jul/16  Updated: 22/Aug/16  Resolved: 27/Jul/16

Status: Closed
Project: Magnolia CLI
Component/s: None
Affects Version/s: None
Fix Version/s: 0.0.1

Type: Improvement Priority: Major
Reporter: Christopher Zimmermann Assignee: Federico Grilli
Resolution: Outdated Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
dependency
depends upon NPMCLI-27 Own config file for mgnl-cli instead ... Closed
relation
is related to NPMCLI-22 make "export MGNLCLI_HOME" easier Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Date of First Response:
Story Points: 8

 Description   

When running the mgnl command, use the mgnl cli config file (i.e., mgnl-config.json) in the current directory or any of its parents. If none exists, then fall back to the global one defined by the MGNLCLI_HOME, or eventually to the global one delivered during the global npm install.

Reason:
Currently it is not that easy to set a project to use a local mgnl cli configuration, and people could easily make mistakes and use the wrong cli configuration if they forget to change the configuration.
This is because the config to be used is set globally via an environment variable. Ideally running mgnl in a directory should use the local config if present. This is how the npm cli works.

A few possible problematic scenarios:

  • I am working on two (or more) projects with custom configs. After a break I come back to a project, but when I start using the cli it's creating files based on the config from another project.
  • I am working on a project in a team. A teammate checked in the mgnl cli configuration, I get the project and start working but did not know that I had to set the ENV variable to use this config and therefore I'm using the wrong one.
  • I set an ENV variable via the 'export' command, but come back to the project later or in another tab and local configuration is no longer used.

Some of these are partially mitigated by the helpful INFO message that the CLI gives

INFO: MGNLCLI_HOME env variable is set. Using prototypes at /Users/czimmermann/Documents/a-projects/lightdev-lab/mgnl-cli/test4

A description based on this ticket and linked NPMCLI-27 of how it would work

The mgnl CLI is installed globally which means you can now access it in the terminal from any location simply by typing "mgnl".

While the CLI is ready to go with sensible defaults, you have the option to customize it to match your needs more closely. For example you can configure what a new component or page contains, which directories are in a new light module, or even which magnolia.properties are set on a new magnolia install. You can easily create the cli configuration files in the current directory with the "mgnl setup" command. This creates the mgnl-config.json file and a directory mgnl-config-prototypes which contains prototypes for the component and page files. Just edit these files to customize how the mgnl cli works.

Whenever you run the mgnl cli, it will use the configuration found in the current directory, or any of its parents. For example, you can run "mgnl setup" in the directory that contains your main "light-modules" directory to create the configuration files there - and then whenever you run the cli in any of your modules, your configuration will be used. This also gives you the flexibility to configure the CLI differently for different projects if you need to.



 Comments   
Comment by Tomáš Gregovský [ 19/Jul/16 ]

I agree and like solution:

"When running the mgnl command, search up the directory tree for the existance of an mgnl cli config file. If none exists, then use the global one. Perhaps an optional simple text file could point to an mgnl cli config to use."

Comment by Christopher Zimmermann [ 25/Jul/16 ]

Just noticed that bower CLI has a similiar mechanism of looking for config files up the tree. Maybe its helpful to see their implementation.
"All .bowerrc files upwards the directory tree"
https://bower.io/docs/config/

Also
"A file named .jshintrc located in the current directory or any parent of the current directory"
http://jshint.com/docs/cli/

Also
"By default, grunt looks in the current or parent directories for the nearest Gruntfile.js or Gruntfile.coffee file."
http://gruntjs.com/using-the-cli

Comment by Federico Grilli [ 27/Jul/16 ]

All solved by NPMCLI-27

Generated at Mon Feb 12 04:45:48 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.