更新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;
|
arch = process.arch;
|
||||||
}
|
}
|
||||||
const debName = `${name}_${tauriConf.package.version}_${arch}.deb`;
|
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`);
|
const distPath = path.resolve(`${name}.deb`);
|
||||||
await fs.copyFile(appPath, distPath);
|
// 增加文件是否存在验证,再决定是否copy文件
|
||||||
await fs.unlink(appPath);
|
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 appImageName = `${name}_${tauriConf.package.version}_${arch}.AppImage`;
|
||||||
const appImagePath = this.getBuildedAppPath(npmDirectory, "appimage", appImageName);
|
const appImagePath = this.getBuildedAppPath(npmDirectory, "appimage", appImageName);
|
||||||
const distAppPath = path.resolve(`${name}.AppImage`);
|
const distAppPath = path.resolve(`${name}.AppImage`);
|
||||||
await fs.copyFile(appImagePath, distAppPath);
|
|
||||||
await fs.unlink(appImagePath);
|
const appExists = await fs.stat(appImagePath)
|
||||||
logger.success('Build success!');
|
.then(() => true)
|
||||||
logger.success('You can find the deb app installer in', distPath);
|
.catch(() => false);
|
||||||
logger.success('You can find the Appimage app installer in', distAppPath);
|
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) {
|
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 {
|
// } else {
|
||||||
// fs.rm
|
// 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)
|
.then(() => true)
|
||||||
.catch(() => false);
|
.catch(() => false);
|
||||||
if (url_exists) {
|
if (url_exists) {
|
||||||
|
logger.warn("you input may a local file");
|
||||||
tauriConf.pake.windows[0].url_type = "local";
|
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 dir_name = path.dirname(url);
|
||||||
const url_path = path.join("dist/", file_name);
|
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 = file_name;
|
||||||
tauriConf.pake.windows[0].url_type = "local";
|
tauriConf.pake.windows[0].url_type = "local";
|
||||||
} else {
|
} 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.package.productName = name;
|
||||||
tauriConf.tauri.bundle.identifier = identifier;
|
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';
|
import { checkUpdateTips } from './helpers/updater.js';
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
import packageJson from '../package.json';
|
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.');
|
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-menu', 'show menu in app', DEFAULT_PAKE_OPTIONS.showMenu)
|
||||||
.option('--show-system-tray', 'show system tray in app', DEFAULT_PAKE_OPTIONS.showSystemTray)
|
.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('--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',
|
// .option('--iter-copy-file',
|
||||||
// 'copy all static file to pake app when url is a static file',
|
// 'copy all static file to pake app when url is a static file',
|
||||||
// DEFAULT_PAKE_OPTIONS.iter_copy_file)
|
// DEFAULT_PAKE_OPTIONS.iter_copy_file)
|
||||||
@@ -48,7 +51,7 @@ program
|
|||||||
await builder.prepare();
|
await builder.prepare();
|
||||||
|
|
||||||
const appOptions = await handleInputOptions(options, url);
|
const appOptions = await handleInputOptions(options, url);
|
||||||
logger.warn(JSON.stringify(appOptions, null, 4));
|
// logger.warn(JSON.stringify(appOptions, null, 4));
|
||||||
builder.build(url, appOptions);
|
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: '',
|
userAgent: '',
|
||||||
showMenu: false,
|
showMenu: false,
|
||||||
showSystemTray: false,
|
showSystemTray: false,
|
||||||
|
targets: '',
|
||||||
// iter_copy_file: false,
|
// iter_copy_file: false,
|
||||||
systemTrayIcon: '',
|
systemTrayIcon: '',
|
||||||
debug: false,
|
debug: false,
|
||||||
|
|||||||
2
bin/types.ts
vendored
2
bin/types.ts
vendored
@@ -34,6 +34,8 @@ export interface PakeCliOptions {
|
|||||||
|
|
||||||
// /** 递归拷贝,当url为本地文件路径时候,将文件所在文件夹下面的所有子文件都拷贝到pake静态文件夹,默认不开启 */
|
// /** 递归拷贝,当url为本地文件路径时候,将文件所在文件夹下面的所有子文件都拷贝到pake静态文件夹,默认不开启 */
|
||||||
// iter_copy_file: false;
|
// iter_copy_file: false;
|
||||||
|
// 包输出产物,对linux用户有效,默认为deb,可选appimage, 或者all(即同时输出deb和all);
|
||||||
|
targets: string;
|
||||||
|
|
||||||
/** 调试模式,会输出更多日志 */
|
/** 调试模式,会输出更多日志 */
|
||||||
debug: boolean;
|
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) {
|
export function validateUrlInput(url: string) {
|
||||||
try {
|
try {
|
||||||
return normalizeUrl(url);
|
return normalizeUrl(url)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Commander.InvalidArgumentError(error.message);
|
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: '',
|
userAgent: '',
|
||||||
showMenu: false,
|
showMenu: false,
|
||||||
showSystemTray: false,
|
showSystemTray: false,
|
||||||
|
targets: '',
|
||||||
// iter_copy_file: false,
|
// iter_copy_file: false,
|
||||||
systemTrayIcon: '',
|
systemTrayIcon: '',
|
||||||
debug: false,
|
debug: false,
|
||||||
@@ -1669,15 +1670,17 @@ function mergeTauriConfig(url, options, tauriConf) {
|
|||||||
// } else {
|
// } else {
|
||||||
// fs.rm
|
// 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)
|
.then(() => true)
|
||||||
.catch(() => false);
|
.catch(() => false);
|
||||||
if (url_exists) {
|
if (url_exists) {
|
||||||
|
logger.warn("you input may a local file");
|
||||||
tauriConf.pake.windows[0].url_type = "local";
|
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 dir_name = path.dirname(url);
|
||||||
const url_path = path.join("dist/", file_name);
|
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 = file_name;
|
||||||
tauriConf.pake.windows[0].url_type = "local";
|
tauriConf.pake.windows[0].url_type = "local";
|
||||||
}
|
}
|
||||||
@@ -1743,6 +1746,17 @@ function mergeTauriConfig(url, options, tauriConf) {
|
|||||||
tauriConf.pake.system_tray.macos = false;
|
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.package.productName = name;
|
||||||
tauriConf.tauri.bundle.identifier = identifier;
|
tauriConf.tauri.bundle.identifier = identifier;
|
||||||
// 处理应用图标
|
// 处理应用图标
|
||||||
@@ -2313,18 +2327,30 @@ class LinuxBuilder {
|
|||||||
arch = process.arch;
|
arch = process.arch;
|
||||||
}
|
}
|
||||||
const debName = `${name}_${tauriConf.package.version}_${arch}.deb`;
|
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`);
|
const distPath = path.resolve(`${name}.deb`);
|
||||||
yield fs.copyFile(appPath, distPath);
|
// 增加文件是否存在验证,再决定是否copy文件
|
||||||
yield fs.unlink(appPath);
|
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 appImageName = `${name}_${tauriConf.package.version}_${arch}.AppImage`;
|
||||||
const appImagePath = this.getBuildedAppPath(npmDirectory, "appimage", appImageName);
|
const appImagePath = this.getBuildedAppPath(npmDirectory, "appimage", appImageName);
|
||||||
const distAppPath = path.resolve(`${name}.AppImage`);
|
const distAppPath = path.resolve(`${name}.AppImage`);
|
||||||
yield fs.copyFile(appImagePath, distAppPath);
|
const appExists = yield fs.stat(appImagePath)
|
||||||
yield fs.unlink(appImagePath);
|
.then(() => true)
|
||||||
logger.success('Build success!');
|
.catch(() => false);
|
||||||
logger.success('You can find the deb app installer in', distPath);
|
if (appExists) {
|
||||||
logger.success('You can find the Appimage app installer in', distAppPath);
|
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) {
|
getBuildedAppPath(npmDirectory, packageType, packageName) {
|
||||||
@@ -2466,6 +2492,7 @@ program
|
|||||||
.option('--show-menu', 'show menu in app', DEFAULT_PAKE_OPTIONS.showMenu)
|
.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('--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('--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',
|
// .option('--iter-copy-file',
|
||||||
// 'copy all static file to pake app when url is a static file',
|
// 'copy all static file to pake app when url is a static file',
|
||||||
// DEFAULT_PAKE_OPTIONS.iter_copy_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