2021-08-27 12:39:41 +02:00
/ *
* This will create ( SVG ) images for all options of all patterns
* To do that , it will load the configuration from :
*
* config / pattern - options . js
*
* Based on that , it will generate SVG images for each option and store them
* in the relevant folder :
*
* markdown / org / docs / patterns / [ pattern ] / [ option ] / [ pattern ] _ [ option ] _sample . svg
*
* /
2023-02-28 12:04:36 -06:00
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import { designs } from '../config/software/index.mjs'
import { cisFemaleAdult32 } from '../packages/models/dist/index.mjs'
import { plugin as noVersions } from '../plugins/plugin-versionfree-svg/dist/index.mjs'
import { capitalize } from '../packages/core/src/utils.mjs'
import { plugin as theme } from '../plugins/plugin-theme/dist/index.mjs'
// when dependabot updates a dependency in a package.json, we want to update it in our dependencies.yaml
const _ _filename = fileURLToPath ( import . meta . url )
const _ _dirname = path . dirname ( _ _filename )
2021-08-27 12:39:41 +02:00
const image = ( pattern , option ) => `
# # Effect of this option on the pattern
2022-07-10 12:32:52 +02:00
! [ This image shows the effect of this option by superimposing several variants that have a different value for this option ] ( $ { pattern } _$ { option . toLowerCase ( ) } _sample . svg "Effect of this option on the pattern" )
`
2021-08-27 12:39:41 +02:00
const insertImage = ( file , pattern , option ) => {
const md = fs . readFileSync ( file , 'utf-8' )
2023-02-07 16:59:20 -06:00
if ( md . indexOf ( 'image shows the effect of this option' ) === - 1 )
fs . writeFileSync ( file , md + image ( pattern , option ) )
2021-08-27 12:39:41 +02:00
}
2023-02-28 12:04:36 -06:00
const createImages = async ( ) => {
for ( const pattern in designs ) {
2023-02-28 12:46:43 -06:00
const Pattern = ( await import ( ` ../designs/ ${ pattern } /dist/index.mjs ` ) ) [ capitalize ( pattern ) ]
for ( const option in Pattern . patternConfig . options ) {
const p = new Pattern ( {
measurements : cisFemaleAdult32 ,
settings : {
idPrefix : ` ${ pattern } _ ${ option } ` ,
embed : true ,
} ,
} )
. use ( theme )
. use ( noVersions )
. _ _init ( )
2023-02-28 12:04:36 -06:00
2023-02-28 12:46:43 -06:00
const file = path . join (
'markdown' ,
'org' ,
'docs' ,
'patterns' ,
pattern ,
'options' ,
option . toLowerCase ( ) ,
` ${ pattern } _ ${ option . toLowerCase ( ) } _sample.svg `
)
try {
const svg = p . sampleOption ( option ) . render ( )
fs . writeFileSync ( path . join ( _ _dirname , '..' , file ) , svg )
insertImage (
path . join (
'markdown' ,
'org' ,
'docs' ,
'patterns' ,
pattern ,
'options' ,
option . toLowerCase ( ) ,
'en.md'
) ,
2023-02-07 16:59:20 -06:00
pattern ,
2023-02-28 12:46:43 -06:00
option
2023-02-07 16:59:20 -06:00
)
2023-02-28 12:46:43 -06:00
console . log ( '✅ ' + file )
} catch ( err ) {
console . log ( '⚠️ ' + file )
console . log ( err )
2022-06-26 20:12:11 +02:00
}
2021-08-27 12:39:41 +02:00
}
}
}
createImages ( )