MCPcopy
hub / github.com/vercel/hyper / main

Function main

cli/index.ts:188–252  ·  view source on GitHub ↗
(argv: string[])

Source from the content-addressed store, hash-verified

186args.option(['v', 'verbose'], 'Verbose mode', false);
187
188const main = (argv: string[]) => {
189 const flags = args.parse(argv, {
190 name: 'hyper',
191 version: false,
192 mri: {
193 boolean: ['v', 'verbose']
194 }
195 } as any);
196
197 if (commandPromise) {
198 return commandPromise;
199 }
200
201 const env = Object.assign({}, process.env, {
202 // this will signal Hyper that it was spawned from this module
203 HYPER_CLI: '1',
204 ELECTRON_NO_ATTACH_CONSOLE: '1'
205 });
206
207 delete env['ELECTRON_RUN_AS_NODE'];
208
209 if (flags.verbose) {
210 env['ELECTRON_ENABLE_LOGGING'] = '1';
211 }
212
213 const options: SpawnOptions = {
214 detached: true,
215 env
216 };
217
218 const args_ = args.sub.map((arg) => {
219 const cwd = isAbsolute(arg) ? arg : resolve(process.cwd(), arg);
220 if (!existsSync(cwd)) {
221 console.error(chalk.red(`Error! Directory or file does not exist: ${cwd}`));
222 process.exit(1);
223 }
224 return cwd;
225 });
226
227 if (!flags.verbose) {
228 options['stdio'] = 'ignore';
229 if (process.platform === 'darwin') {
230 //Use `open` to prevent multiple Hyper process
231 const cmd = `open -b co.zeit.hyper ${args_}`;
232 const opts = {
233 env
234 };
235 return pify(exec)(cmd, opts);
236 }
237 }
238
239 const child = spawn(process.execPath, args_, options);
240
241 if (flags.verbose) {
242 // eslint-disable-next-line @typescript-eslint/no-unsafe-call
243 child.stdout?.on('data', (data) => console.log(data.toString('utf8')));
244 // eslint-disable-next-line @typescript-eslint/no-unsafe-call
245 child.stderr?.on('data', (data) => console.error(data.toString('utf8')));

Callers 1

index.tsFile · 0.70

Calls 10

resolveFunction · 0.85
parseMethod · 0.80
exitMethod · 0.80
onMethod · 0.80
onceMethod · 0.80
spawnFunction · 0.50
errorMethod · 0.45
logMethod · 0.45
toStringMethod · 0.45
resolveMethod · 0.45

Tested by

no test coverage detected