Pake-cli adds the parameter to select the packaging format.

This commit is contained in:
Tlntin
2023-03-18 11:27:06 +08:00
parent 639e296335
commit 3edfa892d1
11 changed files with 203 additions and 113 deletions

8
bin/README.md vendored
View File

@@ -132,6 +132,14 @@ url 为你需要打包的网页链接 🔗,必须提供。
打包结果同时支持英特尔和 m1 芯片,仅适用于 MacOS默认为 `false`。 打包结果同时支持英特尔和 m1 芯片,仅适用于 MacOS默认为 `false`。
#### [targets]
选择输出的包格式支持deb/appimage/all如果选择all,则同时打包deb和appimage该选项仅支持Linux默认为`all`。
```shell
--targets xxx
```
##### 准备工作 ##### 准备工作
- 注意:开启该选项后,需要用 rust 官网的 rustup 安装 rust不支持 brew 安装。 - 注意:开启该选项后,需要用 rust 官网的 rustup 安装 rust不支持 brew 安装。

8
bin/README_EN.md vendored
View File

@@ -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`. 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 ##### Preparation
- Note: After enabling this option, you need to use rustup on the rust official website to install rust, brew installation is not supported. - Note: After enabling this option, you need to use rustup on the rust official website to install rust, brew installation is not supported.

View File

@@ -54,20 +54,24 @@ export default class LinuxBuilder implements IBuilder {
} else { } else {
arch = process.arch; arch = process.arch;
} }
const debName = `${name}_${tauriConf.package.version}_${arch}.deb`; if (options.targets === "deb" || options.targets === "all") {
const appPath = this.getBuildAppPath(npmDirectory, "deb", debName); const debName = `${name}_${tauriConf.package.version}_${arch}.deb`;
const distPath = path.resolve(`${name}.deb`); const appPath = this.getBuildAppPath(npmDirectory, "deb", debName);
await fs.copyFile(appPath, distPath); const distPath = path.resolve(`${name}.deb`);
await fs.unlink(appPath); await fs.copyFile(appPath, distPath);
await fs.unlink(appPath);
const appImageName = `${name}_${tauriConf.package.version}_${arch}.AppImage`; logger.success('Build Deb success!');
const appImagePath = this.getBuildAppPath(npmDirectory, "appimage", appImageName); logger.success('You can find the deb app installer in', distPath);
const distAppPath = path.resolve(`${name}.AppImage`); }
await fs.copyFile(appImagePath, distAppPath); if (options.targets === "appimage" || options.targets === "all") {
await fs.unlink(appImagePath); const appImageName = `${name}_${tauriConf.package.version}_${arch}.AppImage`;
logger.success('Build success!'); const appImagePath = this.getBuildAppPath(npmDirectory, "appimage", appImageName);
logger.success('You can find the deb app installer in', distPath); const distAppPath = path.resolve(`${name}.AppImage`);
logger.success('You can find the AppImage app installer in', distAppPath); 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) { getBuildAppPath(npmDirectory: string, packageType: string, packageName: string) {

View File

@@ -82,6 +82,11 @@ export async function mergeTauriConfig(
updateIconPath = false; updateIconPath = false;
logger.warn(`icon file in Linux must be 512 * 512 pix with .png type, but you give ${customIconExt}`); 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") { if (process.platform === "darwin" && customIconExt !== ".icns") {
@@ -117,13 +122,13 @@ export async function mergeTauriConfig(
let bundleConf = {tauri: {bundle: tauriConf.tauri.bundle}}; let bundleConf = {tauri: {bundle: tauriConf.tauri.bundle}};
await fs.writeFile( await fs.writeFile(
configPath, 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') const configJsonPath = path.join(npmDirectory, 'src-tauri/tauri.conf.json')
await fs.writeFile( await fs.writeFile(
configJsonPath, configJsonPath,
Buffer.from(JSON.stringify(tauriConf), 'utf-8') Buffer.from(JSON.stringify(tauriConf, null, '\t'), 'utf-8')
); );
} }

1
bin/cli.ts vendored
View File

@@ -23,6 +23,7 @@ program
.option('-r, --no-resizable', 'whether the window can be resizable', DEFAULT_PAKE_OPTIONS.resizable) .option('-r, --no-resizable', 'whether the window can be resizable', DEFAULT_PAKE_OPTIONS.resizable)
.option('-d, --debug', 'debug', DEFAULT_PAKE_OPTIONS.debug) .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('-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) => { .action(async (url: string, options: PakeCliOptions) => {
await checkUpdateTips(); await checkUpdateTips();

1
bin/defaults.ts vendored
View File

@@ -9,6 +9,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {
transparent: false, transparent: false,
debug: false, debug: false,
multiArch: false, multiArch: false,
targets: "all",
}; };
export const DEFAULT_APP_NAME = 'Pake'; export const DEFAULT_APP_NAME = 'Pake';

3
bin/types.ts vendored
View File

@@ -25,6 +25,9 @@ export interface PakeCliOptions {
/** mutli arch, Supports both Intel and m1 chips, only for Mac */ /** mutli arch, Supports both Intel and m1 chips, only for Mac */
multiArch: boolean; multiArch: boolean;
/** Select the output package format, support deb/appimage/all, only for Linux */
targets: string,
} }
export interface PakeAppOptions extends PakeCliOptions { export interface PakeAppOptions extends PakeCliOptions {

107
dist/cli.js vendored
View File

@@ -49,6 +49,7 @@ const DEFAULT_PAKE_OPTIONS = {
transparent: false, transparent: false,
debug: false, debug: false,
multiArch: false, multiArch: false,
targets: "all",
}; };
const tlds = [ const tlds = [
@@ -1677,6 +1678,12 @@ function mergeTauriConfig(url, options, tauriConf) {
updateIconPath = false; updateIconPath = false;
logger.warn(`icon file in Linux must be 512 * 512 pix with .png type, but you give ${customIconExt}`); 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") { if (process.platform === "darwin" && customIconExt !== ".icns") {
updateIconPath = false; updateIconPath = false;
@@ -1708,9 +1715,9 @@ function mergeTauriConfig(url, options, tauriConf) {
} }
} }
let bundleConf = { tauri: { bundle: tauriConf.tauri.bundle } }; 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'); 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'));
}); });
} }
@@ -1830,8 +1837,8 @@ function checkRustInstalled() {
var tauri$3 = { var tauri$3 = {
windows: [ windows: [
{ {
url: "https://weread.qq.com/", url: "https://www.baidu.com",
transparent: true, transparent: false,
fullscreen: false, fullscreen: false,
width: 1200, width: 1200,
height: 780, height: 780,
@@ -1843,21 +1850,46 @@ var tauri$3 = {
}, },
updater: { updater: {
active: false 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 = { var CommonConf = {
"package": { "package": {
productName: "WeRead", productName: "baidu",
version: "1.0.0" version: "1.0.0"
}, },
tauri: tauri$3, tauri: tauri$3
build: build
}; };
var tauri$2 = { var tauri$2 = {
@@ -1932,10 +1964,9 @@ var MacConf = {
var tauri = { var tauri = {
bundle: { bundle: {
icon: [ icon: [
"png/weread_256.ico", "/home/tlntin/data/code/rust_study/pake-tw93/Pake/src-tauri/png/icon_512.png"
"png/weread_512.png"
], ],
identifier: "com.tw93.weread", identifier: "pake-f9751d",
active: true, active: true,
category: "DeveloperTool", category: "DeveloperTool",
copyright: "", copyright: "",
@@ -1951,10 +1982,7 @@ var tauri = {
"librsvg2-dev", "librsvg2-dev",
"gnome-video-effects", "gnome-video-effects",
"gnome-video-effects-extra" "gnome-video-effects-extra"
], ]
files: {
"/usr/share/applications/com-tw93-weread.desktop": "assets/com-tw93-weread.desktop"
}
}, },
externalBin: [ externalBin: [
], ],
@@ -1963,8 +1991,7 @@ var tauri = {
], ],
shortDescription: "", shortDescription: "",
targets: [ targets: [
"deb", "deb"
"appimage"
] ]
} }
}; };
@@ -2134,19 +2161,24 @@ class LinuxBuilder {
else { else {
arch = process.arch; arch = process.arch;
} }
const debName = `${name}_${tauriConf.package.version}_${arch}.deb`; if (options.targets === "deb" || options.targets === "all") {
const appPath = this.getBuildAppPath(npmDirectory, "deb", debName); const debName = `${name}_${tauriConf.package.version}_${arch}.deb`;
const distPath = path.resolve(`${name}.deb`); const appPath = this.getBuildAppPath(npmDirectory, "deb", debName);
yield fs.copyFile(appPath, distPath); const distPath = path.resolve(`${name}.deb`);
yield fs.unlink(appPath); yield fs.copyFile(appPath, distPath);
const appImageName = `${name}_${tauriConf.package.version}_${arch}.AppImage`; yield fs.unlink(appPath);
const appImagePath = this.getBuildAppPath(npmDirectory, "appimage", appImageName); logger.success('Build Deb success!');
const distAppPath = path.resolve(`${name}.AppImage`); logger.success('You can find the deb app installer in', distPath);
yield fs.copyFile(appImagePath, distAppPath); }
yield fs.unlink(appImagePath); if (options.targets === "appimage" || options.targets === "all") {
logger.success('Build success!'); const appImageName = `${name}_${tauriConf.package.version}_${arch}.AppImage`;
logger.success('You can find the deb app installer in', distPath); const appImagePath = this.getBuildAppPath(npmDirectory, "appimage", appImageName);
logger.success('You can find the AppImage app installer in', distAppPath); 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) { getBuildAppPath(npmDirectory, packageType, packageName) {
@@ -2170,7 +2202,7 @@ class BuilderFactory {
} }
var name = "pake-cli"; 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 description = "🤱🏻 Turn any webpage into a desktop app with Rust. 🤱🏻 很简单的用 Rust 打包网页生成很小的桌面 App。";
var engines = { var engines = {
node: ">=16.0.0" node: ">=16.0.0"
@@ -2206,7 +2238,7 @@ var scripts = {
build: "npm run tauri build --release", build: "npm run tauri build --release",
"build:mac": "npm run tauri build -- --target universal-apple-darwin", "build:mac": "npm run tauri build -- --target universal-apple-darwin",
"build:all-unix": "chmod +x ./script/build.sh && ./script/build.sh", "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", tauri: "tauri",
cli: "rollup -c rollup.config.js --watch", cli: "rollup -c rollup.config.js --watch",
"cli:build": "cross-env NODE_ENV=production rollup -c rollup.config.js", "cli:build": "cross-env NODE_ENV=production rollup -c rollup.config.js",
@@ -2286,6 +2318,7 @@ program
.option('-r, --no-resizable', 'whether the window can be resizable', DEFAULT_PAKE_OPTIONS.resizable) .option('-r, --no-resizable', 'whether the window can be resizable', DEFAULT_PAKE_OPTIONS.resizable)
.option('-d, --debug', 'debug', DEFAULT_PAKE_OPTIONS.debug) .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('-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* () { .action((url, options) => __awaiter(void 0, void 0, void 0, function* () {
yield checkUpdateTips(); yield checkUpdateTips();
if (!url) { if (!url) {

View File

@@ -1,6 +1,6 @@
{ {
"name": "pake-cli", "name": "pake-cli",
"version": "1.2.7", "version": "1.2.8",
"description": "🤱🏻 Turn any webpage into a desktop app with Rust. 🤱🏻 很简单的用 Rust 打包网页生成很小的桌面 App。", "description": "🤱🏻 Turn any webpage into a desktop app with Rust. 🤱🏻 很简单的用 Rust 打包网页生成很小的桌面 App。",
"engines": { "engines": {
"node": ">=16.0.0" "node": ">=16.0.0"

View File

@@ -1,30 +1,54 @@
{ {
"package": { "package": {
"productName": "WeRead", "productName": "baidu",
"version": "1.0.0" "version": "1.0.0"
}, },
"tauri": { "tauri": {
"windows": [ "windows": [
{ {
"url": "https://weread.qq.com/", "url": "https://www.baidu.com",
"transparent": true, "transparent": false,
"fullscreen": false, "fullscreen": false,
"width": 1200, "width": 1200,
"height": 780, "height": 780,
"resizable": true "resizable": true
} }
], ],
"security": { "security": {
"csp": null "csp": null
}, },
"updater": { "updater": {
"active": false "active": false
} },
}, "bundle": {
"build": { "icon": [
"devPath": "../dist", "/home/tlntin/data/code/rust_study/pake-tw93/Pake/src-tauri/png/icon_512.png"
"distDir": "../dist", ],
"beforeBuildCommand": "", "identifier": "pake-f9751d",
"beforeDevCommand": "" "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"
]
}
}
} }

View File

@@ -1,31 +1,34 @@
{ {
"tauri": { "tauri": {
"bundle": { "bundle": {
"icon": ["png/weread_512.png"], "icon": [
"identifier": "com.tw93.weread", "/home/tlntin/data/code/rust_study/pake-tw93/Pake/src-tauri/png/icon_512.png"
"active": true, ],
"category": "DeveloperTool", "identifier": "pake-f9751d",
"copyright": "", "active": true,
"deb": { "category": "DeveloperTool",
"depends": [ "copyright": "",
"libwebkit2gtk-4.0-dev", "deb": {
"build-essential", "depends": [
"curl", "libwebkit2gtk-4.0-dev",
"wget", "build-essential",
"libssl-dev", "curl",
"libgtk-3-dev", "wget",
"libayatana-appindicator3-dev", "libssl-dev",
"librsvg2-dev", "libgtk-3-dev",
"gnome-video-effects", "libayatana-appindicator3-dev",
"gnome-video-effects-extra" "librsvg2-dev",
], "gnome-video-effects",
"files": {"/usr/share/applications/com-tw93-weread.desktop": "assets/com-tw93-weread.desktop"} "gnome-video-effects-extra"
}, ]
"externalBin": [], },
"longDescription": "", "externalBin": [],
"resources": [], "longDescription": "",
"shortDescription": "", "resources": [],
"targets": ["deb", "appimage"] "shortDescription": "",
} "targets": [
} "deb"
]
}
}
} }