2023-04-30 13:46:47 +02:00
|
|
|
import fs_ from 'fs'
|
|
|
|
import path from 'path'
|
2023-05-05 19:56:51 +02:00
|
|
|
import allDesigns from '../../../config/software/designs.json' assert { type: 'json' }
|
2023-04-30 13:46:47 +02:00
|
|
|
import { capitalize } from '../../../sites/shared/utils.mjs'
|
|
|
|
|
|
|
|
const fs = fs_.promises
|
|
|
|
|
|
|
|
// async import
|
|
|
|
async function loadDesign(design) {
|
|
|
|
let result
|
|
|
|
try {
|
|
|
|
result = await import(`../../../designs/${design}/src/index.mjs`)
|
|
|
|
} catch (err) {
|
|
|
|
console.log(`Failed to load design ${design}:`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
export const prebuildDesigns = async () => {
|
|
|
|
const promises = []
|
|
|
|
const designs = []
|
|
|
|
|
|
|
|
// Compile list of designs
|
2023-05-05 19:56:51 +02:00
|
|
|
for (const design in allDesigns) {
|
|
|
|
console.log(design)
|
|
|
|
if (allDesigns[design]?.tags) designs.push(design)
|
2023-04-30 13:46:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const measurements = {}
|
|
|
|
const options = {}
|
|
|
|
for (const design of designs) {
|
|
|
|
const bundle = await loadDesign(design)
|
|
|
|
const Instance = new bundle[capitalize(design)]()
|
|
|
|
const config = Instance.getConfig()
|
|
|
|
measurements[design] = config.measurements
|
|
|
|
options[design] = config.options
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write out prebuild files
|
|
|
|
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('..', 'org', 'prebuild', 'designs.mjs'),
|
|
|
|
`${header}export const designs = ${JSON.stringify(designs)}${nl}`
|
|
|
|
),
|
|
|
|
fs.writeFile(
|
|
|
|
path.resolve('..', 'org', 'prebuild', 'design-measurements.mjs'),
|
|
|
|
`${header}export const measurements = ${JSON.stringify(measurements)}${nl}`
|
|
|
|
),
|
|
|
|
fs.writeFile(
|
|
|
|
path.resolve('..', 'org', 'prebuild', 'design-options.mjs'),
|
|
|
|
`${header}export const options = ${JSON.stringify(options)}${nl}`
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
await Promise.all(promises)
|
|
|
|
}
|