Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): Fix config import to prepare changes for individual vector config. #3210

Merged
merged 4 commits into from
Mar 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions packages/cli/src/cli/config/action.import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ConfigLayer,
ConfigPrefix,
ConfigProviderMemory,
ConfigTileSet,
TileSetType,
} from '@basemaps/config';
import { GoogleTms, Nztm2000QuadTms, TileMatrixSet } from '@basemaps/geo';
import { Env, fsa, getDefaultConfig, getPreviewUrl, LogConfig, LogType, setDefaultConfig } from '@basemaps/shared';
Expand All @@ -31,8 +31,8 @@ export class CommandImport extends CommandLineAction {
/** List of paths to invalidate at the end of the request */
invalidations: string[] = [];

/** List of changed config ids */
changes: string[] = [];
/** List of changed config */
changes: BaseConfig[] = [];

/** List of paths to invalidate at the end of the request */
backupConfig: ConfigProviderMemory = new ConfigProviderMemory();
Expand Down Expand Up @@ -170,7 +170,7 @@ export class CommandImport extends CommandLineAction {

const hasChanges = await updater.reconcile();
if (hasChanges) {
this.changes.push(config.id);
this.changes.push(config);
this.invalidations.push(updater.invalidatePath());
const oldData = await updater.getOldData();
if (oldData != null) this.backupConfig.put(oldData); // No need to backup anything if there is new insert
Expand Down Expand Up @@ -311,14 +311,14 @@ export class CommandImport extends CommandLineAction {
const individualInserts: string[] = [];
const individualUpdates: string[] = [];
for (const config of mem.objects.values()) {
if (!config.id.startsWith(ConfigPrefix.TileSet)) continue;
if (config.id === 'ts_aerial' || config.id === 'ts_topographic') continue;
if (!mem.TileSet.is(config)) continue;
if (config.id === 'ts_aerial') continue;

if (aerialLayers.has(config.name)) continue;
const tileSet = config as ConfigTileSet;
if (tileSet.layers.length > 1) continue; // Not an individual layer
if (config.type === TileSetType.Vector) continue;
if (config.layers.length > 1) continue; // Not an individual layer
const existing = await cfg.TileSet.get(config.id);
const layer = tileSet.layers[0];
const layer = config.layers[0];
if (existing) await this.outputUpdatedLayers(mem, layer, existing.layers[0], individualUpdates);
else await this.outputNewLayers(mem, layer, individualInserts);
}
Expand All @@ -330,15 +330,16 @@ export class CommandImport extends CommandLineAction {
const vectorUpdate = [];
const styleUpdate = [];
for (const change of this.changes) {
if (change === 'ts_topographic') {
if (mem.TileSet.is(change) && change.type === TileSetType.Vector) {
const id = ConfigId.unprefix(ConfigPrefix.TileSet, change.id);
for (const style of VectorStyles) {
vectorUpdate.push(
`* [${style}](${PublicUrlBase}?config=${this.config.value}&i=topographic&s=${style}&debug)\n`,
`* [${style} - ${id}](${PublicUrlBase}?config=${this.config.value}&i=${id}&s=${style}&debug)\n`,
);
}
}
if (change.startsWith(ConfigPrefix.Style)) {
const style = ConfigId.unprefix(ConfigPrefix.Style, change);
if (mem.Style.is(change)) {
const style = ConfigId.unprefix(ConfigPrefix.Style, change.id);
styleUpdate.push(`* [${style}](${PublicUrlBase}?config=${this.config.value}&i=topographic&s=${style}&debug)\n`);
}
}
Expand Down
Loading