-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): bundle basemaps-server cli so its easier to install (#2218
) * wip * refactor: fixup imports * refactor: add missing file * docs: update docs for new cli * feat(scripts): include shebang in cli bundling * refactor: fix up lint * refactor: add logs to imports * refactor: fix loading require.resolve when not in esm * refactor: bind to all addresses * fix: load all files including local files * fix: create a unique id using the hash of the uri * fix: include .tif files too * fix: ensure virtual tilesets are created from memory * test: add tests for prefix * refactor: use smaller hash * feat: track more fine grained tile creation times * fix: serve wmts even if the provider could not be found
- Loading branch information
Showing
26 changed files
with
408 additions
and
436 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
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,60 +0,0 @@ | ||
#!/usr/bin/env node | ||
import { LogConfig, LoggerFatalError } from '@basemaps/shared'; | ||
import { GitTag } from '@basemaps/shared/build/cli/git.tag.js'; | ||
import { CommandLineParser } from '@rushstack/ts-command-line'; | ||
import 'source-map-support/register.js'; | ||
import * as ulid from 'ulid'; | ||
|
||
/** Useful traceability information */ | ||
export const CliInfo: { package: string; version: string; hash: string } = { | ||
// Detect unlinked packages looks for this string since its a package name, slightly work around it | ||
package: '@' + 'basemaps/cli', | ||
version: process.env.GIT_VERSION ?? GitTag().version, | ||
hash: process.env.GIT_HASH ?? GitTag().hash, | ||
}; | ||
|
||
/** Unique Id for this instance of the cli being run */ | ||
export const CliId = ulid.ulid(); | ||
|
||
export abstract class BaseCommandLine extends CommandLineParser { | ||
verbose = this.defineFlagParameter({ | ||
parameterLongName: '--verbose', | ||
parameterShortName: '-v', | ||
description: 'Show extra logging detail', | ||
}); | ||
extraVerbose = this.defineFlagParameter({ | ||
parameterLongName: '--vv', | ||
parameterShortName: '-V', | ||
description: 'Show extra extra logging detail', | ||
}); | ||
|
||
protected onExecute(): Promise<void> { | ||
if (this.verbose.value) { | ||
LogConfig.get().level = 'debug'; | ||
} else if (this.extraVerbose.value) { | ||
LogConfig.get().level = 'trace'; | ||
} else { | ||
LogConfig.get().level = 'info'; | ||
} | ||
|
||
const logger = LogConfig.get().child({ id: CliId }); | ||
logger.info(CliInfo, 'CliStart'); | ||
LogConfig.set(logger); | ||
|
||
return super.onExecute(); | ||
} | ||
protected onDefineParameters(): void { | ||
// Nothing | ||
} | ||
|
||
public run(): void { | ||
this.executeWithoutErrorHandling().catch((err) => { | ||
if (err instanceof LoggerFatalError) { | ||
LogConfig.get().fatal(err.obj, err.message); | ||
} else { | ||
LogConfig.get().fatal({ err }, 'Failed to run command'); | ||
} | ||
process.exit(1); | ||
}); | ||
} | ||
} | ||
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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import o from 'ospec'; | ||
import { Config } from '../base.config.js'; | ||
import { ConfigPrefix } from '../config/prefix.js'; | ||
|
||
o.spec('ConfigPrefix', () => { | ||
o('should prefix values', () => { | ||
o(Config.prefix(ConfigPrefix.TileSet, '123')).equals('ts_123'); | ||
o(Config.prefix(ConfigPrefix.Imagery, '123')).equals('im_123'); | ||
}); | ||
|
||
o('should unprefix values', () => { | ||
o(Config.unprefix(ConfigPrefix.TileSet, 'ts_123')).equals('123'); | ||
o(Config.unprefix(ConfigPrefix.Imagery, 'im_123')).equals('123'); | ||
}); | ||
|
||
o('should not unprefix unknown values', () => { | ||
o(Config.unprefix(ConfigPrefix.TileSet, 'im_123')).equals('im_123'); | ||
o(Config.unprefix(ConfigPrefix.Imagery, 'ts_123')).equals('ts_123'); | ||
}); | ||
|
||
o('should get prefix values', () => { | ||
o(Config.getPrefix('ts_123')).equals(ConfigPrefix.TileSet); | ||
o(Config.getPrefix('im_123')).equals(ConfigPrefix.Imagery); | ||
}); | ||
|
||
o('should not return unknown prefixes', () => { | ||
o(Config.getPrefix('jj_123')).equals(null); | ||
o(Config.getPrefix('123')).equals(null); | ||
o(Config.getPrefix('_123')).equals(null); | ||
o(Config.getPrefix('123_123')).equals(null); | ||
}); | ||
}); |
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
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
Oops, something went wrong.