-1

I would like my schematics to look for a JSON file on startup. If this file exists, it should read the options (the ones defined in schema.json) from the file, suppressing all prompts.

So if I start it like this and options.json doesn't exist:

ng g my-schematic:foo

It should run normal, print prompts etc. But if options.json does exist, it should read all options from that file and shouldn't print any prompts.

Is this possible?

I know something like this could be done by passing command line options, but I need to do this using a file. I don't want to pass any flags.

Thanks ind advance!

user2297996
  • 1,382
  • 3
  • 18
  • 28

1 Answers1

1

Solution 1

  1. Pass in your path to that json file as an argument with your command.

  2. Use that path via the options variable inside your rulefactory and parse it for the option names and the values set by the user.

Solution 2 - using schema.json

I would suggest that you add a default value to each of these options and DON'T add them to the required array. In this way you get the default values if not specified and if needed user can pass in the values for them via cmd.

I don't know of any hooks that can give a way to intercept the prompt printing.

cafebabe1991
  • 4,928
  • 2
  • 34
  • 42
  • Thanks sounds good! As for the prompts, I checked and you can actually suppress them. Schematics has a built-in flag called "interactive". When this is false, all prompts will be suppressed. If you have any required opts, you must supply them as command line flags. – user2297996 May 12 '20 at 19:59
  • Great. I did not know of this flag. Thanks. – cafebabe1991 May 13 '20 at 18:01