@@ -23,6 +23,7 @@ import {
2323 logVersion
2424} from './logHelper.js' ;
2525import path from 'path' ;
26+ import { getParserOptions } from './utils.js' ;
2627
2728const ensureTrailingSlash = ( inputString : string ) : string => {
2829 if ( ! inputString ) {
@@ -31,25 +32,23 @@ const ensureTrailingSlash = (inputString: string): string => {
3132 return inputString . at ( - 1 ) === path . sep ? inputString : `${ inputString } ` + path . sep ;
3233} ;
3334
34- const getParserFromFormat = ( inputString : string ) : StyleParser | undefined = > {
35+ const getParserFromFormat = ( inputString : string , parserOptions : Record < string , unknown > ) : StyleParser | undefined = > {
3536 if ( ! inputString ) {
3637 throw new Error ( 'No input' ) ;
3738 }
3839 switch ( inputString . toLowerCase ( ) ) {
3940 case 'lyrx' :
4041 return new LyrxParser ( ) ;
4142 case 'mapbox' :
42- return new MapboxParser ( ) ;
43+ return new MapboxParser ( parserOptions ) ;
4344 case 'mapfile' :
4445 case 'map' :
45- return new MapfileParser ( ) ;
46+ return new MapfileParser ( parserOptions ) ;
4647 case 'sld' :
47- return new SLDParser ( ) ;
48- case 'se' :
49- return new SLDParser ( { sldVersion : '1.1.0' } ) ;
48+ return new SLDParser ( parserOptions ) ;
5049 case 'qgis' :
5150 case 'qml' :
52- return new QGISParser ( ) ;
51+ return new QGISParser ( parserOptions ) ;
5352 case 'ol-flat' :
5453 return new OlFlatStyleParser ( ) ;
5554 case 'geostyler' :
@@ -119,7 +118,7 @@ const computeTargetPath = (
119118 outputPath = path . normalize ( outputPath ) ;
120119
121120 // Case file -> directory
122- // Get output name from source and add extension.
121+ // Gets output name from source and add extension.
123122 const pathElements = sourcePathFile . split ( path . sep ) ;
124123 const lastElement = pathElements ?. pop ( ) ;
125124 pathElements . shift ( ) ;
@@ -236,8 +235,10 @@ async function main() {
236235 const {
237236 s,
238237 source,
238+ sourceOptions,
239239 t,
240240 target,
241+ targetOptions,
241242 o,
242243 output,
243244 h,
@@ -270,20 +271,20 @@ async function main() {
270271 isSilent : ! ! quiet || false ,
271272 } ) . start ( ) ;
272273
273- // Check source path arg.
274+ // Check the source path arg.
274275 if ( ! sourcePath ) {
275276 indicator . fail ( 'No input file or folder specified.' ) ;
276277 process . exit ( 1 ) ;
277278 }
278279
279- // Check source exists, is a dir or a file ?
280+ // Check a source exists, is a dir or a file?
280281 if ( sourcePath !== '-' && ! existsSync ( sourcePath ) ) {
281282 indicator . fail ( 'Input file or folder does not exist.' ) ;
282283 process . exit ( 1 ) ;
283284 }
284285 const sourceIsFile = ( sourcePath !== '-' ) && lstatSync ( sourcePath ) . isFile ( ) ;
285286
286- // Try to define type of target (file or dir).
287+ // Try to define the type of target (file or dir).
287288 // Assume the target is the same as the source
288289 let targetIsFile = sourceIsFile ;
289290
@@ -301,28 +302,30 @@ async function main() {
301302 indicator . info ( 'No sourceparser was specified. Input will be parsed as a GeoStyler object.' ) ;
302303 sourceFormat = 'geostyler' ;
303304 }
304- const sourceParser = getParserFromFormat ( sourceFormat ) ;
305+ const sourceParserOptions = getParserOptions ( sourceOptions ) ;
306+ const sourceParser = getParserFromFormat ( sourceFormat , sourceParserOptions ) ;
305307
306- // Get target parser.
308+ // Get the target parser.
307309 if ( ! targetFormat && targetIsFile ) {
308310 targetFormat = getFormatFromFilename ( outputPath ) ;
309311 }
310312 if ( ! targetFormat ) {
311313 indicator . info ( 'No targetparser was specified. Output will be a GeoStyler object.' ) ;
312314 targetFormat = 'geostyler' ;
313315 }
314- const targetParser = getParserFromFormat ( targetFormat ) ;
316+ const targetParserOptions = getParserOptions ( targetOptions ) ;
317+ const targetParser = getParserFromFormat ( targetFormat , targetParserOptions ) ;
315318
316- // Get source(s) path(s).
319+ // Get the source(s) path(s).
317320 const sourcePaths = collectPaths ( sourcePath , sourceIsFile ) ;
318321
319322 const writePromises : Promise < number > [] = [];
320323 sourcePaths.forEach((srcPath) => {
321324 indicator . text = `Transforming ${ srcPath } from ${ sourceFormat } to ${ targetFormat } ` ;
322- // Get correct output path
325+ // Get a correct output path
323326 const outputPathFile = computeTargetPath ( srcPath , outputPath , targetIsFile , targetFormat ) ;
324327
325- // Add the the translation promise.
328+ // Add the translation promise.
326329 writePromises . push ( writeFile ( srcPath , sourceParser , outputPathFile , targetParser , indicator ) ) ;
327330 } ) ;
328331
0 commit comments