Rocky_Mountain_Vending/scripts/sync-manuals-to-public.js
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

71 lines
2.2 KiB
JavaScript

/**
* Script to sync manuals from /manuals to /public/manuals
* This allows static file serving as a backup to the API route
* Useful for GHL hosting or static deployments
*/
import { readdir, copyFile, mkdir, stat } from 'fs/promises'
import { join } from 'path'
import { existsSync } from 'fs'
const PROJECT_ROOT = join(process.cwd(), '..')
const MANUALS_SOURCE = join(PROJECT_ROOT, 'manuals-data', 'manuals')
const MANUALS_PUBLIC = join(process.cwd(), 'public', 'manuals')
async function syncManuals() {
try {
// Create public/manuals directory structure
if (!existsSync(MANUALS_PUBLIC)) {
await mkdir(MANUALS_PUBLIC, { recursive: true })
}
// Get all manufacturer directories
const manufacturers = await readdir(MANUALS_SOURCE, { withFileTypes: true })
for (const manufacturerDir of manufacturers) {
if (!manufacturerDir.isDirectory()) continue
const manufacturer = manufacturerDir.name
const sourcePath = join(MANUALS_SOURCE, manufacturer)
const destPath = join(MANUALS_PUBLIC, manufacturer)
// Create manufacturer directory in public
if (!existsSync(destPath)) {
await mkdir(destPath, { recursive: true })
}
// Get all PDF files
const files = await readdir(sourcePath, { withFileTypes: true })
for (const file of files) {
if (file.isFile() && file.name.toLowerCase().endsWith('.pdf')) {
const sourceFile = join(sourcePath, file.name)
const destFile = join(destPath, file.name)
// Check if file needs updating (compare modification times)
let shouldCopy = true
if (existsSync(destFile)) {
const sourceStats = await stat(sourceFile)
const destStats = await stat(destFile)
shouldCopy = sourceStats.mtime > destStats.mtime
}
if (shouldCopy) {
await copyFile(sourceFile, destFile)
console.log(`Copied: ${manufacturer}/${file.name}`)
}
}
}
}
console.log('✅ Manuals synced to public folder successfully!')
} catch (error) {
console.error('❌ Error syncing manuals:', error)
process.exit(1)
}
}
syncManuals()