serene-pub/scripts/customize-build.js
2025-08-17 13:18:45 -07:00

121 lines
6 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
import fs from "fs"
import path from "path"
const buildFile = "build/index.js"
if (!fs.existsSync(buildFile)) {
console.log("Build file not found:", buildFile)
process.exit(1)
}
console.log("🔧 Customizing server build output...")
let content = fs.readFileSync(buildFile, "utf8")
// Replace console.log messages
let replacements = 0
const originalListeningFd = content
content = content.replace(
/console\.log\(`Listening on file descriptor/g,
"console.log(`🚀 Serene Pub listening on file descriptor"
)
if (content !== originalListeningFd) {
replacements++
console.log("✅ Replaced file descriptor listening message")
}
const originalListeningPath = content
content = content.replace(
/console\.log\(`Listening on \$\{path/g,
"console.log(`🚀 Serene Pub listening on ${path"
)
if (content !== originalListeningPath) {
replacements++
console.log("✅ Replaced path listening message")
}
console.log(`Applied ${replacements} basic replacements`)
// Add launch message after the listening message
content = content.replace(
/console\.log\(`🚀 Serene Pub listening on \$\{path \|\| `http:\/\/\$\{host\}:\$\{port\}`\}`\);/g,
`console.log(\`🚀 Serene Pub listening on \${path || \`http://\${host}:\${port}\`}\`);
if (!path) {
console.log(\`\`);
console.log(\` \`);
console.log(\` \`);
console.log(\` @=@ \`);
console.log(\` @@ @@@ ++== \`);
console.log(\` @@@@ @@-- @++--=@ \`);
console.log(\` @@@@@ @@@@--@ ##===== \`);
console.log(\` @#@@@@@ @**@@---@ @#*+=#@ \`);
console.log(\` @##@@@@*####+**@@-@--@ #@#@ \`);
console.log(\` @##@######*****@----- @%*@# \`);
console.log(\` #######******--@@+-# #%@ \`);
console.log(\` ######***********:- %@% \`);
console.log(\` #####+************@ #%@ \`);
console.log(\` @@###+*@+***********# @% \`);
console.log(\` @##@#*+*****#*****+##***@ @%@ \`);
console.log(\` -- %#%#**+@@**:--------@ #%@ \`);
console.log(\` --- @#*****---------@@ %% \`);
console.log(\` --- @#****------:-@+**@@@@@@@%@ \`);
console.log(\` -- @%@**-----@@--:****@@@@%%#%@ \`);
console.log(\` ---- @@--:-@@@@---*****@%%%%%%%%@ \`);
console.log(\` =- %@@@@@@----***@%%%%%%@%@@%@ \`);
console.log(\` = @%%%@@@------:@%%%%@@%@#%@@@ \`);
console.log(\` @@@@@@@+@ @%%@%-----@%%%@%%%%%%%%@@ \`);
console.log(\` @%@==-----@ @@@@%%@=@@%@@%%%%%%%%@%@%@ \`);
console.log(\` @%%==----- @@%%@%**+@@%%%%%%%%%%%#@%% \`);
console.log(\` %@%%@@=--- @@%%%@%%@@%@%%@%%%%%%%%%%%%@ \`);
console.log(\` @@@@@@@ @%%%@@%%%%%@%%@@%%@%%%@%@%%%%@ \`);
console.log(\` %%%@ %%@@%%%@%%%%%%%%@@%%%@%@@%%%%% \`);
console.log(\` @%%@ %%@@@@%%%%@%%%%%%%%%@@%@%%@%%%%%@ \`);
console.log(\` @%%%@@@%@@@%%%%@%%%%%%%%@@@@%@%%%%%%%@ \`);
console.log(\` @%%%%@%%%@@@%%%%%%%%%%%@@@@%%@@%%%%@%% \`);
console.log(\` @@%%%@%%@%@@@@%%%%%%%%@@@@@%%@%%@%%%%@@ \`);
console.log(\` @@@%%%@@%%@@@@%@@@@@@@@%%@@@@@@@%%%@%%%@@ \`);
console.log(\` %@@@@@@@%%@@@@%@%%%%%%@%@@@%%%%%%%%%@@%%@ \`);
console.log(\` @%@@@@@@@%%@@@@@@%%%%@@@@@@%%%@%%%%%%%@#%@ \`);
console.log(\` @@@----=----@@@+@@%%%%%%%@%%%%%%@@%%%%%@@@ \`);
console.log(\` @@@@---=--@====-@@@%%%%%%%%@@@@@@@@%%%%@@ \`);
console.log(\` @@@@@@##@@=+@@@@@-@%@@@% @@@@@@@@%%@@@ \`);
console.log(\` @@@ %@@@@##@ \`);
console.log(\`\`);
console.log(\`╔═══════════════════════════════════════════════════════════╗\`);
console.log(\`║ ____ ____ _ ║\`);
console.log(\`║ / ___| ___ _ __ ___ _ __ ___ | _ \\\\ _ _| |__ ║\`);
console.log(\`\\\\___ \\\\ / _ \\\\ '__/ _ \\\\ '_ \\\\ / _ \\\\ | |_) | | | | '_ \\\\\`);
console.log(\`║ ___) | __/ | | __/ | | | __/ | __/| |_| | |_) | ║\`);
console.log(\`║ |____/ \\\\___|_| \\\\___|_| |_|\\\\___| |_| \\\\__,_|_.__/ ║\`);
console.log(\`║ ║\`);
console.log(\`╚═══════════════════════════════════════════════════════════╝\`);
console.log(\`🌐 Launch Serene Pub in your browser at http://localhost:\${port} or http://127.0.0.1:\${port}\`);
console.log(\`\`);
// Auto-open browser if SERENE_AUTO_OPEN is not disabled
if (process.env.SERENE_AUTO_OPEN !== '1' && process.env.SERENE_AUTO_OPEN !== 'true') {
setTimeout(() => {
import('open').then(({ default: open }) => {
open(\`http://localhost:\${port}\`);
console.log(\`🚀 Opening Serene Pub in your default browser...\`);
}).catch((err) => {
console.warn(\`⚠️ Could not auto-open browser: \${err.message}\`);
console.log(\`💡 You can manually open http://localhost:\${port} in your browser\`);
});
}, 1000);
} else {
console.log(\` Auto-open browser disabled (SERENE_AUTO_OPEN=\${process.env.SERENE_AUTO_OPEN})\`);
}
}`
)
// Add shutdown message - fix the function call pattern
content = content.replace(
/function graceful_shutdown\(reason\) \{/g,
"function graceful_shutdown(reason) {\n\tconsole.log(`👋 Serene Pub shutting down (${reason})`);"
)
fs.writeFileSync(buildFile, content)
console.log("✅ Server build output customized successfully!")