Files
lobehub/scripts/electronWorkflow/buildDesktopChannel.ts
Innei 4e5a516865 🐛 fix(desktop): add auth required modal and improve error handling (#11574)
* 🐛 fix(desktop): add auth required modal and improve error handling

- Add AuthRequiredModal component to handle authentication expiration
- Improve backend proxy protocol error handling for auth errors
- Add updater manager authentication header support
- Add i18n strings for auth error messages

* 🔧 fix(desktop): update UpdaterManager to leave channel unset for GitHub prerelease matching

- Modify UpdaterManager to leave the channel unset, allowing GitHub to use version tags for prerelease matching.
- Update logging to reflect the new behavior when the channel is unset or kept as is.

Signed-off-by: Innei <tukon479@gmail.com>

* 🔧 fix(desktop): clarify UpdaterManager behavior for GitHub provider

- Update comments and logging in UpdaterManager to clarify that the channel is left unset for beta/nightly, allowing GitHub to use version tags for prerelease matching.
- Ensure logging accurately reflects the new behavior when the channel is unset.

Signed-off-by: Innei <tukon479@gmail.com>

*  feat(desktop): add desktop build channel script and update documentation

- Introduced a new script for building desktop applications for specific release channels (stable, beta, nightly).
- Updated package.json to include a new npm command for the build channel.
- Enhanced README documentation to guide users on simulating CI channel builds and retaining changes.

Signed-off-by: Innei <tukon479@gmail.com>

* 🔧 fix(desktop): streamline NODE_ENV usage in logger and config

- Removed redundant process.env.NODE_ENV definition from electron.vite.config.ts.
- Simplified logger implementation by directly using process.env.NODE_ENV for environment checks.
- Improved readability and maintainability of logging behavior based on the environment.

Signed-off-by: Innei <tukon479@gmail.com>

* 🔧 fix(desktop): enhance logging configuration to support debug mode

- Updated logger configuration to allow for debug level logging when DEBUG environment variable is set.
- Simplified the logic for console logging levels based on the environment, improving clarity and maintainability.

Signed-off-by: Innei <tukon479@gmail.com>

* 🔧 fix(desktop): enhance version generation and logging in UpdaterManager

- Updated version generation logic in manual-build-desktop.yml to handle channel suffixes more effectively.
- Added inferredChannel logging in UpdaterManager to improve clarity on the current update channel being used.

Signed-off-by: Innei <tukon479@gmail.com>

* 🔧 fix(desktop): update localization files and set default entry locale to English

- Changed default entry locale from Chinese (zh-CN) to English (en) in .i18nrc.js.
- Added full disk access messages in multiple languages (Arabic, Bulgarian, German, Spanish, French, Italian, Japanese, Korean, Dutch, Polish, Portuguese, Russian, Turkish, Vietnamese, Traditional Chinese).
- Enhanced menu localization with new settings and permissions options across various languages.

Signed-off-by: Innei <tukon479@gmail.com>

---------

Signed-off-by: Innei <tukon479@gmail.com>
2026-01-18 18:55:18 +08:00

136 lines
3.6 KiB
TypeScript

/* eslint-disable unicorn/no-process-exit */
import fs from 'fs-extra';
import { execSync } from 'node:child_process';
import path from 'node:path';
type ReleaseChannel = 'stable' | 'beta' | 'nightly';
const rootDir = path.resolve(__dirname, '../..');
const desktopDir = path.join(rootDir, 'apps/desktop');
const desktopPackageJsonPath = path.join(desktopDir, 'package.json');
const buildDir = path.join(desktopDir, 'build');
const iconTargets = ['icon.png', 'Icon.icns', 'icon.ico'];
const isFlag = (value: string) => value.startsWith('-');
const parseArgs = (args: string[]) => {
let channel = '';
let version = '';
let keepChanges = false;
for (let i = 0; i < args.length; i += 1) {
const arg = args[i];
if (arg === '--channel' || arg === '-c') {
channel = args[i + 1] ?? '';
i += 1;
continue;
}
if (arg === '--version' || arg === '-v') {
version = args[i + 1] ?? '';
i += 1;
continue;
}
if (arg === '--keep-changes') {
keepChanges = true;
continue;
}
if (!isFlag(arg)) {
if (!channel) {
channel = arg;
continue;
}
if (!version) {
version = arg;
}
}
}
return { channel, keepChanges, version };
};
const resolveDefaultVersion = () => {
const rootPackageJsonPath = path.join(rootDir, 'package.json');
const rootPackageJson = fs.readJsonSync(rootPackageJsonPath);
return rootPackageJson.version as string | undefined;
};
const backupFile = async (filePath: string) => {
try {
return await fs.readFile(filePath);
} catch {
return undefined;
}
};
const restoreFile = async (filePath: string, content?: Buffer) => {
if (!content) return;
await fs.writeFile(filePath, content);
};
const validateChannel = (channel: string): channel is ReleaseChannel =>
channel === 'stable' || channel === 'beta' || channel === 'nightly';
const runCommand = (command: string, env?: Record<string, string | undefined>) => {
execSync(command, {
cwd: rootDir,
env: { ...process.env, ...env },
stdio: 'inherit',
});
};
const main = async () => {
const { channel, version: rawVersion, keepChanges } = parseArgs(process.argv.slice(2));
if (!validateChannel(channel)) {
console.error(
'Missing or invalid channel. Usage: npm run desktop:build-channel -- <stable|beta|nightly> [version] [--keep-changes]',
);
process.exit(1);
}
const version = rawVersion || resolveDefaultVersion();
if (!version) {
console.error('Missing version. Provide it or ensure root package.json has a version.');
process.exit(1);
}
const packageJsonBackup = await backupFile(desktopPackageJsonPath);
const iconBackups = await Promise.all(
iconTargets.map(async (fileName) => ({
content: await backupFile(path.join(buildDir, fileName)),
fileName,
})),
);
console.log(`🚦 CI-style build channel: ${channel}`);
console.log(`🏷️ Desktop version: ${version}`);
console.log(`🧩 Keep local changes: ${keepChanges ? 'yes' : 'no'}`);
try {
runCommand(`npm run workflow:set-desktop-version ${version} ${channel}`);
runCommand('npm run desktop:build', { UPDATE_CHANNEL: channel });
} catch (error) {
console.error('❌ Build failed:', error);
process.exit(1);
} finally {
if (!keepChanges) {
await restoreFile(desktopPackageJsonPath, packageJsonBackup);
await Promise.all(
iconBackups.map(({ fileName, content }) =>
restoreFile(path.join(buildDir, fileName), content),
),
);
console.log('🧹 Restored local desktop package metadata and icons.');
}
}
};
main();