🔧 More appropriate file naming
This commit is contained in:
224
scripts/configure-tauri.mjs
Executable file
224
scripts/configure-tauri.mjs
Executable file
@@ -0,0 +1,224 @@
|
||||
import pakeJson from "../src-tauri/pake.json" with { type: "json" };
|
||||
import tauriJson from "../src-tauri/tauri.conf.json" with { type: "json" };
|
||||
import windowsJson from "../src-tauri/tauri.windows.conf.json" with { type: "json" };
|
||||
import macosJson from "../src-tauri/tauri.macos.conf.json" with { type: "json" };
|
||||
import linuxJson from "../src-tauri/tauri.linux.conf.json" with { type: "json" };
|
||||
|
||||
import { writeFileSync, existsSync, copyFileSync } from "fs";
|
||||
import os from "os";
|
||||
|
||||
/**
|
||||
* Configuration script for Tauri app generation
|
||||
* Sets up platform-specific configurations, icons, and desktop entries
|
||||
*/
|
||||
|
||||
// Environment validation
|
||||
const requiredEnvVars = ["URL", "NAME", "TITLE", "NAME_ZH"];
|
||||
|
||||
function validateEnvironment() {
|
||||
const missing = requiredEnvVars.filter((key) => !(key in process.env));
|
||||
|
||||
if (missing.length > 0) {
|
||||
console.error(
|
||||
`Missing required environment variables: ${missing.join(", ")}`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log("Environment variables:");
|
||||
requiredEnvVars.forEach((key) => {
|
||||
console.log(` ${key}: ${process.env[key]}`);
|
||||
});
|
||||
}
|
||||
|
||||
// Configuration constants
|
||||
const CONFIG = {
|
||||
get identifier() {
|
||||
return `com.pake.${process.env.NAME}`;
|
||||
},
|
||||
get productName() {
|
||||
return `com-pake-${process.env.NAME}`;
|
||||
},
|
||||
|
||||
paths: {
|
||||
pakeConfig: "src-tauri/pake.json",
|
||||
tauriConfig: "src-tauri/tauri.conf.json",
|
||||
},
|
||||
|
||||
platforms: {
|
||||
linux: {
|
||||
configFile: "src-tauri/tauri.linux.conf.json",
|
||||
iconPath: `src-tauri/png/${process.env.NAME}_512.png`,
|
||||
defaultIcon: "src-tauri/png/icon_512.png",
|
||||
icons: [`png/${process.env.NAME}_512.png`],
|
||||
get desktopEntry() {
|
||||
return `[Desktop Entry]
|
||||
Encoding=UTF-8
|
||||
Categories=Office
|
||||
Exec=${CONFIG.productName}
|
||||
Icon=${CONFIG.productName}
|
||||
Name=${CONFIG.productName}
|
||||
Name[zh_CN]=${process.env.NAME_ZH}
|
||||
StartupNotify=true
|
||||
Terminal=false
|
||||
Type=Application
|
||||
`;
|
||||
},
|
||||
get desktopEntryPath() {
|
||||
return `src-tauri/assets/${CONFIG.productName}.desktop`;
|
||||
},
|
||||
get desktopConfig() {
|
||||
return {
|
||||
key: `/usr/share/applications/${CONFIG.productName}.desktop`,
|
||||
value: `assets/${CONFIG.productName}.desktop`,
|
||||
};
|
||||
},
|
||||
},
|
||||
|
||||
darwin: {
|
||||
configFile: "src-tauri/tauri.macos.conf.json",
|
||||
iconPath: `src-tauri/icons/${process.env.NAME}.icns`,
|
||||
defaultIcon: "src-tauri/icons/icon.icns",
|
||||
icons: [`icons/${process.env.NAME}.icns`],
|
||||
},
|
||||
|
||||
win32: {
|
||||
configFile: "src-tauri/tauri.windows.conf.json",
|
||||
iconPath: `src-tauri/png/${process.env.NAME}_32.ico`,
|
||||
hdIconPath: `src-tauri/png/${process.env.NAME}_256.ico`,
|
||||
defaultIcon: "src-tauri/png/icon_32.ico",
|
||||
hdDefaultIcon: "src-tauri/png/icon_256.ico",
|
||||
icons: [
|
||||
`png/${process.env.NAME}_256.ico`,
|
||||
`png/${process.env.NAME}_32.ico`,
|
||||
],
|
||||
resources: [`png/${process.env.NAME}_32.ico`],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// Core configuration functions
|
||||
function updateBaseConfigs() {
|
||||
// Update pake.json
|
||||
pakeJson.windows[0].url = process.env.URL;
|
||||
|
||||
// Update system tray icon path in pake.json
|
||||
if (pakeJson.system_tray_path) {
|
||||
pakeJson.system_tray_path = `icons/${process.env.NAME}.png`;
|
||||
// Note: System tray icons should be provided in default_app_list.json
|
||||
// Don't auto-generate them here to avoid wrong icon content
|
||||
}
|
||||
|
||||
// Update tauri.conf.json
|
||||
tauriJson.productName = process.env.TITLE;
|
||||
tauriJson.identifier = CONFIG.identifier;
|
||||
|
||||
// Update tray icon path in tauri.conf.json
|
||||
if (tauriJson.app && tauriJson.app.trayIcon) {
|
||||
tauriJson.app.trayIcon.iconPath = `png/${process.env.NAME}_512.png`;
|
||||
// Note: Tray icons should be provided in default_app_list.json
|
||||
// Don't auto-generate them here to avoid wrong icon content
|
||||
}
|
||||
}
|
||||
|
||||
function ensureIconExists(iconPath, defaultPath, description = "icon") {
|
||||
if (!existsSync(iconPath)) {
|
||||
// For official release apps, icons should already exist
|
||||
if (process.env.PAKE_CREATE_APP === "1") {
|
||||
console.warn(
|
||||
`${description} for ${process.env.NAME} not found at ${iconPath}`,
|
||||
);
|
||||
return; // Don't auto-generate for release builds
|
||||
}
|
||||
console.warn(
|
||||
`${description} for ${process.env.NAME} not found, using default`,
|
||||
);
|
||||
copyFileSync(defaultPath, iconPath);
|
||||
}
|
||||
}
|
||||
|
||||
function updatePlatformConfig(platformConfig, platformVars) {
|
||||
// Ensure bundle object exists
|
||||
if (!platformConfig.bundle) {
|
||||
platformConfig.bundle = {};
|
||||
}
|
||||
|
||||
platformConfig.bundle.icon = platformVars.icons;
|
||||
platformConfig.identifier = CONFIG.identifier;
|
||||
platformConfig.productName = process.env.TITLE;
|
||||
}
|
||||
|
||||
// Platform-specific handlers
|
||||
const platformHandlers = {
|
||||
linux: (config) => {
|
||||
ensureIconExists(config.iconPath, config.defaultIcon, "Linux icon");
|
||||
|
||||
// Update desktop entry
|
||||
linuxJson.bundle.linux.deb.files = {
|
||||
[config.desktopConfig.key]: config.desktopConfig.value,
|
||||
};
|
||||
writeFileSync(config.desktopEntryPath, config.desktopEntry);
|
||||
|
||||
updatePlatformConfig(linuxJson, config);
|
||||
},
|
||||
|
||||
darwin: (config) => {
|
||||
ensureIconExists(config.iconPath, config.defaultIcon, "macOS icon");
|
||||
updatePlatformConfig(macosJson, config);
|
||||
},
|
||||
|
||||
win32: (config) => {
|
||||
ensureIconExists(config.iconPath, config.defaultIcon, "Windows icon");
|
||||
ensureIconExists(
|
||||
config.hdIconPath,
|
||||
config.hdDefaultIcon,
|
||||
"Windows HD icon",
|
||||
);
|
||||
|
||||
// Update both bundle.icon and bundle.resources for Windows
|
||||
windowsJson.bundle.resources = config.resources;
|
||||
updatePlatformConfig(windowsJson, config);
|
||||
},
|
||||
};
|
||||
|
||||
function saveConfigurations() {
|
||||
const configs = [
|
||||
{ path: CONFIG.paths.pakeConfig, data: pakeJson },
|
||||
{ path: CONFIG.paths.tauriConfig, data: tauriJson },
|
||||
{ path: CONFIG.platforms.linux.configFile, data: linuxJson },
|
||||
{ path: CONFIG.platforms.darwin.configFile, data: macosJson },
|
||||
{ path: CONFIG.platforms.win32.configFile, data: windowsJson },
|
||||
];
|
||||
|
||||
configs.forEach(({ path, data }) => {
|
||||
writeFileSync(path, JSON.stringify(data, null, 2) + "\n");
|
||||
});
|
||||
}
|
||||
|
||||
// Main execution
|
||||
function main() {
|
||||
try {
|
||||
validateEnvironment();
|
||||
updateBaseConfigs();
|
||||
|
||||
const platform = os.platform();
|
||||
const platformConfig = CONFIG.platforms[platform];
|
||||
|
||||
if (!platformConfig) {
|
||||
throw new Error(`Unsupported platform: ${platform}`);
|
||||
}
|
||||
|
||||
const handler = platformHandlers[platform];
|
||||
if (handler) {
|
||||
handler(platformConfig);
|
||||
}
|
||||
|
||||
saveConfigurations();
|
||||
console.log(`✅ Tauri configuration complete for ${platform}`);
|
||||
} catch (error) {
|
||||
console.error("❌ Configuration failed:", error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
224
scripts/github-action-build.js
Executable file
224
scripts/github-action-build.js
Executable file
@@ -0,0 +1,224 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { execa } from "execa";
|
||||
|
||||
/**
|
||||
* GitHub Actions build script for Pake CLI
|
||||
* Handles environment setup, parameter building, and output management
|
||||
*/
|
||||
|
||||
// Environment variables expected from GitHub Actions
|
||||
const ENV_VARS = {
|
||||
required: ["URL", "NAME", "HEIGHT", "WIDTH"],
|
||||
optional: ["ICON", "FULLSCREEN", "HIDE_TITLE_BAR", "MULTI_ARCH", "TARGETS"],
|
||||
};
|
||||
|
||||
// Platform-specific configurations
|
||||
const PLATFORM_CONFIG = {
|
||||
darwin: {
|
||||
supportsHideTitleBar: true,
|
||||
supportsMultiArch: true,
|
||||
needsSystemTray: false,
|
||||
},
|
||||
linux: {
|
||||
supportsTargets: true,
|
||||
needsSystemTray: true,
|
||||
},
|
||||
win32: {
|
||||
needsSystemTray: true,
|
||||
},
|
||||
};
|
||||
|
||||
class PakeBuildManager {
|
||||
constructor() {
|
||||
this.platform = process.platform;
|
||||
this.config = PLATFORM_CONFIG[this.platform] || {};
|
||||
}
|
||||
|
||||
logConfiguration() {
|
||||
console.log("🚀 Pake CLI Build Started");
|
||||
console.log(`📋 Node.js version: ${process.version}`);
|
||||
console.log(`🖥️ Platform: ${this.platform}`);
|
||||
console.log("\n" + "=".repeat(50));
|
||||
console.log("📝 Build Parameters:");
|
||||
|
||||
ENV_VARS.required.forEach((key) => {
|
||||
console.log(` ${key}: ${process.env[key]}`);
|
||||
});
|
||||
|
||||
ENV_VARS.optional.forEach((key) => {
|
||||
if (process.env[key]) {
|
||||
console.log(` ${key}: ${process.env[key]}`);
|
||||
}
|
||||
});
|
||||
console.log("=".repeat(50) + "\n");
|
||||
}
|
||||
|
||||
validateEnvironment() {
|
||||
const missing = ENV_VARS.required.filter((key) => !process.env[key]);
|
||||
|
||||
if (missing.length > 0) {
|
||||
throw new Error(
|
||||
`Missing required environment variables: ${missing.join(", ")}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
setupWorkspace() {
|
||||
const cliPath = path.join(process.cwd(), "node_modules/pake-cli");
|
||||
|
||||
if (!fs.existsSync(cliPath)) {
|
||||
throw new Error(
|
||||
`pake-cli not found at ${cliPath}. Run: npm install pake-cli`,
|
||||
);
|
||||
}
|
||||
|
||||
process.chdir(cliPath);
|
||||
this.cleanPreviousBuilds();
|
||||
|
||||
return cliPath;
|
||||
}
|
||||
|
||||
cleanPreviousBuilds() {
|
||||
const cleanupPaths = [
|
||||
"src-tauri/.pake",
|
||||
"src-tauri/target/.pake",
|
||||
"src-tauri/target/debug/.pake",
|
||||
"src-tauri/target/release/.pake",
|
||||
"src-tauri/target/universal-apple-darwin/.pake",
|
||||
];
|
||||
|
||||
cleanupPaths.forEach((dirPath) => {
|
||||
if (fs.existsSync(dirPath)) {
|
||||
fs.rmSync(dirPath, { recursive: true, force: true });
|
||||
console.log(`🧹 Cleaned: ${dirPath}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
buildCliParameters() {
|
||||
const params = [
|
||||
"dist/cli.js",
|
||||
process.env.URL,
|
||||
"--name",
|
||||
process.env.NAME,
|
||||
"--height",
|
||||
process.env.HEIGHT,
|
||||
"--width",
|
||||
process.env.WIDTH,
|
||||
];
|
||||
|
||||
// Platform-specific parameters
|
||||
if (
|
||||
this.config.supportsHideTitleBar &&
|
||||
process.env.HIDE_TITLE_BAR === "true"
|
||||
) {
|
||||
params.push("--hide-title-bar");
|
||||
}
|
||||
|
||||
if (process.env.FULLSCREEN === "true") {
|
||||
params.push("--fullscreen");
|
||||
}
|
||||
|
||||
if (this.config.supportsMultiArch && process.env.MULTI_ARCH === "true") {
|
||||
params.push("--multi-arch");
|
||||
}
|
||||
|
||||
if (this.config.supportsTargets && process.env.TARGETS) {
|
||||
params.push("--targets", process.env.TARGETS);
|
||||
}
|
||||
|
||||
if (this.config.needsSystemTray) {
|
||||
params.push("--show-system-tray");
|
||||
}
|
||||
|
||||
// Icon handling
|
||||
if (process.env.ICON?.trim()) {
|
||||
params.push("--icon", process.env.ICON);
|
||||
} else {
|
||||
console.log(
|
||||
"ℹ️ No icon provided, will attempt to fetch favicon or use default",
|
||||
);
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
async executeBuild(params) {
|
||||
console.log(`🔧 Command: node ${params.join(" ")}`);
|
||||
console.log(`📱 Building app: ${process.env.NAME}`);
|
||||
console.log("⏳ Compiling...\n");
|
||||
|
||||
await execa("node", params, { stdio: "inherit" });
|
||||
}
|
||||
|
||||
organizeOutput() {
|
||||
const outputDir = "output";
|
||||
|
||||
if (!fs.existsSync(outputDir)) {
|
||||
fs.mkdirSync(outputDir);
|
||||
}
|
||||
|
||||
const appName = process.env.NAME;
|
||||
const filePattern = new RegExp(
|
||||
`^(${this.escapeRegex(appName)}|${this.escapeRegex(appName.toLowerCase())})(_.*|\\..*)$`,
|
||||
"i",
|
||||
);
|
||||
|
||||
const files = fs.readdirSync(".");
|
||||
let movedFiles = 0;
|
||||
|
||||
files.forEach((file) => {
|
||||
if (filePattern.test(file)) {
|
||||
const destPath = path.join(outputDir, file);
|
||||
fs.renameSync(file, destPath);
|
||||
console.log(`📦 Packaged: ${file}`);
|
||||
movedFiles++;
|
||||
}
|
||||
});
|
||||
|
||||
if (movedFiles === 0) {
|
||||
console.warn(
|
||||
"⚠️ Warning: No output files found matching expected pattern",
|
||||
);
|
||||
}
|
||||
|
||||
return movedFiles;
|
||||
}
|
||||
|
||||
escapeRegex(str) {
|
||||
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
}
|
||||
|
||||
async run() {
|
||||
try {
|
||||
this.logConfiguration();
|
||||
this.validateEnvironment();
|
||||
|
||||
this.setupWorkspace();
|
||||
const params = this.buildCliParameters();
|
||||
|
||||
await this.executeBuild(params);
|
||||
|
||||
const fileCount = this.organizeOutput();
|
||||
|
||||
console.log(`\n✅ Build completed successfully!`);
|
||||
console.log(`📦 Generated ${fileCount} output file(s)`);
|
||||
|
||||
// Return to original directory
|
||||
process.chdir("../..");
|
||||
} catch (error) {
|
||||
console.error("\n❌ Build failed:", error.message);
|
||||
|
||||
if (error.stderr) {
|
||||
console.error("Error details:", error.stderr);
|
||||
}
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Execute build
|
||||
const buildManager = new PakeBuildManager();
|
||||
buildManager.run();
|
||||
Reference in New Issue
Block a user