// Apply the DuneRealms palette to the native MIT-licensed LuckPermsWeb editor.
// Run against a clean checkout of the pinned upstream revision, then npm ci && npm run build.
import {readFile,writeFile} from 'node:fs/promises';
import {resolve} from 'node:path';
import {execFileSync} from 'node:child_process';
const root=resolve(process.argv[2]||'.');
export const revision='5e99c720b7c795c7af17cbfc2fd6829a23f19189';
if(execFileSync('git',['-C',root,'rev-parse','HEAD'],{encoding:'utf8'}).trim()!==revision)throw Error('Unexpected LuckPermsWeb revision');
const file=name=>resolve(root,name);
const config=JSON.parse(await readFile(file('config.json'),'utf8'));
config.base='/luckperms-editor/';config.selfHosted=true;
await writeFile(file('config.json'),JSON.stringify(config,null,2));
await writeFile(file('src/scss/variables.scss'),`$brand-color: #d5ab63;
$navy: #0e1c1a;
$grey: #213c30;
$red: #dc8571;
$bg-gradient: linear-gradient(0deg, #142a25, #142a25);
$bg-gradient-dark: linear-gradient(0deg, #0e211a, #0e211a);
`);
let app=await readFile(file('src/App.vue'),'utf8');
app=app.replace('LuckPerms','LuckPerms · DuneRealms').replace('background-color: #141422;','background-color: #142a25;');
await writeFile(file('src/App.vue'),app);
let index=await readFile(file('public/index.html'),'utf8');
index=index.replace(/\s*