Add a command to start the Electron app

This commit is contained in:
Samuel Elliott 2022-04-05 20:48:26 +01:00
parent 3c66bbd95d
commit b677b22809
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
4 changed files with 40 additions and 2 deletions

View File

@ -4,4 +4,4 @@ import createDebug from 'debug';
createDebug.log = console.warn.bind(console);
import('../dist/cli.js').then(cli => cli.default.argv);
import('../dist/cli.js').then(cli => cli.main.call(null));

View File

@ -3,7 +3,7 @@ import createDebug from 'debug';
import Yargs from 'yargs';
import dotenv from 'dotenv';
import dotenvExpand from 'dotenv-expand';
import { paths, YargsArguments } from './util.js';
import { dev, paths, YargsArguments } from './util.js';
import * as commands from './cli/index.js';
const debug = createDebug('cli');
@ -26,6 +26,8 @@ const yargs = Yargs(process.argv.slice(2)).option('data-path', {
export type Arguments = YargsArguments<typeof yargs>;
for (const command of Object.values(commands)) {
if (command.command === 'app' && !dev) continue;
// @ts-expect-error
yargs.command(command);
}
@ -38,3 +40,7 @@ yargs
.showHelpOnFail(false, 'Specify --help for available options');
export default yargs;
export async function main() {
yargs.argv;
}

31
src/cli/app.ts Normal file
View File

@ -0,0 +1,31 @@
import { createRequire } from 'module';
import { execFileSync } from 'child_process';
import createDebug from 'debug';
import type { Arguments as ParentArguments } from '../cli.js';
import { ArgumentsCamelCase, Argv, YargsArguments } from '../util.js';
const debug = createDebug('cli:app');
export const command = 'app';
export const desc = 'Start the Electron app';
export function builder(yargs: Argv<ParentArguments>) {
return yargs;
}
type Arguments = YargsArguments<ReturnType<typeof builder>>;
export async function handler(argv: ArgumentsCamelCase<Arguments>) {
const require = createRequire(import.meta.url);
const electron = require('electron');
if (typeof electron !== 'string') {
throw new Error('Already running in Electron??');
}
execFileSync(electron, [
'dist/app/main/app-entry.cjs',
], {
stdio: 'inherit',
});
}

View File

@ -3,3 +3,4 @@ export * as nso from './nso.js';
export * as splatnet2 from './splatnet2.js';
export * as pctl from './pctl.js';
export * as androidZncaApiServerFrida from './android-znca-api-server-frida.js';
export * as app from './app.js';