@trailstash/ultra 3.1.4 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
Binary file
Binary file
package/cli/build.js CHANGED
@@ -2,9 +2,10 @@ import fs from "fs";
2
2
  import path from "path";
3
3
  import process from "process";
4
4
  import { build } from "esbuild";
5
- import { Command, Flags } from "@oclif/core";
5
+ import { Args, Command, Flags } from "@oclif/core";
6
6
  import { copy } from "esbuild-plugin-copy";
7
7
  import { Liquid } from "liquidjs";
8
+ import { parseSettings } from "../lib/settings.js";
8
9
 
9
10
  const engine = new Liquid();
10
11
  export const getHTMLContext = async (configFile) => {
@@ -15,6 +16,19 @@ export const getHTMLContext = async (configFile) => {
15
16
  return { title, description, url, mastodon };
16
17
  };
17
18
 
19
+ export const buildConfigFromQuery = async (config, query) => {
20
+ const querySettings = parseSettings(fs.readFileSync(query));
21
+ const { defaultMode, modes } = await import(config);
22
+ const settings = {
23
+ ...modes.map.settings,
24
+ ...querySettings,
25
+ loadSettingsFromQueryParams: false,
26
+ };
27
+ const newConfig = `export const defaultMode = "map";
28
+ export const modes = {map: {settings: ${JSON.stringify(settings, null, 2)}}};`;
29
+ return `data:text/javascript;base64,${btoa(newConfig)}`;
30
+ };
31
+
18
32
  export const ultraRoot = path.dirname(
19
33
  path.dirname(new URL(import.meta.url).pathname),
20
34
  );
@@ -52,14 +66,31 @@ export default class Build extends Command {
52
66
  default: path.join(process.cwd(), "/config.js"),
53
67
  }),
54
68
  };
69
+ static args = {
70
+ query: Args.file({
71
+ description: "A query to build an interactive map for",
72
+ }),
73
+ };
55
74
 
56
75
  static description = `Build a release of Ultra`;
57
76
 
58
77
  async run() {
59
- const {
78
+ let {
60
79
  flags: { config },
80
+ args: { query },
61
81
  } = await this.parse(Build);
62
82
 
83
+ if (!fs.existsSync(config)) {
84
+ console.error(
85
+ `"${config}" not found, using ${path.join(ultraRoot, "config.js")}`,
86
+ );
87
+ config = path.join(ultraRoot, "config.js");
88
+ }
89
+
90
+ if (query) {
91
+ config = await buildConfigFromQuery(config, query);
92
+ }
93
+
63
94
  const html = engine.parseAndRenderSync(
64
95
  fs.readFileSync(path.join(ultraRoot, "index.html")),
65
96
  await getHTMLContext(config),
package/cli/serve.js CHANGED
@@ -1,8 +1,13 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
3
  import { context } from "esbuild";
4
- import { Command, Flags } from "@oclif/core";
5
- import Build, { buildOptions, getHTMLContext, ultraRoot } from "./build.js";
4
+ import { Args, Command, Flags } from "@oclif/core";
5
+ import Build, {
6
+ buildConfigFromQuery,
7
+ buildOptions,
8
+ getHTMLContext,
9
+ ultraRoot,
10
+ } from "./build.js";
6
11
  import { Liquid } from "liquidjs";
7
12
 
8
13
  const engine = new Liquid();
@@ -22,15 +27,31 @@ export default class Serve extends Command {
22
27
  parse: parseInt,
23
28
  }),
24
29
  };
30
+ static args = {
31
+ query: Args.file({
32
+ description: "A query to build an interactive map for",
33
+ }),
34
+ };
25
35
 
26
36
  static description = `Run an Ultra development server`;
27
37
 
28
38
  async run() {
29
- const {
39
+ let {
30
40
  args: { query },
31
41
  flags: { config, host, port },
32
42
  } = await this.parse(Serve);
33
43
 
44
+ if (!fs.existsSync(config)) {
45
+ console.error(
46
+ `"${config}" not found, using ${path.join(ultraRoot, "config.js")}`,
47
+ );
48
+ config = path.join(ultraRoot, "config.js");
49
+ }
50
+
51
+ if (query) {
52
+ config = await buildConfigFromQuery(config, query);
53
+ }
54
+
34
55
  const html = engine.parseAndRenderSync(
35
56
  fs.readFileSync(path.join(ultraRoot, "index.html")),
36
57
  await getHTMLContext(config),
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "3.1.4",
6
+ "version": "3.2.1",
7
7
  "description": "A web based tool for making MapLibre GL maps with data from sources such as Overpass, GeoJSON, GPX, KML, TCX, etc",
8
8
  "main": "index.js",
9
9
  "scripts": {