1- // External
1+ import { $ } from 'bun' ;
22//import geojsonArea from '@mapbox/geojson-area';
33//import geojsonBounds from 'geojson-bounds';
44import geojsonPrecision from 'geojson-precision' ;
@@ -14,15 +14,13 @@ import { styleText } from 'bun:util';
1414import { Validator } from 'jsonschema' ;
1515const withLocale = localeCompare ( 'en-US' ) ;
1616
17- // Internal
1817import { fileTree } from '../lib/file_tree.ts' ;
1918import { idgen } from '../lib/idgen.ts' ;
2019import { Matcher } from '../lib/matcher.ts' ;
2120import { simplify } from '../lib/simplify.ts' ;
2221import { sortObject } from '../lib/sort_object.ts' ;
2322import { stemmer } from '../lib/stemmer.ts' ;
2423import { validate } from '../lib/validate.ts' ;
25- import { writeFileWithMeta } from '../lib/write_file_with_meta.ts' ;
2624const matcher = new Matcher ( ) ;
2725
2826// JSON
@@ -37,8 +35,10 @@ const _discard = {};
3735const _keep = { } ;
3836let _loco = null ;
3937
40- await buildAll ( ) ;
38+ $ . nothrow ( ) ; // If a shell command returns nonzero, keep going.
39+
4140
41+ await buildAll ( ) ;
4242
4343async function buildAll ( ) {
4444 // GeoJSON features
@@ -88,10 +88,13 @@ async function buildFeatureCollection() {
8888 console . log ( START ) ;
8989 console . time ( END ) ;
9090
91+ // Start fresh
92+ await $ `rm -f ./dist/json/featureCollection.*` ;
93+
9194 const features = await loadFeatures ( ) ;
9295 const featureCollection = { type : 'FeatureCollection' , features : features } ;
9396 const stringified = stringify ( featureCollection , { maxLength : 9999 } ) + '\n' ;
94- await writeFileWithMeta ( './dist/json/featureCollection.json' , stringified ) ;
97+ await Bun . write ( './dist/json/featureCollection.json' , stringified ) ;
9598
9699 console . timeEnd ( END ) ;
97100 return featureCollection ;
@@ -352,7 +355,9 @@ async function filterCollected() {
352355 const END = '👍 ' + styleText ( 'green' , `done filtering` ) ;
353356 console . log ( START ) ;
354357 console . time ( END ) ;
355- let shownSparkle = false ;
358+
359+ // Start fresh
360+ await $ `rm -rf ./dist/json/filtered` ;
356361
357362 // Before starting, cache genericWords regexes.
358363 let genericRegex = _config . genericWords . map ( s => new RegExp ( s , 'i' ) ) ;
@@ -364,15 +369,6 @@ async function filterCollected() {
364369
365370 let discard = _discard [ t ] = { } ;
366371 let keep = _keep [ t ] = { } ;
367- // let data;
368- //
369- // try { // Load existing "keep" file
370- // data = await Bun.file(`dist/filtered/${t}_keep.json`).json();
371- // lastCollectionDate = +(data._meta.collectionDate) || -1;
372- // keep = _keep[t] = data.keep;
373- // } catch (err) {
374- // /* ignore - we can overwrite the keep file */
375- // }
376372
377373 //
378374 // STEP 1: All the collected "names" from OSM start out in `discard`
@@ -414,8 +410,8 @@ async function filterCollected() {
414410 const keepCount = Object . keys ( keep ) . length ;
415411 console . log ( `${ tree . emoji } ${ t } :\t${ keepCount } keep, ${ discardCount } discard` ) ;
416412
417- await writeFileWithMeta ( ` dist/json/filtered/${ t } _discard.json`, stringify ( { discard : sortObject ( discard ) } ) + '\n' ) ;
418- await writeFileWithMeta ( ` dist/json/filtered/${ t } _keep.json`, stringify ( { keep : sortObject ( keep ) } ) + '\n' ) ;
413+ await Bun . write ( `./ dist/json/filtered/${ t } _discard.json`, stringify ( { discard : sortObject ( discard ) } ) + '\n' ) ;
414+ await Bun . write ( `./ dist/json/filtered/${ t } _keep.json`, stringify ( { keep : sortObject ( keep ) } ) + '\n' ) ;
419415 }
420416
421417 console . timeEnd ( END ) ;
0 commit comments