MCPcopy Index your code
hub / github.com/loopbackio/loopback-next / main

Function main

packages/cli/lib/cli.js:174–233  ·  view source on GitHub ↗
(opts, log)

Source from the content-addressed store, hash-verified

172};
173
174function 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

Callers 2

cli.integration.jsFile · 0.50
cli-main.jsFile · 0.50

Calls 6

printVersionsFunction · 0.85
setupGeneratorsFunction · 0.85
printCommandsFunction · 0.85
runCommandFunction · 0.85
createMethod · 0.65
logFunction · 0.50

Tested by

no test coverage detected