🔧 Global formatting and update formatting
This commit is contained in:
94
script/app_config.mjs
vendored
94
script/app_config.mjs
vendored
@@ -1,11 +1,11 @@
|
||||
import pakeJson from '../src-tauri/pake.json' assert { type: 'json' };
|
||||
import tauriJson from '../src-tauri/tauri.conf.json' assert { type: 'json' };
|
||||
import windowsJson from '../src-tauri/tauri.windows.conf.json' assert { type: 'json' };
|
||||
import macosJson from '../src-tauri/tauri.macos.conf.json' assert { type: 'json' };
|
||||
import linuxJson from '../src-tauri/tauri.linux.conf.json' assert { type: 'json' };
|
||||
import pakeJson from "../src-tauri/pake.json" assert { type: "json" };
|
||||
import tauriJson from "../src-tauri/tauri.conf.json" assert { type: "json" };
|
||||
import windowsJson from "../src-tauri/tauri.windows.conf.json" assert { type: "json" };
|
||||
import macosJson from "../src-tauri/tauri.macos.conf.json" assert { type: "json" };
|
||||
import linuxJson from "../src-tauri/tauri.linux.conf.json" assert { type: "json" };
|
||||
|
||||
import { writeFileSync, existsSync, copyFileSync } from 'fs';
|
||||
import os from 'os';
|
||||
import { writeFileSync, existsSync, copyFileSync } from "fs";
|
||||
import os from "os";
|
||||
|
||||
const desktopEntry = `[Desktop Entry]
|
||||
Encoding=UTF-8
|
||||
@@ -25,15 +25,15 @@ const variables = {
|
||||
title: process.env.TITLE,
|
||||
nameZh: process.env.NAME_ZH,
|
||||
|
||||
pakeConfigPath: 'src-tauri/pake.json',
|
||||
tauriConfigPath: 'src-tauri/tauri.conf.json',
|
||||
pakeConfigPath: "src-tauri/pake.json",
|
||||
tauriConfigPath: "src-tauri/tauri.conf.json",
|
||||
identifier: `com.pake.${process.env.NAME}`,
|
||||
|
||||
linux: {
|
||||
configFilePath: 'src-tauri/tauri.linux.conf.json',
|
||||
configFilePath: "src-tauri/tauri.linux.conf.json",
|
||||
iconPath: `src-tauri/png/${process.env.NAME}_512.png`,
|
||||
productName: `com-pake-${process.env.NAME}`,
|
||||
defaultIconPath: 'src-tauri/png/icon_512.png',
|
||||
defaultIconPath: "src-tauri/png/icon_512.png",
|
||||
icon: [`png/${process.env.NAME}_512.png`],
|
||||
desktopEntry,
|
||||
desktopEntryPath: `src-tauri/assets/com-pake-${process.env.NAME}.desktop`,
|
||||
@@ -43,17 +43,17 @@ const variables = {
|
||||
},
|
||||
},
|
||||
macos: {
|
||||
configFilePath: 'src-tauri/tauri.macos.conf.json',
|
||||
configFilePath: "src-tauri/tauri.macos.conf.json",
|
||||
iconPath: `src-tauri/icons/${process.env.NAME}.icns`,
|
||||
defaultPath: 'src-tauri/icons/icon.icns',
|
||||
defaultPath: "src-tauri/icons/icon.icns",
|
||||
icon: [`icons/${process.env.NAME}.icns`],
|
||||
},
|
||||
windows: {
|
||||
configFilePath: 'src-tauri/tauri.windows.conf.json',
|
||||
configFilePath: "src-tauri/tauri.windows.conf.json",
|
||||
iconPath: `src-tauri/png/${process.env.NAME}_32.ico`,
|
||||
defaultPath: 'src-tauri/png/icon_32.ico',
|
||||
defaultPath: "src-tauri/png/icon_32.ico",
|
||||
hdIconPath: `src-tauri/png/${process.env.NAME}_256.ico`,
|
||||
hdDefaultPath: 'src-tauri/png/icon_256.ico',
|
||||
hdDefaultPath: "src-tauri/png/icon_256.ico",
|
||||
icon: [`png/${process.env.NAME}_256.ico`, `png/${process.env.NAME}_32.ico`],
|
||||
resources: [`png/${process.env.NAME}_32.ico`],
|
||||
},
|
||||
@@ -69,20 +69,23 @@ let platformVariables;
|
||||
let platformConfig;
|
||||
|
||||
switch (os.platform()) {
|
||||
case 'linux':
|
||||
case "linux":
|
||||
platformVariables = variables.linux;
|
||||
platformConfig = linuxJson;
|
||||
updateDesktopEntry();
|
||||
break;
|
||||
case 'darwin':
|
||||
case "darwin":
|
||||
platformVariables = variables.macos;
|
||||
platformConfig = macosJson;
|
||||
break;
|
||||
case 'win32':
|
||||
case "win32":
|
||||
platformConfig = windowsJson;
|
||||
platformVariables = variables.windows;
|
||||
updateResources();
|
||||
updateIconFile(platformVariables.hdIconPath, platformVariables.hdDefaultPath);
|
||||
updateIconFile(
|
||||
platformVariables.hdIconPath,
|
||||
platformVariables.hdDefaultPath,
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -93,29 +96,29 @@ updatePlatformConfig(platformConfig, platformVariables);
|
||||
save();
|
||||
|
||||
function validate() {
|
||||
if (!('URL' in process.env)) {
|
||||
console.log('URL is not set');
|
||||
if (!("URL" in process.env)) {
|
||||
console.log("URL is not set");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`URL: ${process.env.URL}`);
|
||||
|
||||
if (!('NAME' in process.env)) {
|
||||
console.log('NAME is not set');
|
||||
if (!("NAME" in process.env)) {
|
||||
console.log("NAME is not set");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`NAME: ${process.env.NAME}`);
|
||||
|
||||
if (!('TITLE' in process.env)) {
|
||||
console.log('TITLE is not set');
|
||||
if (!("TITLE" in process.env)) {
|
||||
console.log("TITLE is not set");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`TITLE: ${process.env.TITLE}`);
|
||||
|
||||
if (!('NAME_ZH' in process.env)) {
|
||||
console.log('NAME_ZH is not set');
|
||||
if (!("NAME_ZH" in process.env)) {
|
||||
console.log("NAME_ZH is not set");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -128,18 +131,23 @@ function updatePakeJson() {
|
||||
|
||||
function updateTauriJson() {
|
||||
tauriJson.productName = variables.title;
|
||||
writeFileSync('src-tauri/tauri.conf.json', JSON.stringify(tauriJson, null, 2));
|
||||
writeFileSync(
|
||||
"src-tauri/tauri.conf.json",
|
||||
JSON.stringify(tauriJson, null, 2),
|
||||
);
|
||||
}
|
||||
|
||||
function updateIconFile(iconPath, defaultIconPath) {
|
||||
if (!existsSync(iconPath)) {
|
||||
console.warn(`Icon for ${process.env.NAME} not found, will use default icon`);
|
||||
console.warn(
|
||||
`Icon for ${process.env.NAME} not found, will use default icon`,
|
||||
);
|
||||
copyFileSync(defaultIconPath, iconPath);
|
||||
}
|
||||
}
|
||||
|
||||
function updatePlatformConfig(platformConfig, platformVariables) {
|
||||
platformConfig.bundle['icon'] = platformVariables.icon;
|
||||
platformConfig.bundle["icon"] = platformVariables.icon;
|
||||
platformConfig.identifier = variables.identifier;
|
||||
}
|
||||
|
||||
@@ -147,17 +155,31 @@ function save() {
|
||||
writeFileSync(variables.pakeConfigPath, JSON.stringify(pakeJson, null, 2));
|
||||
writeFileSync(variables.tauriConfigPath, JSON.stringify(tauriJson, null, 2));
|
||||
|
||||
writeFileSync(variables.linux.configFilePath, JSON.stringify(linuxJson, null, 2));
|
||||
writeFileSync(platformVariables.configFilePath, JSON.stringify(platformConfig, null, 2));
|
||||
writeFileSync(
|
||||
variables.linux.configFilePath,
|
||||
JSON.stringify(linuxJson, null, 2),
|
||||
);
|
||||
writeFileSync(
|
||||
platformVariables.configFilePath,
|
||||
JSON.stringify(platformConfig, null, 2),
|
||||
);
|
||||
|
||||
writeFileSync(variables.macos.configFilePath, JSON.stringify(macosJson, null, 2));
|
||||
writeFileSync(
|
||||
variables.macos.configFilePath,
|
||||
JSON.stringify(macosJson, null, 2),
|
||||
);
|
||||
|
||||
writeFileSync(variables.windows.configFilePath, JSON.stringify(windowsJson, null, 2));
|
||||
writeFileSync(
|
||||
variables.windows.configFilePath,
|
||||
JSON.stringify(windowsJson, null, 2),
|
||||
);
|
||||
}
|
||||
|
||||
function updateDesktopEntry() {
|
||||
linuxJson.bundle.linux.deb.files = {};
|
||||
linuxJson.bundle.linux.deb.files[variables.linux.desktopEntryConfig.configKey] = variables.linux.desktopEntryConfig.configValue;
|
||||
linuxJson.bundle.linux.deb.files[
|
||||
variables.linux.desktopEntryConfig.configKey
|
||||
] = variables.linux.desktopEntryConfig.configValue;
|
||||
writeFileSync(variables.linux.desktopEntryPath, variables.linux.desktopEntry);
|
||||
}
|
||||
|
||||
|
||||
121
script/build_with_pake_cli.js
vendored
121
script/build_with_pake_cli.js
vendored
@@ -1,62 +1,73 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import axios from 'axios';
|
||||
import { execa } from 'execa';
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import axios from "axios";
|
||||
import { execa } from "execa";
|
||||
|
||||
// Configuration logging
|
||||
const logConfiguration = () => {
|
||||
console.log('Welcome to use pake-cli to build app');
|
||||
console.log('Node.js info in your localhost:', process.version);
|
||||
console.log('\n=======================\n');
|
||||
console.log('Pake parameters:');
|
||||
console.log('url:', process.env.URL);
|
||||
console.log('name:', process.env.NAME);
|
||||
console.log('icon:', process.env.ICON);
|
||||
console.log('height:', process.env.HEIGHT);
|
||||
console.log('width:', process.env.WIDTH);
|
||||
console.log('fullscreen:', process.env.FULLSCREEN);
|
||||
console.log('hide-title-bar:', process.env.HIDE_TITLE_BAR);
|
||||
console.log('is multi arch? only for Mac:', process.env.MULTI_ARCH);
|
||||
console.log('targets type? only for Linux:', process.env.TARGETS);
|
||||
console.log('===========================\n');
|
||||
console.log("Welcome to use pake-cli to build app");
|
||||
console.log("Node.js info in your localhost:", process.version);
|
||||
console.log("\n=======================\n");
|
||||
console.log("Pake parameters:");
|
||||
console.log("url:", process.env.URL);
|
||||
console.log("name:", process.env.NAME);
|
||||
console.log("icon:", process.env.ICON);
|
||||
console.log("height:", process.env.HEIGHT);
|
||||
console.log("width:", process.env.WIDTH);
|
||||
console.log("fullscreen:", process.env.FULLSCREEN);
|
||||
console.log("hide-title-bar:", process.env.HIDE_TITLE_BAR);
|
||||
console.log("is multi arch? only for Mac:", process.env.MULTI_ARCH);
|
||||
console.log("targets type? only for Linux:", process.env.TARGETS);
|
||||
console.log("===========================\n");
|
||||
};
|
||||
|
||||
// Build parameters construction
|
||||
const buildParameters = () => {
|
||||
const params = ['cli.js', process.env.URL, '--name', process.env.NAME, '--height', process.env.HEIGHT, '--width', process.env.WIDTH];
|
||||
const params = [
|
||||
"cli.js",
|
||||
process.env.URL,
|
||||
"--name",
|
||||
process.env.NAME,
|
||||
"--height",
|
||||
process.env.HEIGHT,
|
||||
"--width",
|
||||
process.env.WIDTH,
|
||||
];
|
||||
|
||||
if (process.env.HIDE_TITLE_BAR === 'true') {
|
||||
params.push('--hide-title-bar');
|
||||
if (process.env.HIDE_TITLE_BAR === "true") {
|
||||
params.push("--hide-title-bar");
|
||||
}
|
||||
|
||||
if (process.env.FULLSCREEN === 'true') {
|
||||
params.push('--fullscreen');
|
||||
if (process.env.FULLSCREEN === "true") {
|
||||
params.push("--fullscreen");
|
||||
}
|
||||
|
||||
if (process.env.MULTI_ARCH === 'true') {
|
||||
if (process.env.MULTI_ARCH === "true") {
|
||||
// We'll handle rustup separately since it's a different command
|
||||
params.push('--multi-arch');
|
||||
params.push("--multi-arch");
|
||||
}
|
||||
|
||||
if (process.env.TARGETS) {
|
||||
params.push('--targets', process.env.TARGETS);
|
||||
params.push("--targets", process.env.TARGETS);
|
||||
}
|
||||
|
||||
if (process.platform === 'win32' || process.platform === 'linux') {
|
||||
params.push('--show-system-tray');
|
||||
if (process.platform === "win32" || process.platform === "linux") {
|
||||
params.push("--show-system-tray");
|
||||
}
|
||||
|
||||
return params;
|
||||
};
|
||||
|
||||
// Icon download handling
|
||||
const downloadIcon = async iconFile => {
|
||||
const downloadIcon = async (iconFile) => {
|
||||
try {
|
||||
const response = await axios.get(process.env.ICON, { responseType: 'arraybuffer' });
|
||||
const response = await axios.get(process.env.ICON, {
|
||||
responseType: "arraybuffer",
|
||||
});
|
||||
fs.writeFileSync(iconFile, response.data);
|
||||
return ['--icon', iconFile];
|
||||
return ["--icon", iconFile];
|
||||
} catch (error) {
|
||||
console.error('Error occurred during icon download:', error);
|
||||
console.error("Error occurred during icon download:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -64,14 +75,14 @@ const downloadIcon = async iconFile => {
|
||||
// Get icon file name based on platform
|
||||
const getIconFileName = () => {
|
||||
switch (process.platform) {
|
||||
case 'linux':
|
||||
return 'icon.png';
|
||||
case 'darwin':
|
||||
return 'icon.icns';
|
||||
case 'win32':
|
||||
return 'icon.ico';
|
||||
case "linux":
|
||||
return "icon.png";
|
||||
case "darwin":
|
||||
return "icon.icns";
|
||||
case "win32":
|
||||
return "icon.ico";
|
||||
default:
|
||||
throw new Error('Unable to detect your OS system');
|
||||
throw new Error("Unable to detect your OS system");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -80,47 +91,49 @@ const main = async () => {
|
||||
try {
|
||||
logConfiguration();
|
||||
|
||||
const cliPath = path.join(process.cwd(), 'node_modules/pake-cli');
|
||||
const cliPath = path.join(process.cwd(), "node_modules/pake-cli");
|
||||
process.chdir(cliPath);
|
||||
|
||||
let params = buildParameters();
|
||||
|
||||
if (process.env.MULTI_ARCH === 'true') {
|
||||
await execa('rustup', ['target', 'add', 'aarch64-apple-darwin']);
|
||||
if (process.env.MULTI_ARCH === "true") {
|
||||
await execa("rustup", ["target", "add", "aarch64-apple-darwin"]);
|
||||
}
|
||||
|
||||
if (process.env.ICON && process.env.ICON !== '') {
|
||||
if (process.env.ICON && process.env.ICON !== "") {
|
||||
const iconFile = getIconFileName();
|
||||
const iconParams = await downloadIcon(iconFile);
|
||||
params.push(...iconParams);
|
||||
} else {
|
||||
console.log("Won't download the icon as ICON environment variable is not defined!");
|
||||
console.log(
|
||||
"Won't download the icon as ICON environment variable is not defined!",
|
||||
);
|
||||
}
|
||||
|
||||
console.log('Pake parameters:', params.join(' '));
|
||||
console.log('Compiling....');
|
||||
console.log("Pake parameters:", params.join(" "));
|
||||
console.log("Compiling....");
|
||||
|
||||
// Execute the CLI command
|
||||
await execa('node', params, { stdio: 'inherit' });
|
||||
await execa("node", params, { stdio: "inherit" });
|
||||
|
||||
// Create output directory if it doesn't exist
|
||||
if (!fs.existsSync('output')) {
|
||||
fs.mkdirSync('output');
|
||||
if (!fs.existsSync("output")) {
|
||||
fs.mkdirSync("output");
|
||||
}
|
||||
|
||||
// Move built files to output directory
|
||||
const files = fs.readdirSync('.');
|
||||
const files = fs.readdirSync(".");
|
||||
const namePattern = new RegExp(`^${process.env.NAME}\\..*$`);
|
||||
for (const file of files) {
|
||||
if (namePattern.test(file)) {
|
||||
await execa('mv', [file, path.join('output', file)]);
|
||||
await execa("mv", [file, path.join("output", file)]);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Build Success');
|
||||
process.chdir('../..');
|
||||
console.log("Build Success");
|
||||
process.chdir("../..");
|
||||
} catch (error) {
|
||||
console.error('Build failed:', error);
|
||||
console.error("Build failed:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user