🎨 Simplify usage
This commit is contained in:
29
bin/cli.ts
vendored
29
bin/cli.ts
vendored
@@ -1,5 +1,5 @@
|
||||
import ora from "ora";
|
||||
import log from 'loglevel';
|
||||
import chalk from 'chalk';
|
||||
import { program } from 'commander';
|
||||
|
||||
import { PakeCliOptions } from './types';
|
||||
@@ -11,8 +11,8 @@ import { validateNumberInput, validateUrlInput } from './utils/validate';
|
||||
import { DEFAULT_PAKE_OPTIONS as DEFAULT } from './defaults';
|
||||
|
||||
program
|
||||
.version(packageJson.version)
|
||||
.description('A CLI that can turn any webpage into a desktop app with Rust.')
|
||||
.description(chalk.green('Pake: A CLI that can turn any webpage into a desktop app with Rust.'))
|
||||
.usage('[url] [options]')
|
||||
.showHelpAfterError();
|
||||
|
||||
program
|
||||
@@ -21,7 +21,7 @@ program
|
||||
.option('--icon <string>', 'Application icon', DEFAULT.icon)
|
||||
.option('--height <number>', 'Window height', validateNumberInput, DEFAULT.height)
|
||||
.option('--width <number>', 'Window width', validateNumberInput, DEFAULT.width)
|
||||
.option('--no-resizable', 'Whether the window can be resizable', DEFAULT.resizable)
|
||||
.option('--resizable', 'Whether the window can be resizable', DEFAULT.resizable)
|
||||
.option('--fullscreen', 'Start the packaged app in full screen', DEFAULT.fullscreen)
|
||||
.option('--transparent', 'Transparent title bar', DEFAULT.transparent)
|
||||
.option('--user-agent <string>', 'Custom user agent', DEFAULT.userAgent)
|
||||
@@ -29,17 +29,23 @@ program
|
||||
.option('--show-system-tray', 'Show system tray in app', DEFAULT.showSystemTray)
|
||||
.option('--system-tray-icon <string>', 'Custom system tray icon', DEFAULT.systemTrayIcon)
|
||||
.option('--iter-copy-file', 'Copy files to app when URL is a local file', DEFAULT.iterCopyFile)
|
||||
.option('--multi-arch', 'Available for Mac only, supports both Intel and M1', DEFAULT.multiArch)
|
||||
.option('--multi-arch', 'Only for Mac, supports both Intel and M1', DEFAULT.multiArch)
|
||||
.option('--targets <string>', 'Only for Linux, option "deb", "appimage" or "all"', DEFAULT.targets)
|
||||
.option('--debug', 'Debug mode', DEFAULT.debug)
|
||||
.version(packageJson.version, '-v, --version', 'Output the current version')
|
||||
.action(async (url: string, options: PakeCliOptions) => {
|
||||
|
||||
//Check for update prompt
|
||||
await checkUpdateTips();
|
||||
|
||||
// If no URL is provided, display help information
|
||||
if (!url) {
|
||||
program.help();
|
||||
program.outputHelp((str) => {
|
||||
const filteredOutput = str
|
||||
.split('\n')
|
||||
.filter((line) => !/((-h,|--help)|((-v|-V),|--version))\s+.+$/.test(line))
|
||||
.join('\n');
|
||||
return filteredOutput.trim(); // Trim any leading/trailing whitespace
|
||||
});
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
log.setDefaultLevel('info');
|
||||
@@ -47,14 +53,11 @@ program
|
||||
log.setLevel('debug');
|
||||
}
|
||||
|
||||
const spinner = ora('Preparing...').start();
|
||||
const builder = BuilderProvider.create();
|
||||
await builder.prepare();
|
||||
const appOptions = await handleInputOptions(options, url);
|
||||
spinner.succeed();
|
||||
|
||||
log.debug('PakeAppOptions', appOptions);
|
||||
|
||||
const builder = BuilderProvider.create();
|
||||
await builder.prepare();
|
||||
await builder.build(url, appOptions);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user