🔀 merge dev
This commit is contained in:
17
bin/builders/LinuxBuilder.ts
vendored
17
bin/builders/LinuxBuilder.ts
vendored
@@ -5,6 +5,7 @@ import { checkRustInstalled, installRust } from '@/helpers/rust.js';
|
||||
import { PakeAppOptions } from '@/types.js';
|
||||
import { IBuilder } from './base.js';
|
||||
import { shellExec } from '@/utils/shell.js';
|
||||
import {isChinaDomain} from '@/utils/ip_addr.js';
|
||||
// @ts-expect-error 加上resolveJsonModule rollup会打包报错
|
||||
// import tauriConf from '../../src-tauri/tauri.windows.conf.json';
|
||||
import tauriConf from './tauriConf.js';
|
||||
@@ -44,10 +45,22 @@ export default class LinuxBuilder implements IBuilder {
|
||||
async build(url: string, options: PakeAppOptions) {
|
||||
logger.debug('PakeAppOptions', options);
|
||||
const { name } = options;
|
||||
|
||||
await mergeTauriConfig(url, options, tauriConf);
|
||||
await shellExec(`cd "${npmDirectory}" && npm install --verbose && npm run build`);
|
||||
const isChina = isChinaDomain("www.npmjs.com")
|
||||
|
||||
if (isChina) {
|
||||
// crates.io也顺便换源
|
||||
const rust_project_dir = path.join(npmDirectory, 'src-tauri', ".cargo");
|
||||
const project_cn_conf = path.join(rust_project_dir, "cn_config.bak");
|
||||
const project_conf = path.join(rust_project_dir, "config");
|
||||
fs.copyFile(project_cn_conf, project_conf);
|
||||
|
||||
const _ = await shellExec(
|
||||
`cd ${npmDirectory} && npm install --registry=https://registry.npmmirror.com && npm run build`
|
||||
);
|
||||
} else {
|
||||
const _ = await shellExec(`cd ${npmDirectory} && npm install && npm run build`);
|
||||
}
|
||||
let arch: string;
|
||||
if (process.arch === "x64") {
|
||||
arch = "amd64";
|
||||
|
||||
25
bin/builders/MacBuilder.ts
vendored
25
bin/builders/MacBuilder.ts
vendored
@@ -11,6 +11,7 @@ import tauriConf from './tauriConf.js';
|
||||
import log from 'loglevel';
|
||||
import { mergeTauriConfig } from './common.js';
|
||||
import { npmDirectory } from '@/utils/dir.js';
|
||||
import {isChinaDomain} from '@/utils/ip_addr.js';
|
||||
import logger from '@/options/logger.js';
|
||||
|
||||
export default class MacBuilder implements IBuilder {
|
||||
@@ -41,10 +42,30 @@ export default class MacBuilder implements IBuilder {
|
||||
await mergeTauriConfig(url, options, tauriConf);
|
||||
let dmgName: string;
|
||||
if (options.multiArch) {
|
||||
await shellExec(`cd "${npmDirectory}" && npm install --verbose && npm run build:mac`);
|
||||
const isChina = isChinaDomain("www.npmjs.com")
|
||||
if (isChina) {
|
||||
// crates.io也顺便换源
|
||||
const rust_project_dir = path.join(npmDirectory, 'src-tauri', ".cargo");
|
||||
const project_cn_conf = path.join(rust_project_dir, "cn_config.bak");
|
||||
const project_conf = path.join(rust_project_dir, "config");
|
||||
fs.copyFile(project_cn_conf, project_conf);
|
||||
|
||||
const _ = await shellExec(
|
||||
`cd ${npmDirectory} && npm install --registry=https://registry.npmmirror.com && npm run build:mac`
|
||||
);
|
||||
} else {
|
||||
const _ = await shellExec(`cd ${npmDirectory} && npm install && npm run build:mac`);
|
||||
}
|
||||
dmgName = `${name}_${tauriConf.package.version}_universal.dmg`;
|
||||
} else {
|
||||
await shellExec(`cd "${npmDirectory}" && npm install --verbose && npm run build`);
|
||||
const isChina = isChinaDomain("www.npmjs.com")
|
||||
if (isChina) {
|
||||
const _ = await shellExec(
|
||||
`cd ${npmDirectory} && npm install --registry=https://registry.npmmirror.com && npm run build`
|
||||
);
|
||||
} else {
|
||||
const _ = await shellExec(`cd ${npmDirectory} && npm install && npm run build`);
|
||||
}
|
||||
let arch = "x64";
|
||||
if (process.arch === "arm64") {
|
||||
arch = "aarch64";
|
||||
|
||||
16
bin/builders/WinBulider.ts
vendored
16
bin/builders/WinBulider.ts
vendored
@@ -11,6 +11,7 @@ import tauriConf from './tauriConf.js';
|
||||
import logger from '@/options/logger.js';
|
||||
import { mergeTauriConfig } from './common.js';
|
||||
import { npmDirectory } from '@/utils/dir.js';
|
||||
import {isChinaDomain} from '@/utils/ip_addr.js';
|
||||
|
||||
export default class WinBuilder implements IBuilder {
|
||||
async prepare() {
|
||||
@@ -45,7 +46,20 @@ export default class WinBuilder implements IBuilder {
|
||||
|
||||
await mergeTauriConfig(url, options, tauriConf);
|
||||
|
||||
await shellExec(`cd "${npmDirectory}" && npm install --verbose && npm run build`);
|
||||
const isChina = isChinaDomain("www.npmjs.com")
|
||||
if (isChina) {
|
||||
// crates.io也顺便换源
|
||||
const rust_project_dir = path.join(npmDirectory, 'src-tauri', ".cargo");
|
||||
const project_cn_conf = path.join(rust_project_dir, "cn_config.bak");
|
||||
const project_conf = path.join(rust_project_dir, "config");
|
||||
fs.copyFile(project_cn_conf, project_conf);
|
||||
|
||||
const _ = await shellExec(
|
||||
`cd ${npmDirectory} && npm install --registry=https://registry.npmmirror.com && npm run build`
|
||||
);
|
||||
} else {
|
||||
const _ = await shellExec(`cd ${npmDirectory} && npm install && npm run build`);
|
||||
}
|
||||
const language = tauriConf.tauri.bundle.windows.wix.language[0];
|
||||
const arch = process.arch;
|
||||
const msiName = `${name}_${tauriConf.package.version}_${arch}_${language}.msi`;
|
||||
|
||||
179
bin/builders/common.ts
vendored
179
bin/builders/common.ts
vendored
@@ -1,10 +1,12 @@
|
||||
import { PakeAppOptions } from '@/types.js';
|
||||
import prompts from 'prompts';
|
||||
import prompts, { override } from 'prompts';
|
||||
import path from 'path';
|
||||
import fs from 'fs/promises';
|
||||
import fs2 from 'fs-extra';
|
||||
import { npmDirectory } from '@/utils/dir.js';
|
||||
import logger from '@/options/logger.js';
|
||||
|
||||
|
||||
export async function promptText(message: string, initial?: string) {
|
||||
const response = await prompts({
|
||||
type: 'text',
|
||||
@@ -15,6 +17,7 @@ export async function promptText(message: string, initial?: string) {
|
||||
return response.content;
|
||||
}
|
||||
|
||||
|
||||
export async function mergeTauriConfig(
|
||||
url: string,
|
||||
options: PakeAppOptions,
|
||||
@@ -26,6 +29,11 @@ export async function mergeTauriConfig(
|
||||
fullscreen,
|
||||
transparent,
|
||||
resizable,
|
||||
userAgent,
|
||||
showMenu,
|
||||
showSystemTray,
|
||||
systemTrayIcon,
|
||||
iterCopyFile,
|
||||
identifier,
|
||||
name,
|
||||
} = options;
|
||||
@@ -56,10 +64,132 @@ export async function mergeTauriConfig(
|
||||
}
|
||||
}
|
||||
|
||||
// logger.warn(JSON.stringify(tauriConf.pake.windows, null, 4));
|
||||
Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions });
|
||||
// 判断一下url类型,是文件还是网站
|
||||
// 如果是文件,并且开启了递归拷贝功能,则需要将该文件以及所在文件夹下的所有文件拷贝到src目录下,否则只拷贝单个文件。
|
||||
|
||||
const url_exists = await fs.stat(url)
|
||||
.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 dir_name = path.dirname(url);
|
||||
if (!iterCopyFile) {
|
||||
const url_path = path.join(npmDirectory,"dist/", file_name);
|
||||
await fs.copyFile(url, url_path);
|
||||
} else {
|
||||
const old_dir = path.join(npmDirectory,"dist/");
|
||||
const new_dir = path.join(npmDirectory,"dist_bak/");
|
||||
fs2.moveSync(old_dir, new_dir, {"overwrite": true});
|
||||
fs2.copySync(dir_name, old_dir, {"overwrite": true});
|
||||
// logger.warn("dir name", dir_name);
|
||||
// 将dist_bak里面的cli.js和about_pake.html拷贝回去
|
||||
const cli_path = path.join(new_dir, "cli.js")
|
||||
const cli_path_target = path.join(old_dir, "cli.js")
|
||||
const about_pake_path = path.join(new_dir, "about_pake.html");
|
||||
const about_patk_path_target = path.join(old_dir, "about_pake.html")
|
||||
fs.copyFile(cli_path, cli_path_target);
|
||||
fs.copyFile(about_pake_path, about_patk_path_target);
|
||||
}
|
||||
tauriConf.pake.windows[0].url = file_name;
|
||||
tauriConf.pake.windows[0].url_type = "local";
|
||||
} else {
|
||||
tauriConf.pake.windows[0].url_type = "web";
|
||||
}
|
||||
|
||||
// 处理user-agent
|
||||
logger.warn(userAgent);
|
||||
if (userAgent.length > 0) {
|
||||
if (process.platform === "win32") {
|
||||
tauriConf.pake.user_agent.windows = userAgent;
|
||||
}
|
||||
|
||||
if (process.platform === "linux") {
|
||||
tauriConf.pake.user_agent.linux = userAgent;
|
||||
}
|
||||
|
||||
if (process.platform === "darwin") {
|
||||
tauriConf.pake.user_agent.macos = userAgent;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理菜单栏
|
||||
if (showMenu) {
|
||||
if (process.platform === "win32") {
|
||||
tauriConf.pake.menu.windows = true;
|
||||
}
|
||||
|
||||
if (process.platform === "linux") {
|
||||
tauriConf.pake.menu.linux = true;
|
||||
}
|
||||
|
||||
if (process.platform === "darwin") {
|
||||
tauriConf.pake.user_agent.macos = true;
|
||||
}
|
||||
} else {
|
||||
if (process.platform === "win32") {
|
||||
tauriConf.pake.menu.windows = false;
|
||||
}
|
||||
|
||||
if (process.platform === "linux") {
|
||||
tauriConf.pake.menu.linux = false;
|
||||
}
|
||||
|
||||
if (process.platform === "darwin") {
|
||||
tauriConf.pake.user_agent.macos = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理托盘
|
||||
if (showSystemTray) {
|
||||
if (process.platform === "win32") {
|
||||
tauriConf.pake.system_tray.windows = true;
|
||||
}
|
||||
|
||||
if (process.platform === "linux") {
|
||||
tauriConf.pake.system_tray.linux = true;
|
||||
}
|
||||
|
||||
if (process.platform === "darwin") {
|
||||
tauriConf.pake.system_tray.macos = true;
|
||||
}
|
||||
} else {
|
||||
if (process.platform === "win32") {
|
||||
tauriConf.pake.system_tray.windows = false;
|
||||
}
|
||||
|
||||
if (process.platform === "linux") {
|
||||
tauriConf.pake.system_tray.linux = false;
|
||||
}
|
||||
|
||||
if (process.platform === "darwin") {
|
||||
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"];
|
||||
}
|
||||
|
||||
Object.assign(tauriConf.tauri.windows[0], { url, ...tauriConfWindowOptions });
|
||||
tauriConf.package.productName = name;
|
||||
tauriConf.tauri.bundle.identifier = identifier;
|
||||
|
||||
// 删除映射关系
|
||||
if (process.platform === "linux") {
|
||||
delete tauriConf.tauri.bundle.deb.files;
|
||||
}
|
||||
|
||||
// 处理应用图标
|
||||
const exists = await fs.stat(options.icon)
|
||||
.then(() => true)
|
||||
.catch(() => false);
|
||||
@@ -83,18 +213,21 @@ export async function mergeTauriConfig(
|
||||
} else {
|
||||
updateIconPath = false;
|
||||
logger.warn(`icon file in Windows must be 256 * 256 pix with .ico type, but you give ${customIconExt}`);
|
||||
tauriConf.tauri.bundle.icon = ["png/icon_256.ico"];
|
||||
}
|
||||
}
|
||||
if (process.platform === "linux") {
|
||||
if (customIconExt != ".png") {
|
||||
updateIconPath = false;
|
||||
logger.warn(`icon file in Linux must be 512 * 512 pix with .png type, but you give ${customIconExt}`);
|
||||
tauriConf.tauri.bundle.icon = ["png/icon_512.png"];
|
||||
}
|
||||
}
|
||||
|
||||
if (process.platform === "darwin" && customIconExt !== ".icns") {
|
||||
updateIconPath = false;
|
||||
logger.warn(`icon file in MacOS must be .icns type, but you give ${customIconExt}`);
|
||||
tauriConf.tauri.bundle.icon = ["icons/icon.icns"];
|
||||
}
|
||||
if (updateIconPath) {
|
||||
tauriConf.tauri.bundle.icon = [options.icon];
|
||||
@@ -120,7 +253,40 @@ export async function mergeTauriConfig(
|
||||
}
|
||||
}
|
||||
|
||||
// 处理托盘自定义图标
|
||||
let useDefaultIcon = true; // 是否使用默认托盘图标
|
||||
if (systemTrayIcon.length > 0) {
|
||||
const icon_exists = await fs.stat(systemTrayIcon)
|
||||
.then(() => true)
|
||||
.catch(() => false);
|
||||
if (icon_exists) {
|
||||
// 需要判断图标格式,默认只支持ico和png两种
|
||||
let iconExt = path.extname(systemTrayIcon).toLowerCase();
|
||||
if (iconExt == ".png" || iconExt == ".icon") {
|
||||
useDefaultIcon = false;
|
||||
const trayIcoPath = path.join(npmDirectory, `src-tauri/png/${name.toLowerCase()}${iconExt}`);
|
||||
tauriConf.tauri.systemTray.iconPath = `png/${name.toLowerCase()}${iconExt}`;
|
||||
await fs.copyFile(systemTrayIcon, trayIcoPath);
|
||||
} else {
|
||||
logger.warn(`file type for system tray icon mut be .ico or .png , but you give ${iconExt}`);
|
||||
logger.warn(`system tray icon file will not change with default.`);
|
||||
}
|
||||
} else {
|
||||
logger.warn(`${systemTrayIcon} not exists!`)
|
||||
logger.warn(`system tray icon file will not change with default.`);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理托盘默认图标
|
||||
if (useDefaultIcon) {
|
||||
if (process.platform === "linux" || process.platform === "win32") {
|
||||
tauriConf.tauri.systemTray.iconPath = tauriConf.tauri.bundle.icon[0];
|
||||
} else {
|
||||
tauriConf.tauri.systemTray.iconPath = "png/icon_512.png";
|
||||
}
|
||||
}
|
||||
|
||||
// 保存配置文件
|
||||
let configPath = "";
|
||||
switch (process.platform) {
|
||||
case "win32": {
|
||||
@@ -143,6 +309,15 @@ export async function mergeTauriConfig(
|
||||
Buffer.from(JSON.stringify(bundleConf, null, '\t'), 'utf-8')
|
||||
);
|
||||
|
||||
const pakeConfigPath = path.join(npmDirectory, 'src-tauri/pake.json')
|
||||
await fs.writeFile(
|
||||
pakeConfigPath,
|
||||
Buffer.from(JSON.stringify(tauriConf.pake, null, 4), 'utf-8')
|
||||
);
|
||||
|
||||
let tauriConf2 = JSON.parse(JSON.stringify(tauriConf));
|
||||
delete tauriConf2.pake;
|
||||
delete tauriConf2.tauri.bundle;
|
||||
|
||||
const configJsonPath = path.join(npmDirectory, 'src-tauri/tauri.conf.json')
|
||||
await fs.writeFile(
|
||||
|
||||
4
bin/builders/tauriConf.js
vendored
4
bin/builders/tauriConf.js
vendored
@@ -1,11 +1,13 @@
|
||||
import CommonConf from '../../src-tauri/tauri.conf.json';
|
||||
import pakeConf from '../../src-tauri/pake.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,
|
||||
tauri: CommonConf.tauri
|
||||
tauri: CommonConf.tauri,
|
||||
pake: pakeConf
|
||||
}
|
||||
switch (process.platform) {
|
||||
case "win32": {
|
||||
|
||||
Reference in New Issue
Block a user