-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): adding info/validate command (#6)
* build: add a sample mbtiles * wip: create info/serve cli * feat(cli): adding info command
- Loading branch information
Showing
15 changed files
with
192 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,5 +28,6 @@ | |
"nohoist": [ | ||
"**/@types/**" | ||
] | ||
} | ||
}, | ||
"files": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Cloud Optimized Vector Tiles (COVT) - CLI (@covt/cli) | ||
|
||
## Create cloud optimized | ||
|
||
```bash | ||
covt create --output sample.covt sample.mbtiles --verbose | ||
``` | ||
|
||
|
||
```bash | ||
covt serve sample.covt | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env node | ||
|
||
|
||
require('../build/src/index.js').CreateCovt.run().catch(require('@oclif/errors/handle')) | ||
require('@oclif/command').run() | ||
.catch(require('@oclif/errors/handle')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Command, flags } from '@oclif/command'; | ||
import { existsSync } from 'fs'; | ||
import { logger } from '../log'; | ||
import { toTarTiles } from '../create/mbtiles.to.ttiles'; | ||
import { toTarTilesIndex } from '../create/tar.to.ttiles'; | ||
|
||
export class CreateCovt extends Command { | ||
static flags = { | ||
force: flags.boolean({ description: 'force overwriting existing files' }), | ||
decompress: flags.boolean({ | ||
description: 'decompress gzip encoded tiles before storing in tar', | ||
default: false, | ||
}), | ||
|
||
output: flags.string({ description: 'output file', required: true }), | ||
verbose: flags.boolean({ description: 'verbose logging' }), | ||
index: flags.boolean({ description: 'Only create the index', default: false }), | ||
}; | ||
|
||
static args = [{ name: 'inputFile', required: true }]; | ||
|
||
async run(): Promise<void> { | ||
const { args, flags } = this.parse(CreateCovt); | ||
if (flags.verbose) logger.level = 'debug'; | ||
|
||
if (existsSync(flags.output) && !flags.force) { | ||
logger.error({ output: flags.output }, 'Output file exists, aborting..'); | ||
return; | ||
} | ||
|
||
if (!args.inputFile.endsWith('.mbtiles')) { | ||
logger.error({ input: args.inputFile }, 'Input file must be a mbtiles file'); | ||
return; | ||
} | ||
logger.info({ output: flags.output }, 'Covt:Create'); | ||
|
||
const startTime = Date.now(); | ||
if (flags.index === false) await toTarTiles(args.inputFile, flags.output, flags.decompress, logger); | ||
await toTarTilesIndex(flags.output, flags.output + '.index', logger); | ||
|
||
const duration = Date.now() - startTime; | ||
logger.info({ output: flags.output, duration }, 'Covt:Created'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { SourceFile } from '@cogeotiff/source-file'; | ||
import { Covt, xyzToPath } from '@covt/core'; | ||
import Command, { flags } from '@oclif/command'; | ||
import { promises as fs } from 'fs'; | ||
import { readMbTiles } from '../create/mbtiles.to.ttiles'; | ||
import { logger } from '../log'; | ||
|
||
export class CreateCovt extends Command { | ||
static flags = { | ||
verbose: flags.boolean({ description: 'verbose logging' }), | ||
mbtiles: flags.string({ description: 'Source MBTiles for validation' }), | ||
}; | ||
|
||
static args = [{ name: 'inputFile', required: true }]; | ||
|
||
async run(): Promise<void> { | ||
const { args, flags } = this.parse(CreateCovt); | ||
if (flags.verbose) logger.level = 'debug'; | ||
|
||
logger.info({ fileName: args.inputFile }, 'Covt.Load'); | ||
|
||
const source = new SourceFile(args.inputFile); | ||
logger.debug({ indexPath: args.inputFile + '.index' }, 'Index:Load'); | ||
const sourceIndex = await fs.readFile(args.inputFile + '.index'); | ||
|
||
const index = JSON.parse(sourceIndex.toString()); | ||
|
||
const covt = await Covt.create(source, index); | ||
logger.info({ fileName: args.inputFile, files: covt.index.size }, 'Covt.Loaded'); | ||
|
||
if (flags.mbtiles) { | ||
const failures = []; | ||
|
||
for await (const { tile, index, total } of readMbTiles(flags.mbtiles)) { | ||
if (index === 0) logger.info({ total }, 'Covt.Validation:Start'); | ||
else if (index % 25_000 === 0) logger.debug({ total, index }, 'Covt.Validation:Progress'); | ||
|
||
const tileName = xyzToPath(tile.tile_column, tile.tile_row, tile.zoom_level); | ||
|
||
const covtTile = covt.index.get(tileName); | ||
if (covtTile == null) failures.push(tileName); | ||
} | ||
|
||
if (failures.length > 0) { | ||
logger.error({ total: failures.length }, 'Covt.Validation:Failure'); | ||
logger.error({ failures: failures.slice(0, 25) }, 'Covt.Validation:Failures'); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1 @@ | ||
import { Command, flags } from '@oclif/command'; | ||
import { existsSync } from 'fs'; | ||
import pino from 'pino'; | ||
import { PrettyTransform } from 'pretty-json-log'; | ||
import { toTarTiles } from './mbtiles.to.ttiles'; | ||
import { toTarTilesIndex } from './tar.to.ttiles'; | ||
|
||
const logger = process.stdout.isTTY ? pino(PrettyTransform.stream()) : pino(); | ||
|
||
export class CreateCovt extends Command { | ||
static flags = { | ||
force: flags.boolean({ description: 'force overwriting existing files' }), | ||
decompress: flags.boolean({ | ||
description: 'decompress gzip encoded tiles before storing in tar', | ||
default: false, | ||
}), | ||
verbose: flags.boolean({ description: 'verbose logging' }), | ||
}; | ||
|
||
static args = [ | ||
{ name: 'outputFile', required: true }, | ||
{ name: 'inputFile', required: true }, | ||
]; | ||
|
||
async run(): Promise<void> { | ||
const { args, flags } = this.parse(CreateCovt); | ||
if (flags.verbose) logger.level = 'debug'; | ||
|
||
if (existsSync(args.outputFile) && !flags.force) { | ||
logger.error({ output: args.outputFile }, 'Output file exists, aborting..'); | ||
return; | ||
} | ||
|
||
if (!args.inputFile.endsWith('.mbtiles')) { | ||
logger.error({ input: args.inputFile }, 'Input file must be a mbtiles file'); | ||
return; | ||
} | ||
logger.info({ output: args.outputFile }, 'Covt:Create'); | ||
|
||
const startTime = Date.now(); | ||
await toTarTiles(args.inputFile, args.outputFile, flags.decompress, logger); | ||
await toTarTilesIndex(args.outputFile, args.outputFile + '.index', logger); | ||
|
||
const duration = Date.now() - startTime; | ||
logger.info({ output: args.outputFile, duration }, 'Covt:Created'); | ||
} | ||
} | ||
export { run } from '@oclif/command'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import pino from 'pino'; | ||
import { PrettyTransform } from 'pretty-json-log'; | ||
|
||
export const logger = process.stdout.isTTY ? pino(PrettyTransform.stream()) : pino(); |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.