🔧 Global formatting and update formatting
This commit is contained in:
125
bin/cli.ts
vendored
125
bin/cli.ts
vendored
@@ -3,7 +3,10 @@ import { program, Option } from 'commander';
|
||||
import log from 'loglevel';
|
||||
import packageJson from '../package.json';
|
||||
import BuilderProvider from './builders/BuilderProvider';
|
||||
import { DEFAULT_PAKE_OPTIONS as DEFAULT, DEFAULT_PAKE_OPTIONS } from './defaults';
|
||||
import {
|
||||
DEFAULT_PAKE_OPTIONS as DEFAULT,
|
||||
DEFAULT_PAKE_OPTIONS,
|
||||
} from './defaults';
|
||||
import { checkUpdateTips } from './helpers/updater';
|
||||
import handleInputOptions from './options/index';
|
||||
|
||||
@@ -18,7 +21,10 @@ ${green('| __/ (_| | < __/')} ${yellow('https://github.com/tw93/pake')}
|
||||
${green('|_| \\__,_|_|\\_\\___| can turn any webpage into a desktop app with Rust.')}
|
||||
`;
|
||||
|
||||
program.addHelpText('beforeAll', logo).usage(`[url] [options]`).showHelpAfterError();
|
||||
program
|
||||
.addHelpText('beforeAll', logo)
|
||||
.usage(`[url] [options]`)
|
||||
.showHelpAfterError();
|
||||
|
||||
program
|
||||
.argument('[url]', 'The web URL you want to package', validateUrlInput)
|
||||
@@ -26,15 +32,26 @@ program
|
||||
// If the platform is Linux, use `-` as the connector, and convert all characters to lowercase.
|
||||
// For example, Google Translate will become google-translate.
|
||||
.option('--name <string...>', 'Application name', (value, previous) => {
|
||||
const platform = process.platform
|
||||
const connector = platform === 'linux' ? '-' : ' '
|
||||
const name = previous === undefined ? value : `${previous}${connector}${value}`
|
||||
|
||||
return platform === 'linux' ? name.toLowerCase() : name
|
||||
const platform = process.platform;
|
||||
const connector = platform === 'linux' ? '-' : ' ';
|
||||
const name =
|
||||
previous === undefined ? value : `${previous}${connector}${value}`;
|
||||
|
||||
return platform === 'linux' ? name.toLowerCase() : name;
|
||||
})
|
||||
.option('--icon <string>', 'Application icon', DEFAULT.icon)
|
||||
.option('--width <number>', 'Window width', validateNumberInput, DEFAULT.width)
|
||||
.option('--height <number>', 'Window height', validateNumberInput, DEFAULT.height)
|
||||
.option(
|
||||
'--width <number>',
|
||||
'Window width',
|
||||
validateNumberInput,
|
||||
DEFAULT.width,
|
||||
)
|
||||
.option(
|
||||
'--height <number>',
|
||||
'Window height',
|
||||
validateNumberInput,
|
||||
DEFAULT.height,
|
||||
)
|
||||
.option('--use-local-file', 'Use local file packaging', DEFAULT.useLocalFile)
|
||||
.option('--fullscreen', 'Start in full screen', DEFAULT.fullscreen)
|
||||
.option('--hide-title-bar', 'For Mac, hide title bar', DEFAULT.hideTitleBar)
|
||||
@@ -44,41 +61,93 @@ program
|
||||
'Injection of .js or .css files',
|
||||
(val, previous) => {
|
||||
if (!val) return DEFAULT.inject;
|
||||
|
||||
|
||||
// Split by comma and trim whitespace, filter out empty strings
|
||||
const files = val.split(',')
|
||||
.map(item => item.trim())
|
||||
.filter(item => item.length > 0);
|
||||
|
||||
const files = val
|
||||
.split(',')
|
||||
.map((item) => item.trim())
|
||||
.filter((item) => item.length > 0);
|
||||
|
||||
// If previous values exist (from multiple --inject options), merge them
|
||||
return previous ? [...previous, ...files] : files;
|
||||
},
|
||||
DEFAULT.inject,
|
||||
)
|
||||
.option('--debug', 'Debug build and more output', DEFAULT.debug)
|
||||
.addOption(new Option('--proxy-url <url>', 'Proxy URL for all network requests').default(DEFAULT_PAKE_OPTIONS.proxyUrl).hideHelp())
|
||||
.addOption(new Option('--user-agent <string>', 'Custom user agent').default(DEFAULT.userAgent).hideHelp())
|
||||
.addOption(new Option('--targets <string>', 'For Linux, option "deb" or "appimage"').default(DEFAULT.targets).hideHelp())
|
||||
.addOption(new Option('--app-version <string>', 'App version, the same as package.json version').default(DEFAULT.appVersion).hideHelp())
|
||||
.addOption(new Option('--always-on-top', 'Always on the top level').default(DEFAULT.alwaysOnTop).hideHelp())
|
||||
.addOption(new Option('--dark-mode', 'Force Mac app to use dark mode').default(DEFAULT.darkMode).hideHelp())
|
||||
.addOption(new Option('--disabled-web-shortcuts', 'Disabled webPage shortcuts').default(DEFAULT.disabledWebShortcuts).hideHelp())
|
||||
.addOption(
|
||||
new Option('--activation-shortcut <string>', 'Shortcut key to active App').default(DEFAULT_PAKE_OPTIONS.activationShortcut).hideHelp(),
|
||||
new Option('--proxy-url <url>', 'Proxy URL for all network requests')
|
||||
.default(DEFAULT_PAKE_OPTIONS.proxyUrl)
|
||||
.hideHelp(),
|
||||
)
|
||||
.addOption(
|
||||
new Option('--user-agent <string>', 'Custom user agent')
|
||||
.default(DEFAULT.userAgent)
|
||||
.hideHelp(),
|
||||
)
|
||||
.addOption(
|
||||
new Option('--targets <string>', 'For Linux, option "deb" or "appimage"')
|
||||
.default(DEFAULT.targets)
|
||||
.hideHelp(),
|
||||
)
|
||||
.addOption(
|
||||
new Option(
|
||||
'--app-version <string>',
|
||||
'App version, the same as package.json version',
|
||||
)
|
||||
.default(DEFAULT.appVersion)
|
||||
.hideHelp(),
|
||||
)
|
||||
.addOption(
|
||||
new Option('--always-on-top', 'Always on the top level')
|
||||
.default(DEFAULT.alwaysOnTop)
|
||||
.hideHelp(),
|
||||
)
|
||||
.addOption(
|
||||
new Option('--dark-mode', 'Force Mac app to use dark mode')
|
||||
.default(DEFAULT.darkMode)
|
||||
.hideHelp(),
|
||||
)
|
||||
.addOption(
|
||||
new Option('--disabled-web-shortcuts', 'Disabled webPage shortcuts')
|
||||
.default(DEFAULT.disabledWebShortcuts)
|
||||
.hideHelp(),
|
||||
)
|
||||
.addOption(
|
||||
new Option('--activation-shortcut <string>', 'Shortcut key to active App')
|
||||
.default(DEFAULT_PAKE_OPTIONS.activationShortcut)
|
||||
.hideHelp(),
|
||||
)
|
||||
.addOption(
|
||||
new Option('--show-system-tray', 'Show system tray in app')
|
||||
.default(DEFAULT.showSystemTray)
|
||||
.hideHelp(),
|
||||
)
|
||||
.addOption(
|
||||
new Option('--system-tray-icon <string>', 'Custom system tray icon')
|
||||
.default(DEFAULT.systemTrayIcon)
|
||||
.hideHelp(),
|
||||
)
|
||||
.addOption(
|
||||
new Option('--hide-on-close', 'Hide window on close instead of exiting')
|
||||
.default(DEFAULT.hideOnClose)
|
||||
.hideHelp(),
|
||||
)
|
||||
.addOption(
|
||||
new Option('--installer-language <string>', 'Installer language')
|
||||
.default(DEFAULT.installerLanguage)
|
||||
.hideHelp(),
|
||||
)
|
||||
.addOption(new Option('--show-system-tray', 'Show system tray in app').default(DEFAULT.showSystemTray).hideHelp())
|
||||
.addOption(new Option('--system-tray-icon <string>', 'Custom system tray icon').default(DEFAULT.systemTrayIcon).hideHelp())
|
||||
.addOption(new Option('--hide-on-close', 'Hide window on close instead of exiting').default(DEFAULT.hideOnClose).hideHelp())
|
||||
.addOption(new Option('--installer-language <string>', 'Installer language').default(DEFAULT.installerLanguage).hideHelp())
|
||||
.version(packageJson.version, '-v, --version', 'Output the current version')
|
||||
.action(async (url: string, options: PakeCliOptions) => {
|
||||
await checkUpdateTips();
|
||||
|
||||
if (!url) {
|
||||
program.outputHelp(str => {
|
||||
program.outputHelp((str) => {
|
||||
return str
|
||||
.split('\n')
|
||||
.filter(line => !/((-h,|--help)|((-v|-V),|--version))\s+.+$/.test(line))
|
||||
.filter(
|
||||
(line) => !/((-h,|--help)|((-v|-V),|--version))\s+.+$/.test(line),
|
||||
)
|
||||
.join('\n');
|
||||
});
|
||||
process.exit(0);
|
||||
|
||||
Reference in New Issue
Block a user