import fs from 'fs' import path from 'path' const loadPatterns = () => { const patterns = fs.readFileSync( path.resolve('..', 'freesewing.lab', 'patterns.json'), 'utf-8' ) return JSON.parse(patterns) } const pageTemplate = design => ` /* This page was auto-generated by the prebuild script * Any changes you make to it will be lost on the next (pre)build. * * If you want to make changes, update the pageTemplate in: * * packages/freesewing.shared/prebuild/lab.mjs * */ import pattern from 'pkgs/${design}/src/index.js' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import PageTemplate from 'site/page-templates/workbench.js' const Page = () => export default Page export async function getStaticProps({ locale }) { return { props: { ...(await serverSideTranslations(locale)), } } } ` /* * Main method that does what needs doing */ export const prebuildLab = async (site) => { const patterns = loadPatterns() for (const section in patterns) { console.log(`Generating pages for ${section} patterns`) for (const design of patterns[section]) { console.log(` - ${design}`) const page = pageTemplate(design) fs.writeFileSync( path.resolve('..', `freesewing.lab`, 'pages', section, `${design}.js`), page ) fs.writeFileSync( path.resolve('..', `freesewing.lab`, 'pages', `${design}.js`), page ) } } }