/**
* Cross-platform build script for concatenating cheatsheet with custom instructions.
* Replaces Unix-specific `cat` command that doesn't work on Windows.
*/
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const projectRoot = join(__dirname, '..');
// Files to concatenate
const cheatsheetPath = join(projectRoot, 'Roam_Markdown_Cheatsheet.md');
const customInstructionsPrefix = process.env.CUSTOM_INSTRUCTIONS_PREFIX || '';
const customInstructionsPath = join(projectRoot, '.roam', `${customInstructionsPrefix}custom-instructions.md`);
const outputPath = join(projectRoot, 'build', 'Roam_Markdown_Cheatsheet.md');
// Ensure build directory exists
const buildDir = dirname(outputPath);
if (!existsSync(buildDir)) {
mkdirSync(buildDir, { recursive: true });
}
// Read and concatenate files
let content = '';
if (existsSync(cheatsheetPath)) {
content += readFileSync(cheatsheetPath, 'utf8');
} else {
console.error(`Warning: Cheatsheet not found at ${cheatsheetPath}`);
}
if (existsSync(customInstructionsPath)) {
content += '\n\n' + readFileSync(customInstructionsPath, 'utf8');
console.log(`✓ Concatenated custom instructions from: ${customInstructionsPath}`);
} else {
console.log(`Note: No custom instructions found at ${customInstructionsPath}`);
}
// Write output
writeFileSync(outputPath, content, 'utf8');
console.log(`✓ Build cheatsheet written to: ${outputPath}`);