更新pake-cli,增加Linux端targets选项,增加打包本地文件功能

This commit is contained in:
Tlntin
2022-12-29 11:05:25 +08:00
parent 6d69b1144c
commit c7717ffda5
8 changed files with 647 additions and 29 deletions

View File

@@ -54,20 +54,33 @@ export default class LinuxBuilder implements IBuilder {
arch = process.arch;
}
const debName = `${name}_${tauriConf.package.version}_${arch}.deb`;
const appPath = this.getBuildedAppPath(npmDirectory, "deb", debName);
const debPath = this.getBuildedAppPath(npmDirectory, "deb", debName);
const distPath = path.resolve(`${name}.deb`);
await fs.copyFile(appPath, distPath);
await fs.unlink(appPath);
// 增加文件是否存在验证再决定是否copy文件
const debExists = await fs.stat(debPath)
.then(() => true)
.catch(() => false);
if (debExists) {
await fs.copyFile(debPath, distPath);
await fs.unlink(debPath);
logger.success('Build success!');
logger.success('You can find the deb app installer in', distPath);
}
const appImageName = `${name}_${tauriConf.package.version}_${arch}.AppImage`;
const appImagePath = this.getBuildedAppPath(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);
const appExists = await fs.stat(appImagePath)
.then(() => true)
.catch(() => false);
if (appExists) {
await fs.copyFile(appImagePath, distAppPath);
await fs.unlink(appImagePath);
logger.success('Build success!');
logger.success('You can find the Appimage app installer in', distAppPath);
}
}
getBuildedAppPath(npmDirectory: string,packageType: string, packageName: string) {

View File

@@ -75,15 +75,17 @@ export async function mergeTauriConfig(
// } else {
// fs.rm
// }
const url_exists = await fs.stat(url)
let file_path = url.slice(8, url.length);
const url_exists = await fs.stat(file_path)
.then(() => true)
.catch(() => false);
if (url_exists) {
logger.warn("you input may a local file");
tauriConf.pake.windows[0].url_type = "local";
const file_name = path.basename(url);
const file_name = path.basename(file_path);
// const dir_name = path.dirname(url);
const url_path = path.join("dist/", file_name);
await fs.copyFile(url, url_path);
await fs.copyFile(file_path, url_path);
tauriConf.pake.windows[0].url = file_name;
tauriConf.pake.windows[0].url_type = "local";
} else {
@@ -160,6 +162,17 @@ export async function mergeTauriConfig(
}
}
// 处理targets 暂时只对linux开放
if (process.platform === "linux") {
if (options.targets.length > 0) {
if (options.targets === "deb" || options.targets === "appimage" || options.targets === "all") {
tauriConf.tauri.bundle.targets = [options.targets];
}
}
} else {
tauriConf.tauri.bundle.targets = ["deb"];
}
tauriConf.package.productName = name;
tauriConf.tauri.bundle.identifier = identifier;

7
bin/cli.ts vendored
View File

@@ -9,7 +9,6 @@ import BuilderFactory from './builders/BuilderFactory.js';
import { checkUpdateTips } from './helpers/updater.js';
// @ts-expect-error
import packageJson from '../package.json';
import logger from './options/logger.js';
program.version(packageJson.version).description('A cli application can package a web page to desktop application.');
@@ -27,6 +26,10 @@ program
.option('--show-menu', 'show menu in app', DEFAULT_PAKE_OPTIONS.showMenu)
.option('--show-system-tray', 'show system tray in app', DEFAULT_PAKE_OPTIONS.showSystemTray)
.option('--system-tray-icon <string>', 'custom system tray icon', DEFAULT_PAKE_OPTIONS.systemTrayIcon)
.option(
'--targets <string>',
'only for linux, default is "deb", option "appaimge" or "all"(deb & appimage)',
DEFAULT_PAKE_OPTIONS.targets)
// .option('--iter-copy-file',
// 'copy all static file to pake app when url is a static file',
// DEFAULT_PAKE_OPTIONS.iter_copy_file)
@@ -48,7 +51,7 @@ program
await builder.prepare();
const appOptions = await handleInputOptions(options, url);
logger.warn(JSON.stringify(appOptions, null, 4));
// logger.warn(JSON.stringify(appOptions, null, 4));
builder.build(url, appOptions);
});

1
bin/defaults.ts vendored
View File

