2022-03-26 18:06:02 +01:00
|
|
|
import fs_ from 'fs'
|
2022-02-09 18:58:16 +01:00
|
|
|
import path from 'path'
|
2022-08-29 08:29:55 +02:00
|
|
|
import { capitalize } from '../utils.mjs'
|
2022-08-29 17:44:50 +02:00
|
|
|
import { designsByType, plugins, designs } from '../../../config/software/index.mjs'
|
2022-02-09 18:58:16 +01:00
|
|
|
|
2022-03-26 18:06:02 +01:00
|
|
|
const fs = fs_.promises
|
2022-02-09 18:58:16 +01:00
|
|
|
|
2022-03-26 18:06:02 +01:00
|
|
|
const header = `/*
|
|
|
|
*
|
|
|
|
* This page was auto-generated by the prebuild script
|
2022-02-09 18:58:16 +01:00
|
|
|
* Any changes you make to it will be lost on the next (pre)build.
|
|
|
|
*
|
|
|
|
* If you want to make changes, update the pageTemplate in:
|
|
|
|
*
|
2022-06-17 12:02:09 +02:00
|
|
|
* sites/shared/prebuild/lab.mjs
|
2022-02-09 18:58:16 +01:00
|
|
|
*
|
2022-08-29 08:29:55 +02:00
|
|
|
*/`
|
2022-03-26 18:06:02 +01:00
|
|
|
|
2023-02-05 17:59:22 +01:00
|
|
|
const pageTemplate = (design) => `${header}
|
2022-08-29 08:29:55 +02:00
|
|
|
import { ${capitalize(design)} } from 'designs/${design}/src/index.mjs'
|
2022-03-26 18:06:02 +01:00
|
|
|
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
|
2023-02-05 17:59:22 +01:00
|
|
|
import { WorkbenchPage } from 'site/page-templates/workbench.mjs'
|
2022-03-26 18:06:02 +01:00
|
|
|
|
2023-02-05 17:59:22 +01:00
|
|
|
const Page = (props) => <WorkbenchPage {...props} design={${capitalize(design)}} version="next"/>
|
2022-03-26 18:06:02 +01:00
|
|
|
export default Page
|
|
|
|
|
|
|
|
export async function getStaticProps({ locale }) {
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
...(await serverSideTranslations(locale)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2022-02-09 18:58:16 +01:00
|
|
|
/*
|
|
|
|
* Main method that does what needs doing
|
|
|
|
*/
|
2022-03-26 18:06:02 +01:00
|
|
|
|
2022-02-09 18:58:16 +01:00
|
|
|
export const prebuildLab = async (site) => {
|
2022-03-26 18:06:02 +01:00
|
|
|
const promises = []
|
2022-06-17 12:02:09 +02:00
|
|
|
for (const section in designsByType) {
|
2022-03-26 18:06:02 +01:00
|
|
|
// Iterate over sections
|
2022-06-17 12:02:09 +02:00
|
|
|
console.log(`Generating pages for ${section} designs`)
|
|
|
|
for (const design in designsByType[section]) {
|
2022-03-26 18:06:02 +01:00
|
|
|
// Generate pattern pages for next
|
2022-02-09 18:58:16 +01:00
|
|
|
console.log(` - ${design}`)
|
|
|
|
const page = pageTemplate(design)
|
2022-06-17 12:02:09 +02:00
|
|
|
const pages = ['..', 'lab', 'pages']
|
|
|
|
await fs.mkdir(path.resolve(...pages, 'v', 'next'), { recursive: true })
|
2022-03-26 18:06:02 +01:00
|
|
|
promises.push(
|
2023-02-05 17:59:22 +01:00
|
|
|
fs.writeFile(path.resolve(...pages, `${design}.mjs`), page),
|
|
|
|
fs.writeFile(path.resolve(...pages, section, `${design}.mjs`), page)
|
2022-05-14 15:43:52 +02:00
|
|
|
)
|
2022-02-09 18:58:16 +01:00
|
|
|
}
|
|
|
|
}
|
2022-03-26 18:06:02 +01:00
|
|
|
|
2022-08-29 17:44:50 +02:00
|
|
|
// Write designs file
|
2023-02-05 17:59:22 +01:00
|
|
|
const header =
|
|
|
|
'// This file is auto-generated by the prebuild script | Any changes will be overwritten\n'
|
|
|
|
const nl = '\n'
|
2022-08-29 17:44:50 +02:00
|
|
|
promises.push(
|
|
|
|
fs.writeFile(
|
|
|
|
path.resolve('..', 'lab', 'prebuild', 'designs.mjs'),
|
|
|
|
`${header}export const designs = ${JSON.stringify(Object.keys(designs))}${nl}`
|
|
|
|
),
|
|
|
|
fs.writeFile(
|
|
|
|
path.resolve('..', 'lab', 'prebuild', 'plugins.mjs'),
|
|
|
|
`${header}export const plugins = ${JSON.stringify(Object.keys(plugins))}${nl}`
|
|
|
|
),
|
|
|
|
fs.writeFile(
|
|
|
|
path.resolve('..', 'lab', 'prebuild', 'designs-by-type.mjs'),
|
|
|
|
`${header}export const designsByType = ${JSON.stringify(designsByType)}${nl}`
|
2023-02-05 17:59:22 +01:00
|
|
|
)
|
2022-08-29 17:44:50 +02:00
|
|
|
)
|
|
|
|
|
2022-03-26 18:06:02 +01:00
|
|
|
await Promise.all(promises)
|
2022-02-09 18:58:16 +01:00
|
|
|
}
|