Files
trackgo-fe/apps/desktop/scripts/copy-web-dist.ts
T
shancheas 67ae5b6c11 refactor: improve code formatting and consistency across multiple files
- Standardized import statements and removed unnecessary line breaks for better readability in various components.
- Enhanced error handling and logging in the useElectronPrinter hook.
- Updated sample data formatting in AgGridShowcase for improved clarity.
- Refactored JSX elements for consistent indentation and structure in LandingSample, AuthPage, and EventsPage components.
- Consolidated and simplified conditional rendering logic in several components.

These changes aim to enhance code maintainability and readability throughout the project.
2026-08-25 17:50:48 +07:00

70 lines
2.9 KiB
TypeScript

/**
* copy-web-dist.ts
*
* Prebuild script for apps/desktop.
* Copies the build output of the target web app into ./web-dist/
* so electron-builder can bundle it into the packaged application.
*
* Reads DESKTOP_TARGET_APP from .env (default: "web").
*
* Directory layout:
* monorepo-root/
* apps/
* desktop/
* scripts/ ← this file lives here
* web-dist/ ← destination
* web/
* dist/ ← source
*/
import { cpSync, existsSync, mkdirSync, rmSync, readFileSync } from 'fs';
import { resolve } from 'path';
import { fileURLToPath } from 'url';
// ── Resolve paths ──────────────────────────────────────────────
// Use import.meta.url for ESM compatibility (works across Node versions)
const SCRIPT_DIR = resolve(fileURLToPath(import.meta.url), '..');
const DESKTOP_DIR = resolve(SCRIPT_DIR, '..');
const MONOREPO_ROOT = resolve(DESKTOP_DIR, '..', '..');
const DEST_DIR = resolve(DESKTOP_DIR, 'web-dist');
// ── Read .env for target app name ──────────────────────────────
function loadTargetApp(): string {
const envPath = resolve(DESKTOP_DIR, '.env');
if (existsSync(envPath)) {
const content = readFileSync(envPath, 'utf-8');
const match = content.match(/^DESKTOP_TARGET_APP=(.+)$/m);
if (match) return match[1].trim();
}
return 'web';
}
const targetApp = process.env.DESKTOP_TARGET_APP || loadTargetApp();
const SOURCE_DIR = resolve(MONOREPO_ROOT, 'apps', targetApp, 'dist');
// ── Debug: print resolved paths ────────────────────────────────
console.log(`\n📦 copy-web-dist`);
console.log(` Target app : ${targetApp}`);
console.log(` Monorepo root: ${MONOREPO_ROOT}`);
console.log(` Source : ${SOURCE_DIR}`);
console.log(` Destination : ${DEST_DIR}`);
// ── Validate ───────────────────────────────────────────────────
if (!existsSync(SOURCE_DIR)) {
console.error(
`\n❌ Build output not found at: ${SOURCE_DIR}\n` + ` Run "pnpm build --filter=${targetApp}" first.\n`,
);
process.exit(1);
}
// ── Clean destination ──────────────────────────────────────────
if (existsSync(DEST_DIR)) {
rmSync(DEST_DIR, { recursive: true, force: true });
}
mkdirSync(DEST_DIR, { recursive: true });
// ── Copy ───────────────────────────────────────────────────────
cpSync(SOURCE_DIR, DEST_DIR, { recursive: true });
console.log(`✅ Copied ${targetApp} build → web-dist/\n`);