Skip to content

Commit d93ac94

Browse files
committed
Updating the dist and cleanup scripts
1 parent 4ddba7c commit d93ac94

File tree

6 files changed

+107
-156
lines changed

6 files changed

+107
-156
lines changed

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
coverage/
2-
dist/javascript/
3-
dist/js/
4-
dist/json/
5-
dist/ts/
2+
dist/
63
node_modules/
74

85
.DS_Store

RELEASE.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
```bash
66
git checkout main
77
git pull origin
8-
npm install
9-
npm run build
10-
npm run wikidata
11-
npm run dist # version number updates automatically and will print to console
8+
bun install
9+
bun run build
10+
bun run wikidata
11+
bun run dist # version number updates automatically and will print to console
1212
git add . && git commit -m 'vA.B.C'
1313
git tag vA.B.C
1414
git push origin main vA.B.C
15-
npm publish
15+
bun publish
1616
```
1717

1818
### Purge JSDelivr CDN cache

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@
9494
"build:json": "bun ./scripts/build_json.ts",
9595
"build:ts": "tsc",
9696
"clean": "bun ./scripts/clean.ts",
97-
"dist": "run-s dist:version dist:files",
98-
"dist:files": "bun ./scripts/dist_files.js",
99-
"dist:version": "bun ./scripts/dist_version.js",
97+
"dist": "bun ./scripts/dist.ts",
10098
"lint": "eslint ./test/*.js",
10199
"prepublishOnly": "bun ./scripts/prepublish.ts",
102100
"postpublish": "bun ./scripts/postpublish.ts",

scripts/build_json.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// External
1+
import { $ } from 'bun';
22
//import geojsonArea from '@mapbox/geojson-area';
33
//import geojsonBounds from 'geojson-bounds';
44
import geojsonPrecision from 'geojson-precision';
@@ -14,15 +14,13 @@ import { styleText } from 'bun:util';
1414
import { Validator } from 'jsonschema';
1515
const withLocale = localeCompare('en-US');
1616

17-
// Internal
1817
import { fileTree } from '../lib/file_tree.ts';
1918
import { idgen } from '../lib/idgen.ts';
2019
import { Matcher } from '../lib/matcher.ts';
2120
import { simplify } from '../lib/simplify.ts';
2221
import { sortObject } from '../lib/sort_object.ts';
2322
import { stemmer } from '../lib/stemmer.ts';
2423
import { validate } from '../lib/validate.ts';
25-
import { writeFileWithMeta } from '../lib/write_file_with_meta.ts';
2624
const matcher = new Matcher();
2725

2826
// JSON
@@ -37,8 +35,10 @@ const _discard = {};
3735
const _keep = {};
3836
let _loco = null;
3937

40-
await buildAll();
38+
$.nothrow(); // If a shell command returns nonzero, keep going.
39+
4140

41+
await buildAll();
4242

4343
async 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);

scripts/clean.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { $, Glob } from 'bun';
22

3+
$.nothrow(); // If a shell command returns nonzero, keep going.
4+
35
// Remove these files if found anywhere
46
const files = [
57
'.DS_Store',
@@ -17,11 +19,13 @@ for (const f of files) {
1719
}
1820

1921
// Remove these specific folders
22+
// (Because some of the files in ./dist/json take a while to generate,
23+
// each script will be responsible for removing them)
2024
const folders = [
2125
'./coverage',
2226
'./dist/javascript',
2327
'./dist/js',
24-
'./dist/json',
28+
// './dist/json',
2529
'./dist/ts'
2630
];
2731
for (const f of folders) {

0 commit comments

Comments
 (0)