Skip to content

Commit

Permalink
Pake-cli adds the parameter to select the packaging format.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tlntin committed Mar 18, 2023
1 parent b9e884c commit 03b7192
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 113 deletions.
8 changes: 8 additions & 0 deletions bin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ url 为你需要打包的网页链接 🔗,必须提供。

打包结果同时支持英特尔和 m1 芯片,仅适用于 MacOS,默认为 `false`

#### [targets]

选择输出的包格式,支持deb/appimage/all,如果选择all,则同时打包deb和appimage,该选项仅支持Linux,默认为`all`

```shell
--targets xxx
```

##### 准备工作

- 注意:开启该选项后,需要用 rust 官网的 rustup 安装 rust,不支持 brew 安装。
Expand Down
8 changes: 8 additions & 0 deletions bin/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ Use the command below to disable this feature.

Package results support both Intel and m1 chips, only for MacOS. The default is `false`.

#### [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`.

```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.
Expand Down
32 changes: 18 additions & 14 deletions bin/builders/LinuxBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,24 @@ export default class LinuxBuilder implements IBuilder {
} else {
arch = process.arch;
}
const debName = `${name}_${tauriConf.package.version}_${arch}.deb`;
const appPath = this.getBuildAppPath(npmDirectory, "deb", debName);
const distPath = path.resolve(`${name}.deb`);
await fs.copyFile(appPath, distPath);
await fs.unlink(appPath);

const appImageName = `${name}_${tauriConf.package.version}_${arch}.AppImage`;
const appImagePath = this.getBuildAppPath(npmDirectory, "appimage", appImageName);
const distAppPath = path.resolve(`${name}.AppImage`);
await fs.copyFile(appImagePath, distAppPath);
await fs.unlink(appImagePath);
logger.success('Build success!');
logger.success('You can find the deb app installer in', distPath);
logger.success('You can find the AppImage app installer in', distAppPath);
if (options.targets === "deb" || options.targets === "all") {
const debName = `${name}_${tauriConf.package.version}_${arch}.deb`;
const appPath = this.getBuildAppPath(npmDirectory, "deb", debName);
const distPath = path.resolve(`${name}.deb`);
await fs.copyFile(appPath, distPath);
await fs.unlink(appPath);
logger.success('Build Deb success!');
logger.success('You can find the deb app installer in', distPath);
}
if (options.targets === "appimage" || options.targets === "all") {
const appImageName = `${name}_${tauriConf.package.version}_${arch}.AppImage`;
const appImagePath = this.getBuildAppPath(npmDirectory, "appimage", appImageName);
const distAppPath = path.resolve(`${name}.AppImage`);
await fs.copyFile(appImagePath, distAppPath);
await fs.unlink(appImagePath);
logger.success('Build AppImage success!');
logger.success('You can find the AppImage app installer in', distAppPath);
}
}

getBuildAppPath(npmDirectory: string, packageType: string, packageName: string) {
Expand Down
9 changes: 7 additions & 2 deletions bin/builders/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ export async function mergeTauriConfig(
updateIconPath = false;
logger.warn(`icon file in Linux must be 512 * 512 pix with .png type, but you give ${customIconExt}`);
}
if (["all", "deb", "appimage"].includes(options.targets)) {
tauriConf.tauri.bundle.targets = [options.targets];
} else {
logger.warn("targets must be 'all', 'deb', 'appimage', we will use default 'all'");
}
}

if (process.platform === "darwin" && customIconExt !== ".icns") {
Expand Down Expand Up @@ -117,13 +122,13 @@ export async function mergeTauriConfig(
let bundleConf = {tauri: {bundle: tauriConf.tauri.bundle}};
await fs.writeFile(
configPath,
Buffer.from(JSON.stringify(bundleConf), 'utf-8')
Buffer.from(JSON.stringify(bundleConf, null, '\t'), 'utf-8')
);


const configJsonPath = path.join(npmDirectory, 'src-tauri/tauri.conf.json')
await fs.writeFile(
configJsonPath,
Buffer.from(JSON.stringify(tauriConf), 'utf-8')
Buffer.from(JSON.stringify(tauriConf, null, '\t'), 'utf-8')
);
}
1 change: 1 addition & 0 deletions bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ program
.option('-r, --no-resizable', 'whether the window can be resizable', DEFAULT_PAKE_OPTIONS.resizable)
.option('-d, --debug', 'debug', DEFAULT_PAKE_OPTIONS.debug)
.option('-m, --multi-arch', "available for Mac only, and supports both Intel and M1", DEFAULT_PAKE_OPTIONS.multiArch)
.option('--targets <string>', "Select the output package format, support deb/appimage/all, only for Linux", DEFAULT_PAKE_OPTIONS.targets)
.action(async (url: string, options: PakeCliOptions) => {

await checkUpdateTips();
Expand Down
1 change: 1 addition & 0 deletions bin/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {
transparent: false,
debug: false,
multiArch: false,
targets: "all",
};

export const DEFAULT_APP_NAME = 'Pake';
3 changes: 3 additions & 0 deletions bin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export interface PakeCliOptions {

/** mutli arch, Supports both Intel and m1 chips, only for Mac */
multiArch: boolean;

/** Select the output package format, support deb/appimage/all, only for Linux */
targets: string,
}

export interface PakeAppOptions extends PakeCliOptions {
Expand Down
107 changes: 70 additions & 37 deletions dist/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const DEFAULT_PAKE_OPTIONS = {
transparent: false,
debug: false,
multiArch: false,
targets: "all",
};

const tlds = [
Expand Down Expand Up @@ -1677,6 +1678,12 @@ function mergeTauriConfig(url, options, tauriConf) {
updateIconPath = false;
logger.warn(`icon file in Linux must be 512 * 512 pix with .png type, but you give ${customIconExt}`);
}
if (["all", "deb", "appimage"].includes(options.targets)) {
tauriConf.tauri.bundle.targets = [options.targets];
}
else {
logger.warn("targets must be 'all', 'deb', 'appimage', we will use default 'all'");
}
}
if (process.platform === "darwin" && customIconExt !== ".icns") {
updateIconPath = false;
Expand Down Expand Up @@ -1708,9 +1715,9 @@ function mergeTauriConfig(url, options, tauriConf) {
}
}
let bundleConf = { tauri: { bundle: tauriConf.tauri.bundle } };
yield fs.writeFile(configPath, Buffer.from(JSON.stringify(bundleConf), 'utf-8'));
yield fs.writeFile(configPath, Buffer.from(JSON.stringify(bundleConf, null, '\t'), 'utf-8'));
const configJsonPath = path.join(npmDirectory, 'src-tauri/tauri.conf.json');
yield fs.writeFile(configJsonPath, Buffer.from(JSON.stringify(tauriConf), 'utf-8'));
yield fs.writeFile(configJsonPath, Buffer.from(JSON.stringify(tauriConf, null, '\t'), 'utf-8'));
});
}

Expand Down Expand Up @@ -1830,8 +1837,8 @@ function checkRustInstalled() {
var tauri$3 = {
windows: [
{
url: "https://weread.qq.com/",
transparent: true,
url: "https://www.baidu.com",
transparent: false,
fullscreen: false,
width: 1200,
height: 780,
Expand All @@ -1843,21 +1850,46 @@ var tauri$3 = {
},
updater: {
active: false
},
bundle: {
icon: [
"/home/tlntin/data/code/rust_study/pake-tw93/Pake/src-tauri/png/icon_512.png"
],
identifier: "pake-f9751d",
active: true,
category: "DeveloperTool",
copyright: "",
deb: {
depends: [
"libwebkit2gtk-4.0-dev",
"build-essential",
"curl",
"wget",
"libssl-dev",
"libgtk-3-dev",
"libayatana-appindicator3-dev",
"librsvg2-dev",
"gnome-video-effects",
"gnome-video-effects-extra"
]
},
externalBin: [
],
longDescription: "",
resources: [
],
shortDescription: "",
targets: [
"deb"
]
}
};
var build = {
devPath: "../dist",
distDir: "../dist",
beforeBuildCommand: "",
beforeDevCommand: ""
};
var CommonConf = {
"package": {
productName: "WeRead",
productName: "baidu",
version: "1.0.0"
},
tauri: tauri$3,
build: build
tauri: tauri$3
};

var tauri$2 = {
Expand Down Expand Up @@ -1932,10 +1964,9 @@ var MacConf = {
var tauri = {
bundle: {
icon: [
"png/weread_256.ico",
"png/weread_512.png"
"/home/tlntin/data/code/rust_study/pake-tw93/Pake/src-tauri/png/icon_512.png"
],
identifier: "com.tw93.weread",
identifier: "pake-f9751d",
active: true,
category: "DeveloperTool",
copyright: "",
Expand All @@ -1951,10 +1982,7 @@ var tauri = {
"librsvg2-dev",
"gnome-video-effects",
"gnome-video-effects-extra"
],
files: {
"/usr/share/applications/com-tw93-weread.desktop": "assets/com-tw93-weread.desktop"
}
]
},
externalBin: [
],
Expand All @@ -1963,8 +1991,7 @@ var tauri = {
],
shortDescription: "",
targets: [
"deb",
"appimage"
"deb"
]
}
};
Expand Down Expand Up @@ -2134,19 +2161,24 @@ class LinuxBuilder {
else {
arch = process.arch;
}
const debName = `${name}_${tauriConf.package.version}_${arch}.deb`;
const appPath = this.getBuildAppPath(npmDirectory, "deb", debName);
const distPath = path.resolve(`${name}.deb`);
yield fs.copyFile(appPath, distPath);
yield fs.unlink(appPath);
const appImageName = `${name}_${tauriConf.package.version}_${arch}.AppImage`;
const appImagePath = this.getBuildAppPath(npmDirectory, "appimage", appImageName);
const distAppPath = path.resolve(`${name}.AppImage`);
yield fs.copyFile(appImagePath, distAppPath);
yield fs.unlink(appImagePath);
logger.success('Build success!');
logger.success('You can find the deb app installer in', distPath);
logger.success('You can find the AppImage app installer in', distAppPath);
if (options.targets === "deb" || options.targets === "all") {
const debName = `${name}_${tauriConf.package.version}_${arch}.deb`;
const appPath = this.getBuildAppPath(npmDirectory, "deb", debName);
const distPath = path.resolve(`${name}.deb`);
yield fs.copyFile(appPath, distPath);
yield fs.unlink(appPath);
logger.success('Build Deb success!');
logger.success('You can find the deb app installer in', distPath);
}
if (options.targets === "appimage" || options.targets === "all") {
const appImageName = `${name}_${tauriConf.package.version}_${arch}.AppImage`;
const appImagePath = this.getBuildAppPath(npmDirectory, "appimage", appImageName);
const distAppPath = path.resolve(`${name}.AppImage`);
yield fs.copyFile(appImagePath, distAppPath);
yield fs.unlink(appImagePath);
logger.success('Build AppImage success!');
logger.success('You can find the AppImage app installer in', distAppPath);
}
});
}
getBuildAppPath(npmDirectory, packageType, packageName) {
Expand All @@ -2170,7 +2202,7 @@ class BuilderFactory {
}

var name = "pake-cli";
var version = "1.2.7";
var version = "1.2.8";
var description = "🤱🏻 Turn any webpage into a desktop app with Rust. 🤱🏻 很简单的用 Rust 打包网页生成很小的桌面 App。";
var engines = {
node: ">=16.0.0"
Expand Down Expand Up @@ -2206,7 +2238,7 @@ var scripts = {
build: "npm run tauri build --release",
"build:mac": "npm run tauri build -- --target universal-apple-darwin",
"build:all-unix": "chmod +x ./script/build.sh && ./script/build.sh",
"build:all-windows": ".\\script\\build.bat",
"build:all-windows": "pwsh ./script/build.ps1",
tauri: "tauri",
cli: "rollup -c rollup.config.js --watch",
"cli:build": "cross-env NODE_ENV=production rollup -c rollup.config.js",
Expand Down Expand Up @@ -2286,6 +2318,7 @@ program
.option('-r, --no-resizable', 'whether the window can be resizable', DEFAULT_PAKE_OPTIONS.resizable)
.option('-d, --debug', 'debug', DEFAULT_PAKE_OPTIONS.debug)
.option('-m, --multi-arch', "available for Mac only, and supports both Intel and M1", DEFAULT_PAKE_OPTIONS.multiArch)
.option('--targets <string>', "Select the output package format, support deb/appimage/all, only for Linux", DEFAULT_PAKE_OPTIONS.targets)
.action((url, options) => __awaiter(void 0, void 0, void 0, function* () {
yield checkUpdateTips();
if (!url) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pake-cli",
"version": "1.2.7",
"version": "1.2.8",
"description": "🤱🏻 Turn any webpage into a desktop app with Rust. 🤱🏻 很简单的用 Rust 打包网页生成很小的桌面 App。",
"engines": {
"node": ">=16.0.0"
Expand Down
Loading

0 comments on commit 03b7192

Please sign in to comment.