Files
HolodoriCalc/scripts/finalize-offline-build.mjs
T

57 lines
2.4 KiB
JavaScript

import { readFile, rm, writeFile } from 'node:fs/promises';
import path from 'node:path';
const output = path.resolve('offline-dist');
const htmlPath = path.join(output, 'index.html');
const scriptPath = path.join(output, 'assets', 'app.js');
const stylePath = path.join(output, 'assets', 'app.css');
const packageJson = JSON.parse(await readFile(path.resolve('package.json'), 'utf8'));
let html = await readFile(htmlPath, 'utf8');
html = html.replace(/<script type="module" crossorigin src=/g, '<script defer src=');
html = html.replace(/<link rel="stylesheet" crossorigin href=/g, '<link rel="stylesheet" href=');
await writeFile(htmlPath, html);
let script = await readFile(scriptPath, 'utf8');
script = script.replaceAll('/icons/', './icons/');
await writeFile(scriptPath, script);
let style = await readFile(stylePath, 'utf8');
style = style.replaceAll('/icons/', '../icons/');
style += `
/* file://에서는 CSS 마스크 대신 읽기 쉬운 텍스트 뱃지를 사용한다. */
.description-stat-icon { display: none !important; }
.stat-badge .stat-icon,
.filter-options label .stat-icon {
width: auto !important;
height: auto !important;
background: none !important;
mask: none !important;
-webkit-mask: none !important;
font-size: 12px;
font-weight: 800;
line-height: 1;
}
.stat-badge .stat-icon-performance::after,
.filter-options label .stat-icon-performance::after { content: '퍼포먼스'; }
.stat-badge .stat-icon-technique::after,
.filter-options label .stat-icon-technique::after { content: '테크닉'; }
.stat-badge .stat-icon-sense::after,
.filter-options label .stat-icon-sense::after { content: '센스'; }
`;
await writeFile(stylePath, style);
// 채보는 app.js에 포함되므로 public 디렉터리에서 복사된 중복 파일은 제거한다.
await rm(path.join(output, 'data'), { recursive: true, force: true });
await writeFile(path.join(output, 'VERSION.txt'), `${packageJson.version}\n`);
await writeFile(path.join(output, 'README.txt'), `홀로도리 계산기 ${packageJson.version}
1. 압축파일의 내용을 모두 한 폴더에 풀어 주세요.
2. index.html을 Chrome 또는 Edge로 열어 주세요.
3. assets와 icons 폴더는 index.html과 같은 위치에 그대로 두어야 합니다.
계산과 데이터 저장은 사용자의 브라우저에서 처리됩니다.
새 버전으로 교체하기 전에는 사용자 데이터 화면에서 백업 파일을 저장해 주세요.
`);