gtfs-to-html 2.4.3 → 2.5.0

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/CHANGELOG.md CHANGED
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [2.5.0] - 2022-12-31
9
+
10
+ ### Updated
11
+
12
+ - Updated to node-gtfs v4
13
+ - Dependency updates
14
+
15
+ ## [2.4.4] - 2022-12-22
16
+
17
+ ### Updated
18
+
19
+ - Use adjacent duplicate stoptimes as arrival/depart if different times
20
+ - Updates to gtfstohtml.com documentation website dependencies
21
+ - Dependency updates
22
+
8
23
  ## [2.4.3] - 2022-11-10
9
24
 
10
25
  ### Updated
package/app/index.js CHANGED
@@ -39,7 +39,9 @@ config.log = console.log;
39
39
  config.logWarning = console.warn;
40
40
  config.logError = console.error;
41
41
 
42
- openDb(config).catch((error) => {
42
+ try {
43
+ openDb(config);
44
+ } catch (error) {
43
45
  if (error instanceof Error && error.code === 'SQLITE_CANTOPEN') {
44
46
  config.logError(
45
47
  `Unable to open sqlite database "${config.sqlitePath}" defined as \`sqlitePath\` config.json. Ensure the parent directory exists or remove \`sqlitePath\` from config.json.`
@@ -47,7 +49,7 @@ openDb(config).catch((error) => {
47
49
  }
48
50
 
49
51
  throw error;
50
- });
52
+ }
51
53
 
52
54
  /*
53
55
  * Show all timetable pages
@@ -56,7 +58,7 @@ router.get('/', async (request, response, next) => {
56
58
  try {
57
59
  const timetablePages = [];
58
60
  const timetablePageIds = map(
59
- await getTimetablePagesForAgency(config),
61
+ getTimetablePagesForAgency(config),
60
62
  'timetable_page_id'
61
63
  );
62
64
 
@@ -61,27 +61,22 @@ const simplifyGeoJSON = (geojson, config) => {
61
61
  /*
62
62
  * Get the geoJSON for a timetable.
63
63
  */
64
- export async function getTimetableGeoJSON(timetable, config) {
65
- const [shapesGeojsons, stopsGeojsons] = await Promise.all([
66
- await Promise.all(
67
- timetable.route_ids.map((routeId) =>
68
- getShapesAsGeoJSON({
69
- route_id: routeId,
70
- direction_id: timetable.direction_id,
71
- trip_id: timetable.orderedTrips.map((trip) => trip.trip_id),
72
- })
73
- )
74
- ),
75
- await Promise.all(
76
- timetable.route_ids.map((routeId) =>
77
- getStopsAsGeoJSON({
78
- route_id: routeId,
79
- direction_id: timetable.direction_id,
80
- trip_id: timetable.orderedTrips.map((trip) => trip.trip_id),
81
- })
82
- )
83
- ),
84
- ]);
64
+ export function getTimetableGeoJSON(timetable, config) {
65
+ const shapesGeojsons = timetable.route_ids.map((routeId) =>
66
+ getShapesAsGeoJSON({
67
+ route_id: routeId,
68
+ direction_id: timetable.direction_id,
69
+ trip_id: timetable.orderedTrips.map((trip) => trip.trip_id),
70
+ })
71
+ );
72
+
73
+ const stopsGeojsons = timetable.route_ids.map((routeId) =>
74
+ getStopsAsGeoJSON({
75
+ route_id: routeId,
76
+ direction_id: timetable.direction_id,
77
+ trip_id: timetable.orderedTrips.map((trip) => trip.trip_id),
78
+ })
79
+ );
85
80
 
86
81
  const geojson = mergeGeojson(...shapesGeojsons, ...stopsGeojsons);
87
82
  return simplifyGeoJSON(geojson, config);
@@ -90,11 +85,9 @@ export async function getTimetableGeoJSON(timetable, config) {
90
85
  /*
91
86
  * Get the geoJSON for an agency (all routes and stops).
92
87
  */
93
- export async function getAgencyGeoJSON(config) {
94
- const [shapesGeojsons, stopsGeojsons] = await Promise.all([
95
- getShapesAsGeoJSON(),
96
- getStopsAsGeoJSON(),
97
- ]);
88
+ export function getAgencyGeoJSON(config) {
89
+ const shapesGeojsons = getShapesAsGeoJSON();
90
+ const stopsGeojsons = getStopsAsGeoJSON();
98
91
 
99
92
  const geojson = mergeGeojson(shapesGeojsons, stopsGeojsons);
100
93
  return simplifyGeoJSON(geojson, config);
@@ -2,7 +2,7 @@ import path from 'node:path';
2
2
  import { mkdir, writeFile } from 'node:fs/promises';
3
3
 
4
4
  import { map } from 'lodash-es';
5
- import { openDb, getDb, importGtfs } from 'gtfs';
5
+ import { openDb, importGtfs } from 'gtfs';
6
6
  import sanitize from 'sanitize-filename';
7
7
  import Timer from 'timer-machine';
8
8
 
@@ -35,6 +35,7 @@ import {
35
35
  /*
36
36
  * Generate HTML timetables from GTFS.
37
37
  */
38
+ /* eslint-disable complexity */
38
39
  const gtfsToHtml = async (initialConfig) => {
39
40
  const config = setDefaultConfig(initialConfig);
40
41
  const timer = new Timer();
@@ -45,7 +46,9 @@ const gtfsToHtml = async (initialConfig) => {
45
46
 
46
47
  timer.start();
47
48
 
48
- await openDb(config).catch((error) => {
49
+ try {
50
+ openDb(config);
51
+ } catch (error) {
49
52
  if (error instanceof Error && error.code === 'SQLITE_CANTOPEN') {
50
53
  config.logError(
51
54
  `Unable to open sqlite database "${config.sqlitePath}" defined as \`sqlitePath\` config.json. Ensure the parent directory exists or remove \`sqlitePath\` from config.json.`
@@ -53,17 +56,6 @@ const gtfsToHtml = async (initialConfig) => {
53
56
  }
54
57
 
55
58
  throw error;
56
- });
57
-
58
- if (config.debug === true) {
59
- const db = getDb();
60
-
61
- db.on('profile', (sql, nsecs) => {
62
- if (sql.startsWith('SELECT')) {
63
- console.log(sql);
64
- console.log(nsecs);
65
- }
66
- });
67
59
  }
68
60
 
69
61
  if (!config.agencies || config.agencies.length === 0) {
@@ -91,7 +83,7 @@ const gtfsToHtml = async (initialConfig) => {
91
83
 
92
84
  const timetablePages = [];
93
85
  const timetablePageIds = map(
94
- await getTimetablePagesForAgency(config),
86
+ getTimetablePagesForAgency(config),
95
87
  'timetable_page_id'
96
88
  );
97
89
  await prepDirectory(exportPath);
@@ -190,7 +182,7 @@ const gtfsToHtml = async (initialConfig) => {
190
182
  }
191
183
 
192
184
  // Generate output log.txt
193
- const logText = await generateLogText(outputStats, config);
185
+ const logText = generateLogText(outputStats, config);
194
186
  await writeFile(path.join(exportPath, 'log.txt'), logText);
195
187
 
196
188
  // Zip output, if specified
@@ -217,5 +209,6 @@ const gtfsToHtml = async (initialConfig) => {
217
209
 
218
210
  timer.stop();
219
211
  };
212
+ /* eslint-enable complexity */
220
213
 
221
214
  export default gtfsToHtml;
package/lib/log-utils.js CHANGED
@@ -11,8 +11,8 @@ pe.start();
11
11
  /*
12
12
  * Creates text for a log of output details.
13
13
  */
14
- export async function generateLogText(outputStats, config) {
15
- const feedInfo = await getFeedInfo();
14
+ export function generateLogText(outputStats, config) {
15
+ const feedInfo = getFeedInfo();
16
16
  const feedVersion =
17
17
  feedInfo.length > 0 && feedInfo[0].feed_version
18
18
  ? feedInfo[0].feed_version