🎨 Fix the packaging issue for Linux and Windows
This commit is contained in:
40
bin/builders/BaseBuilder.ts
vendored
40
bin/builders/BaseBuilder.ts
vendored
@@ -57,50 +57,50 @@ export default abstract class BaseBuilder {
|
||||
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;
|
||||
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 appPath = this.getBuildAppPath(npmDirectory, fileName);
|
||||
const distPath = path.resolve(`${name}.${this.getExtension()}`);
|
||||
const fileType = this.getFileType(target);
|
||||
const appPath = this.getBuildAppPath(npmDirectory, fileName, fileType);
|
||||
const distPath = path.resolve(`${name}.${fileType}`);
|
||||
await fsExtra.copy(appPath, distPath);
|
||||
await fsExtra.remove(appPath);
|
||||
logger.success('✔ Build success!');
|
||||
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 getExtension(): string;
|
||||
|
||||
protected getArch() {
|
||||
return process.arch === "x64" ? "amd64" : process.arch;
|
||||
}
|
||||
|
||||
protected getBuildCommand(): string {
|
||||
return "npm run build";
|
||||
}
|
||||
|
||||
protected runBuildCommand() {
|
||||
const spinner = getSpinner('Building app...');
|
||||
setTimeout(() => spinner.stop(), 3000);
|
||||
return shellExec(`cd ${npmDirectory} && ${this.getBuildCommand()}`);
|
||||
}
|
||||
|
||||
protected getBasePath(): string {
|
||||
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(
|
||||
npmDirectory,
|
||||
this.getBasePath(),
|
||||
this.getExtension().toLowerCase(),
|
||||
`${fileName}.${this.getExtension()}`
|
||||
fileType,
|
||||
`${fileName}.${fileType}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
28
bin/builders/LinuxBuilder.ts
vendored
28
bin/builders/LinuxBuilder.ts
vendored
@@ -3,29 +3,31 @@ import { PakeAppOptions } from '@/types';
|
||||
import tauriConfig from '@/helpers/tauriConfig';
|
||||
|
||||
export default class LinuxBuilder extends BaseBuilder {
|
||||
|
||||
constructor(options: PakeAppOptions) {
|
||||
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) {
|
||||
const targetTypes = ['deb', 'appimage'];
|
||||
for (const type of targetTypes) {
|
||||
if (this.options.targets === type || this.options.targets === "all") {
|
||||
await this.buildAndCopy(url);
|
||||
const targetTypes = ["deb", "appimage"];
|
||||
for (const target of targetTypes) {
|
||||
if (this.options.targets === target || this.options.targets === "all") {
|
||||
await this.buildAndCopy(url, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getFileName(): string {
|
||||
const { name } = this.options;
|
||||
const arch = this.getArch();
|
||||
return `${name}_${tauriConfig.package.version}_${arch}`;
|
||||
}
|
||||
|
||||
getExtension(): string {
|
||||
if (this.options.targets === 'appimage') {
|
||||
protected getFileType(target: string): string {
|
||||
if (target === 'appimage') {
|
||||
return 'AppImage';
|
||||
}
|
||||
return this.options.targets;
|
||||
return super.getFileType(target);
|
||||
}
|
||||
}
|
||||
|
||||
9
bin/builders/MacBuilder.ts
vendored
9
bin/builders/MacBuilder.ts
vendored
@@ -5,10 +5,7 @@ import BaseBuilder from './BaseBuilder';
|
||||
export default class MacBuilder extends BaseBuilder {
|
||||
constructor(options: PakeAppOptions) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
async build(url: string) {
|
||||
await this.buildAndCopy(url);
|
||||
this.options.targets = "dmg";
|
||||
}
|
||||
|
||||
getFileName(): string {
|
||||
@@ -22,10 +19,6 @@ export default class MacBuilder extends BaseBuilder {
|
||||
return `${name}_${tauriConfig.package.version}_${arch}`;
|
||||
}
|
||||
|
||||
getExtension(): string {
|
||||
return "dmg";
|
||||
}
|
||||
|
||||
protected getBuildCommand(): string {
|
||||
return this.options.multiArch ? 'npm run build:mac' : super.getBuildCommand();
|
||||
}
|
||||
|
||||
11
bin/builders/WinBuilder.ts
vendored
11
bin/builders/WinBuilder.ts
vendored
@@ -5,20 +5,13 @@ import tauriConfig from '@/helpers/tauriConfig';
|
||||
export default class WinBuilder extends BaseBuilder {
|
||||
constructor(options: PakeAppOptions) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
async build(url: string) {
|
||||
await this.buildAndCopy(url);
|
||||
this.options.targets = "msi";
|
||||
}
|
||||
|
||||
getFileName(): string {
|
||||
const { name } = this.options;
|
||||
const arch = this.getArch();
|
||||
const { arch } = process;
|
||||
const language = tauriConfig.tauri.bundle.windows.wix.language[0];
|
||||
return `${name}_${tauriConfig.package.version}_${arch}_${language}`;
|
||||
}
|
||||
|
||||
getExtension(): string {
|
||||
return "msi";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user