🐛 Fix name compatibility

This commit is contained in:
Tw93
2025-08-13 19:40:00 +08:00
parent 72652d814f
commit 09a122dd6b
5 changed files with 17 additions and 14 deletions

View File

@@ -79,9 +79,10 @@ npm run build:mac # macOS universal build
### CLI Tool (`bin/`)
- `bin/cli.ts` - Main entry point
- `bin/builders/` - Platform-specific builders
- `bin/options/` - Configuration processing
- `bin/cli.ts` - Main entry point with Commander.js
- `bin/builders/` - Platform-specific builders (Mac, Windows, Linux)
- `bin/options/` - CLI option processing and validation
- `bin/helpers/merge.ts` - Configuration merging (name setting at line 55)
### Tauri Application (`src-tauri/`)

View File

@@ -173,6 +173,9 @@ pake url [OPTIONS]...
# Feel free to play with Pake! It might take a while to prepare the environment the first time you launch Pake.
pake https://weekly.tw93.fun --name Weekly --hide-title-bar
# Also supports names with spaces (cross-platform compatible)
pake https://translate.google.com --name "Google Translate" --hide-title-bar
```
If you are new to the command line, you can compile packages online with _GitHub Actions_. See the [Tutorial](<https://github.com/tw93/Pake/wiki/Online-Compilation-(used-by-ordinary-users)>) for more information.

6
bin/README_CN.md vendored
View File

@@ -61,16 +61,16 @@ pake [url] [options]
指定应用程序的名称,如果未指定,系统会提示您输入,建议使用英文单词。
**注意**: 支持多个单词,会自动处理不同平台的命名规范:
**注意**: 支持带空格的名称,会自动处理不同平台的命名规范:
- **Windows/macOS**: 保持空格和大小写(如 `"Google Translate"`
- **Linux**: 转换为小写并用连字符连接(如 `"google-translate"`
- **Linux**: 自动转换为小写并用连字符连接(如 `"google-translate"`
```shell
--name <string>
--name MyApp
# 多个单词(如需要):
# 带空格的名称:
--name "Google Translate"
```

9
bin/cli.ts vendored
View File

@@ -31,14 +31,7 @@ program
// 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 <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;
})
.option('--name <string>', 'Application name')
.option('--icon <string>', 'Application icon', DEFAULT.icon)
.option(
'--width <number>',

View File

@@ -36,6 +36,12 @@ export default async function handleOptions(
name = namePrompt || defaultName;
}
// Handle platform-specific name formatting
if (name && platform === 'linux') {
// Convert to lowercase and replace spaces with dashes for Linux
name = name.toLowerCase().replace(/\s+/g, '-');
}
if (!isValidName(name, platform)) {
const LINUX_NAME_ERROR = `✕ Name should only include lowercase letters, numbers, and dashes (not leading dashes). Examples: com-123-xxx, 123pan, pan123, weread, we-read, 123.`;
const DEFAULT_NAME_ERROR = `✕ Name should only include letters, numbers, dashes, and spaces (not leading dashes and spaces). Examples: 123pan, 123Pan, Pan123, weread, WeRead, WERead, we-read, We Read, 123.`;