更新Linux平台pake-cli
This commit is contained in:
6
bin/builders/BuilderFactory.ts
vendored
6
bin/builders/BuilderFactory.ts
vendored
@@ -1,7 +1,8 @@
|
||||
import { IS_MAC, IS_WIN } from '@/utils/platform.js';
|
||||
import { IS_MAC, IS_WIN, IS_LINUX } from '@/utils/platform.js';
|
||||
import { IBuilder } from './base.js';
|
||||
import MacBuilder from './MacBuilder.js';
|
||||
import WinBuilder from './WinBulider.js';
|
||||
import LinuxBuilder from './LinuxBuilder.js';
|
||||
|
||||
export default class BuilderFactory {
|
||||
static create(): IBuilder {
|
||||
@@ -12,6 +13,9 @@ export default class BuilderFactory {
|
||||
if (IS_WIN) {
|
||||
return new WinBuilder();
|
||||
}
|
||||
if (IS_LINUX) {
|
||||
return new LinuxBuilder();
|
||||
}
|
||||
throw new Error('The current system does not support!!');
|
||||
}
|
||||
}
|
||||
|
||||
87
bin/builders/LinuxBuilder.ts
vendored
87
bin/builders/LinuxBuilder.ts
vendored
@@ -0,0 +1,87 @@
|
||||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
import prompts from 'prompts';
|
||||
import { checkRustInstalled, installRust } from '@/helpers/rust.js';
|
||||
import { PakeAppOptions } from '@/types.js';
|
||||
import { IBuilder } from './base.js';
|
||||
import { shellExec } from '@/utils/shell.js';
|
||||
// @ts-expect-error 加上resolveJsonModule rollup会打包报错
|
||||
// import tauriConf from '../../src-tauri/tauri.windows.conf.json';
|
||||
import tauriConf from './tauriConf.js';
|
||||
|
||||
import { fileURLToPath } from 'url';
|
||||
import logger from '@/options/logger.js';
|
||||
import { mergeTauriConfig } from './common.js';
|
||||
import { npmDirectory } from '@/utils/dir.js';
|
||||
|
||||
export default class LinuxBuilder implements IBuilder {
|
||||
async prepare() {
|
||||
logger.info(
|
||||
'To build the Windows app, you need to install Rust and VS Build Tools.'
|
||||
);
|
||||
logger.info(
|
||||
'See more in https://tauri.app/v1/guides/getting-started/prerequisites#installing\n'
|
||||
);
|
||||
if (checkRustInstalled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await prompts({
|
||||
type: 'confirm',
|
||||
message: 'We detected that you have not installed Rust. Install it now?',
|
||||
name: 'value',
|
||||
});
|
||||
|
||||
if (res.value) {
|
||||
// TODO 国内有可能会超时
|
||||
await installRust();
|
||||
} else {
|
||||
logger.error('Error: Pake needs Rust to package your webapp!!!');
|
||||
process.exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
async build(url: string, options: PakeAppOptions) {
|
||||
logger.debug('PakeAppOptions', options);
|
||||
const { name } = options;
|
||||
|
||||
await mergeTauriConfig(url, options, tauriConf);
|
||||
// write desktop
|
||||
const assertSrc = `src-tauri/assets/${name}.desktop`;
|
||||
const assertPath = path.join(npmDirectory, assertSrc);
|
||||
const desktopStr = `
|
||||
[Desktop Entry]
|
||||
Encoding=UTF-8
|
||||
Categories=Office
|
||||
Exec=${name}
|
||||
Icon=${name}
|
||||
Name=${name}
|
||||
StartupNotify=true
|
||||
Terminal=false
|
||||
Type=Application
|
||||
`
|
||||
await fs.writeFile(assertPath, desktopStr);
|
||||
const _ = await shellExec(`cd ${npmDirectory} && npm install && npm run build:release`);
|
||||
let arch = "";
|
||||
if (process.arch === "x64") {
|
||||
arch = "amd64";
|
||||
} else {
|
||||
arch = process.arch;
|
||||
}
|
||||
const debName = `${name}_${tauriConf.package.version}_${arch}.deb`;
|
||||
const appPath = this.getBuildedAppPath(npmDirectory, debName);
|
||||
const distPath = path.resolve(`${name}.deb`);
|
||||
await fs.copyFile(appPath, distPath);
|
||||
await fs.unlink(appPath);
|
||||
logger.success('Build success!');
|
||||
logger.success('You can find the app installer in', distPath);
|
||||
}
|
||||
|
||||
getBuildedAppPath(npmDirectory: string, dmgName: string) {
|
||||
return path.join(
|
||||
npmDirectory,
|
||||
'src-tauri/target/release/bundle/deb',
|
||||
dmgName
|
||||
);
|
||||
}
|
||||
}
|
||||
16
bin/builders/common.ts
vendored
16
bin/builders/common.ts
vendored
@@ -44,8 +44,18 @@ export async function mergeTauriConfig(
|
||||
if (process.platform === "win32") {
|
||||
const ico_path = path.join(npmDirectory, 'src-tauri/png/weread_32.ico');
|
||||
await fs.copyFile(options.icon, ico_path);
|
||||
|
||||
}
|
||||
if (process.platform === "linux") {
|
||||
const installSrc = `/usr/share/applications/${name}.desktop`;
|
||||
const assertSrc = `src-tauri/assets/${name}.desktop`;
|
||||
const assertPath = path.join(npmDirectory, assertSrc);
|
||||
tauriConf.tauri.bundle.deb.files = {
|
||||
[installSrc]: assertPath
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
let configPath = "";
|
||||
switch (process.platform) {
|
||||
case "win32": {
|
||||
@@ -56,6 +66,10 @@ export async function mergeTauriConfig(
|
||||
configPath = path.join(npmDirectory, 'src-tauri/tauri.macos.conf.json');
|
||||
break;
|
||||
}
|
||||
case "linux": {
|
||||
configPath = path.join(npmDirectory, 'src-tauri/tauri.linux.conf.json');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let bundleConf = {tauri: {bundle: tauriConf.tauri.bundle}};
|
||||
|
||||
5
bin/builders/tauriConf.js
vendored
5
bin/builders/tauriConf.js
vendored
@@ -1,6 +1,7 @@
|
||||
import CommonConf from '../../src-tauri/tauri.conf.json';
|
||||
import WinConf from '../../src-tauri/tauri.windows.conf.json';
|
||||
import MacConf from '../../src-tauri/tauri.macos.conf.json';
|
||||
import LinuxConf from '../../src-tauri/tauri.linux.conf.json';
|
||||
|
||||
let tauriConf = {
|
||||
package: CommonConf.package,
|
||||
@@ -15,6 +16,10 @@ switch (process.platform) {
|
||||
tauriConf.tauri.bundle = MacConf.tauri.bundle;
|
||||
break;
|
||||
}
|
||||
case "linux": {
|
||||
tauriConf.tauri.bundle = LinuxConf.tauri.bundle;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
export default tauriConf;
|
||||
|
||||
Reference in New Issue
Block a user