Support test packaging process

This commit is contained in:
Tw93
2025-08-14 20:51:42 +08:00
parent b2072b5e80
commit f76d567895
10 changed files with 640 additions and 29 deletions

4
bin/README.md vendored
View File

@@ -47,6 +47,8 @@ pake [url] [options]
The packaged application will be located in the current working directory by default. The first packaging might take some time due to environment configuration. Please be patient.
> **macOS Output**: On macOS, Pake creates DMG installers by default. To create `.app` bundles for testing (to avoid user interaction), set the environment variable `PAKE_CREATE_APP=1`.
>
> **Note**: Packaging requires the Rust environment. If Rust is not installed, you will be prompted for installation confirmation. In case of installation failure or timeout, you can [install it manually](https://www.rust-lang.org/tools/install).
### [url]
@@ -279,7 +281,7 @@ Supports both comma-separated and multiple option formats:
#### [proxy-url]
Set proxy server for all network requests. Supports HTTP, HTTPS, and SOCKS5.
Set proxy server for all network requests. Supports HTTP, HTTPS, and SOCKS5. Available on Windows and Linux. On macOS, requires macOS 14+.
```shell
--proxy-url http://127.0.0.1:7890

4
bin/README_CN.md vendored
View File

@@ -47,6 +47,8 @@ pake [url] [options]
应用程序的打包结果将默认保存在当前工作目录。由于首次打包需要配置环境,这可能需要一些时间,请耐心等待。
> **macOS 输出**:在 macOS 上Pake 默认创建 DMG 安装程序。如需创建 `.app` 包进行测试(避免用户交互),请设置环境变量 `PAKE_CREATE_APP=1`。
>
> **注意**:打包过程需要使用 `Rust` 环境。如果您没有安装 `Rust`,系统会提示您是否要安装。如果遇到安装失败或超时的问题,您可以 [手动安装](https://www.rust-lang.org/tools/install)。
### [url]
@@ -281,7 +283,7 @@ pake [url] [options]
#### [proxy-url]
为所有网络请求设置代理服务器。支持 HTTP、HTTPS 和 SOCKS5。
为所有网络请求设置代理服务器。支持 HTTP、HTTPS 和 SOCKS5。在 Windows 和 Linux 上可用。在 macOS 上需要 macOS 14+。
```shell
--proxy-url http://127.0.0.1:7890

View File

@@ -118,8 +118,44 @@ export default abstract class BaseBuilder {
abstract getFileName(): string;
protected getBuildCommand(): string {
// the debug option should support `--debug` and `--release`
return this.options.debug ? 'npm run build:debug' : 'npm run build';
const baseCommand = this.options.debug
? 'npm run build:debug'
: 'npm run build';
// Use temporary config directory to avoid modifying source files
const configPath = path.join(
npmDirectory,
'src-tauri',
'.pake',
'tauri.conf.json',
);
let fullCommand = `${baseCommand} -- -c "${configPath}"`;
// For macOS, use app bundles by default unless DMG is explicitly requested
if (IS_MAC && this.options.targets === 'app') {
fullCommand += ' --bundles app';
}
// Add macos-proxy feature for modern macOS (Darwin 23+ = macOS 14+)
if (IS_MAC) {
const macOSVersion = this.getMacOSMajorVersion();
if (macOSVersion >= 23) {
fullCommand += ' --features macos-proxy';
}
}
return fullCommand;
}
private getMacOSMajorVersion(): number {
try {
const os = require('os');
const release = os.release();
const majorVersion = parseInt(release.split('.')[0], 10);
return majorVersion;
} catch (error) {
return 0; // Disable proxy feature if version detection fails
}
}
protected getBasePath(): string {
@@ -132,10 +168,13 @@ export default abstract class BaseBuilder {
fileName: string,
fileType: string,
): string {
// For app bundles on macOS, the directory is 'macos', not 'app'
const bundleDir =
fileType.toLowerCase() === 'app' ? 'macos' : fileType.toLowerCase();
return path.join(
npmDirectory,
this.getBasePath(),
fileType.toLowerCase(),
bundleDir,
`${fileName}.${fileType}`,
);
}

View File

@@ -5,11 +5,24 @@ import BaseBuilder from './BaseBuilder';
export default class MacBuilder extends BaseBuilder {
constructor(options: PakeAppOptions) {
super(options);
this.options.targets = 'dmg';
// Use DMG by default for distribution
// Only create app bundles for testing to avoid user interaction
if (process.env.PAKE_CREATE_APP === '1') {
this.options.targets = 'app';
} else {
this.options.targets = 'dmg';
}
}
getFileName(): string {
const { name } = this.options;
// For app bundles, use simple name without version/arch
if (this.options.targets === 'app') {
return name;
}
// For DMG files, use versioned filename
let arch: string;
if (this.options.multiArch) {
arch = 'universal';

29
bin/helpers/merge.ts vendored
View File

@@ -1,17 +1,42 @@
import path from 'path';
import fsExtra from 'fs-extra';
import { npmDirectory } from '@/utils/dir';
import combineFiles from '@/utils/combine';
import logger from '@/options/logger';
import { PakeAppOptions, PlatformMap } from '@/types';
import { tauriConfigDirectory } from '@/utils/dir';
import { tauriConfigDirectory, npmDirectory } from '@/utils/dir';
export async function mergeConfig(
url: string,
options: PakeAppOptions,
tauriConf: any,
) {
// Ensure .pake directory exists and copy source templates if needed
const srcTauriDir = path.join(npmDirectory, 'src-tauri');
await fsExtra.ensureDir(tauriConfigDirectory);
// Copy source config files to .pake directory (as templates)
const sourceFiles = [
'tauri.conf.json',
'tauri.macos.conf.json',
'tauri.windows.conf.json',
'tauri.linux.conf.json',
'pake.json',
];
await Promise.all(
sourceFiles.map(async (file) => {
const sourcePath = path.join(srcTauriDir, file);
const destPath = path.join(tauriConfigDirectory, file);
if (
(await fsExtra.pathExists(sourcePath)) &&
!(await fsExtra.pathExists(destPath))
) {
await fsExtra.copy(sourcePath, destPath);
}
}),
);
const {
width,
height,

9
bin/utils/dir.ts vendored
View File

@@ -7,7 +7,8 @@ const currentModulePath = fileURLToPath(import.meta.url);
// Resolve the parent directory of the current module
export const npmDirectory = path.join(path.dirname(currentModulePath), '..');
export const tauriConfigDirectory =
process.env.NODE_ENV === 'development'
? path.join(npmDirectory, 'src-tauri', '.pake')
: path.join(npmDirectory, 'src-tauri');
export const tauriConfigDirectory = path.join(
npmDirectory,
'src-tauri',
'.pake',
);