From 785c289327c502d3137fa71409ecd51764bd94e9 Mon Sep 17 00:00:00 2001 From: Yue Yang Date: Fri, 3 Jan 2025 08:21:12 +0000 Subject: [PATCH] chore: make the name Linux-compatible --- bin/cli.ts | 11 +++++++++-- dist/cli.js | 10 ++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/bin/cli.ts b/bin/cli.ts index 35b9a5048..bdd70b605 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -22,9 +22,16 @@ program.addHelpText('beforeAll', logo).usage(`[url] [options]`).showHelpAfterErr program .argument('[url]', 'The web URL you want to package', validateUrlInput) + // Refer to https://github.com/tj/commander.js#custom-option-processing, turn string array into a string connected with custom connectors. + // 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 ', 'Application name', (value, previous) => { - return previous === undefined ? value : `${previous} ${value}` - }) // Refer to https://github.com/tj/commander.js#custom-option-processing, turn string array into a string connected with spaces. + const platform = process.platform + const connector = platform === 'linux' ? '-' : ' ' + const name = previous === undefined ? value : `${previous}${connector}${value}` + + return platform === 'linux' ? name.toLowerCase() : name + }) .option('--icon ', 'Application icon', DEFAULT.icon) .option('--width ', 'Window width', validateNumberInput, DEFAULT.width) .option('--height ', 'Window height', validateNumberInput, DEFAULT.height) diff --git a/dist/cli.js b/dist/cli.js index d2e43ff5c..e57702579 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -960,9 +960,15 @@ ${green('|_| \\__,_|_|\\_\\___| can turn any webpage into a desktop app with program.addHelpText('beforeAll', logo).usage(`[url] [options]`).showHelpAfterError(); program .argument('[url]', 'The web URL you want to package', validateUrlInput) + // Refer to https://github.com/tj/commander.js#custom-option-processing, turn string array into a string connected with custom connectors. + // 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 ', 'Application name', (value, previous) => { - return previous === undefined ? value : `${previous} ${value}`; -}) // Refer to https://github.com/tj/commander.js#custom-option-processing, turn string array into a string connected with spaces. + const platform = process.platform; + const connector = platform === 'linux' ? '-' : ' '; + const name = previous === undefined ? value : `${previous}${connector}${value}`; + return platform === 'linux' ? name.toLowerCase() : name; +}) .option('--icon ', 'Application icon', DEFAULT_PAKE_OPTIONS.icon) .option('--width ', 'Window width', validateNumberInput, DEFAULT_PAKE_OPTIONS.width) .option('--height ', 'Window height', validateNumberInput, DEFAULT_PAKE_OPTIONS.height)