gtfs-to-html 2.9.2 → 2.9.4

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.
package/dist/app/index.js CHANGED
@@ -5,7 +5,7 @@ var __export = (target, all) => {
5
5
  };
6
6
 
7
7
  // src/app/index.ts
8
- import path2 from "node:path";
8
+ import { dirname as dirname2, join as join2 } from "node:path";
9
9
  import { fileURLToPath as fileURLToPath2 } from "node:url";
10
10
  import { readFileSync } from "node:fs";
11
11
  import { map } from "lodash-es";
@@ -131,7 +131,7 @@ import sqlString from "sqlstring";
131
131
  import toposort from "toposort";
132
132
 
133
133
  // src/lib/file-utils.ts
134
- import path from "node:path";
134
+ import { dirname, join, resolve } from "node:path";
135
135
  import { fileURLToPath } from "node:url";
136
136
  import _ from "lodash-es";
137
137
  import archiver from "archiver";
@@ -258,13 +258,24 @@ function formatTripNameForCSV(trip, timetable) {
258
258
  }
259
259
 
260
260
  // src/lib/file-utils.ts
261
- function getTemplatePath(templateFileName, config2) {
262
- let fullTemplateFileName = templateFileName;
263
- if (config2.noHead !== true) {
264
- fullTemplateFileName += "_full";
261
+ function getPathToViewsFolder(config2) {
262
+ if (config2.templatePath) {
263
+ return untildify(config2.templatePath);
264
+ }
265
+ const __dirname = dirname(fileURLToPath(import.meta.url));
266
+ let viewsFolderPath;
267
+ if (__dirname.endsWith("/dist/bin") || __dirname.endsWith("/dist/app")) {
268
+ viewsFolderPath = resolve(__dirname, "../../views/default");
269
+ } else if (__dirname.endsWith("/dist")) {
270
+ viewsFolderPath = resolve(__dirname, "../views/default");
271
+ } else {
272
+ viewsFolderPath = resolve(__dirname, "views/default");
265
273
  }
266
- const templatePath = config2.templatePath === void 0 ? path.join(fileURLToPath(import.meta.url), "../../../views/default") : untildify(config2.templatePath);
267
- return path.join(templatePath, `${fullTemplateFileName}.pug`);
274
+ return viewsFolderPath;
275
+ }
276
+ function getPathToTemplateFile(templateFileName, config2) {
277
+ const fullTemplateFileName = config2.noHead !== true ? `${templateFileName}_full.pug` : `${templateFileName}.pug`;
278
+ return join(getPathToViewsFolder(config2), fullTemplateFileName);
268
279
  }
269
280
  function generateFileName(timetable, config2, extension = "html") {
270
281
  let filename = timetable.timetable_id;
@@ -278,7 +289,7 @@ function generateFileName(timetable, config2, extension = "html") {
278
289
  return sanitize(filename).toLowerCase();
279
290
  }
280
291
  async function renderTemplate(templateFileName, templateVars, config2) {
281
- const templatePath = getTemplatePath(templateFileName, config2);
292
+ const templatePath = getPathToTemplateFile(templateFileName, config2);
282
293
  const html = await renderFile(templatePath, {
283
294
  _,
284
295
  md: (text) => insane(marked.parseInline(text)),
@@ -365,7 +376,7 @@ function getAgencyGeoJSON(config2) {
365
376
  }
366
377
 
367
378
  // package.json
368
- var version = "2.9.1";
379
+ var version = "2.9.3";
369
380
 
370
381
  // src/lib/utils.ts
371
382
  var isTimepoint = (stoptime) => {
@@ -1344,7 +1355,10 @@ function setDefaultConfig(initialConfig) {
1344
1355
  config2.menuType = "none";
1345
1356
  }
1346
1357
  config2.hasGtfsRealtime = config2.agencies.some(
1347
- (agency) => agency.realtimeTripUpdates?.url || agency.realtimeVehiclePositions?.url
1358
+ (agency) => agency.realtimeTripUpdates?.url || agency.realtimeVehiclePositions?.url || agency.realtimeAlerts?.url
1359
+ );
1360
+ config2.hasGtfsRealtimeAlerts = config2.agencies.some(
1361
+ (agency) => agency.realtimeAlerts?.url
1348
1362
  );
1349
1363
  return config2;
1350
1364
  }
@@ -1772,7 +1786,7 @@ var argv = yargs(hideBin(process.argv)).option("c", {
1772
1786
  }).parseSync();
1773
1787
  var app = express();
1774
1788
  var router = express.Router();
1775
- var configPath = argv.configPath || new URL("../../config.json", import.meta.url);
1789
+ var configPath = argv.configPath || join2(process.cwd(), "config.json");
1776
1790
  var selectedConfig = JSON.parse(readFileSync(configPath, "utf8"));
1777
1791
  var config = setDefaultConfig(selectedConfig);
1778
1792
  config.noHead = false;
@@ -1836,24 +1850,21 @@ router.get("/timetables/:timetablePageId", async (request, response, next) => {
1836
1850
  next(error);
1837
1851
  }
1838
1852
  });
1839
- app.set("views", path2.join(fileURLToPath2(import.meta.url), "../../../views"));
1853
+ app.set("views", getPathToViewsFolder(config));
1840
1854
  app.set("view engine", "pug");
1841
1855
  app.use(logger("dev"));
1842
- var staticAssetPath = config.templatePath === void 0 ? path2.join(fileURLToPath2(import.meta.url), "../../../views/default") : untildify2(config.templatePath);
1856
+ var staticAssetPath = config.templatePath === void 0 ? getPathToViewsFolder(config) : untildify2(config.templatePath);
1843
1857
  app.use(express.static(staticAssetPath));
1844
1858
  app.use(
1845
1859
  "/js",
1846
1860
  express.static(
1847
- path2.join(fileURLToPath2(import.meta.url), "../../../node_modules/pbf/dist")
1861
+ join2(dirname2(fileURLToPath2(import.meta.resolve("pbf"))), "dist")
1848
1862
  )
1849
1863
  );
1850
1864
  app.use(
1851
1865
  "/js",
1852
1866
  express.static(
1853
- path2.join(
1854
- fileURLToPath2(import.meta.url),
1855
- "../../../node_modules/gtfs-realtime-pbf-js-module"
1856
- )
1867
+ dirname2(fileURLToPath2(import.meta.resolve("gtfs-realtime-pbf-js-module")))
1857
1868
  )
1858
1869
  );
1859
1870
  app.use("/", router);