// 앱 빌드: 메인·preload (CJS, node_modules 는 그대로 두고 asar 로 묶음) + 렌더러(React 번들) + 스키마 사본 import { build } from 'esbuild'; import fs from 'node:fs'; import path from 'node:path'; const root = import.meta.dirname; // Windows 에서 URL.pathname 은 /C:/... 라 쓰면 안 된다 const shared = path.join(root, '..', 'packages', 'shared', 'src', 'index.ts'); fs.writeFileSync( path.join(root, 'src/core/db/schema.ts'), '// 자동 생성: schema.sql 사본 (npm run build 가 다시 만든다)\nexport const SCHEMA_SQL = ' + JSON.stringify(fs.readFileSync(path.join(root, 'src/core/db/schema.sql'), 'utf8')) + ';\n', ); fs.rmSync(path.join(root, 'dist'), { recursive: true, force: true }); // 겜녹이 기본 봇 토큰은 exe 에 넣지 않는다. 로그인한 등록 유저에게 사이트 서버가 내려준다 (src/core/auth.ts) const common = { bundle: true, platform: 'node', target: 'node22', format: 'cjs', sourcemap: true, alias: { '@gvr/shared': shared }, logLevel: 'info' }; await build({ ...common, entryPoints: ['src/main/main.ts'], outfile: 'dist/main.cjs', packages: 'external', external: ['electron'] }); await build({ ...common, entryPoints: ['src/main/preload.ts'], outfile: 'dist/preload.cjs', external: ['electron'] }); await build({ ...common, entryPoints: ['src/core/cli.ts'], outfile: 'dist/cli.cjs', packages: 'external' }); if (fs.existsSync(path.join(root, 'src/renderer/main.tsx'))) { await build({ entryPoints: ['src/renderer/main.tsx'], bundle: true, outfile: 'dist/renderer/renderer.js', platform: 'browser', target: 'chrome130', jsx: 'automatic', loader: { '.png': 'file', '.svg': 'file' }, alias: { '@gvr/shared': shared }, define: { 'process.env.NODE_ENV': '"production"' }, minify: true, logLevel: 'info', }); fs.copyFileSync('src/renderer/index.html', 'dist/renderer/index.html'); }