diff --git a/bin/builders/LinuxBuilder.ts b/bin/builders/LinuxBuilder.ts index cec50b1..de8920a 100644 --- a/bin/builders/LinuxBuilder.ts +++ b/bin/builders/LinuxBuilder.ts @@ -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) { diff --git a/bin/builders/common.ts b/bin/builders/common.ts index 212e330..aba7cbf 100644 --- a/bin/builders/common.ts +++ b/bin/builders/common.ts @@ -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; diff --git a/bin/cli.ts b/bin/cli.ts index 9c7eacf..312dc44 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -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 ', 'custom system tray icon', DEFAULT_PAKE_OPTIONS.systemTrayIcon) + .option( + '--targets ', + '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); }); diff --git a/bin/defaults.ts b/bin/defaults.ts index c28cdb5..3804864 100644 --- a/bin/defaults.ts +++ b/bin/defaults.ts @@ -10,6 +10,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = { userAgent: '', showMenu: false, showSystemTray: false, + targets: '', // iter_copy_file: false, systemTrayIcon: '', debug: false, diff --git a/bin/types.ts b/bin/types.ts index d0ec34e..6725079 100644 --- a/bin/types.ts +++ b/bin/types.ts @@ -34,6 +34,8 @@ export interface PakeCliOptions { // /** 递归拷贝,当url为本地文件路径时候,将文件所在文件夹下面的所有子文件都拷贝到pake静态文件夹,默认不开启 */ // iter_copy_file: false; + // 包输出产物,对linux用户有效,默认为deb,可选appimage, 或者all(即同时输出deb和all); + targets: string; /** 调试模式,会输出更多日志 */ debug: boolean; diff --git a/bin/utils/validate.ts b/bin/utils/validate.ts index a97821c..39b09f8 100644 --- a/bin/utils/validate.ts +++ b/bin/utils/validate.ts @@ -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); + } } diff --git a/dist/cli.js b/dist/cli.js index 4f5aafa..615dd30 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -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 ', 'custom system tray icon', DEFAULT_PAKE_OPTIONS.systemTrayIcon) + .option('--targets ', '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) diff --git a/dist/index.html b/dist/index.html new file mode 100644 index 0000000..8a32f1a --- /dev/null +++ b/dist/index.html @@ -0,0 +1,559 @@ +AriaNg \ No newline at end of file