🎨 Fix the packaging issue for Linux and Windows

This commit is contained in:
Tw93
2023-06-23 18:12:10 +08:00
parent 2e020a6528
commit aa0964e2c1
6 changed files with 72 additions and 90 deletions

View File

@@ -57,50 +57,50 @@ export default abstract class BaseBuilder {
spinner.succeed('Package installed.'); spinner.succeed('Package installed.');
} }
async buildAndCopy(url: string) { async build(url: string) {
await this.buildAndCopy(url, this.options.targets);
}
async buildAndCopy(url: string, target: string) {
const { name } = this.options; const { name } = this.options;
await mergeConfig(url, this.options, tauriConfig); await mergeConfig(url, this.options, tauriConfig);
await this.runBuildCommand();
// Build app
const spinner = getSpinner('Building app...');
setTimeout(() => spinner.stop(), 3000);
await shellExec(`cd ${npmDirectory} && ${this.getBuildCommand()}`);
// Copy app
const fileName = this.getFileName(); const fileName = this.getFileName();
const appPath = this.getBuildAppPath(npmDirectory, fileName); const fileType = this.getFileType(target);
const distPath = path.resolve(`${name}.${this.getExtension()}`); const appPath = this.getBuildAppPath(npmDirectory, fileName, fileType);
const distPath = path.resolve(`${name}.${fileType}`);
await fsExtra.copy(appPath, distPath); await fsExtra.copy(appPath, distPath);
await fsExtra.remove(appPath); await fsExtra.remove(appPath);
logger.success('✔ Build success!'); logger.success('✔ Build success!');
logger.success('✔ App installer located in', distPath); logger.success('✔ App installer located in', distPath);
} }
abstract build(url: string): Promise<void>; protected getFileType(target: string): string {
return target.toLowerCase();
}
abstract getFileName(): string; abstract getFileName(): string;
abstract getExtension(): string;
protected getArch() {
return process.arch === "x64" ? "amd64" : process.arch;
}
protected getBuildCommand(): string { protected getBuildCommand(): string {
return "npm run build"; return "npm run build";
} }
protected runBuildCommand() {
const spinner = getSpinner('Building app...');
setTimeout(() => spinner.stop(), 3000);
return shellExec(`cd ${npmDirectory} && ${this.getBuildCommand()}`);
}
protected getBasePath(): string { protected getBasePath(): string {
return 'src-tauri/target/release/bundle/'; return 'src-tauri/target/release/bundle/';
} }
protected getBuildAppPath(npmDirectory: string, fileName: string): string { protected getBuildAppPath(npmDirectory: string, fileName: string, fileType: string): string {
return path.join( return path.join(
npmDirectory, npmDirectory,
this.getBasePath(), this.getBasePath(),
this.getExtension().toLowerCase(), fileType,
`${fileName}.${this.getExtension()}` `${fileName}.${fileType}`
); );
} }
} }

View File

@@ -3,29 +3,31 @@ import { PakeAppOptions } from '@/types';
import tauriConfig from '@/helpers/tauriConfig'; import tauriConfig from '@/helpers/tauriConfig';
export default class LinuxBuilder extends BaseBuilder { export default class LinuxBuilder extends BaseBuilder {
constructor(options: PakeAppOptions) { constructor(options: PakeAppOptions) {
super(options); super(options);
} }
getFileName(): string {
const { name } = this.options;
const arch = process.arch === "x64" ? "amd64" : process.arch;
return `${name}_${tauriConfig.package.version}_${arch}`;
}
// Customize it, considering that there are all targets.
async build(url: string) { async build(url: string) {
const targetTypes = ['deb', 'appimage']; const targetTypes = ["deb", "appimage"];
for (const type of targetTypes) { for (const target of targetTypes) {
if (this.options.targets === type || this.options.targets === "all") { if (this.options.targets === target || this.options.targets === "all") {
await this.buildAndCopy(url); await this.buildAndCopy(url, target);
} }
} }
} }
getFileName(): string { protected getFileType(target: string): string {
const { name } = this.options; if (target === 'appimage') {
const arch = this.getArch();
return `${name}_${tauriConfig.package.version}_${arch}`;
}
getExtension(): string {
if (this.options.targets === 'appimage') {
return 'AppImage'; return 'AppImage';
} }
return this.options.targets; return super.getFileType(target);
} }
} }

