MCPcopy
hub / github.com/yeoman/yo / init

Function init

lib/cli.js:118–180  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

116};
117
118async function init() {
119 const {createEnv} = await import('yeoman-environment');
120 const env = createEnv();
121
122 // Lookup for every namespaces, within the environments.paths and lookups
123 await env.lookup(firstCmd.opts.localOnly || false);
124 const generatorList = createGeneratorList(env);
125
126 // List generators
127 if (firstCmd.opts.generators) {
128 console.log('Available Generators:\n\n' + generatorList);
129 env.emit('finished');
130 return;
131 }
132
133 // Start the interactive UI if no generator is passed
134 if (!cmd) {
135 if (firstCmd.opts.help) {
136 const usageText = fs.readFileSync(path.join(__dirname, 'usage.txt'), 'utf8');
137 console.log(`${usageText}\nAvailable Generators:\n\n${generatorList}`);
138 env.emit('finished');
139 return;
140 }
141
142 try {
143 await runYo(env);
144 } catch (error) {
145 onError(error);
146 }
147
148 return;
149 }
150
151 // More detailed error message
152 // If users type in generator name with prefix 'generator-'
153 if (cmd.startsWith('generator-')) {
154 const generatorName = cmd.replace('generator-', '');
155 const generatorCommand = chalk.yellow('yo ' + generatorName);
156
157 console.log(chalk.red('Installed generators don\'t need the "generator-" prefix.'));
158 console.log(`In the future, run ${generatorCommand} instead!\n`);
159
160 try {
161 await env.run(generatorName, firstCmd.opts);
162 } catch (error) {
163 onError(error);
164 }
165
166 return;
167 }
168
169 // Note: at some point, nopt needs to know about the generator options, the
170 // one that will be triggered by the below args. Maybe the nopt parsing
171 // should be done internally, from the args.
172 for (const generator of cli) {
173 try {
174 // eslint-disable-next-line no-await-in-loop
175 await env.run(generator.args, generator.opts);

Callers 1

preFunction · 0.85

Calls 3

createGeneratorListFunction · 0.85
runYoFunction · 0.85
onErrorFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…