Add the multi_arch parameter of the master branch to the pake-cli

This commit is contained in:
Tlntin
2023-04-08 11:18:48 +08:00
parent 709f7532a4
commit da615bb1c7
6 changed files with 104 additions and 15 deletions

36
bin/README.md vendored
View File

@@ -128,4 +128,40 @@ url 为你需要打包的网页链接 🔗或者本地html文件必须提供
```shell
--copy-iter-file
```
#### [multi-arch]
打包结果同时支持英特尔和 m1 芯片,仅适用于 MacOS默认为 `false`
##### 准备工作
- 注意:开启该选项后,需要用 rust 官网的 rustup 安装 rust不支持 brew 安装。
- 对于 intel 芯片用户,需要安装 arm64 跨平台包,使安装包支持 m1 芯片,使用下面命令安装。
```shell
rustup target add aarch64-apple-darwin
```
- 对于 M1 芯片用户,需要安装 x86 跨平台包,使安装包支持 interl 芯片,使用下面的命令安装。
```shell
rustup target add x86_64-apple-darwin
```
##### 使用方法
```shell
--multi-arch
# 或者
-m
```
#### [targets]
选择输出的包格式支持deb/appimage/all如果选择all,则同时打包deb和appimage该选项仅支持Linux默认为`all`
```shell
--targets xxx
```

36
bin/README_EN.md vendored
View File

@@ -128,3 +128,39 @@ Recursive copy, when the url is a local file path, if this option is enabled, th
```shell
--copy-iter-file
```
#### [multi-arch]
Package results support both Intel and m1 chips, only for MacOS. The default is `false`.
```shell
--targets xxx
```
##### Preparation
- Note: After enabling this option, you need to use rustup on the rust official website to install rust, brew installation is not supported.
- For intel chip users, you need to install the arm64 cross-platform package to make the installation package support the m1 chip, and use the following command to install.
```shell
rustup target add aarch64-apple-darwin
```
- For M1 chip users, you need to install the x86 cross-platform package to make the installation package support the interl chip, and use the following command to install.
```shell
rustup target add x86_64-apple-darwin
```
##### Instructions
```shell
--multi-arch
# or
-m
```
#### [targets]
Select the output package format, support deb/appimage/all, if all is selected, deb and appimage will be packaged at the same time, this option only supports Linux, the default is `all`.

View File

@@ -39,16 +39,21 @@ export default class MacBuilder implements IBuilder {
const { name } = options;
await mergeTauriConfig(url, options, tauriConf);
const _ = await shellExec(`cd ${npmDirectory} && npm install && npm run build`);
let arch = "x64";
if (process.arch === "arm64") {
arch = "aarch64";
let dmgName: string;
if (options.multiArch) {
await shellExec(`cd "${npmDirectory}" && npm install --verbose && npm run build:mac`);
dmgName = `${name}_${tauriConf.package.version}_universal.dmg`;
} else {
arch = process.arch;
await shellExec(`cd "${npmDirectory}" && npm install --verbose && npm run build`);
let arch = "x64";
if (process.arch === "arm64") {
arch = "aarch64";
} else {
arch = process.arch;
}
dmgName = `${name}_${tauriConf.package.version}_${arch}.dmg`;
}
const dmgName = `${name}_${tauriConf.package.version}_${arch}.dmg`;
const appPath = this.getBuildedAppPath(npmDirectory, dmgName);
const appPath = this.getBuildAppPath(npmDirectory, dmgName, options.multiArch);
const distPath = path.resolve(`${name}.dmg`);
await fs.copyFile(appPath, distPath);
await fs.unlink(appPath);
@@ -57,11 +62,13 @@ export default class MacBuilder implements IBuilder {
logger.success('You can find the app installer in', distPath);
}
getBuildedAppPath(npmDirectory: string, dmgName: string) {
return path.join(
npmDirectory,
'src-tauri/target/release/bundle/dmg',
dmgName
);
getBuildAppPath(npmDirectory: string, dmgName: string, multiArch: boolean) {
let dmgPath: string;
if (multiArch) {
dmgPath = 'src-tauri/target/universal-apple-darwin/release/bundle/dmg';
} else {
dmgPath = 'src-tauri/target/release/bundle/dmg';
}
return path.join(npmDirectory, dmgPath, dmgName);
}
}

8
bin/cli.ts vendored
View File

@@ -30,10 +30,16 @@ program
.option('--iter-copy-file',
'copy all static file to pake app when url is a local file',
DEFAULT_PAKE_OPTIONS.iterCopyFile)
.option(
'-m, --multi-arch',
"available for Mac only, and supports both Intel and M1",
DEFAULT_PAKE_OPTIONS.multiArch
)
.option(
'--targets <string>',
'only for linux, default is "deb", option "appaimge" or "all"(deb & appimage)',
DEFAULT_PAKE_OPTIONS.targets)
DEFAULT_PAKE_OPTIONS.targets
)
.option('--debug', 'debug', DEFAULT_PAKE_OPTIONS.transparent)
.action(async (url: string, options: PakeCliOptions) => {
checkUpdateTips();

1
bin/defaults.ts vendored
View File

@@ -10,6 +10,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {
userAgent: '',
showMenu: false,
showSystemTray: false,
multiArch: false,
targets: 'deb',
iterCopyFile: false,
systemTrayIcon: '',

3
bin/types.ts vendored
View File

@@ -35,6 +35,9 @@ export interface PakeCliOptions {
// /** 递归拷贝当url为本地文件路径时候若开启该选项则将url路径文件所在文件夹以及所有子文件都拷贝到pake静态文件夹默认不开启 */
iterCopyFile: false;
/** mutli arch, Supports both Intel and m1 chips, only for Mac */
multiArch: boolean;
// 包输出产物对linux用户有效默认为deb可选appimage, 或者all即同时输出deb和all;
targets: string;