本文整理匯總了TypeScript中@electron-forge/core.api.start方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript api.start方法的具體用法?TypeScript api.start怎麽用?TypeScript api.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@electron-forge/core.api
的用法示例。
在下文中一共展示了api.start方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: launch
(async () => {
let commandArgs = process.argv;
let appArgs;
const doubleDashIndex = process.argv.indexOf('--');
if (doubleDashIndex !== -1) {
commandArgs = process.argv.slice(0, doubleDashIndex);
appArgs = process.argv.slice(doubleDashIndex + 1);
}
let dir = process.cwd();
program
.version(require('../package.json').version)
.arguments('[cwd]')
.option('-p, --app-path <path>', 'Override the path to the Electron app to launch (defaults to \'.\')')
.option('-l, --enable-logging', 'Enable advanced logging. This will log internal Electron things')
.option('-n, --run-as-node', 'Run the Electron app as a Node.JS script')
.option('--vscode', 'Used to enable arg transformation for debugging Electron through VSCode. Do not use yourself.')
.option('-i, --inspect-electron', 'Triggers inspect mode on Electron to allow debugging the main process. Electron >1.7 only')
.action((cwd) => {
if (!cwd) return;
if (path.isAbsolute(cwd) && fs.existsSync(cwd)) {
dir = cwd;
} else if (fs.existsSync(path.resolve(dir, cwd))) {
dir = path.resolve(dir, cwd);
}
})
.parse(commandArgs);
program.on('--help', () => {
console.log(' Any arguments found after "--" will be passed to the Electron app, e.g.');
console.log('');
console.log(' $ electron-forge /path/to/project -l -- -d -f foo.txt');
console.log('');
console.log(' will pass the arguments "-d -f foo.txt" to the Electron app');
});
const opts: StartOptions = {
dir,
interactive: true,
enableLogging: !!program.enableLogging,
runAsNode: !!program.runAsNode,
inspect: !!program.inspectElectron,
};
if (program.vscode && appArgs) {
// Args are in the format ~arg~ so we need to strip the "~"
appArgs = appArgs
.map(arg => arg.substr(1, arg.length - 2))
.filter(arg => arg.length > 0);
}
if (program.appPath) opts.appPath = program.appPath;
if (appArgs) opts.args = appArgs;
const spawned = await api.start(opts);
await new Promise((resolve) => {
spawned.on('exit', (code: number) => {
if ((spawned as any).restarted) return;
if (code !== 0) {
process.exit(code);
}
resolve();
});
});
})();