Skip to content

Commit

Permalink
fix: create working dir (#393)
Browse files Browse the repository at this point in the history
fix: add missing script
  • Loading branch information
vnugent authored Feb 20, 2024
1 parent b854fa8 commit 6f8c716
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
16 changes: 16 additions & 0 deletions scripts/gen-tiles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# Generate map tiles from geojson exports
# See also https://github.com/felt/tippecanoe

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

. ${SCRIPT_DIR}/../.env
. ${SCRIPT_DIR}/../.env.local

echo "Generating crags tiles file"
tippecanoe --force -o ${MAPTILES_WORKING_DIR}/crags.mbtiles -l crags -n "Crags" -zg ${MAPTILES_WORKING_DIR}/crags.*.geojson

echo "Generating crag group tiles file"
tippecanoe --force -o ${MAPTILES_WORKING_DIR}/crag-groups.mbtiles -l crag-groups -n "Crag groups" -zg ${MAPTILES_WORKING_DIR}/crag-groups.geojson

exit $?
25 changes: 16 additions & 9 deletions src/db/utils/jobs/MapTiles/exportCmd.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WriteStream, createWriteStream } from 'node:fs'
import { WriteStream, createWriteStream, existsSync, mkdirSync } from 'node:fs'
import {
point,
feature,
Expand Down Expand Up @@ -27,14 +27,7 @@ import { workingDir } from './init.js'
async function exportLeafCrags (): Promise<void> {
const model = getAreaModel()

let features: Array<
Feature<
Point,
{
name: string
}
>
> = []
let features: Array<Feature<Point, { name: string }>> = []

let fileIndex = 0
let stream: WriteStream = createWriteStream(`${workingDir}/crags.${fileIndex}.geojson`, {
Expand Down Expand Up @@ -219,8 +212,22 @@ async function exportCragGroups (): Promise<void> {
stream.close()
}

/**
* Create working directory if it does not exist
*/
function prepareWorkingDir (): void {
if (!existsSync(workingDir)) {
logger.info(`Working dir doesn't exist. Creating ${workingDir}`)
mkdirSync(workingDir, { recursive: true })
}
}

/**
* Export crag data as Geojson
*/
async function onDBConnected (): Promise<void> {
logger.info('Start exporting crag data as Geojson')
prepareWorkingDir()
await exportLeafCrags()
await exportCragGroups()
await gracefulExit()
Expand Down

0 comments on commit 6f8c716

Please sign in to comment.