@@ -7,6 +7,7 @@ import path from "path";
77
88import nextConfig from "../next.config.js" ;
99import config from "../src/lib/config" ;
10+ import ErrorHandler , { ErrorType , TextColor } from "./errorHandler.js" ;
1011import Positioner from "./positioner" ;
1112
1213import { Flag , Item } from "@/lib/types" ;
@@ -21,6 +22,7 @@ const quadrants = config.quadrants.map((q, i) => ({ ...q, position: i + 1 }));
2122const quadrantIds = quadrants . map ( ( q ) => q . id ) ;
2223const tags = ( config as { tags ?: string [ ] } ) . tags || [ ] ;
2324const positioner = new Positioner ( size , quadrants , rings ) ;
25+ const errorHandler = new ErrorHandler ( quadrants , rings ) ;
2426
2527const marked = new Marked (
2628 markedHighlight ( {
@@ -170,17 +172,25 @@ function postProcessItems(items: Item[]): {
170172 const filteredItems = items . filter ( ( item ) => {
171173 // check if the items' quadrant and ring are valid
172174 if ( ! item . quadrant || ! item . ring ) {
173- console . warn ( `Item ${ item . id } has no quadrant or ring` ) ;
175+ errorHandler . processBuildErrors ( ErrorType . NoQuadrant , item . id ) ;
174176 return false ;
175177 }
176178
177179 if ( ! quadrantIds . includes ( item . quadrant ) ) {
178- console . warn ( `Item ${ item . id } has invalid quadrant ${ item . quadrant } ` ) ;
180+ errorHandler . processBuildErrors (
181+ ErrorType . InvalidQuadrant ,
182+ item . id ,
183+ item . quadrant ,
184+ ) ;
179185 return false ;
180186 }
181187
182188 if ( ! ringIds . includes ( item . ring ) ) {
183- console . warn ( `Item ${ item . id } has invalid ring ${ item . ring } ` ) ;
189+ errorHandler . processBuildErrors (
190+ ErrorType . InvalidRing ,
191+ item . id ,
192+ item . ring ,
193+ ) ;
184194 return false ;
185195 }
186196
@@ -193,6 +203,8 @@ function postProcessItems(items: Item[]): {
193203 return true ;
194204 } ) ;
195205
206+ errorHandler . checkForBuildErrors ( ) ;
207+
196208 const releases = getUniqueReleases ( filteredItems ) ;
197209 const uniqueTags = getUniqueTags ( filteredItems ) ;
198210 const processedItems = filteredItems . map ( ( item ) => {
@@ -230,21 +242,30 @@ function postProcessItems(items: Item[]): {
230242 return { releases, tags : uniqueTags , items : processedItems } ;
231243}
232244
233- // Parse the data and write radar data to JSON file
234- parseDirectory ( dataPath ( "radar" ) ) . then ( ( items ) => {
245+ async function main ( ) {
246+ // Parse the data and write radar data to JSON file
247+ const items = await parseDirectory ( dataPath ( "radar" ) ) ;
235248 const data = postProcessItems ( items ) ;
236249
237250 if ( data . items . length === 0 ) {
238- console . error ( "No valid radar items found." ) ;
239- console . log ( "Please check the markdown files in the `radar` directory." ) ;
240- process . exit ( 1 ) ;
251+ errorHandler . processBuildErrors ( ErrorType . NoRadarItems ) ;
241252 }
242253
254+ errorHandler . checkForBuildErrors ( true ) ;
255+
243256 const json = JSON . stringify ( data , null , 2 ) ;
244257 fs . writeFileSync ( dataPath ( "data.json" ) , json ) ;
245- } ) ;
246258
247- // write about data to JSON file
248- const about = readMarkdownFile ( dataPath ( "about.md" ) ) ;
249- fs . writeFileSync ( dataPath ( "about.json" ) , JSON . stringify ( about , null , 2 ) ) ;
250- console . log ( "ℹ️ Data written to data/data.json and data/about.json" ) ;
259+ // write about data to JSON file
260+ const about = readMarkdownFile ( dataPath ( "about.md" ) ) ;
261+ fs . writeFileSync ( dataPath ( "about.json" ) , JSON . stringify ( about , null , 2 ) ) ;
262+ console . log (
263+ "ℹ️ Data written to data/data.json and data/about.json\n\n" +
264+ errorHandler . colorizeBackground (
265+ " Build was successfull " ,
266+ TextColor . Green ,
267+ ) ,
268+ ) ;
269+ }
270+
271+ main ( ) ;
0 commit comments