()
| 160 | } |
| 161 | |
| 162 | async setOptions() { |
| 163 | let opts = {}; |
| 164 | const jsonFileOrValue = this.options.config; |
| 165 | debug( |
| 166 | 'Loading generator options from CLI args and/or stdin.', |
| 167 | ...(this.option.config === undefined |
| 168 | ? ['(No config was provided.)'] |
| 169 | : ['Config:', this.options.config]), |
| 170 | ); |
| 171 | try { |
| 172 | if ( |
| 173 | jsonFileOrValue === 'stdin' || |
| 174 | (!jsonFileOrValue && !process.stdin.isTTY) |
| 175 | ) { |
| 176 | debug(' enabling --yes and reading config from stdin'); |
| 177 | this.options['yes'] = true; |
| 178 | opts = await this._readJSONFromStdin(); |
| 179 | } else if (typeof jsonFileOrValue === 'string') { |
| 180 | const jsonFile = path.resolve(process.cwd(), jsonFileOrValue); |
| 181 | if (fs.existsSync(jsonFile)) { |
| 182 | debug(' reading config from file', jsonFile); |
| 183 | opts = this.fs.readJSON(jsonFile); |
| 184 | } else { |
| 185 | debug(' parsing config from string', jsonFileOrValue); |
| 186 | // Try parse the config as stringified json |
| 187 | opts = JSON.parse(jsonFileOrValue); |
| 188 | } |
| 189 | } |
| 190 | } catch (e) { |
| 191 | this.exit(e); |
| 192 | return; |
| 193 | } |
| 194 | if (typeof opts !== 'object') { |
| 195 | this.exit('Invalid config file or value: ' + jsonFileOrValue); |
| 196 | return; |
| 197 | } |
| 198 | for (const o in opts) { |
| 199 | if (!this.options[o]) { |
| 200 | this.options[o] = opts[o]; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | const packageManager = |
| 205 | this.options.packageManager || this.config.get('packageManager') || 'npm'; |
| 206 | if (!supportedPackageManagers.includes(packageManager)) { |
| 207 | const supported = supportedPackageManagers.join(' or '); |
| 208 | this.exit( |
| 209 | `Package manager '${packageManager}' is not supported. Use ${supported}.`, |
| 210 | ); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * Check if a question can be skipped in `express` mode |
nothing calls this directly
no test coverage detected