1
0
Fork 0

wip: Changes to lab for v3

This commit is contained in:
Joost De Cock 2022-08-29 08:29:55 +02:00
parent 1de3e428c1
commit 0431764a66
9 changed files with 19 additions and 751 deletions

View file

@ -1,531 +0,0 @@
{
"2.20.8": [
"aaron",
"albert",
"bee",
"bella",
"benjamin",
"bent",
"breanna",
"brian",
"bruce",
"carlita",
"carlton",
"cathrin",
"charlie",
"cornelius",
"diana",
"examples",
"florence",
"florent",
"holmes",
"hortensia",
"huey",
"hugo",
"jaeger",
"legend",
"lunetius",
"paco",
"penelope",
"plugintest",
"rendertest",
"sandy",
"shin",
"simon",
"simone",
"sven",
"tamiko",
"teagan",
"theo",
"tiberius",
"titan",
"trayvon",
"tutorial",
"ursula",
"wahid",
"walburga",
"waralee",
"yuri"
],
"2.20.7": [
"aaron",
"albert",
"bee",
"bella",
"benjamin",
"bent",
"breanna",
"brian",
"bruce",
"carlita",
"carlton",
"cathrin",
"charlie",
"cornelius",
"diana",
"examples",
"florence",
"florent",
"holmes",
"hortensia",
"huey",
"hugo",
"jaeger",
"legend",
"lunetius",
"paco",
"penelope",
"plugintest",
"rendertest",
"sandy",
"shin",
"simon",
"simone",
"sven",
"tamiko",
"teagan",
"theo",
"tiberius",
"titan",
"trayvon",
"tutorial",
"ursula",
"wahid",
"walburga",
"waralee",
"yuri"
],
"2.20.0": [
"aaron",
"albert",
"bee",
"bella",
"benjamin",
"bent",
"breanna",
"brian",
"bruce",
"carlita",
"carlton",
"cathrin",
"charlie",
"cornelius",
"diana",
"examples",
"florence",
"florent",
"holmes",
"hortensia",
"huey",
"hugo",
"jaeger",
"legend",
"lunetius",
"paco",
"penelope",
"plugintest",
"rendertest",
"sandy",
"shin",
"simon",
"simone",
"sven",
"tamiko",
"teagan",
"theo",
"tiberius",
"titan",
"trayvon",
"tutorial",
"ursula",
"wahid",
"walburga",
"waralee",
"yuri"
],
"2.19.9": [
"aaron",
"albert",
"bee",
"bella",
"benjamin",
"bent",
"breanna",
"brian",
"bruce",
"carlita",
"carlton",
"cathrin",
"charlie",
"cornelius",
"diana",
"examples",
"florence",
"florent",
"holmes",
"hortensia",
"huey",
"hugo",
"jaeger",
"legend",
"lunetius",
"paco",
"penelope",
"rendertest",
"sandy",
"shin",
"simon",
"simone",
"sven",
"tamiko",
"teagan",
"theo",
"tiberius",
"titan",
"trayvon",
"tutorial",
"ursula",
"wahid",
"walburga",
"waralee",
"yuri"
],
"2.19.0": [
"aaron",
"albert",
"bee",
"bella",
"benjamin",
"bent",
"breanna",
"brian",
"bruce",
"carlita",
"carlton",
"cathrin",
"charlie",
"cornelius",
"diana",
"examples",
"florence",
"florent",
"holmes",
"hortensia",
"huey",
"hugo",
"jaeger",
"legend",
"lunetius",
"paco",
"penelope",
"rendertest",
"sandy",
"shin",
"simon",
"simone",
"sven",
"tamiko",
"teagan",
"theo",
"tiberius",
"titan",
"trayvon",
"tutorial",
"ursula",
"wahid",
"walburga",
"waralee",
"yuri"
],
"2.18.0": [
"aaron",
"albert",
"bella",
"benjamin",
"bent",
"breanna",
"brian",
"bruce",
"carlita",
"carlton",
"cathrin",
"charlie",
"cornelius",
"diana",
"examples",
"florence",
"florent",
"holmes",
"hortensia",
"huey",
"hugo",
"jaeger",
"legend",
"paco",
"penelope",
"rendertest",
"sandy",
"shin",
"simon",
"simone",
"sven",
"tamiko",
"teagan",
"theo",
"titan",
"trayvon",
"tutorial",
"ursula",
"wahid",
"waralee",
"yuri"
],
"2.17.1": [
"aaron",
"albert",
"bella",
"benjamin",
"bent",
"breanna",
"brian",
"bruce",
"carlita",
"carlton",
"cathrin",
"charlie",
"cornelius",
"diana",
"examples",
"florence",
"florent",
"holmes",
"hortensia",
"huey",
"hugo",
"jaeger",
"legend",
"paco",
"penelope",
"rendertest",
"sandy",
"shin",
"simon",
"simone",
"sven",
"tamiko",
"teagan",
"theo",
"titan",
"trayvon",
"tutorial",
"ursula",
"wahid",
"waralee"
],
"2.17.0": [
"aaron",
"albert",
"bella",
"benjamin",
"bent",
"breanna",
"brian",
"bruce",
"carlita",
"carlton",
"cathrin",
"charlie",
"cornelius",
"diana",
"examples",
"florence",
"florent",
"holmes",
"hortensia",
"huey",
"hugo",
"jaeger",
"legend",
"paco",
"penelope",
"rendertest",
"sandy",
"shin",
"simon",
"simone",
"sven",
"tamiko",
"teagan",
"theo",
"titan",
"trayvon",
"tutorial",
"ursula",
"wahid",
"waralee"
],
"2.16.2": [
"aaron",
"albert",
"bella",
"benjamin",
"bent",
"breanna",
"brian",
"bruce",
"carlita",
"carlton",
"cathrin",
"charlie",
"cornelius",
"diana",
"examples",
"florence",
"florent",
"holmes",
"hortensia",
"huey",
"hugo",
"jaeger",
"legend",
"paco",
"penelope",
"rendertest",
"sandy",
"shin",
"simon",
"simone",
"sven",
"tamiko",
"teagan",
"theo",
"titan",
"trayvon",
"tutorial",
"wahid",
"waralee"
],
"2.16.0": [
"aaron",
"albert",
"bella",
"benjamin",
"bent",
"breanna",
"brian",
"bruce",
"carlita",
"carlton",
"cathrin",
"charlie",
"cornelius",
"diana",
"examples",
"florence",
"florent",
"holmes",
"hortensia",
"huey",
"hugo",
"jaeger",
"legend",
"paco",
"penelope",
"rendertest",
"sandy",
"shin",
"simon",
"simone",
"sven",
"tamiko",
"teagan",
"theo",
"titan",
"trayvon",
"tutorial",
"wahid",
"waralee"
],
"2.15.4": [
"aaron",
"albert",
"bella",
"benjamin",
"bent",
"breanna",
"brian",
"bruce",
"carlita",
"carlton",
"cathrin",
"charlie",
"cornelius",
"diana",
"examples",
"florence",
"florent",
"holmes",
"hortensia",
"huey",
"hugo",
"jaeger",
"legend",
"paco",
"penelope",
"rendertest",
"sandy",
"shin",
"simon",
"simone",
"sven",
"tamiko",
"teagan",
"theo",
"titan",
"trayvon",
"tutorial",
"wahid",
"waralee"
],
"2.15.0": [
"aaron",
"albert",
"bella",
"benjamin",
"bent",
"breanna",
"brian",
"bruce",
"carlita",
"carlton",
"cathrin",
"charlie",
"cornelius",
"diana",
"examples",
"florence",
"florent",
"holmes",
"hortensia",
"huey",
"hugo",
"jaeger",
"legend",
"paco",
"penelope",
"rendertest",
"sandy",
"shin",
"simon",
"simone",
"sven",
"tamiko",
"teagan",
"theo",
"titan",
"trayvon",
"tutorial",
"wahid",
"waralee"
]
}

