feat: 카드·영상 스크립트를 윈도우에서도 돌게 — 외부 프로그램 위치를 scripts/bin.mjs 로 모음, 크롬이 45초 넘게 멈추면 그 장만 다시 찍음, claude 프롬프트는 stdin 으로
This commit is contained in:
1 parent
63b4fa74fe
commit
e28359ff47
15 files changed
+150
-51
No files matched your search
+12
-5
@@ -8,6 +8,7 @@
|
||||
import { execFileSync } from 'node:child_process'
|
||||
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
import { CHROME, toJpeg } from './bin.mjs'
|
||||
|
||||
const SLIDES = { tarot: 5, ootd: 4, intro: 8, foliage: 5 }
|
||||
// 기본 문구가 서비스 데이터 그대로라 Claude 기획이 꼭 필요한 템플릿 (src/cards/templates.tsx autoPlan)
|
||||
@@ -16,7 +17,6 @@ const AUTO_PLAN = ['tarot']
|
||||
const THEMES = ['sunset', 'sky', 'mint', 'berry', 'lemon', 'lavender']
|
||||
const ADMIN_URL = process.env.ADMIN_URL ?? 'http://localhost:5175'
|
||||
const API_URL = process.env.VITE_API_BASE_URL ?? 'http://localhost:9810'
|
||||
const CHROME = process.env.CHROME_PATH ?? '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
|
||||
|
||||
function fail(message) {
|
||||
console.error(message)
|
||||
@@ -46,7 +46,7 @@ const [template] = args
|
||||
|
||||
if (!SLIDES[template]) fail(`사용: npm run card -- <${Object.keys(SLIDES).join('|')}> [--topic 주제] [--feedback 피드백] [--color ${THEMES.join('|')}] [--copy 값] [--out 폴더]`)
|
||||
if (color && !THEMES.includes(color)) fail(`색은 ${THEMES.join(', ')} 중 하나예요.`)
|
||||
if (!existsSync(CHROME)) fail(`Chrome을 찾지 못했어요: ${CHROME}\nCHROME_PATH 환경변수로 경로를 알려 주세요.`)
|
||||
if (/[\\/]/.test(CHROME) && !existsSync(CHROME)) fail(`Chrome을 찾지 못했어요: ${CHROME}\nCHROME_PATH 환경변수로 경로를 알려 주세요.`)
|
||||
|
||||
await fetch(`${API_URL}/v1/region/list`).catch((e) => fail(`날씨각 API(${API_URL})에 연결하지 못했어요. 백엔드가 켜져 있는지 확인하세요. (${e.message})`))
|
||||
await fetch(ADMIN_URL).catch(() => fail(`관리자 화면(${ADMIN_URL})이 꺼져 있어요. admin 폴더에서 npm run dev 를 먼저 켜 주세요.`))
|
||||
@@ -128,7 +128,7 @@ for (let slide = 1; slide <= SLIDES[template]; slide++) {
|
||||
if (copy) query.set('copy', copy)
|
||||
const png = resolve(outDir, `${day}_${template}_${slide}.png`)
|
||||
const jpg = png.replace(/\.png$/, '.jpg')
|
||||
execFileSync(CHROME, [
|
||||
const shot = [
|
||||
'--headless=new',
|
||||
'--disable-gpu',
|
||||
'--hide-scrollbars',
|
||||
@@ -137,8 +137,15 @@ for (let slide = 1; slide <= SLIDES[template]; slide++) {
|
||||
'--virtual-time-budget=20000',
|
||||
`--screenshot=${png}`,
|
||||
`${ADMIN_URL}/render?${query}`,
|
||||
], { stdio: 'ignore' })
|
||||
execFileSync('sips', ['-s', 'format', 'jpeg', '-s', 'formatOptions', '92', png, '--out', jpg], { stdio: 'ignore' })
|
||||
]
|
||||
// 크롬이 한 장에서 멈추는 일이 있어 45초 넘으면 끊고 그 장만 한 번 더 찍는다
|
||||
try {
|
||||
execFileSync(CHROME, shot, { stdio: 'ignore', timeout: 45_000 })
|
||||
} catch {
|
||||
console.log(`${slide}번째 장이 45초 넘게 멈춰 다시 찍어요`)
|
||||
execFileSync(CHROME, shot, { stdio: 'ignore', timeout: 45_000 })
|
||||
}
|
||||
toJpeg(png, jpg)
|
||||
rmSync(png)
|
||||
files.push(jpg)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user