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' )
let capitalize = require ( '../packages/utils/capitalize/index.js' )
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
! [ 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" ) `
const insertImage = ( file , pattern , option ) => {
const md = fs . readFileSync ( file , 'utf-8' )
if ( md . indexOf ( 'image shows the effect of this option' ) === - 1 ) fs . writeFileSync ( file , md + image ( pattern , option ) )
}
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 ,
}
} ) . use ( theme ) . use ( noVersions )
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' ) ,
pattern ,
option
)
console . log ( '✅ ' + file )
} catch ( err ) {
console . log ( '⚠️ ' + file )
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 ( )