Coder Social home page Coder Social logo

Comments (3)

rthor avatar rthor commented on July 25, 2024

Ahh good catch! Will fix as soon as I have time. Unless you want to submit a PR 😉

from cra-generate.

hjaltisan avatar hjaltisan commented on July 25, 2024

Hmm.

The Problem

The way I see it this is the order of importance:

  1. User explicitly X via the cli command
  2. X is taken from packages.json
  3. X is taken from defaultOptions (in config.js)

Given that X = whether or not to use semicolons,
Always take the option from 1, if it doesn't exist there than take the option from 2 and so on.

Solutions?

use_semicolons: user specifies via cli that he wants semicolons
skip_semicolons: user specifies via cli that he doesn't want semicolons
default: user wants to use the settings from packages.json or defaultOptions

Commander boolean flag options:

  1. option('-s, --semi, 'use semicolons)
    1. use_semicolons: cra-generate -s demo
    2. skip_semicolons: ... not possible!
    3. default: cra-generate demo

  1. option('--no-semi', 'skip semicolons)
    1. use_semicolons: ... not possible!
    2. skip_semicolons: cra-generate --no-semi demo
    3. default: cra-generate demo

  1. option('-s, --semi [bool]', 'either true or false')
    1. use_semicolons: cra-generate -s true demo
    2. skip_semicolons: cra-generate -s false demo
    3. default: cra-generate demo

  1. option('-s, --semicolons, 'use semicolons') and option('--no-semi', 'skip semicolons')
    1. use_semicolons: cra-generate -s demo
    2. skip_semicolons: cra-generate --no-semi demo
    3. default: cra-generate demo

Issues

  1. No way to explicitly state that the user doesn't want semicolons
  2. No way to explicitly state that the user wants semicolons
  3. Solves the problem, but isn't really pretty.
  4. Solves the problem, is prettier, but introduces a new issue cra-generate -s --no-semi demo...

And of course we get the same problem for -f...
What solution would you go with?
Or is there some other better solution that I am missing?
The way I see it solution 3 is the best solution, even though it is quite unusual. People are probably used to boolean flags to work like 1 or 2. But if we go with either of those, then we have to either always ignore packages.json or not offer the user to specify all options via cli...

from cra-generate.

rthor avatar rthor commented on July 25, 2024

I think it would be better to keep certain config values only in package.json. F.ex. the semicolon thing is something that you want to set globally for the entire project and you don't want any one component behaving differently.

Regarding the --functional flag. Maybe it should be possible to set a default type in the config, eg functional/classical and the explicitly pick a type in the cli tool. Eg

{
  "craGenerate": {
    "defaultType": "functional",
    "semi": false
  }
}
$ cra-generate --classical FooBar

This way, the semicolon thing will be config/default only, and we'll remove it from the flags list. And the functional flag will now adhere to the config/defaults but can be overridden explicitly if need be.

from cra-generate.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.