(opts, log)
| 172 | }; |
| 173 | |
| 174 | function main(opts, log) { |
| 175 | const dryRun = opts.dryRun || opts['dry-run']; |
| 176 | log = log || console.log; |
| 177 | if (opts.version) { |
| 178 | printVersions(log); |
| 179 | return; |
| 180 | } |
| 181 | |
| 182 | const env = setupGenerators(); |
| 183 | |
| 184 | // list generators |
| 185 | if (opts.commands) { |
| 186 | printCommands(env, log); |
| 187 | return; |
| 188 | } |
| 189 | |
| 190 | const yoJsonFile = path.join(__dirname, '../.yo-rc.json'); |
| 191 | if (opts.meta) { |
| 192 | const optionsAndArgs = { |
| 193 | base: baseOptions, |
| 194 | }; |
| 195 | const meta = env.getGeneratorsMeta(); |
| 196 | for (const ns in meta) { |
| 197 | const gen = env.create(ns, {options: {help: true}}); |
| 198 | const name = ns.substring('loopback4:'.length); |
| 199 | const commandOptions = {}; |
| 200 | for (const n in gen._options) { |
| 201 | const opt = gen._options[n]; |
| 202 | commandOptions[n] = {...opt, type: opt.type.name}; |
| 203 | } |
| 204 | const commandArgs = []; |
| 205 | if (!gen) { |
| 206 | for (const arg of gen._arguments) { |
| 207 | commandArgs.push({...arg, type: arg.type.name}); |
| 208 | } |
| 209 | } |
| 210 | optionsAndArgs[name] = { |
| 211 | options: commandOptions, |
| 212 | arguments: commandArgs, |
| 213 | name, |
| 214 | }; |
| 215 | } |
| 216 | |
| 217 | const yoJson = fs.readJsonSync(yoJsonFile); |
| 218 | const str = JSON.stringify(yoJson.commands, null, 2); |
| 219 | yoJson.commands = optionsAndArgs; |
| 220 | if (str !== JSON.stringify(optionsAndArgs, null, 2)) { |
| 221 | if (!dryRun) { |
| 222 | fs.writeJsonSync(yoJsonFile, yoJson, {spaces: 2, encoding: 'utf-8'}); |
| 223 | } |
| 224 | log('%s has been updated.', path.relative(process.cwd(), yoJsonFile)); |
| 225 | } else { |
| 226 | log('%s is up to date.', path.relative(process.cwd(), yoJsonFile)); |
| 227 | } |
| 228 | |
| 229 | return optionsAndArgs; |
| 230 | } |
| 231 |
no test coverage detected