View File

@@ -5,10 +5,7 @@ import BaseBuilder from './BaseBuilder';
export default class MacBuilder extends BaseBuilder { export default class MacBuilder extends BaseBuilder {
constructor(options: PakeAppOptions) { constructor(options: PakeAppOptions) {
super(options); super(options);
} this.options.targets = "dmg";
async build(url: string) {
await this.buildAndCopy(url);
} }
getFileName(): string { getFileName(): string {
@@ -22,10 +19,6 @@ export default class MacBuilder extends BaseBuilder {
return `${name}_${tauriConfig.package.version}_${arch}`; return `${name}_${tauriConfig.package.version}_${arch}`;
} }
getExtension(): string {
return "dmg";
}
protected getBuildCommand(): string { protected getBuildCommand(): string {
return this.options.multiArch ? 'npm run build:mac' : super.getBuildCommand(); return this.options.multiArch ? 'npm run build:mac' : super.getBuildCommand();
} }

View File

@@ -5,20 +5,13 @@ import tauriConfig from '@/helpers/tauriConfig';
export default class WinBuilder extends BaseBuilder { export default class WinBuilder extends BaseBuilder {
constructor(options: PakeAppOptions) { constructor(options: PakeAppOptions) {
super(options); super(options);
} this.options.targets = "msi";
async build(url: string) {
await this.buildAndCopy(url);
} }
getFileName(): string { getFileName(): string {
const { name } = this.options; const { name } = this.options;
const arch = this.getArch(); const { arch } = process;
const language = tauriConfig.tauri.bundle.windows.wix.language[0]; const language = tauriConfig.tauri.bundle.windows.wix.language[0];
return `${name}_${tauriConfig.package.version}_${arch}_${language}`; return `${name}_${tauriConfig.package.version}_${arch}_${language}`;
} }
getExtension(): string {
return "msi";
}
} }

72
dist/cli.js vendored
View File

@@ -20,7 +20,7 @@ import isUrl from 'is-url';
import fs from 'fs'; import fs from 'fs';
var name = "pake-cli"; var name = "pake-cli";
var version = "2.1.2"; var version = "2.1.3";
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"
@@ -654,43 +654,44 @@ class BaseBuilder {
} }
spinner.succeed('Package installed.'); spinner.succeed('Package installed.');
} }
async buildAndCopy(url) { async build(url) {
await this.buildAndCopy(url, this.options.targets);
}
async buildAndCopy(url, target) {
const { name } = this.options; const { name } = this.options;
await mergeConfig(url, this.options, tauriConfig); await mergeConfig(url, this.options, tauriConfig);
await this.runBuildCommand(); // Build app
const spinner = getSpinner('Building app...');
setTimeout(() => spinner.stop(), 3000);
await shellExec(`cd ${npmDirectory} && ${this.getBuildCommand()}`);
// Copy app
const fileName = this.getFileName(); const fileName = this.getFileName();
const appPath = this.getBuildAppPath(npmDirectory, fileName); const fileType = this.getFileType(target);
const distPath = path.resolve(`${name}.${this.getExtension()}`); const appPath = this.getBuildAppPath(npmDirectory, fileName, fileType);
const distPath = path.resolve(`${name}.${fileType}`);
await fsExtra.copy(appPath, distPath); await fsExtra.copy(appPath, distPath);
await fsExtra.remove(appPath); await fsExtra.remove(appPath);
logger.success('✔ Build success!'); logger.success('✔ Build success!');
logger.success('✔ App installer located in', distPath); logger.success('✔ App installer located in', distPath);
} }
getArch() { getFileType(target) {
return process.arch === "x64" ? "amd64" : process.arch; return target.toLowerCase();
} }
getBuildCommand() { getBuildCommand() {
return "npm run build"; return "npm run build";
} }
runBuildCommand() {
const spinner = getSpinner('Building app...');
setTimeout(() => spinner.stop(), 3000);
return shellExec(`cd ${npmDirectory} && ${this.getBuildCommand()}`);
}
getBasePath() { getBasePath() {
return 'src-tauri/target/release/bundle/'; return 'src-tauri/target/release/bundle/';
} }
getBuildAppPath(npmDirectory, fileName) { getBuildAppPath(npmDirectory, fileName, fileType) {
return path.join(npmDirectory, this.getBasePath(), this.getExtension().toLowerCase(), `${fileName}.${this.getExtension()}`); return path.join(npmDirectory, this.getBasePath(), fileType, `${fileName}.${fileType}`);
} }
} }
class MacBuilder extends BaseBuilder { class MacBuilder extends BaseBuilder {
constructor(options) { constructor(options) {
super(options); super(options);
} this.options.targets = "dmg";
async build(url) {
await this.buildAndCopy(url);
} }
getFileName() { getFileName() {
const { name } = this.options; const { name } = this.options;
@@ -703,9 +704,6 @@ class MacBuilder extends BaseBuilder {
} }
return `${name}_${tauriConfig.package.version}_${arch}`; return `${name}_${tauriConfig.package.version}_${arch}`;
} }
getExtension() {
return "dmg";
}
getBuildCommand() { getBuildCommand() {
return this.options.multiArch ? 'npm run build:mac' : super.getBuildCommand(); return this.options.multiArch ? 'npm run build:mac' : super.getBuildCommand();
} }
@@ -719,43 +717,39 @@ class MacBuilder extends BaseBuilder {
class WinBuilder extends BaseBuilder { class WinBuilder extends BaseBuilder {
constructor(options) { constructor(options) {
super(options); super(options);
} this.options.targets = "msi";
async build(url) {
await this.buildAndCopy(url);
} }
getFileName() { getFileName() {
const { name } = this.options; const { name } = this.options;
const arch = this.getArch(); const { arch } = process;
const language = tauriConfig.tauri.bundle.windows.wix.language[0]; const language = tauriConfig.tauri.bundle.windows.wix.language[0];
return `${name}_${tauriConfig.package.version}_${arch}_${language}`; return `${name}_${tauriConfig.package.version}_${arch}_${language}`;
} }
getExtension() {
return "msi";
}
} }
class LinuxBuilder extends BaseBuilder { class LinuxBuilder extends BaseBuilder {
constructor(options) { constructor(options) {
super(options); super(options);
} }
getFileName() {
const { name } = this.options;
const arch = process.arch === "x64" ? "amd64" : process.arch;
return `${name}_${tauriConfig.package.version}_${arch}`;
}
// Customize it, considering that there are all targets.
async build(url) { async build(url) {
const targetTypes = ['deb', 'appimage']; const targetTypes = ["deb", "appimage"];
for (const type of targetTypes) { for (const target of targetTypes) {
if (this.options.targets === type || this.options.targets === "all") { if (this.options.targets === target || this.options.targets === "all") {
await this.buildAndCopy(url); await this.buildAndCopy(url, target);
} }
} }
} }
getFileName() { getFileType(target) {
const { name } = this.options; if (target === 'appimage') {
const arch = this.getArch();
return `${name}_${tauriConfig.package.version}_${arch}`;
}
getExtension() {
if (this.options.targets === 'appimage') {
return 'AppImage'; return 'AppImage';
} }
return this.options.targets; return super.getFileType(target);
} }
} }

View File

@@ -1,6 +1,6 @@
{ {
"name": "pake-cli", "name": "pake-cli",
"version": "2.1.2", "version": "2.1.3",
"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"