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
*
* /
const fs = require ( 'fs' )
const path = require ( 'path' )
const core = require ( '../packages/core/dist' )
const pi = require ( '../packages/pattern-info/dist' )
const models = require ( '../packages/models/dist' )
const wb32 = models . withBreasts . size32
2022-06-26 20:12:11 +02:00
const noVersions = require ( '../plugins/plugin-versionfree-svg' )
2023-02-07 16:59:20 -06:00
let { capitalize } = require ( '../packages/core/src/utils.mjs' )
2022-06-26 20:12:11 +02:00
capitalize = capitalize . default
2022-06-27 11:13:55 +02:00
let theme = require ( '../plugins/plugin-theme/dist' )
theme = theme . default
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
}
const createImages = ( ) => {
for ( const pattern of pi . list ) {
2022-06-27 11:13:55 +02:00
if ( true || pattern === 'unice' ) {
2022-06-26 20:12:11 +02:00
const Pattern = require ( ` ../designs/ ${ pattern } /dist/index.js ` ) [ capitalize ( pattern ) ]
for ( const option of pi . options [ pattern ] ) {
const p = new Pattern ( {
measurements : wb32 ,
settings : {
idPrefix : ` ${ pattern } _ ${ option } ` ,
embed : true ,
2023-02-07 16:59:20 -06:00
} ,
} )
. use ( theme )
. use ( noVersions )
const file = path . join (
'markdown' ,
'org' ,
'docs' ,
'patterns' ,
pattern ,
'options' ,
option . toLowerCase ( ) ,
` ${ pattern } _ ${ option . toLowerCase ( ) } _sample.svg `
)
2022-06-26 20:12:11 +02:00
try {
const svg = p . sampleOption ( option ) . render ( )
fs . writeFileSync ( path . join ( _ _dirname , '..' , file ) , svg )
insertImage (
2023-02-07 16:59:20 -06:00
path . join (
'markdown' ,
'org' ,
'docs' ,
'patterns' ,
pattern ,
'options' ,
option . toLowerCase ( ) ,
'en.md'
) ,
2022-06-26 20:12:11 +02:00
pattern ,
option
)
2023-02-07 16:59:20 -06:00
console . log ( '✅ ' + file )
2022-06-26 20:12:11 +02:00
} catch ( err ) {
2023-02-07 16:59:20 -06:00
console . log ( '⚠️ ' + file )
2022-06-26 20:12:11 +02:00
console . log ( err )
2021-08-27 12:39:41 +02:00
}
2022-06-26 20:12:11 +02:00
}
2021-08-27 12:39:41 +02:00
}
}
}
createImages ( )