@@ -10,6 +10,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {
userAgent: '',
showMenu: false,
showSystemTray: false,
targets: '',
// iter_copy_file: false,
systemTrayIcon: '',
debug: false,

2
bin/types.ts vendored
View File

@@ -34,6 +34,8 @@ export interface PakeCliOptions {
// /** 递归拷贝当url为本地文件路径时候将文件所在文件夹下面的所有子文件都拷贝到pake静态文件夹默认不开启 */
// iter_copy_file: false;
// 包输出产物对linux用户有效默认为deb可选appimage, 或者all即同时输出deb和all;
targets: string;
/** 调试模式,会输出更多日志 */
debug: boolean;

10
bin/utils/validate.ts vendored
View File

@@ -10,9 +10,9 @@ export function validateNumberInput(value: string) {
}
export function validateUrlInput(url: string) {
try {
return normalizeUrl(url);
} catch (error) {
throw new Commander.InvalidArgumentError(error.message);
}
try {
return normalizeUrl(url)
} catch (error) {
throw new Commander.InvalidArgumentError(error.message);
}
}

49
dist/cli.js vendored
View File

@@ -50,6 +50,7 @@ const DEFAULT_PAKE_OPTIONS = {
userAgent: '',
showMenu: false,
showSystemTray: false,
targets: '',
// iter_copy_file: false,
systemTrayIcon: '',
debug: false,
@@ -1669,15 +1670,17 @@ function mergeTauriConfig(url, options, tauriConf) {
// } else {
// fs.rm
// }
const url_exists = yield fs.stat(url)
let file_path = url.slice(8, url.length);
const url_exists = yield fs.stat(file_path)
.then(() => true)
.catch(() => false);
if (url_exists) {
logger.warn("you input may a local file");
tauriConf.pake.windows[0].url_type = "local";
const file_name = path.basename(url);
const file_name = path.basename(file_path);
// const dir_name = path.dirname(url);
const url_path = path.join("dist/", file_name);
yield fs.copyFile(url, url_path);
yield fs.copyFile(file_path, url_path);
tauriConf.pake.windows[0].url = file_name;
tauriConf.pake.windows[0].url_type = "local";
}
@@ -1743,6 +1746,17 @@ function mergeTauriConfig(url, options, tauriConf) {
tauriConf.pake.system_tray.macos = false;
}
}
// 处理targets 暂时只对linux开放
if (process.platform === "linux") {
if (options.targets.length > 0) {
if (options.targets === "deb" || options.targets === "appimage" || options.targets === "all") {
tauriConf.tauri.bundle.targets = [options.targets];
}
}
}
else {
tauriConf.tauri.bundle.targets = ["deb"];
}
tauriConf.package.productName = name;
tauriConf.tauri.bundle.identifier = identifier;
// 处理应用图标
@@ -2313,18 +2327,30 @@ class LinuxBuilder {
arch = process.arch;
}
const debName = `${name}_${tauriConf.package.version}_${arch}.deb`;
const appPath = this.getBuildedAppPath(npmDirectory, "deb", debName);
const debPath = this.getBuildedAppPath(npmDirectory, "deb", debName);
const distPath = path.resolve(`${name}.deb`);
yield fs.copyFile(appPath, distPath);
yield fs.unlink(appPath);
// 增加文件是否存在验证再决定是否copy文件
const debExists = yield fs.stat(debPath)
.then(() => true)
.catch(() => false);
if (debExists) {
yield fs.copyFile(debPath, distPath);
yield fs.unlink(debPath);
logger.success('Build success!');
logger.success('You can find the deb app installer in', distPath);
}
const appImageName = `${name}_${tauriConf.package.version}_${arch}.AppImage`;
const appImagePath = this.getBuildedAppPath(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);
const appExists = yield fs.stat(appImagePath)
.then(() => true)
.catch(() => false);
if (appExists) {
yield fs.copyFile(appImagePath, distAppPath);
yield fs.unlink(appImagePath);
logger.success('Build success!');
logger.success('You can find the Appimage app installer in', distAppPath);
}
});
}
getBuildedAppPath(npmDirectory, packageType, packageName) {
@@ -2466,6 +2492,7 @@ program
.option('--show-menu', 'show menu in app', DEFAULT_PAKE_OPTIONS.showMenu)
.option('--show-system-tray', 'show system tray in app', DEFAULT_PAKE_OPTIONS.showSystemTray)
.option('--system-tray-icon <string>', 'custom system tray icon', DEFAULT_PAKE_OPTIONS.systemTrayIcon)
.option('--targets <string>', 'only for linux, default is "deb", option "appaimge" or "all"(deb & appimage)', DEFAULT_PAKE_OPTIONS.targets)
// .option('--iter-copy-file',
// 'copy all static file to pake app when url is a static file',
// DEFAULT_PAKE_OPTIONS.iter_copy_file)

559
dist/index.html vendored Normal file

File diff suppressed because one or more lines are too long