View file

@ -13,6 +13,13 @@ const config = {
pageExtensions: [ 'js', 'mjs' ], pageExtensions: [ 'js', 'mjs' ],
webpack: (config, options) => { webpack: (config, options) => {
// JSON support
config.module.rules.push({
test: /\.json$/,
type: 'json',
use: 'json-loader'
})
// YAML support // YAML support
config.module.rules.push({ config.module.rules.push({
test: /\.ya?ml$/, test: /\.ya?ml$/,
@ -37,18 +44,16 @@ const config = {
// Load designs from source, rather than compiled package // Load designs from source, rather than compiled package
for (const design in designs) { for (const design in designs) {
config.resolve.alias[`@freesewing/${design}$`] = path.resolve(`../../designs/${design}/src/index.js`) config.resolve.alias[`@freesewing/${design}$`] = path.resolve(`../../designs/${design}/src/index.mjs`)
} }
// Load plugins from source, rather than compiled package // Load plugins from source, rather than compiled package
for (const plugin in plugins) { for (const plugin in plugins) {
config.resolve.alias[`@freesewing/${plugin}$`] = path.resolve(`../../plugins/${plugin}/src/index.js`) config.resolve.alias[`@freesewing/${plugin}$`] = path.resolve(`../../plugins/${plugin}/src/index.mjs`)
} }
// Load these from source, rather than compiled package // Load these from source, rather than compiled package
for (const pkg of ['core', 'config-helpers', 'i18n', 'models']) { for (const pkg of ['core', 'i18n', 'models']) {
config.resolve.alias[`@freesewing/${pkg}$`] = path.resolve(`../../packages/${pkg}/src/index.js`) config.resolve.alias[`@freesewing/${pkg}$`] = path.resolve(`../../packages/${pkg}/src/index.mjs`)
} }
// @freesewing/snapseries is replaced by @freesewing/config-helpers
config.resolve.alias[`@freesewing/snapseries`] = path.resolve(`../../packages/config-helpers/src/index.js`)
if (!greeting) { if (!greeting) {
greeting = true greeting = true

View file

@ -1,67 +0,0 @@
import React from 'react'
import Page from 'site/components/wrappers/page.js'
import useApp from 'site/hooks/useApp.js'
import Link from 'next/link'
import { formatVersionTitle } from 'site/components/version-picker.js'
import Layout from 'site/components/layouts/bare'
import { PageTitle } from 'shared/components/layouts/default'
import availableVersions from 'site/available-versions.json'
const DesignLinks = ({ list, prefix='', version=false }) => (
<ul className="flex flex-row flex-wrap ml-8">
{list.map( d => (
<li key={d} className="p-2">
<Link href={`${prefix}/${d}`}>
<a className="capitalize text-secondary hover:text-secondary-focus hover:underline">
{d}
</a>
</Link>
</li>
))}
</ul>
)
const VersionLinks = ({ list, prefix='', version=false, currentDesigns=[] }) => (
<ul className="flex flex-col flex-wrap gap-2">
<li className="p-2">
<Link href={`v/next`}>
<a className="capitalize text-xl p-4 font-bold text-secondary hover:text-secondary-focus hover:underline">
Next <span className="font-normal">(Current develop branch)</span>
</a>
</Link>
<DesignLinks list={currentDesigns} />
</li>
{list.map( v => (
<li key={v} className="p-2">
<Link href={`v/${v}`}>
<a className="capitalize text-xl p-4 font-bold text-secondary hover:text-secondary-focus hover:underline">
v{v}
</a>
</Link>
<DesignLinks list={availableVersions[v]} />
</li>
))}
</ul>
)
const VersionListPage = ({ section=false, version=false }) => {
const app = useApp()
const currentDesigns = []
for (const section in app.designs) currentDesigns.push(...app.designs[section])
return (
<Page app={app} title={`FreeSewing Lab: ${formatVersionTitle(version)}`} layout={Layout}>
<div className="max-w-7xl m-auto py-20 md:py-36 min-h-screen">
<section className="px-8">
<PageTitle app={app} title="Versions" />
<VersionLinks list={Object.keys(availableVersions)} currentDesigns={currentDesigns} />
</section>
</div>
</Page>
)
}
export default VersionListPage

View file

@ -1,15 +0,0 @@
[
"2.20.8",
"2.20.7",
"2.20.0",
"2.19.9",
"2.19.0",
"2.18.0",
"2.17.1",
"2.17.0",
"2.16.2",
"2.16.0",
"2.15.4",
"2.15.0"
]

View file

@ -1,6 +1,6 @@
import Worker from 'web-worker'; import Worker from 'web-worker';
import fileSaver from 'file-saver' import fileSaver from 'file-saver'
import theme from '@freesewing/plugin-theme' import { themePlugin } from '@freesewing/plugin-theme'
import { pagesPlugin } from '../layout/print/plugin' import { pagesPlugin } from '../layout/print/plugin'
import {utils} from '@freesewing/core' import {utils} from '@freesewing/core'
@ -75,7 +75,7 @@ export const handleExport = async(format, gist, design, t, app, onComplete, onEr
let pattern = new design({...gist, layout}) let pattern = new design({...gist, layout})
// add the theme and translation to the pattern // add the theme and translation to the pattern
pattern.use(theme, {stripped: format !== 'svg'}) pattern.use(themePlugin, {stripped: format !== 'svg'})
pattern.use({ pattern.use({
hooks: { hooks: {
insertText: (locale, text, {t}) => t(text) insertText: (locale, text, {t}) => t(text)

View file

@ -1,6 +1,6 @@
import fs_ from 'fs' import fs_ from 'fs'
import path from 'path' import path from 'path'
import axios from 'axios' import { capitalize } from '../utils.mjs'
import { designsByType } from '../../../config/software/index.mjs' import { designsByType } from '../../../config/software/index.mjs'
const fs = fs_.promises const fs = fs_.promises
@ -14,28 +14,14 @@ const header = `/*
* *
* sites/shared/prebuild/lab.mjs * sites/shared/prebuild/lab.mjs
* *
*/ */`
`
const loadFromUnpkg = (design, version) => {
const start = Date.now()
return axios
.get(`https://unpkg.com/@freesewing/${design}@${version}/dist/index.mjs`)
.then(res => {
if (res.data) {
console.log(`Downloaded @freesewing/${design}@${version} in ${Date.now() - start}ms`)
return res.data
}
return false
})
.catch(err => false)
}
const pageTemplate = design => `${header} const pageTemplate = design => `${header}
import design from 'designs/${design}/src/index.js' import { ${capitalize(design)} } from 'designs/${design}/src/index.mjs'
import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
import PageTemplate from 'site/page-templates/workbench.js' import PageTemplate from 'site/page-templates/workbench.mjs'
const Page = (props) => <PageTemplate {...props} design={design} version="next"/> const Page = (props) => <PageTemplate {...props} design={${capitalize(design)}} version="next"/>
export default Page export default Page
export async function getStaticProps({ locale }) { export async function getStaticProps({ locale }) {
@ -47,54 +33,12 @@ export async function getStaticProps({ locale }) {
} }
` `
const versionedPageTemplate = (design, version) => `${header}
import design from 'lib/${version}/${design}.mjs'
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
import PageTemplate from 'site/page-templates/workbench.js'
const Page = (props) => <PageTemplate {...props} design={design} version="${version}"/>
export default Page
export async function getStaticProps({ locale }) {
return {
props: {
...(await serverSideTranslations(locale)),
}
}
}
`
const versionOverviewPage = (version) => `${header}
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
import Template from 'site/page-templates/design-list.js'
const Page = props => <Template {...props} version="${version}" />
export default Page
export async function getStaticProps({ locale }) {
return {
props: {
...(await serverSideTranslations(locale)),
}
}
}
`
/* /*
* Main method that does what needs doing * Main method that does what needs doing
*/ */
export const prebuildLab = async (site) => { export const prebuildLab = async (site) => {
const promises = [] const promises = []
const availableVersions = {}
// Load config
const versions = JSON.parse(await fs.readFile(
path.resolve('..', 'lab', 'versions.json'),
'utf-8'
))
for (const section in designsByType) { for (const section in designsByType) {
// Iterate over sections // Iterate over sections
console.log(`Generating pages for ${section} designs`) console.log(`Generating pages for ${section} designs`)
@ -114,75 +58,7 @@ export const prebuildLab = async (site) => {
path.resolve(...pages, section, `${design}.mjs`), path.resolve(...pages, section, `${design}.mjs`),
page page
), ),
fs.writeFile(
path.resolve(...pages, 'v', 'next', `${design}.mjs`),
page
) )
)
if (process.env.BUILD_ALL_VERSIONS) {
// Download published versions from unpkg
for (const version of versions) {
if (typeof availableVersions[version] === 'undefined') availableVersions[version] = new Set()
// Assume that if the file is on disk, it's good to go (caching)
const file = path.resolve('..', 'lab', 'lib', version, `${design}.mjs`)
let cached
try {
await fs.access(file)
cached = true
}
catch(err) {
cached = false
}
if (!cached) {
await fs.mkdir(path.resolve('..', 'lab', 'lib', version), { recursive: true })
await fs.mkdir(path.resolve('..', 'lab', 'pages', 'v', version), { recursive: true })
const code = (await loadFromUnpkg(design, version))
if (code) {
availableVersions[version].add(design)
promises.push(
fs.writeFile(
path.resolve('..', 'lab', 'lib', version, `${design}.mjs`),
code
),
fs.writeFile(
path.resolve('..', 'lab', 'pages', 'v', version, `${design}.mjs`),
versionedPageTemplate(design, version)
),
)
} else console.log(`No ${version} for ${design}`)
} else {
availableVersions[version].add(design)
}
}
}
}
}
if (process.env.BUILD_ALL_VERSIONS) {
// Write available versions file
const av = {}
for (const [v, set] of Object.entries(availableVersions)) av[v] = [...set].sort()
promises.push(
fs.writeFile(
path.resolve('..', 'lab', 'available-versions.json'),
JSON.stringify(av, null, 2)
)
)
// Also add version overview pages
for (const version of versions) {
// Assume that if the file is on disk, it's good to go (caching)
const page = path.resolve('..', 'lab', 'pages', 'v', version, 'index.js')
let cached
try {
await fs.access(page)
cached = true
}
catch(err) {
cached = false
}
// Create page if it's not there already
if (!cached) promises.push(fs.writeFile(page, versionOverviewPage(version)))
} }
} }