1- import { ConfigLayer , ConfigTileSetRaster , ConfigTileSetVector } from '@basemaps/config' ;
1+ import { ConfigLayer , ConfigTileSet , ConfigTileSetRaster , ConfigTileSetVector } from '@basemaps/config' ;
22import { LogType , fsa } from '@basemaps/shared' ;
33import { Category , DefaultCategorySetting } from '../cogify/action.make.cog.pr.js' ;
44import { Github } from './github.js' ;
5+ import prettier from 'prettier' ;
56
67export class MakeCogGithub extends Github {
78 imagery : string ;
@@ -10,6 +11,18 @@ export class MakeCogGithub extends Github {
1011 this . imagery = imagery ;
1112 }
1213
14+ async formatConfigFile ( targetPath : string , tileSet : ConfigTileSet ) : Promise < string > {
15+ const cfg = await prettier . resolveConfigFile ( targetPath ) ;
16+ if ( cfg == null ) {
17+ this . logger . error ( 'Prettier:MissingConfig' ) ;
18+ return JSON . stringify ( tileSet , null , 2 ) ;
19+ }
20+ const options = await prettier . resolveConfig ( cfg ) ;
21+ this . logger . info ( { configPath : cfg , prettierOptions : options } , 'Prettier:Config' ) ;
22+ const formatted = prettier . format ( JSON . stringify ( tileSet ) , { ...options , parser : 'json' } ) ;
23+ return formatted ;
24+ }
25+
1326 /**
1427 * Prepare and create pull request for the aerial tileset config
1528 */
@@ -23,13 +36,13 @@ export class MakeCogGithub extends Github {
2336
2437 // Prepare new aerial tileset config
2538 this . logger . info ( { imagery : this . imagery } , 'GitHub: Get the master TileSet config file' ) ;
26- const path = ` ${ this . repoName } / config/ tileset/ ${ filename } .json`;
27- const tileSet = await fsa . readJson < ConfigTileSetRaster > ( path ) ;
39+ const tileSetPath = fsa . joinAll ( this . repoName , ' config' , ' tileset' , ` ${ filename } .json`) ;
40+ const tileSet = await fsa . readJson < ConfigTileSetRaster > ( tileSetPath ) ;
2841 const newTileSet = await this . prepareRasterTileSetConfig ( layer , tileSet , category ) ;
2942
3043 // skip pull request if not an urban or rural imagery
3144 if ( newTileSet == null ) return ;
32- await fsa . write ( path , JSON . stringify ( newTileSet , null , 2 ) ) ;
45+ await fsa . write ( tileSetPath , await this . formatConfigFile ( tileSetPath , newTileSet ) ) ;
3346
3447 // Commit and push the changes
3548 const message = `config(raster): Add imagery ${ this . imagery } to ${ filename } config file.` ;
@@ -118,13 +131,13 @@ export class MakeCogGithub extends Github {
118131
119132 // Prepare new aerial tileset config
120133 this . logger . info ( { imagery : this . imagery } , 'GitHub: Get the master TileSet config file' ) ;
121- const path = ` ${ this . repoName } / config/ tileset/ ${ filename } .json`;
122- const tileSet = await fsa . readJson < ConfigTileSetVector > ( path ) ;
134+ const tileSetPath = fsa . joinAll ( this . repoName , ' config' , ' tileset' , ` ${ filename } .json`) ;
135+ const tileSet = await fsa . readJson < ConfigTileSetVector > ( tileSetPath ) ;
123136 const newTileSet = await this . prepareVectorTileSetConfig ( layer , tileSet ) ;
124137
125138 // skip pull request if not an urban or rural imagery
126139 if ( newTileSet == null ) return ;
127- await fsa . write ( path , JSON . stringify ( newTileSet , null , 2 ) ) ;
140+ await fsa . write ( tileSetPath , await this . formatConfigFile ( tileSetPath , newTileSet ) ) ;
128141
129142 // Commit and push the changes
130143 const message = `config(vector): Update the ${ this . imagery } to ${ filename } config file.` ;
0 commit comments