更新pake-cli,增加Linux端targets选项,增加打包本地文件功能
This commit is contained in:
29
bin/builders/LinuxBuilder.ts
vendored
29
bin/builders/LinuxBuilder.ts
vendored
@@ -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) {
|
||||
|
||||
19
bin/builders/common.ts
vendored
19
bin/builders/common.ts
vendored
@@ -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
7
bin/cli.ts
vendored
@@ -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
1
bin/defaults.ts
vendored
@@ -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
2
bin/types.ts
vendored
@@ -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
10
bin/utils/validate.ts
vendored
@@ -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
49
dist/cli.js
vendored
@@ -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
559
dist/index.html
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user