Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow names with spaces (Windows & macOS) #876

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string>', 'Application name')
.option('--name <string...>', '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 <string>', 'Application icon', DEFAULT.icon)
.option('--width <number>', 'Window width', validateNumberInput, DEFAULT.width)
.option('--height <number>', 'Window height', validateNumberInput, DEFAULT.height)
Expand Down
8 changes: 4 additions & 4 deletions bin/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
12 changes: 7 additions & 5 deletions dist/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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 <string>', 'Application name')
.option('--name <string...>', '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 <string>', 'Application icon', DEFAULT_PAKE_OPTIONS.icon)
.option('--width <number>', 'Window width', validateNumberInput, DEFAULT_PAKE_OPTIONS.width)
.option('--height <number>', 'Window height', validateNumberInput, DEFAULT_PAKE_OPTIONS.height)
Expand Down