From 6a644acdd9050ef0c3f1963b9889f7796c7fe952 Mon Sep 17 00:00:00 2001 From: Yue Yang Date: Tue, 24 Dec 2024 14:08:31 +0000 Subject: [PATCH 1/2] feat: allow names with spaces --- bin/cli.ts | 4 +++- bin/options/index.ts | 8 ++++---- dist/cli.js | 12 +++++++----- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/bin/cli.ts b/bin/cli.ts index 55148c5af..35b9a5048 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -22,7 +22,9 @@ program.addHelpText('beforeAll', logo).usage(`[url] [options]`).showHelpAfterErr program .argument('[url]', 'The web URL you want to package', validateUrlInput) - .option('--name ', 'Application name') + .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. .option('--icon ', 'Application icon', DEFAULT.icon) .option('--width ', 'Window width', validateNumberInput, DEFAULT.width) .option('--height ', 'Window height', validateNumberInput, DEFAULT.height) diff --git a/bin/options/index.ts b/bin/options/index.ts index dc90f54b8..f1295df5c 100644 --- a/bin/options/index.ts +++ b/bin/options/index.ts @@ -13,8 +13,8 @@ function resolveAppName(name: string, platform: NodeJS.Platform): string { function isValidName(name: string, platform: NodeJS.Platform): boolean { const platformRegexMapping: PlatformMap = { - linux: /^[a-z0-9]+(-[a-z0-9]+)*$/, - default: /^[a-zA-Z0-9]+([-a-zA-Z0-9])*$/, + linux: /^[a-z0-9][a-z0-9-]*$/, + default: /^[a-zA-Z0-9][a-zA-Z0-9- ]*$/, }; const reg = platformRegexMapping[platform] || platformRegexMapping.default; return !!name && reg.test(name); @@ -34,8 +34,8 @@ export default async function handleOptions(options: PakeCliOptions, url: string } if (!isValidName(name, platform)) { - const LINUX_NAME_ERROR = `✕ name should only include lowercase letters, numbers, and dashes, and must contain at least one lowercase letter. Examples: com-123-xxx, 123pan, pan123, weread, we-read.`; - const DEFAULT_NAME_ERROR = `✕ Name should only include letters and numbers, and dashes (dashes must not at the beginning), and must contain at least one letter. Examples: 123pan, 123Pan, Pan123, weread, WeRead, WERead, we-read.`; + const LINUX_NAME_ERROR = `✕ Name should only include lowercase letters, numbers, and dashes (not leading dashes), and must contain at least one lowercase letter or number. Examples: com-123-xxx, 123pan, pan123, weread, we-read.`; + const DEFAULT_NAME_ERROR = `✕ Name should only include letters, numbers, dashes, and spaces (not leading dashes and spaces), and must contain at least one letter or number. Examples: 123pan, 123Pan, Pan123, weread, WeRead, WERead, we-read, We Read.`; const errorMsg = platform === 'linux' ? LINUX_NAME_ERROR : DEFAULT_NAME_ERROR; logger.error(errorMsg); if (isActions) { diff --git a/dist/cli.js b/dist/cli.js index 2c0e43ea0..d2e43ff5c 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -891,8 +891,8 @@ function resolveAppName(name, platform) { } function isValidName(name, platform) { const platformRegexMapping = { - linux: /^[a-z0-9]+(-[a-z0-9]+)*$/, - default: /^[a-zA-Z0-9]+([-a-zA-Z0-9])*$/, + linux: /^[a-z0-9][a-z0-9-]*$/, + default: /^[a-zA-Z0-9][a-zA-Z0-9- ]*$/, }; const reg = platformRegexMapping[platform] || platformRegexMapping.default; return !!name && reg.test(name); @@ -909,8 +909,8 @@ async function handleOptions(options, url) { name = namePrompt || defaultName; } if (!isValidName(name, platform)) { - const LINUX_NAME_ERROR = `✕ name should only include lowercase letters, numbers, and dashes, and must contain at least one lowercase letter. Examples: com-123-xxx, 123pan, pan123, weread, we-read.`; - const DEFAULT_NAME_ERROR = `✕ Name should only include letters and numbers, and dashes (dashes must not at the beginning), and must contain at least one letter. Examples: 123pan, 123Pan, Pan123, weread, WeRead, WERead, we-read.`; + const LINUX_NAME_ERROR = `✕ Name should only include lowercase letters, numbers, and dashes (not leading dashes), and must contain at least one lowercase letter or number. Examples: com-123-xxx, 123pan, pan123, weread, we-read.`; + const DEFAULT_NAME_ERROR = `✕ Name should only include letters, numbers, dashes, and spaces (not leading dashes and spaces), and must contain at least one letter or number. Examples: 123pan, 123Pan, Pan123, weread, WeRead, WERead, we-read, We Read.`; const errorMsg = platform === 'linux' ? LINUX_NAME_ERROR : DEFAULT_NAME_ERROR; logger.error(errorMsg); if (isActions) { @@ -960,7 +960,9 @@ ${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) - .option('--name ', 'Application name') + .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. .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) From 785c289327c502d3137fa71409ecd51764bd94e9 Mon Sep 17 00:00:00 2001 From: Yue Yang Date: Fri, 3 Jan 2025 08:21:12 +0000 Subject: [PATCH 2/2] 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)