1
0
Fork 0
freesewing/sites/shared/prebuild/lab.mjs

65 lines
2 KiB
JavaScript
Raw Normal View History

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'
2023-05-17 17:04:15 +02:00
import { plugins, designs } from '../../../config/software/index.mjs'
2022-02-09 18:58:16 +01:00
const fs = fs_.promises
2022-02-09 18:58:16 +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-02-09 18:58:16 +01:00
/*
* Main method that does what needs doing
*/
2023-02-05 19:58:25 +01:00
export const prebuildLab = async () => {
2023-05-17 17:04:15 +02:00
// FIXME: handle this
return
const promises = []
2022-06-17 12:02:09 +02:00
for (const section in designsByType) {
// Iterate over sections
2022-06-17 12:02:09 +02:00
console.log(`Generating pages for ${section} designs`)
for (const design in designsByType[section]) {
// 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 })
await fs.mkdir(path.resolve(...pages, section, 'v', 'next'), { recursive: true })
promises.push(
fs.writeFile(path.resolve(...pages, `${design}.mjs`), page),
fs.writeFile(path.resolve(...pages, section, `${design}.mjs`), page)
)
2022-02-09 18:58:16 +01:00
}
}
// Write designs file
const header =
'// This file is auto-generated by the prebuild script | Any changes will be overwritten\n'
const nl = '\n'
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}`
)
)
await Promise.all(promises)
2022-02-09 18:58:16 +01:00
}