transit-departures-widget 2.7.2 → 2.8.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/README.md +1 -0
- package/dist/app/index.d.ts +1 -2
- package/dist/app/index.js +81 -552
- package/dist/app/index.js.map +1 -1
- package/dist/bin/transit-departures-widget.d.ts +1 -1
- package/dist/bin/transit-departures-widget.js +23 -638
- package/dist/bin/transit-departures-widget.js.map +1 -1
- package/dist/browser/THIRD_PARTY_LICENSES.txt +87 -0
- package/dist/browser/pbf.js +1 -0
- package/dist/index.d.ts +29 -26
- package/dist/index.js +2 -590
- package/dist/src-D_ggoL9P.js +55 -0
- package/dist/src-D_ggoL9P.js.map +1 -0
- package/dist/utils-BxiS6d7j.js +368 -0
- package/dist/utils-BxiS6d7j.js.map +1 -0
- package/package.json +11 -12
- package/dist/frontend_libraries/pbf.js +0 -1
- package/dist/index.js.map +0 -1
- /package/dist/{frontend_libraries → browser}/accessible-autocomplete.min.css +0 -0
- /package/dist/{frontend_libraries → browser}/accessible-autocomplete.min.js +0 -0
- /package/dist/{frontend_libraries → browser}/gtfs-realtime.browser.proto.js +0 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import { join } from "path";
|
|
2
|
+
import { groupBy, last, maxBy, noop, size, sortBy, uniqBy } from "lodash-es";
|
|
3
|
+
import { access, copyFile, cp, mkdir, readFile, readdir, rm } from "node:fs/promises";
|
|
4
|
+
import { getDirections, getRoutes, getStops, getTrips, openDb } from "gtfs";
|
|
5
|
+
import untildify from "untildify";
|
|
6
|
+
import { dirname, join as join$1, resolve } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import beautify from "js-beautify";
|
|
9
|
+
import pug from "pug";
|
|
10
|
+
import { clearLine, cursorTo } from "node:readline";
|
|
11
|
+
import * as colors from "yoctocolors";
|
|
12
|
+
import { I18n } from "i18n";
|
|
13
|
+
import sqlString from "sqlstring-sqlite";
|
|
14
|
+
import toposort from "toposort";
|
|
15
|
+
|
|
16
|
+
//#region src/lib/file-utils.ts
|
|
17
|
+
async function getConfig(argv) {
|
|
18
|
+
try {
|
|
19
|
+
const data = await readFile(resolve(untildify(argv.configPath)), "utf8").catch((error) => {
|
|
20
|
+
console.error(/* @__PURE__ */ new Error(`Cannot find configuration file at \`${argv.configPath}\`. Use config-sample.json as a starting point, pass --configPath option`));
|
|
21
|
+
throw error;
|
|
22
|
+
});
|
|
23
|
+
const config = JSON.parse(data);
|
|
24
|
+
if (argv.skipImport === true) config.skipImport = argv.skipImport;
|
|
25
|
+
return config;
|
|
26
|
+
} catch (error) {
|
|
27
|
+
console.error(/* @__PURE__ */ new Error(`Cannot parse configuration file at \`${argv.configPath}\`. Check to ensure that it is valid JSON.`));
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function getPathToThisModuleFolder() {
|
|
32
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
33
|
+
let distFolderPath;
|
|
34
|
+
if (__dirname.endsWith("/dist/bin") || __dirname.endsWith("/dist/app")) distFolderPath = resolve(__dirname, "../../");
|
|
35
|
+
else if (__dirname.endsWith("/dist")) distFolderPath = resolve(__dirname, "../");
|
|
36
|
+
else distFolderPath = resolve(__dirname, "../../");
|
|
37
|
+
return distFolderPath;
|
|
38
|
+
}
|
|
39
|
+
function getPathToViewsFolder(config) {
|
|
40
|
+
if (config.templatePath) return untildify(config.templatePath);
|
|
41
|
+
return join$1(getPathToThisModuleFolder(), "views/widget");
|
|
42
|
+
}
|
|
43
|
+
function getPathToTemplateFile(templateFileName, config) {
|
|
44
|
+
const fullTemplateFileName = config.noHead !== true ? `${templateFileName}_full.pug` : `${templateFileName}.pug`;
|
|
45
|
+
return join$1(getPathToViewsFolder(config), fullTemplateFileName);
|
|
46
|
+
}
|
|
47
|
+
async function prepDirectory(outputPath, config) {
|
|
48
|
+
try {
|
|
49
|
+
await access(outputPath);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
try {
|
|
52
|
+
await mkdir(outputPath, { recursive: true });
|
|
53
|
+
await mkdir(join$1(outputPath, "data"));
|
|
54
|
+
} catch (error) {
|
|
55
|
+
if (error?.code === "ENOENT") throw new Error(`Unable to write to ${outputPath}. Try running this command from a writable directory.`);
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const files = await readdir(outputPath);
|
|
60
|
+
if (config.overwriteExistingFiles === false && files.length > 0) throw new Error(`Output directory ${outputPath} is not empty. Please specify an empty directory.`);
|
|
61
|
+
if (config.overwriteExistingFiles === true) await rm(join$1(outputPath, "*"), {
|
|
62
|
+
recursive: true,
|
|
63
|
+
force: true
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
async function copyStaticAssets(config, outputPath) {
|
|
67
|
+
const viewsFolderPath = getPathToViewsFolder(config);
|
|
68
|
+
const thisModuleFolderPath = getPathToThisModuleFolder();
|
|
69
|
+
for (const folder of ["css", "js"]) if (await access(join$1(viewsFolderPath, folder)).then(() => true).catch(() => false)) await cp(join$1(viewsFolderPath, folder), join$1(outputPath, folder), { recursive: true });
|
|
70
|
+
await copyFile(join$1(thisModuleFolderPath, "dist/browser/pbf.js"), join$1(outputPath, "js/pbf.js"));
|
|
71
|
+
await copyFile(join$1(thisModuleFolderPath, "dist/browser/gtfs-realtime.browser.proto.js"), join$1(outputPath, "js/gtfs-realtime.browser.proto.js"));
|
|
72
|
+
await copyFile(join$1(thisModuleFolderPath, "dist/browser/accessible-autocomplete.min.js"), join$1(outputPath, "js/accessible-autocomplete.min.js"));
|
|
73
|
+
await copyFile(join$1(thisModuleFolderPath, "dist/browser/accessible-autocomplete.min.css"), join$1(outputPath, "css/accessible-autocomplete.min.css"));
|
|
74
|
+
}
|
|
75
|
+
async function renderFile(templateFileName, templateVars, config) {
|
|
76
|
+
const templatePath = getPathToTemplateFile(templateFileName, config);
|
|
77
|
+
const html = await pug.renderFile(templatePath, templateVars);
|
|
78
|
+
if (config.beautify === true) return beautify.html_beautify(html, { indent_size: 2 });
|
|
79
|
+
return html;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/lib/logging/log.ts
|
|
84
|
+
const formatWarning = (text) => {
|
|
85
|
+
const warningMessage = `${colors.underline("Warning")}: ${text}`;
|
|
86
|
+
return colors.yellow(warningMessage);
|
|
87
|
+
};
|
|
88
|
+
const formatError = (error) => {
|
|
89
|
+
const messageText = error instanceof Error ? error.message : error;
|
|
90
|
+
const errorMessage = `${colors.underline("Error")}: ${messageText.replace("Error: ", "")}`;
|
|
91
|
+
return colors.red(errorMessage);
|
|
92
|
+
};
|
|
93
|
+
const logInfo = (config) => {
|
|
94
|
+
if (config.verbose === false) return noop;
|
|
95
|
+
if (config.logFunction) return config.logFunction;
|
|
96
|
+
return (text, overwrite) => {
|
|
97
|
+
if (overwrite === true && process.stdout.isTTY) {
|
|
98
|
+
clearLine(process.stdout, 0);
|
|
99
|
+
cursorTo(process.stdout, 0);
|
|
100
|
+
} else process.stdout.write("\n");
|
|
101
|
+
process.stdout.write(text);
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
const logWarn = (config) => {
|
|
105
|
+
if (config.logFunction) return config.logFunction;
|
|
106
|
+
return (text) => {
|
|
107
|
+
process.stdout.write(`\n${formatWarning(text)}\n`);
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
const logError = (config) => {
|
|
111
|
+
if (config.logFunction) return config.logFunction;
|
|
112
|
+
return (text) => {
|
|
113
|
+
process.stdout.write(`\n${formatError(text)}\n`);
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
function createLogger(config) {
|
|
117
|
+
return {
|
|
118
|
+
info: logInfo(config),
|
|
119
|
+
warn: logWarn(config),
|
|
120
|
+
error: logError(config)
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/lib/config/defaults.ts
|
|
126
|
+
function setDefaultConfig(initialConfig) {
|
|
127
|
+
const config = Object.assign({
|
|
128
|
+
beautify: false,
|
|
129
|
+
noHead: false,
|
|
130
|
+
refreshIntervalSeconds: 20,
|
|
131
|
+
skipImport: false,
|
|
132
|
+
timeFormat: "12hour",
|
|
133
|
+
includeCoordinates: false,
|
|
134
|
+
overwriteExistingFiles: true,
|
|
135
|
+
verbose: true
|
|
136
|
+
}, initialConfig);
|
|
137
|
+
const i18n = new I18n({
|
|
138
|
+
directory: join(getPathToViewsFolder(config), "locales"),
|
|
139
|
+
defaultLocale: config.locale,
|
|
140
|
+
updateFiles: false
|
|
141
|
+
});
|
|
142
|
+
return Object.assign(config, { __: i18n.__ });
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/lib/logging/messages.ts
|
|
147
|
+
const messages = {
|
|
148
|
+
noActiveCalendarsGlobal: "No active calendars found for the configured date range - returning empty routes and stops",
|
|
149
|
+
noActiveCalendarsForRoute: (routeId) => `route_id ${routeId} has no active calendars in range - skipping directions`,
|
|
150
|
+
noActiveCalendarsForDirection: (routeId, directionId) => `route_id ${routeId} direction ${directionId} has no active calendars in range - skipping stops`,
|
|
151
|
+
routeHasNoDirections: (routeId) => `route_id ${routeId} has no directions - skipping`,
|
|
152
|
+
stopNotFound: (routeId, directionId, stopId) => `stop_id ${stopId} for route ${routeId} direction ${directionId} not found - dropping`
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/lib/utils.ts
|
|
157
|
+
const getCalendarsForDateRange = (config) => {
|
|
158
|
+
const db = openDb(config);
|
|
159
|
+
let whereClause = "";
|
|
160
|
+
const whereClauses = [];
|
|
161
|
+
if (config.endDate) whereClauses.push(`start_date <= ${sqlString.escape(config.endDate)}`);
|
|
162
|
+
if (config.startDate) whereClauses.push(`end_date >= ${sqlString.escape(config.startDate)}`);
|
|
163
|
+
if (whereClauses.length > 0) whereClause = `WHERE ${whereClauses.join(" AND ")}`;
|
|
164
|
+
return db.prepare(`SELECT * FROM calendar ${whereClause}`).all();
|
|
165
|
+
};
|
|
166
|
+
function formatRouteName(route) {
|
|
167
|
+
let routeName = "";
|
|
168
|
+
if (route.route_short_name !== null) routeName += route.route_short_name;
|
|
169
|
+
if (route.route_short_name !== null && route.route_long_name !== null) routeName += " - ";
|
|
170
|
+
if (route.route_long_name !== null) routeName += route.route_long_name;
|
|
171
|
+
return routeName;
|
|
172
|
+
}
|
|
173
|
+
function getDirectionsForRoute(route, config) {
|
|
174
|
+
const logger = createLogger(config);
|
|
175
|
+
const db = openDb(config);
|
|
176
|
+
const directions = getDirections({ route_id: route.route_id }, ["direction_id", "direction"]).filter((direction) => direction.direction_id !== void 0).map((direction) => ({
|
|
177
|
+
direction_id: direction.direction_id,
|
|
178
|
+
direction: direction.direction
|
|
179
|
+
}));
|
|
180
|
+
const calendars = getCalendarsForDateRange(config);
|
|
181
|
+
if (calendars.length === 0) {
|
|
182
|
+
logger.warn(messages.noActiveCalendarsForRoute(route.route_id));
|
|
183
|
+
return [];
|
|
184
|
+
}
|
|
185
|
+
if (directions.length === 0) {
|
|
186
|
+
const headsigns = db.prepare(`SELECT direction_id, trip_headsign, count(*) AS count FROM trips WHERE route_id = ? AND service_id IN (${calendars.map((calendar) => `'${calendar.service_id}'`).join(", ")}) GROUP BY direction_id, trip_headsign`).all(route.route_id);
|
|
187
|
+
for (const group of Object.values(groupBy(headsigns, "direction_id"))) {
|
|
188
|
+
const mostCommonHeadsign = maxBy(group, "count");
|
|
189
|
+
directions.push({
|
|
190
|
+
direction_id: mostCommonHeadsign.direction_id,
|
|
191
|
+
direction: config.__("To {{{headsign}}}", { headsign: mostCommonHeadsign.trip_headsign })
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return directions;
|
|
196
|
+
}
|
|
197
|
+
function sortStopIdsBySequence(stoptimes) {
|
|
198
|
+
const stoptimesGroupedByTrip = groupBy(stoptimes, "trip_id");
|
|
199
|
+
try {
|
|
200
|
+
const stopGraph = [];
|
|
201
|
+
for (const tripStoptimes of Object.values(stoptimesGroupedByTrip)) {
|
|
202
|
+
const sortedStopIds = sortBy(tripStoptimes, "stop_sequence").map((stoptime) => stoptime.stop_id);
|
|
203
|
+
for (const [index, stopId] of sortedStopIds.entries()) {
|
|
204
|
+
if (index === sortedStopIds.length - 1) continue;
|
|
205
|
+
stopGraph.push([stopId, sortedStopIds[index + 1]]);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return toposort(stopGraph);
|
|
209
|
+
} catch {}
|
|
210
|
+
const longestTripStoptimes = maxBy(Object.values(stoptimesGroupedByTrip), (stoptimes) => size(stoptimes));
|
|
211
|
+
if (!longestTripStoptimes) return [];
|
|
212
|
+
return longestTripStoptimes.map((stoptime) => stoptime.stop_id);
|
|
213
|
+
}
|
|
214
|
+
function getStopsForDirection(route, direction, config, stopCache) {
|
|
215
|
+
const logger = createLogger(config);
|
|
216
|
+
const db = openDb(config);
|
|
217
|
+
const calendars = getCalendarsForDateRange(config);
|
|
218
|
+
if (calendars.length === 0) {
|
|
219
|
+
logger.warn(messages.noActiveCalendarsForDirection(route.route_id, direction.direction_id));
|
|
220
|
+
return [];
|
|
221
|
+
}
|
|
222
|
+
const whereClause = formatWhereClauses({
|
|
223
|
+
direction_id: direction.direction_id,
|
|
224
|
+
route_id: route.route_id,
|
|
225
|
+
service_id: calendars.map((calendar) => calendar.service_id)
|
|
226
|
+
});
|
|
227
|
+
const deduplicatedStopIds = sortStopIdsBySequence(db.prepare(`SELECT stop_id, stop_sequence, trip_id FROM stop_times WHERE trip_id IN (SELECT trip_id FROM trips ${whereClause}) ORDER BY stop_sequence ASC`).all()).reduce((memo, stopId) => {
|
|
228
|
+
if (last(memo) !== stopId) memo.push(stopId);
|
|
229
|
+
return memo;
|
|
230
|
+
}, []);
|
|
231
|
+
deduplicatedStopIds.pop();
|
|
232
|
+
const stopFields = [
|
|
233
|
+
"stop_id",
|
|
234
|
+
"stop_name",
|
|
235
|
+
"stop_code",
|
|
236
|
+
"parent_station"
|
|
237
|
+
];
|
|
238
|
+
if (config.includeCoordinates) stopFields.push("stop_lat", "stop_lon");
|
|
239
|
+
const missingStopIds = stopCache ? deduplicatedStopIds.filter((stopId) => !stopCache.has(stopId)) : deduplicatedStopIds;
|
|
240
|
+
const fetchedStops = missingStopIds.length ? getStops({ stop_id: missingStopIds }, stopFields) : [];
|
|
241
|
+
if (stopCache) for (const stop of fetchedStops) stopCache.set(stop.stop_id, stop);
|
|
242
|
+
return deduplicatedStopIds.map((stopId) => {
|
|
243
|
+
const stop = stopCache?.get(stopId) ?? fetchedStops.find((candidate) => candidate.stop_id === stopId);
|
|
244
|
+
if (!stop) logger.warn(messages.stopNotFound(route.route_id, direction.direction_id, stopId));
|
|
245
|
+
return stop;
|
|
246
|
+
}).filter(Boolean);
|
|
247
|
+
}
|
|
248
|
+
function generateTransitDeparturesWidgetHtml(config) {
|
|
249
|
+
return renderFile("widget", {
|
|
250
|
+
config,
|
|
251
|
+
__: config.__
|
|
252
|
+
}, config);
|
|
253
|
+
}
|
|
254
|
+
function generateTransitDeparturesWidgetJson(config) {
|
|
255
|
+
const logger = createLogger(config);
|
|
256
|
+
const calendars = getCalendarsForDateRange(config);
|
|
257
|
+
if (calendars.length === 0) {
|
|
258
|
+
logger.warn(messages.noActiveCalendarsGlobal);
|
|
259
|
+
return {
|
|
260
|
+
routes: [],
|
|
261
|
+
stops: []
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
const routes = getRoutes();
|
|
265
|
+
const stops = [];
|
|
266
|
+
const filteredRoutes = [];
|
|
267
|
+
const stopCache = /* @__PURE__ */ new Map();
|
|
268
|
+
for (const route of routes) {
|
|
269
|
+
const routeWithFullName = {
|
|
270
|
+
...route,
|
|
271
|
+
route_full_name: formatRouteName(route)
|
|
272
|
+
};
|
|
273
|
+
const directions = getDirectionsForRoute(routeWithFullName, config);
|
|
274
|
+
if (directions.length === 0) {
|
|
275
|
+
logger.warn(messages.routeHasNoDirections(route.route_id));
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
const directionsWithData = directions.map((direction) => {
|
|
279
|
+
const directionStops = getStopsForDirection(routeWithFullName, direction, config, stopCache);
|
|
280
|
+
if (directionStops.length === 0) return null;
|
|
281
|
+
stops.push(...directionStops);
|
|
282
|
+
const trips = getTrips({
|
|
283
|
+
route_id: route.route_id,
|
|
284
|
+
direction_id: direction.direction_id,
|
|
285
|
+
service_id: calendars.map((calendar) => calendar.service_id)
|
|
286
|
+
}, ["trip_id"]);
|
|
287
|
+
return {
|
|
288
|
+
...direction,
|
|
289
|
+
stopIds: directionStops.map((stop) => stop.stop_id),
|
|
290
|
+
tripIds: trips.map((trip) => trip.trip_id)
|
|
291
|
+
};
|
|
292
|
+
}).filter(Boolean);
|
|
293
|
+
if (directionsWithData.length === 0) continue;
|
|
294
|
+
filteredRoutes.push({
|
|
295
|
+
...routeWithFullName,
|
|
296
|
+
directions: directionsWithData
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
const sortedRoutes = [...filteredRoutes].sort((a, b) => {
|
|
300
|
+
const aShort = a.route_short_name ?? "";
|
|
301
|
+
const bShort = b.route_short_name ?? "";
|
|
302
|
+
const aNum = Number.parseInt(aShort, 10);
|
|
303
|
+
const bNum = Number.parseInt(bShort, 10);
|
|
304
|
+
if (!Number.isNaN(aNum) && !Number.isNaN(bNum) && aNum !== bNum) return aNum - bNum;
|
|
305
|
+
if (Number.isNaN(aNum) && !Number.isNaN(bNum)) return 1;
|
|
306
|
+
if (!Number.isNaN(aNum) && Number.isNaN(bNum)) return -1;
|
|
307
|
+
return aShort.localeCompare(bShort, void 0, {
|
|
308
|
+
numeric: true,
|
|
309
|
+
sensitivity: "base"
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
const parentStationIds = new Set(stops.map((stop) => stop.parent_station));
|
|
313
|
+
const parentStationStops = getStops({ stop_id: Array.from(parentStationIds) }, [
|
|
314
|
+
"stop_id",
|
|
315
|
+
"stop_name",
|
|
316
|
+
"stop_code",
|
|
317
|
+
"parent_station"
|
|
318
|
+
]);
|
|
319
|
+
stops.push(...parentStationStops.map((stop) => ({
|
|
320
|
+
...stop,
|
|
321
|
+
is_parent_station: true
|
|
322
|
+
})));
|
|
323
|
+
const sortedStops = sortBy(uniqBy(stops, "stop_id"), "stop_name");
|
|
324
|
+
return {
|
|
325
|
+
routes: arrayOfArrays(removeNulls(sortedRoutes)),
|
|
326
|
+
stops: arrayOfArrays(removeNulls(sortedStops))
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
function removeNulls(data) {
|
|
330
|
+
if (Array.isArray(data)) return data.map(removeNulls).filter((item) => item !== null && item !== void 0);
|
|
331
|
+
else if (data !== null && typeof data === "object" && Object.getPrototypeOf(data) === Object.prototype) return Object.entries(data).reduce((acc, [key, value]) => {
|
|
332
|
+
const cleanedValue = removeNulls(value);
|
|
333
|
+
if (cleanedValue !== null && cleanedValue !== void 0) acc[key] = cleanedValue;
|
|
334
|
+
return acc;
|
|
335
|
+
}, {});
|
|
336
|
+
else return data;
|
|
337
|
+
}
|
|
338
|
+
function arrayOfArrays(array) {
|
|
339
|
+
if (array.length === 0) return {
|
|
340
|
+
fields: [],
|
|
341
|
+
rows: []
|
|
342
|
+
};
|
|
343
|
+
const fields = Array.from(array.reduce((fieldSet, item) => {
|
|
344
|
+
Object.keys(item ?? {}).forEach((key) => fieldSet.add(key));
|
|
345
|
+
return fieldSet;
|
|
346
|
+
}, /* @__PURE__ */ new Set()));
|
|
347
|
+
return {
|
|
348
|
+
fields,
|
|
349
|
+
rows: array.map((item) => fields.map((field) => item?.[field] ?? null))
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
function formatWhereClause(key, value) {
|
|
353
|
+
if (Array.isArray(value)) {
|
|
354
|
+
let whereClause = `${sqlString.escapeId(key)} IN (${value.filter((v) => v !== null).map((v) => sqlString.escape(v)).join(", ")})`;
|
|
355
|
+
if (value.includes(null)) whereClause = `(${whereClause} OR ${sqlString.escapeId(key)} IS NULL)`;
|
|
356
|
+
return whereClause;
|
|
357
|
+
}
|
|
358
|
+
if (value === null) return `${sqlString.escapeId(key)} IS NULL`;
|
|
359
|
+
return `${sqlString.escapeId(key)} = ${sqlString.escape(value)}`;
|
|
360
|
+
}
|
|
361
|
+
function formatWhereClauses(query) {
|
|
362
|
+
if (Object.keys(query).length === 0) return "";
|
|
363
|
+
return `WHERE ${Object.entries(query).map(([key, value]) => formatWhereClause(key, value)).join(" AND ")}`;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
//#endregion
|
|
367
|
+
export { formatError as a, getPathToViewsFolder as c, createLogger as i, prepDirectory as l, generateTransitDeparturesWidgetJson as n, copyStaticAssets as o, setDefaultConfig as r, getConfig as s, generateTransitDeparturesWidgetHtml as t };
|
|
368
|
+
//# sourceMappingURL=utils-BxiS6d7j.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-BxiS6d7j.js","names":["join"],"sources":["../src/lib/file-utils.ts","../src/lib/logging/log.ts","../src/lib/config/defaults.ts","../src/lib/logging/messages.ts","../src/lib/utils.ts"],"sourcesContent":["import { dirname, join, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport {\n access,\n cp,\n copyFile,\n mkdir,\n readdir,\n readFile,\n rm,\n} from 'node:fs/promises'\nimport beautify from 'js-beautify'\nimport pug from 'pug'\nimport untildify from 'untildify'\n\nimport { Config } from '../types/global_interfaces.ts'\n\n/*\n * Attempt to parse the specified config JSON file.\n */\nexport async function getConfig(argv) {\n try {\n const data = await readFile(\n resolve(untildify(argv.configPath)),\n 'utf8',\n ).catch((error) => {\n console.error(\n new Error(\n `Cannot find configuration file at \\`${argv.configPath}\\`. Use config-sample.json as a starting point, pass --configPath option`,\n ),\n )\n throw error\n })\n const config = JSON.parse(data)\n\n if (argv.skipImport === true) {\n config.skipImport = argv.skipImport\n }\n\n return config\n } catch (error) {\n console.error(\n new Error(\n `Cannot parse configuration file at \\`${argv.configPath}\\`. Check to ensure that it is valid JSON.`,\n ),\n )\n throw error\n }\n}\n\n/*\n * Get the full path to this module's folder.\n */\nexport function getPathToThisModuleFolder() {\n const __dirname = dirname(fileURLToPath(import.meta.url))\n\n // Dynamically calculate the path to this module's folder\n let distFolderPath\n if (__dirname.endsWith('/dist/bin') || __dirname.endsWith('/dist/app')) {\n // When the file is in 'dist/bin' or 'dist/app'\n distFolderPath = resolve(__dirname, '../../')\n } else if (__dirname.endsWith('/dist')) {\n // When the file is in 'dist'\n distFolderPath = resolve(__dirname, '../')\n } else {\n // In case it's neither, fallback to project root\n distFolderPath = resolve(__dirname, '../../')\n }\n\n return distFolderPath\n}\n\n/*\n * Get the full path to the views folder.\n */\nexport function getPathToViewsFolder(config: Config) {\n if (config.templatePath) {\n return untildify(config.templatePath)\n }\n\n return join(getPathToThisModuleFolder(), 'views/widget')\n}\n\n/*\n * Get the full path of a template file.\n */\nfunction getPathToTemplateFile(templateFileName: string, config: Config) {\n const fullTemplateFileName =\n config.noHead !== true\n ? `${templateFileName}_full.pug`\n : `${templateFileName}.pug`\n\n return join(getPathToViewsFolder(config), fullTemplateFileName)\n}\n\n/*\n * Prepare the outputPath directory for writing timetable files.\n */\nexport async function prepDirectory(outputPath: string, config: Config) {\n // Check if outputPath exists\n try {\n await access(outputPath)\n } catch (error: any) {\n try {\n await mkdir(outputPath, { recursive: true })\n await mkdir(join(outputPath, 'data'))\n } catch (error: any) {\n if (error?.code === 'ENOENT') {\n throw new Error(\n `Unable to write to ${outputPath}. Try running this command from a writable directory.`,\n )\n }\n\n throw error\n }\n }\n\n // Check if outputPath is empty\n const files = await readdir(outputPath)\n if (config.overwriteExistingFiles === false && files.length > 0) {\n throw new Error(\n `Output directory ${outputPath} is not empty. Please specify an empty directory.`,\n )\n }\n\n // Delete all files in outputPath if `overwriteExistingFiles` is true\n if (config.overwriteExistingFiles === true) {\n await rm(join(outputPath, '*'), { recursive: true, force: true })\n }\n}\n\n/*\n * Copy needed CSS and JS to export path.\n */\nexport async function copyStaticAssets(config: Config, outputPath: string) {\n const viewsFolderPath = getPathToViewsFolder(config)\n const thisModuleFolderPath = getPathToThisModuleFolder()\n\n const foldersToCopy = ['css', 'js']\n\n for (const folder of foldersToCopy) {\n if (\n await access(join(viewsFolderPath, folder))\n .then(() => true)\n .catch(() => false)\n ) {\n await cp(join(viewsFolderPath, folder), join(outputPath, folder), {\n recursive: true,\n })\n }\n }\n\n // Copy js and css libraries from node_modules\n await copyFile(\n join(thisModuleFolderPath, 'dist/browser/pbf.js'),\n join(outputPath, 'js/pbf.js'),\n )\n\n await copyFile(\n join(thisModuleFolderPath, 'dist/browser/gtfs-realtime.browser.proto.js'),\n join(outputPath, 'js/gtfs-realtime.browser.proto.js'),\n )\n\n await copyFile(\n join(thisModuleFolderPath, 'dist/browser/accessible-autocomplete.min.js'),\n join(outputPath, 'js/accessible-autocomplete.min.js'),\n )\n\n await copyFile(\n join(thisModuleFolderPath, 'dist/browser/accessible-autocomplete.min.css'),\n join(outputPath, 'css/accessible-autocomplete.min.css'),\n )\n}\n\n/*\n * Render the HTML based on the config.\n */\nexport async function renderFile(\n templateFileName: string,\n templateVars: any,\n config: Config,\n) {\n const templatePath = getPathToTemplateFile(templateFileName, config)\n const html = await pug.renderFile(templatePath, templateVars)\n\n // Beautify HTML if setting is set\n if (config.beautify === true) {\n return beautify.html_beautify(html, { indent_size: 2 })\n }\n\n return html\n}\n","import { clearLine, cursorTo } from 'node:readline'\nimport { noop } from 'lodash-es'\nimport * as colors from 'yoctocolors'\n\nimport { Config } from '../../types/global_interfaces.ts'\n\nexport type Logger = {\n info: (text: string, overwrite?: boolean) => void\n warn: (text: string) => void\n error: (text: string) => void\n}\n\nconst formatWarning = (text: string) => {\n const warningMessage = `${colors.underline('Warning')}: ${text}`\n return colors.yellow(warningMessage)\n}\n\nexport const formatError = (error: any) => {\n const messageText = error instanceof Error ? error.message : error\n const errorMessage = `${colors.underline('Error')}: ${messageText.replace(\n 'Error: ',\n '',\n )}`\n return colors.red(errorMessage)\n}\n\nconst logInfo = (config: Config) => {\n if (config.verbose === false) {\n return noop\n }\n\n if (config.logFunction) {\n return config.logFunction\n }\n\n return (text: string, overwrite?: boolean) => {\n if (overwrite === true && process.stdout.isTTY) {\n clearLine(process.stdout, 0)\n cursorTo(process.stdout, 0)\n } else {\n process.stdout.write('\\n')\n }\n\n process.stdout.write(text)\n }\n}\n\nconst logWarn = (config: Config) => {\n if (config.logFunction) {\n return config.logFunction\n }\n\n return (text: string) => {\n process.stdout.write(`\\n${formatWarning(text)}\\n`)\n }\n}\n\nconst logError = (config: Config) => {\n if (config.logFunction) {\n return config.logFunction\n }\n\n return (text: string) => {\n process.stdout.write(`\\n${formatError(text)}\\n`)\n }\n}\n\n/*\n * Create a structured logger with consistent methods.\n */\nexport function createLogger(config: Config): Logger {\n return {\n info: logInfo(config),\n warn: logWarn(config),\n error: logError(config),\n }\n}\n","import { join } from 'path'\nimport { I18n } from 'i18n'\n\nimport { Config } from '../../types/global_interfaces.ts'\nimport { getPathToViewsFolder } from '../file-utils.ts'\n\n/*\n * Initialize configuration with defaults.\n */\nexport function setDefaultConfig(initialConfig: Config) {\n const defaults = {\n beautify: false,\n noHead: false,\n refreshIntervalSeconds: 20,\n skipImport: false,\n timeFormat: '12hour',\n includeCoordinates: false,\n overwriteExistingFiles: true,\n verbose: true,\n }\n\n const config = Object.assign(defaults, initialConfig)\n const viewsFolderPath = getPathToViewsFolder(config)\n const i18n = new I18n({\n directory: join(viewsFolderPath, 'locales'),\n defaultLocale: config.locale,\n updateFiles: false,\n })\n const configWithI18n = Object.assign(config, {\n __: i18n.__,\n })\n return configWithI18n\n}\n","export const messages = {\n noActiveCalendarsGlobal:\n 'No active calendars found for the configured date range - returning empty routes and stops',\n noActiveCalendarsForRoute: (routeId: string) =>\n `route_id ${routeId} has no active calendars in range - skipping directions`,\n noActiveCalendarsForDirection: (\n routeId: string,\n directionId: string | number,\n ) =>\n `route_id ${routeId} direction ${directionId} has no active calendars in range - skipping stops`,\n routeHasNoDirections: (routeId: string) =>\n `route_id ${routeId} has no directions - skipping`,\n stopNotFound: (\n routeId: string,\n directionId: string | number,\n stopId: string,\n ) =>\n `stop_id ${stopId} for route ${routeId} direction ${directionId} not found - dropping`,\n}\n","import { openDb, getDirections, getRoutes, getStops, getTrips } from 'gtfs'\nimport { groupBy, last, maxBy, size, sortBy, uniqBy } from 'lodash-es'\nimport { renderFile } from './file-utils.ts'\nimport sqlString from 'sqlstring-sqlite'\nimport toposort from 'toposort'\n\nimport { Config, SqlWhere, SqlValue } from '../types/global_interfaces.ts'\nimport {\n ConfigWithI18n,\n GTFSCalendar,\n GTFSRoute,\n GTFSRouteDirection,\n GTFSStop,\n} from '../types/gtfs.ts'\nimport { createLogger } from './logging/log.ts'\nimport { messages } from './logging/messages.ts'\nexport { setDefaultConfig } from './config/defaults.ts'\n\n/*\n * Get calendars for a specified date range\n */\nconst getCalendarsForDateRange = (config: Config): GTFSCalendar[] => {\n const db = openDb(config)\n let whereClause = ''\n const whereClauses = []\n\n if (config.endDate) {\n whereClauses.push(`start_date <= ${sqlString.escape(config.endDate)}`)\n }\n\n if (config.startDate) {\n whereClauses.push(`end_date >= ${sqlString.escape(config.startDate)}`)\n }\n\n if (whereClauses.length > 0) {\n whereClause = `WHERE ${whereClauses.join(' AND ')}`\n }\n\n return db.prepare(`SELECT * FROM calendar ${whereClause}`).all()\n}\n\n/*\n * Format a route name.\n */\nfunction formatRouteName(route: GTFSRoute) {\n let routeName = ''\n\n if (route.route_short_name !== null) {\n routeName += route.route_short_name\n }\n\n if (route.route_short_name !== null && route.route_long_name !== null) {\n routeName += ' - '\n }\n\n if (route.route_long_name !== null) {\n routeName += route.route_long_name\n }\n\n return routeName\n}\n\n/*\n * Get directions for a route\n */\nfunction getDirectionsForRoute(route: GTFSRoute, config: ConfigWithI18n) {\n const logger = createLogger(config)\n const db = openDb(config)\n\n // Lookup direction names from non-standard directions.txt file\n const directions = getDirections({ route_id: route.route_id }, [\n 'direction_id',\n 'direction',\n ])\n .filter((direction) => direction.direction_id !== undefined)\n .map((direction) => ({\n direction_id: direction.direction_id as number | string,\n direction: direction.direction,\n }))\n\n const calendars = getCalendarsForDateRange(config)\n if (calendars.length === 0) {\n logger.warn(messages.noActiveCalendarsForRoute(route.route_id))\n return []\n }\n\n // Else use the most common headsigns as directions from trips.txt file\n if (directions.length === 0) {\n const headsigns = db\n .prepare(\n `SELECT direction_id, trip_headsign, count(*) AS count FROM trips WHERE route_id = ? AND service_id IN (${calendars\n .map((calendar: GTFSCalendar) => `'${calendar.service_id}'`)\n .join(', ')}) GROUP BY direction_id, trip_headsign`,\n )\n .all(route.route_id)\n\n for (const group of Object.values(groupBy(headsigns, 'direction_id'))) {\n const mostCommonHeadsign = maxBy(group, 'count')\n directions.push({\n direction_id: mostCommonHeadsign.direction_id,\n direction: config.__('To {{{headsign}}}', {\n headsign: mostCommonHeadsign.trip_headsign,\n }),\n })\n }\n }\n\n return directions\n}\n\n/*\n * Sort an array of stoptimes by stop_sequence using a directed graph\n */\nfunction sortStopIdsBySequence(stoptimes: Record<string, string>[]) {\n const stoptimesGroupedByTrip = groupBy(stoptimes, 'trip_id')\n\n // First, try using a directed graph to determine stop order.\n try {\n const stopGraph = []\n\n for (const tripStoptimes of Object.values(stoptimesGroupedByTrip)) {\n const sortedStopIds = sortBy(tripStoptimes, 'stop_sequence').map(\n (stoptime) => stoptime.stop_id,\n )\n\n for (const [index, stopId] of sortedStopIds.entries()) {\n if (index === sortedStopIds.length - 1) {\n continue\n }\n\n stopGraph.push([stopId, sortedStopIds[index + 1]])\n }\n }\n\n return toposort(\n stopGraph as unknown as readonly [string, string | undefined][],\n )\n } catch {\n // Ignore errors and move to next strategy.\n }\n\n // Finally, fall back to using the stop order from the trip with the most stoptimes.\n const longestTripStoptimes = maxBy(\n Object.values(stoptimesGroupedByTrip),\n (stoptimes) => size(stoptimes),\n )\n\n if (!longestTripStoptimes) {\n return []\n }\n\n return longestTripStoptimes.map((stoptime) => stoptime.stop_id)\n}\n\nfunction getStopsForDirection(\n route: GTFSRoute,\n direction: GTFSRouteDirection,\n config: Config,\n stopCache?: Map<string, GTFSStop>,\n) {\n const logger = createLogger(config)\n const db = openDb(config)\n const calendars = getCalendarsForDateRange(config)\n if (calendars.length === 0) {\n logger.warn(\n messages.noActiveCalendarsForDirection(\n route.route_id,\n direction.direction_id,\n ),\n )\n return []\n }\n const whereClause = formatWhereClauses({\n direction_id: direction.direction_id,\n route_id: route.route_id,\n service_id: calendars.map((calendar: GTFSCalendar) => calendar.service_id),\n })\n const stoptimes = db\n .prepare(\n `SELECT stop_id, stop_sequence, trip_id FROM stop_times WHERE trip_id IN (SELECT trip_id FROM trips ${whereClause}) ORDER BY stop_sequence ASC`,\n )\n .all()\n\n const sortedStopIds = sortStopIdsBySequence(stoptimes)\n\n const deduplicatedStopIds = sortedStopIds.reduce(\n (memo: string[], stopId: string) => {\n // Remove duplicated stop_ids in a row\n if (last(memo) !== stopId) {\n memo.push(stopId)\n }\n\n return memo\n },\n [],\n )\n\n // Remove last stop of route since boarding is not allowed\n deduplicatedStopIds.pop()\n\n // Fetch stop details\n const stopFields: (keyof GTFSStop)[] = [\n 'stop_id',\n 'stop_name',\n 'stop_code',\n 'parent_station',\n ]\n\n if (config.includeCoordinates) {\n stopFields.push('stop_lat', 'stop_lon')\n }\n\n const missingStopIds = stopCache\n ? deduplicatedStopIds.filter((stopId) => !stopCache.has(stopId))\n : deduplicatedStopIds\n\n const fetchedStops = missingStopIds.length\n ? (getStops as unknown as (query: any, fields?: any) => GTFSStop[])(\n { stop_id: missingStopIds },\n stopFields,\n )\n : []\n\n if (stopCache) {\n for (const stop of fetchedStops) {\n stopCache.set(stop.stop_id, stop)\n }\n }\n\n return deduplicatedStopIds\n .map((stopId: string) => {\n const stop =\n stopCache?.get(stopId) ??\n fetchedStops.find((candidate) => candidate.stop_id === stopId)\n\n if (!stop) {\n logger.warn(\n messages.stopNotFound(route.route_id, direction.direction_id, stopId),\n )\n }\n\n return stop\n })\n .filter(Boolean) as GTFSStop[]\n}\n\n/*\n * Generate HTML for transit departures widget.\n */\nexport function generateTransitDeparturesWidgetHtml(config: ConfigWithI18n) {\n const templateVars = {\n config,\n __: config.__,\n }\n return renderFile('widget', templateVars, config)\n}\n\n/*\n * Generate JSON of routes and stops for transit departures widget.\n */\nexport function generateTransitDeparturesWidgetJson(config: ConfigWithI18n) {\n const logger = createLogger(config)\n const calendars = getCalendarsForDateRange(config)\n if (calendars.length === 0) {\n logger.warn(messages.noActiveCalendarsGlobal)\n return { routes: [], stops: [] }\n }\n\n const routes = getRoutes() as GTFSRoute[]\n const stops: GTFSStop[] = []\n const filteredRoutes: GTFSRoute[] = []\n const stopCache = new Map<string, GTFSStop>()\n\n for (const route of routes) {\n const routeWithFullName: GTFSRoute = {\n ...route,\n route_full_name: formatRouteName(route),\n }\n\n const directions = getDirectionsForRoute(routeWithFullName, config)\n\n // Filter out routes with no directions\n if (directions.length === 0) {\n logger.warn(messages.routeHasNoDirections(route.route_id))\n continue\n }\n\n const directionsWithData = directions\n .map((direction) => {\n const directionStops = getStopsForDirection(\n routeWithFullName,\n direction,\n config,\n stopCache,\n )\n\n if (directionStops.length === 0) {\n return null\n }\n\n stops.push(...directionStops)\n\n const trips = getTrips(\n {\n route_id: route.route_id,\n direction_id: direction.direction_id,\n service_id: calendars.map(\n (calendar: GTFSCalendar) => calendar.service_id,\n ),\n },\n ['trip_id'],\n )\n\n return {\n ...direction,\n stopIds: directionStops.map((stop) => stop.stop_id),\n tripIds: trips.map((trip) => trip.trip_id),\n }\n })\n .filter(Boolean) as GTFSRouteDirection[]\n\n if (directionsWithData.length === 0) {\n continue\n }\n\n filteredRoutes.push({\n ...routeWithFullName,\n directions: directionsWithData,\n })\n }\n\n // Sort routes deterministically, handling mixed numeric/alphanumeric IDs\n const sortedRoutes = [...filteredRoutes].sort((a, b) => {\n const aShort = a.route_short_name ?? ''\n const bShort = b.route_short_name ?? ''\n const aNum = Number.parseInt(aShort, 10)\n const bNum = Number.parseInt(bShort, 10)\n\n if (!Number.isNaN(aNum) && !Number.isNaN(bNum) && aNum !== bNum) {\n return aNum - bNum\n }\n\n if (Number.isNaN(aNum) && !Number.isNaN(bNum)) {\n return 1\n }\n\n if (!Number.isNaN(aNum) && Number.isNaN(bNum)) {\n return -1\n }\n\n return aShort.localeCompare(bShort, undefined, {\n numeric: true,\n sensitivity: 'base',\n })\n })\n\n // Get Parent Station Stops\n const parentStationIds = new Set(stops.map((stop) => stop.parent_station))\n\n const parentStationStops = getStops(\n { stop_id: Array.from(parentStationIds) },\n ['stop_id', 'stop_name', 'stop_code', 'parent_station'],\n )\n\n stops.push(\n ...parentStationStops.map((stop) => ({\n ...stop,\n is_parent_station: true,\n })),\n )\n\n // Sort unique list of stops\n const sortedStops = sortBy(uniqBy(stops, 'stop_id'), 'stop_name')\n\n return {\n routes: arrayOfArrays(removeNulls(sortedRoutes)),\n stops: arrayOfArrays(removeNulls(sortedStops)),\n }\n}\n\n/*\n * Remove null values from array or object\n */\nfunction removeNulls(data: any): any {\n if (Array.isArray(data)) {\n return data\n .map(removeNulls)\n .filter((item) => item !== null && item !== undefined)\n } else if (\n data !== null &&\n typeof data === 'object' &&\n Object.getPrototypeOf(data) === Object.prototype\n ) {\n return Object.entries(data).reduce<Record<string, unknown>>(\n (acc, [key, value]) => {\n const cleanedValue = removeNulls(value)\n if (cleanedValue !== null && cleanedValue !== undefined) {\n acc[key] = cleanedValue\n }\n return acc\n },\n {},\n )\n } else {\n return data\n }\n}\n\n/*\n * Convert an array of objects into an Array-of-arrays JSON: { \"fields\": [...], \"rows\": [[...], ...] }\n */\nfunction arrayOfArrays(array: any[]): { fields: string[]; rows: any[][] } {\n if (array.length === 0) {\n return { fields: [], rows: [] }\n }\n\n const fields: string[] = Array.from(\n array.reduce<Set<string>>((fieldSet, item) => {\n Object.keys(item ?? {}).forEach((key) => fieldSet.add(key))\n return fieldSet\n }, new Set<string>()),\n )\n\n return {\n fields,\n rows: array.map((item) => fields.map((field) => item?.[field] ?? null)),\n }\n}\n\nexport function formatWhereClause(\n key: string,\n value: null | SqlValue | SqlValue[],\n) {\n if (Array.isArray(value)) {\n let whereClause = `${sqlString.escapeId(key)} IN (${value\n .filter((v) => v !== null)\n .map((v) => sqlString.escape(v))\n .join(', ')})`\n\n if (value.includes(null)) {\n whereClause = `(${whereClause} OR ${sqlString.escapeId(key)} IS NULL)`\n }\n\n return whereClause\n }\n\n if (value === null) {\n return `${sqlString.escapeId(key)} IS NULL`\n }\n\n return `${sqlString.escapeId(key)} = ${sqlString.escape(value)}`\n}\n\nexport function formatWhereClauses(query: SqlWhere) {\n if (Object.keys(query).length === 0) {\n return ''\n }\n\n const whereClauses = Object.entries(query).map(([key, value]) =>\n formatWhereClause(key, value),\n )\n return `WHERE ${whereClauses.join(' AND ')}`\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAoBA,eAAsB,UAAU,MAAM;CACpC,IAAI;EACF,MAAM,OAAO,MAAM,SACjB,QAAQ,UAAU,KAAK,UAAU,CAAC,GAClC,MACF,CAAC,CAAC,OAAO,UAAU;GACjB,QAAQ,sBACN,IAAI,MACF,uCAAuC,KAAK,WAAW,yEACzD,CACF;GACA,MAAM;EACR,CAAC;EACD,MAAM,SAAS,KAAK,MAAM,IAAI;EAE9B,IAAI,KAAK,eAAe,MACtB,OAAO,aAAa,KAAK;EAG3B,OAAO;CACT,SAAS,OAAO;EACd,QAAQ,sBACN,IAAI,MACF,wCAAwC,KAAK,WAAW,2CAC1D,CACF;EACA,MAAM;CACR;AACF;AAKA,SAAgB,4BAA4B;CAC1C,MAAM,YAAY,QAAQ,cAAc,OAAO,KAAK,GAAG,CAAC;CAGxD,IAAI;CACJ,IAAI,UAAU,SAAS,WAAW,KAAK,UAAU,SAAS,WAAW,GAEnE,iBAAiB,QAAQ,WAAW,QAAQ;MACvC,IAAI,UAAU,SAAS,OAAO,GAEnC,iBAA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c,IAAI,YAAY,MAAM,UAAU,SAAS,GAAG,EAAE;EAG9D,OAAO;CACT;CAEA,IAAI,UAAU,MACZ,OAAO,GAAG,UAAU,SAAS,GAAG,EAAE;CAGpC,OAAO,GAAG,UAAU,SAAS,GAAG,EAAE,KAAK,UAAU,OAAO,KAAK;AAC/D;AAEA,SAAgB,mBAAmB,OAAiB;CAClD,IAAI,OAAO,KAAK,KAAK,CAAC,CAAC,WAAW,GAChC,OAAO;CAMT,OAAO,SAHc,OAAO,QAAQ,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,WACpD,kBAAkB,KAAK,KAAK,CAEH,CAAC,CAAC,KAAK,OAAO;AAC3C"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "transit-departures-widget",
|
|
3
3
|
"description": "Build a realtime transit departures tool from GTFS and GTFS-Realtime.",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.8.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"transit",
|
|
7
7
|
"gtfs",
|
|
@@ -22,11 +22,10 @@
|
|
|
22
22
|
],
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"scripts": {
|
|
25
|
-
"build": "
|
|
26
|
-
"postbuild": "node scripts/postinstall.js",
|
|
25
|
+
"build": "tsdown && node scripts/copy-browser-assets.js",
|
|
27
26
|
"start": "node ./dist/app",
|
|
28
27
|
"prepare": "husky && npm run build",
|
|
29
|
-
"
|
|
28
|
+
"prepack": "husky && pnpm run build"
|
|
30
29
|
},
|
|
31
30
|
"bin": {
|
|
32
31
|
"transit-departures-widget": "dist/bin/transit-departures-widget.js"
|
|
@@ -40,12 +39,12 @@
|
|
|
40
39
|
"dependencies": {
|
|
41
40
|
"accessible-autocomplete": "^3.0.1",
|
|
42
41
|
"express": "^5.2.1",
|
|
43
|
-
"gtfs": "^4.
|
|
42
|
+
"gtfs": "^4.19.1",
|
|
44
43
|
"gtfs-realtime-pbf-js-module": "^1.0.0",
|
|
45
44
|
"i18n": "^0.15.3",
|
|
46
45
|
"js-beautify": "^1.15.4",
|
|
47
|
-
"lodash-es": "^4.
|
|
48
|
-
"pbf": "^
|
|
46
|
+
"lodash-es": "^4.18.1",
|
|
47
|
+
"pbf": "^5.1.0",
|
|
49
48
|
"pretty-error": "^4.0.0",
|
|
50
49
|
"pug": "^3.0.4",
|
|
51
50
|
"sanitize-filename": "^1.6.4",
|
|
@@ -68,13 +67,13 @@
|
|
|
68
67
|
"@types/toposort": "^2.0.7",
|
|
69
68
|
"@types/yargs": "^17.0.35",
|
|
70
69
|
"husky": "^9.1.7",
|
|
71
|
-
"lint-staged": "^
|
|
72
|
-
"prettier": "^3.8.
|
|
73
|
-
"
|
|
74
|
-
"typescript": "^6.0.
|
|
70
|
+
"lint-staged": "^17.0.7",
|
|
71
|
+
"prettier": "^3.8.4",
|
|
72
|
+
"tsdown": "^0.22.2",
|
|
73
|
+
"typescript": "^6.0.3"
|
|
75
74
|
},
|
|
76
75
|
"engines": {
|
|
77
|
-
"node": ">=
|
|
76
|
+
"node": ">= 22"
|
|
78
77
|
},
|
|
79
78
|
"release-it": {
|
|
80
79
|
"github": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):(t="undefined"!=typeof globalThis?globalThis:t||self).Pbf=i()}(this,(function(){"use strict";const t=4294967296,i=1/t,e="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8");function s(t,i,e){return e?4294967296*i+(t>>>0):4294967296*(i>>>0)+(t>>>0)}function r(t,i,e){const s=i<=16383?1:i<=2097151?2:i<=268435455?3:Math.floor(Math.log(i)/(7*Math.LN2));e.realloc(s);for(let i=e.pos-1;i>=t;i--)e.buf[i+s]=e.buf[i]}function o(t,i){for(let e=0;e<t.length;e++)i.writeVarint(t[e])}function h(t,i){for(let e=0;e<t.length;e++)i.writeSVarint(t[e])}function n(t,i){for(let e=0;e<t.length;e++)i.writeFloat(t[e])}function a(t,i){for(let e=0;e<t.length;e++)i.writeDouble(t[e])}function d(t,i){for(let e=0;e<t.length;e++)i.writeBoolean(t[e])}function l(t,i){for(let e=0;e<t.length;e++)i.writeFixed32(t[e])}function u(t,i){for(let e=0;e<t.length;e++)i.writeSFixed32(t[e])}function f(t,i){for(let e=0;e<t.length;e++)i.writeFixed64(t[e])}function p(t,i){for(let e=0;e<t.length;e++)i.writeSFixed64(t[e])}return class{constructor(t=new Uint8Array(16)){this.buf=ArrayBuffer.isView(t)?t:new Uint8Array(t),this.dataView=new DataView(this.buf.buffer),this.pos=0,this.type=0,this.length=this.buf.length}readFields(t,i,e=this.length){for(;this.pos<e;){const e=this.readVarint(),s=e>>3,r=this.pos;this.type=7&e,t(s,i,this),this.pos===r&&this.skip(e)}return i}readMessage(t,i){return this.readFields(t,i,this.readVarint()+this.pos)}readFixed32(){const t=this.dataView.getUint32(this.pos,!0);return this.pos+=4,t}readSFixed32(){const t=this.dataView.getInt32(this.pos,!0);return this.pos+=4,t}readFixed64(){const i=this.dataView.getUint32(this.pos,!0)+this.dataView.getUint32(this.pos+4,!0)*t;return this.pos+=8,i}readSFixed64(){const i=this.dataView.getUint32(this.pos,!0)+this.dataView.getInt32(this.pos+4,!0)*t;return this.pos+=8,i}readFloat(){const t=this.dataView.getFloat32(this.pos,!0);return this.pos+=4,t}readDouble(){const t=this.dataView.getFloat64(this.pos,!0);return this.pos+=8,t}readVarint(t){const i=this.buf;let e,r;return r=i[this.pos++],e=127&r,r<128?e:(r=i[this.pos++],e|=(127&r)<<7,r<128?e:(r=i[this.pos++],e|=(127&r)<<14,r<128?e:(r=i[this.pos++],e|=(127&r)<<21,r<128?e:(r=i[this.pos],e|=(15&r)<<28,function(t,i,e){const r=e.buf;let o,h;if(h=r[e.pos++],o=(112&h)>>4,h<128)return s(t,o,i);if(h=r[e.pos++],o|=(127&h)<<3,h<128)return s(t,o,i);if(h=r[e.pos++],o|=(127&h)<<10,h<128)return s(t,o,i);if(h=r[e.pos++],o|=(127&h)<<17,h<128)return s(t,o,i);if(h=r[e.pos++],o|=(127&h)<<24,h<128)return s(t,o,i);if(h=r[e.pos++],o|=(1&h)<<31,h<128)return s(t,o,i);throw new Error("Expected varint not more than 10 bytes")}(e,t,this)))))}readVarint64(){return this.readVarint(!0)}readSVarint(){const t=this.readVarint();return t%2==1?(t+1)/-2:t/2}readBoolean(){return Boolean(this.readVarint())}readString(){const t=this.readVarint()+this.pos,i=this.pos;return this.pos=t,t-i>=12&&e?e.decode(this.buf.subarray(i,t)):function(t,i,e){let s="",r=i;for(;r<e;){const i=t[r];let o,h,n,a=null,d=i>239?4:i>223?3:i>191?2:1;if(r+d>e)break;1===d?i<128&&(a=i):2===d?(o=t[r+1],128==(192&o)&&(a=(31&i)<<6|63&o,a<=127&&(a=null))):3===d?(o=t[r+1],h=t[r+2],128==(192&o)&&128==(192&h)&&(a=(15&i)<<12|(63&o)<<6|63&h,(a<=2047||a>=55296&&a<=57343)&&(a=null))):4===d&&(o=t[r+1],h=t[r+2],n=t[r+3],128==(192&o)&&128==(192&h)&&128==(192&n)&&(a=(15&i)<<18|(63&o)<<12|(63&h)<<6|63&n,(a<=65535||a>=1114112)&&(a=null))),null===a?(a=65533,d=1):a>65535&&(a-=65536,s+=String.fromCharCode(a>>>10&1023|55296),a=56320|1023&a),s+=String.fromCharCode(a),r+=d}return s}(this.buf,i,t)}readBytes(){const t=this.readVarint()+this.pos,i=this.buf.subarray(this.pos,t);return this.pos=t,i}readPackedVarint(t=[],i){const e=this.readPackedEnd();for(;this.pos<e;)t.push(this.readVarint(i));return t}readPackedSVarint(t=[]){const i=this.readPackedEnd();for(;this.pos<i;)t.push(this.readSVarint());return t}readPackedBoolean(t=[]){const i=this.readPackedEnd();for(;this.pos<i;)t.push(this.readBoolean());return t}readPackedFloat(t=[]){const i=this.readPackedEnd();for(;this.pos<i;)t.push(this.readFloat());return t}readPackedDouble(t=[]){const i=this.readPackedEnd();for(;this.pos<i;)t.push(this.readDouble());return t}readPackedFixed32(t=[]){const i=this.readPackedEnd();for(;this.pos<i;)t.push(this.readFixed32());return t}readPackedSFixed32(t=[]){const i=this.readPackedEnd();for(;this.pos<i;)t.push(this.readSFixed32());return t}readPackedFixed64(t=[]){const i=this.readPackedEnd();for(;this.pos<i;)t.push(this.readFixed64());return t}readPackedSFixed64(t=[]){const i=this.readPackedEnd();for(;this.pos<i;)t.push(this.readSFixed64());return t}readPackedEnd(){return 2===this.type?this.readVarint()+this.pos:this.pos+1}skip(t){const i=7&t;if(0===i)for(;this.buf[this.pos++]>127;);else if(2===i)this.pos=this.readVarint()+this.pos;else if(5===i)this.pos+=4;else{if(1!==i)throw new Error(`Unimplemented type: ${i}`);this.pos+=8}}writeTag(t,i){this.writeVarint(t<<3|i)}realloc(t){let i=this.length||16;for(;i<this.pos+t;)i*=2;if(i!==this.length){const t=new Uint8Array(i);t.set(this.buf),this.buf=t,this.dataView=new DataView(t.buffer),this.length=i}}finish(){return this.length=this.pos,this.pos=0,this.buf.subarray(0,this.length)}writeFixed32(t){this.realloc(4),this.dataView.setInt32(this.pos,t,!0),this.pos+=4}writeSFixed32(t){this.realloc(4),this.dataView.setInt32(this.pos,t,!0),this.pos+=4}writeFixed64(t){this.realloc(8),this.dataView.setInt32(this.pos,-1&t,!0),this.dataView.setInt32(this.pos+4,Math.floor(t*i),!0),this.pos+=8}writeSFixed64(t){this.realloc(8),this.dataView.setInt32(this.pos,-1&t,!0),this.dataView.setInt32(this.pos+4,Math.floor(t*i),!0),this.pos+=8}writeVarint(t){(t=+t||0)>268435455||t<0?function(t,i){let e,s;t>=0?(e=t%4294967296|0,s=t/4294967296|0):(e=~(-t%4294967296),s=~(-t/4294967296),4294967295^e?e=e+1|0:(e=0,s=s+1|0));if(t>=0x10000000000000000||t<-0x10000000000000000)throw new Error("Given varint doesn't fit into 10 bytes");i.realloc(10),function(t,i,e){e.buf[e.pos++]=127&t|128,t>>>=7,e.buf[e.pos++]=127&t|128,t>>>=7,e.buf[e.pos++]=127&t|128,t>>>=7,e.buf[e.pos++]=127&t|128,t>>>=7,e.buf[e.pos]=127&t}(e,0,i),function(t,i){const e=(7&t)<<4;if(i.buf[i.pos++]|=e|((t>>>=3)?128:0),!t)return;if(i.buf[i.pos++]=127&t|((t>>>=7)?128:0),!t)return;if(i.buf[i.pos++]=127&t|((t>>>=7)?128:0),!t)return;if(i.buf[i.pos++]=127&t|((t>>>=7)?128:0),!t)return;if(i.buf[i.pos++]=127&t|((t>>>=7)?128:0),!t)return;i.buf[i.pos++]=127&t}(s,i)}(t,this):(this.realloc(4),this.buf[this.pos++]=127&t|(t>127?128:0),t<=127||(this.buf[this.pos++]=127&(t>>>=7)|(t>127?128:0),t<=127||(this.buf[this.pos++]=127&(t>>>=7)|(t>127?128:0),t<=127||(this.buf[this.pos++]=t>>>7&127))))}writeSVarint(t){this.writeVarint(t<0?2*-t-1:2*t)}writeBoolean(t){this.writeVarint(+t)}writeString(t){t=String(t),this.realloc(4*t.length),this.pos++;const i=this.pos;this.pos=function(t,i,e){for(let s,r,o=0;o<i.length;o++){if(s=i.charCodeAt(o),s>55295&&s<57344){if(!r){s>56319||o+1===i.length?(t[e++]=239,t[e++]=191,t[e++]=189):r=s;continue}if(s<56320){t[e++]=239,t[e++]=191,t[e++]=189,r=s;continue}s=r-55296<<10|s-56320|65536,r=null}else r&&(t[e++]=239,t[e++]=191,t[e++]=189,r=null);s<128?t[e++]=s:(s<2048?t[e++]=s>>6|192:(s<65536?t[e++]=s>>12|224:(t[e++]=s>>18|240,t[e++]=s>>12&63|128),t[e++]=s>>6&63|128),t[e++]=63&s|128)}return e}(this.buf,t,this.pos);const e=this.pos-i;e>=128&&r(i,e,this),this.pos=i-1,this.writeVarint(e),this.pos+=e}writeFloat(t){this.realloc(4),this.dataView.setFloat32(this.pos,t,!0),this.pos+=4}writeDouble(t){this.realloc(8),this.dataView.setFloat64(this.pos,t,!0),this.pos+=8}writeBytes(t){const i=t.length;this.writeVarint(i),this.realloc(i);for(let e=0;e<i;e++)this.buf[this.pos++]=t[e]}writeRawMessage(t,i){this.pos++;const e=this.pos;t(i,this);const s=this.pos-e;s>=128&&r(e,s,this),this.pos=e-1,this.writeVarint(s),this.pos+=s}writeMessage(t,i,e){this.writeTag(t,2),this.writeRawMessage(i,e)}writePackedVarint(t,i){i.length&&this.writeMessage(t,o,i)}writePackedSVarint(t,i){i.length&&this.writeMessage(t,h,i)}writePackedBoolean(t,i){i.length&&this.writeMessage(t,d,i)}writePackedFloat(t,i){i.length&&this.writeMessage(t,n,i)}writePackedDouble(t,i){i.length&&this.writeMessage(t,a,i)}writePackedFixed32(t,i){i.length&&this.writeMessage(t,l,i)}writePackedSFixed32(t,i){i.length&&this.writeMessage(t,u,i)}writePackedFixed64(t,i){i.length&&this.writeMessage(t,f,i)}writePackedSFixed64(t,i){i.length&&this.writeMessage(t,p,i)}writeBytesField(t,i){this.writeTag(t,2),this.writeBytes(i)}writeFixed32Field(t,i){this.writeTag(t,5),this.writeFixed32(i)}writeSFixed32Field(t,i){this.writeTag(t,5),this.writeSFixed32(i)}writeFixed64Field(t,i){this.writeTag(t,1),this.writeFixed64(i)}writeSFixed64Field(t,i){this.writeTag(t,1),this.writeSFixed64(i)}writeVarintField(t,i){this.writeTag(t,0),this.writeVarint(i)}writeSVarintField(t,i){this.writeTag(t,0),this.writeSVarint(i)}writeStringField(t,i){this.writeTag(t,2),this.writeString(i)}writeFloatField(t,i){this.writeTag(t,5),this.writeFloat(i)}writeDoubleField(t,i){this.writeTag(t,1),this.writeDouble(i)}writeBooleanField(t,i){this.writeVarintField(t,+i)}}}));
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/transit-departures-widget.ts","../src/lib/file-utils.ts","../src/lib/logging/log.ts","../src/lib/config/defaults.ts","../src/lib/utils.ts","../src/lib/logging/messages.ts"],"sourcesContent":["import path from 'path'\nimport { clone, omit } from 'lodash-es'\nimport { writeFile } from 'node:fs/promises'\nimport { importGtfs, openDb, type ConfigAgency } from 'gtfs'\nimport sanitize from 'sanitize-filename'\nimport Timer from 'timer-machine'\nimport untildify from 'untildify'\n\nimport { copyStaticAssets, prepDirectory } from './file-utils.ts'\nimport { createLogger } from './logging/log.ts'\nimport { setDefaultConfig } from './config/defaults.ts'\nimport {\n generateTransitDeparturesWidgetHtml,\n generateTransitDeparturesWidgetJson,\n} from './utils.ts'\nimport { Config } from '../types/global_interfaces.ts'\n\n/*\n * Generate transit departures widget HTML from GTFS.\n */\nasync function transitDeparturesWidget(initialConfig: Config) {\n const config = setDefaultConfig(initialConfig)\n const logger = createLogger(config)\n\n try {\n openDb(config)\n } catch (error: any) {\n if (error?.code === 'SQLITE_CANTOPEN') {\n logger.error(\n `Unable to open sqlite database \"${config.sqlitePath}\" defined as \\`sqlitePath\\` config.json. Ensure the parent directory exists or remove \\`sqlitePath\\` from config.json.`,\n )\n }\n\n throw error\n }\n\n if (!config.agency) {\n throw new Error('No agency defined in `config.json`')\n }\n\n const timer = new Timer()\n const agencyKey = config.agency.agency_key ?? 'unknown'\n\n const outputPath = config.outputPath\n ? untildify(config.outputPath)\n : path.join(process.cwd(), 'html', sanitize(agencyKey))\n\n timer.start()\n\n if (!config.skipImport) {\n // Import GTFS\n const gtfsPath = config.agency.gtfs_static_path\n const gtfsUrl = config.agency.gtfs_static_url\n\n if (!gtfsPath && !gtfsUrl) {\n throw new Error(\n 'Missing GTFS source. Set `agency.gtfs_static_path` or `agency.gtfs_static_url` in config.json.',\n )\n }\n\n const agencyImportConfig: ConfigAgency = gtfsPath\n ? { path: gtfsPath }\n : { url: gtfsUrl as string }\n\n const gtfsImportConfig = {\n ...clone(omit(config, 'agency')),\n agencies: [agencyImportConfig],\n }\n\n await importGtfs(gtfsImportConfig)\n }\n\n await prepDirectory(outputPath, config)\n\n if (config.noHead !== true) {\n await copyStaticAssets(config, outputPath)\n }\n\n logger.info(`${agencyKey}: Generating Transit Departures Widget HTML`)\n\n config.assetPath = ''\n\n // Generate JSON of routes and stops\n const { routes, stops } = generateTransitDeparturesWidgetJson(config)\n await writeFile(\n path.join(outputPath, 'data', 'routes.json'),\n JSON.stringify(routes),\n )\n await writeFile(\n path.join(outputPath, 'data', 'stops.json'),\n JSON.stringify(stops),\n )\n\n const html = await generateTransitDeparturesWidgetHtml(config)\n await writeFile(path.join(outputPath, 'index.html'), html)\n\n timer.stop()\n\n // Print stats\n logger.info(\n `${agencyKey}: Transit Departures Widget HTML created at ${outputPath}`,\n )\n\n const seconds = Math.round(timer.time() / 1000)\n logger.info(`${agencyKey}: HTML generation required ${seconds} seconds`)\n}\n\nexport default transitDeparturesWidget\n","import { dirname, join, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport {\n access,\n cp,\n copyFile,\n mkdir,\n readdir,\n readFile,\n rm,\n} from 'node:fs/promises'\nimport beautify from 'js-beautify'\nimport pug from 'pug'\nimport untildify from 'untildify'\n\nimport { Config } from '../types/global_interfaces.ts'\n\n/*\n * Attempt to parse the specified config JSON file.\n */\nexport async function getConfig(argv) {\n try {\n const data = await readFile(\n resolve(untildify(argv.configPath)),\n 'utf8',\n ).catch((error) => {\n console.error(\n new Error(\n `Cannot find configuration file at \\`${argv.configPath}\\`. Use config-sample.json as a starting point, pass --configPath option`,\n ),\n )\n throw error\n })\n const config = JSON.parse(data)\n\n if (argv.skipImport === true) {\n config.skipImport = argv.skipImport\n }\n\n return config\n } catch (error) {\n console.error(\n new Error(\n `Cannot parse configuration file at \\`${argv.configPath}\\`. Check to ensure that it is valid JSON.`,\n ),\n )\n throw error\n }\n}\n\n/*\n * Get the full path to this module's folder.\n */\nexport function getPathToThisModuleFolder() {\n const __dirname = dirname(fileURLToPath(import.meta.url))\n\n // Dynamically calculate the path to this module's folder\n let distFolderPath\n if (__dirname.endsWith('/dist/bin') || __dirname.endsWith('/dist/app')) {\n // When the file is in 'dist/bin' or 'dist/app'\n distFolderPath = resolve(__dirname, '../../')\n } else if (__dirname.endsWith('/dist')) {\n // When the file is in 'dist'\n distFolderPath = resolve(__dirname, '../')\n } else {\n // In case it's neither, fallback to project root\n distFolderPath = resolve(__dirname, '../../')\n }\n\n return distFolderPath\n}\n\n/*\n * Get the full path to the views folder.\n */\nexport function getPathToViewsFolder(config: Config) {\n if (config.templatePath) {\n return untildify(config.templatePath)\n }\n\n return join(getPathToThisModuleFolder(), 'views/widget')\n}\n\n/*\n * Get the full path of a template file.\n */\nfunction getPathToTemplateFile(templateFileName: string, config: Config) {\n const fullTemplateFileName =\n config.noHead !== true\n ? `${templateFileName}_full.pug`\n : `${templateFileName}.pug`\n\n return join(getPathToViewsFolder(config), fullTemplateFileName)\n}\n\n/*\n * Prepare the outputPath directory for writing timetable files.\n */\nexport async function prepDirectory(outputPath: string, config: Config) {\n // Check if outputPath exists\n try {\n await access(outputPath)\n } catch (error: any) {\n try {\n await mkdir(outputPath, { recursive: true })\n await mkdir(join(outputPath, 'data'))\n } catch (error: any) {\n if (error?.code === 'ENOENT') {\n throw new Error(\n `Unable to write to ${outputPath}. Try running this command from a writable directory.`,\n )\n }\n\n throw error\n }\n }\n\n // Check if outputPath is empty\n const files = await readdir(outputPath)\n if (config.overwriteExistingFiles === false && files.length > 0) {\n throw new Error(\n `Output directory ${outputPath} is not empty. Please specify an empty directory.`,\n )\n }\n\n // Delete all files in outputPath if `overwriteExistingFiles` is true\n if (config.overwriteExistingFiles === true) {\n await rm(join(outputPath, '*'), { recursive: true, force: true })\n }\n}\n\n/*\n * Copy needed CSS and JS to export path.\n */\nexport async function copyStaticAssets(config: Config, outputPath: string) {\n const viewsFolderPath = getPathToViewsFolder(config)\n const thisModuleFolderPath = getPathToThisModuleFolder()\n\n const foldersToCopy = ['css', 'js']\n\n for (const folder of foldersToCopy) {\n if (\n await access(join(viewsFolderPath, folder))\n .then(() => true)\n .catch(() => false)\n ) {\n await cp(join(viewsFolderPath, folder), join(outputPath, folder), {\n recursive: true,\n })\n }\n }\n\n // Copy js and css libraries from node_modules\n await copyFile(\n join(thisModuleFolderPath, 'dist/frontend_libraries/pbf.js'),\n join(outputPath, 'js/pbf.js'),\n )\n\n await copyFile(\n join(\n thisModuleFolderPath,\n 'dist/frontend_libraries/gtfs-realtime.browser.proto.js',\n ),\n join(outputPath, 'js/gtfs-realtime.browser.proto.js'),\n )\n\n await copyFile(\n join(\n thisModuleFolderPath,\n 'dist/frontend_libraries/accessible-autocomplete.min.js',\n ),\n join(outputPath, 'js/accessible-autocomplete.min.js'),\n )\n\n await copyFile(\n join(\n thisModuleFolderPath,\n 'dist/frontend_libraries/accessible-autocomplete.min.css',\n ),\n join(outputPath, 'css/accessible-autocomplete.min.css'),\n )\n}\n\n/*\n * Render the HTML based on the config.\n */\nexport async function renderFile(\n templateFileName: string,\n templateVars: any,\n config: Config,\n) {\n const templatePath = getPathToTemplateFile(templateFileName, config)\n const html = await pug.renderFile(templatePath, templateVars)\n\n // Beautify HTML if setting is set\n if (config.beautify === true) {\n return beautify.html_beautify(html, { indent_size: 2 })\n }\n\n return html\n}\n","import { clearLine, cursorTo } from 'node:readline'\nimport { noop } from 'lodash-es'\nimport * as colors from 'yoctocolors'\n\nimport { Config } from '../../types/global_interfaces.ts'\n\nexport type Logger = {\n info: (text: string, overwrite?: boolean) => void\n warn: (text: string) => void\n error: (text: string) => void\n}\n\nconst formatWarning = (text: string) => {\n const warningMessage = `${colors.underline('Warning')}: ${text}`\n return colors.yellow(warningMessage)\n}\n\nexport const formatError = (error: any) => {\n const messageText = error instanceof Error ? error.message : error\n const errorMessage = `${colors.underline('Error')}: ${messageText.replace(\n 'Error: ',\n '',\n )}`\n return colors.red(errorMessage)\n}\n\nconst logInfo = (config: Config) => {\n if (config.verbose === false) {\n return noop\n }\n\n if (config.logFunction) {\n return config.logFunction\n }\n\n return (text: string, overwrite?: boolean) => {\n if (overwrite === true && process.stdout.isTTY) {\n clearLine(process.stdout, 0)\n cursorTo(process.stdout, 0)\n } else {\n process.stdout.write('\\n')\n }\n\n process.stdout.write(text)\n }\n}\n\nconst logWarn = (config: Config) => {\n if (config.logFunction) {\n return config.logFunction\n }\n\n return (text: string) => {\n process.stdout.write(`\\n${formatWarning(text)}\\n`)\n }\n}\n\nconst logError = (config: Config) => {\n if (config.logFunction) {\n return config.logFunction\n }\n\n return (text: string) => {\n process.stdout.write(`\\n${formatError(text)}\\n`)\n }\n}\n\n/*\n * Create a structured logger with consistent methods.\n */\nexport function createLogger(config: Config): Logger {\n return {\n info: logInfo(config),\n warn: logWarn(config),\n error: logError(config),\n }\n}\n","import { join } from 'path'\nimport { I18n } from 'i18n'\n\nimport { Config } from '../../types/global_interfaces.ts'\nimport { getPathToViewsFolder } from '../file-utils.ts'\n\n/*\n * Initialize configuration with defaults.\n */\nexport function setDefaultConfig(initialConfig: Config) {\n const defaults = {\n beautify: false,\n noHead: false,\n refreshIntervalSeconds: 20,\n skipImport: false,\n timeFormat: '12hour',\n includeCoordinates: false,\n overwriteExistingFiles: true,\n verbose: true,\n }\n\n const config = Object.assign(defaults, initialConfig)\n const viewsFolderPath = getPathToViewsFolder(config)\n const i18n = new I18n({\n directory: join(viewsFolderPath, 'locales'),\n defaultLocale: config.locale,\n updateFiles: false,\n })\n const configWithI18n = Object.assign(config, {\n __: i18n.__,\n })\n return configWithI18n\n}\n","import { openDb, getDirections, getRoutes, getStops, getTrips } from 'gtfs'\nimport { groupBy, last, maxBy, size, sortBy, uniqBy } from 'lodash-es'\nimport { renderFile } from './file-utils.ts'\nimport sqlString from 'sqlstring-sqlite'\nimport toposort from 'toposort'\n\nimport { Config, SqlWhere, SqlValue } from '../types/global_interfaces.ts'\nimport {\n ConfigWithI18n,\n GTFSCalendar,\n GTFSRoute,\n GTFSRouteDirection,\n GTFSStop,\n} from '../types/gtfs.ts'\nimport { createLogger } from './logging/log.ts'\nimport { messages } from './logging/messages.ts'\nexport { setDefaultConfig } from './config/defaults.ts'\n\n/*\n * Get calendars for a specified date range\n */\nconst getCalendarsForDateRange = (config: Config): GTFSCalendar[] => {\n const db = openDb(config)\n let whereClause = ''\n const whereClauses = []\n\n if (config.endDate) {\n whereClauses.push(`start_date <= ${sqlString.escape(config.endDate)}`)\n }\n\n if (config.startDate) {\n whereClauses.push(`end_date >= ${sqlString.escape(config.startDate)}`)\n }\n\n if (whereClauses.length > 0) {\n whereClause = `WHERE ${whereClauses.join(' AND ')}`\n }\n\n return db.prepare(`SELECT * FROM calendar ${whereClause}`).all()\n}\n\n/*\n * Format a route name.\n */\nfunction formatRouteName(route: GTFSRoute) {\n let routeName = ''\n\n if (route.route_short_name !== null) {\n routeName += route.route_short_name\n }\n\n if (route.route_short_name !== null && route.route_long_name !== null) {\n routeName += ' - '\n }\n\n if (route.route_long_name !== null) {\n routeName += route.route_long_name\n }\n\n return routeName\n}\n\n/*\n * Get directions for a route\n */\nfunction getDirectionsForRoute(route: GTFSRoute, config: ConfigWithI18n) {\n const logger = createLogger(config)\n const db = openDb(config)\n\n // Lookup direction names from non-standard directions.txt file\n const directions = getDirections({ route_id: route.route_id }, [\n 'direction_id',\n 'direction',\n ])\n .filter((direction) => direction.direction_id !== undefined)\n .map((direction) => ({\n direction_id: direction.direction_id as number | string,\n direction: direction.direction,\n }))\n\n const calendars = getCalendarsForDateRange(config)\n if (calendars.length === 0) {\n logger.warn(messages.noActiveCalendarsForRoute(route.route_id))\n return []\n }\n\n // Else use the most common headsigns as directions from trips.txt file\n if (directions.length === 0) {\n const headsigns = db\n .prepare(\n `SELECT direction_id, trip_headsign, count(*) AS count FROM trips WHERE route_id = ? AND service_id IN (${calendars\n .map((calendar: GTFSCalendar) => `'${calendar.service_id}'`)\n .join(', ')}) GROUP BY direction_id, trip_headsign`,\n )\n .all(route.route_id)\n\n for (const group of Object.values(groupBy(headsigns, 'direction_id'))) {\n const mostCommonHeadsign = maxBy(group, 'count')\n directions.push({\n direction_id: mostCommonHeadsign.direction_id,\n direction: config.__('To {{{headsign}}}', {\n headsign: mostCommonHeadsign.trip_headsign,\n }),\n })\n }\n }\n\n return directions\n}\n\n/*\n * Sort an array of stoptimes by stop_sequence using a directed graph\n */\nfunction sortStopIdsBySequence(stoptimes: Record<string, string>[]) {\n const stoptimesGroupedByTrip = groupBy(stoptimes, 'trip_id')\n\n // First, try using a directed graph to determine stop order.\n try {\n const stopGraph = []\n\n for (const tripStoptimes of Object.values(stoptimesGroupedByTrip)) {\n const sortedStopIds = sortBy(tripStoptimes, 'stop_sequence').map(\n (stoptime) => stoptime.stop_id,\n )\n\n for (const [index, stopId] of sortedStopIds.entries()) {\n if (index === sortedStopIds.length - 1) {\n continue\n }\n\n stopGraph.push([stopId, sortedStopIds[index + 1]])\n }\n }\n\n return toposort(\n stopGraph as unknown as readonly [string, string | undefined][],\n )\n } catch {\n // Ignore errors and move to next strategy.\n }\n\n // Finally, fall back to using the stop order from the trip with the most stoptimes.\n const longestTripStoptimes = maxBy(\n Object.values(stoptimesGroupedByTrip),\n (stoptimes) => size(stoptimes),\n )\n\n if (!longestTripStoptimes) {\n return []\n }\n\n return longestTripStoptimes.map((stoptime) => stoptime.stop_id)\n}\n\nfunction getStopsForDirection(\n route: GTFSRoute,\n direction: GTFSRouteDirection,\n config: Config,\n stopCache?: Map<string, GTFSStop>,\n) {\n const logger = createLogger(config)\n const db = openDb(config)\n const calendars = getCalendarsForDateRange(config)\n if (calendars.length === 0) {\n logger.warn(\n messages.noActiveCalendarsForDirection(\n route.route_id,\n direction.direction_id,\n ),\n )\n return []\n }\n const whereClause = formatWhereClauses({\n direction_id: direction.direction_id,\n route_id: route.route_id,\n service_id: calendars.map((calendar: GTFSCalendar) => calendar.service_id),\n })\n const stoptimes = db\n .prepare(\n `SELECT stop_id, stop_sequence, trip_id FROM stop_times WHERE trip_id IN (SELECT trip_id FROM trips ${whereClause}) ORDER BY stop_sequence ASC`,\n )\n .all()\n\n const sortedStopIds = sortStopIdsBySequence(stoptimes)\n\n const deduplicatedStopIds = sortedStopIds.reduce(\n (memo: string[], stopId: string) => {\n // Remove duplicated stop_ids in a row\n if (last(memo) !== stopId) {\n memo.push(stopId)\n }\n\n return memo\n },\n [],\n )\n\n // Remove last stop of route since boarding is not allowed\n deduplicatedStopIds.pop()\n\n // Fetch stop details\n const stopFields: (keyof GTFSStop)[] = [\n 'stop_id',\n 'stop_name',\n 'stop_code',\n 'parent_station',\n ]\n\n if (config.includeCoordinates) {\n stopFields.push('stop_lat', 'stop_lon')\n }\n\n const missingStopIds = stopCache\n ? deduplicatedStopIds.filter((stopId) => !stopCache.has(stopId))\n : deduplicatedStopIds\n\n const fetchedStops = missingStopIds.length\n ? (getStops as unknown as (query: any, fields?: any) => GTFSStop[])(\n { stop_id: missingStopIds },\n stopFields,\n )\n : []\n\n if (stopCache) {\n for (const stop of fetchedStops) {\n stopCache.set(stop.stop_id, stop)\n }\n }\n\n return deduplicatedStopIds\n .map((stopId: string) => {\n const stop =\n stopCache?.get(stopId) ??\n fetchedStops.find((candidate) => candidate.stop_id === stopId)\n\n if (!stop) {\n logger.warn(\n messages.stopNotFound(route.route_id, direction.direction_id, stopId),\n )\n }\n\n return stop\n })\n .filter(Boolean) as GTFSStop[]\n}\n\n/*\n * Generate HTML for transit departures widget.\n */\nexport function generateTransitDeparturesWidgetHtml(config: ConfigWithI18n) {\n const templateVars = {\n config,\n __: config.__,\n }\n return renderFile('widget', templateVars, config)\n}\n\n/*\n * Generate JSON of routes and stops for transit departures widget.\n */\nexport function generateTransitDeparturesWidgetJson(config: ConfigWithI18n) {\n const logger = createLogger(config)\n const calendars = getCalendarsForDateRange(config)\n if (calendars.length === 0) {\n logger.warn(messages.noActiveCalendarsGlobal)\n return { routes: [], stops: [] }\n }\n\n const routes = getRoutes() as GTFSRoute[]\n const stops: GTFSStop[] = []\n const filteredRoutes: GTFSRoute[] = []\n const stopCache = new Map<string, GTFSStop>()\n\n for (const route of routes) {\n const routeWithFullName: GTFSRoute = {\n ...route,\n route_full_name: formatRouteName(route),\n }\n\n const directions = getDirectionsForRoute(routeWithFullName, config)\n\n // Filter out routes with no directions\n if (directions.length === 0) {\n logger.warn(messages.routeHasNoDirections(route.route_id))\n continue\n }\n\n const directionsWithData = directions\n .map((direction) => {\n const directionStops = getStopsForDirection(\n routeWithFullName,\n direction,\n config,\n stopCache,\n )\n\n if (directionStops.length === 0) {\n return null\n }\n\n stops.push(...directionStops)\n\n const trips = getTrips(\n {\n route_id: route.route_id,\n direction_id: direction.direction_id,\n service_id: calendars.map(\n (calendar: GTFSCalendar) => calendar.service_id,\n ),\n },\n ['trip_id'],\n )\n\n return {\n ...direction,\n stopIds: directionStops.map((stop) => stop.stop_id),\n tripIds: trips.map((trip) => trip.trip_id),\n }\n })\n .filter(Boolean) as GTFSRouteDirection[]\n\n if (directionsWithData.length === 0) {\n continue\n }\n\n filteredRoutes.push({\n ...routeWithFullName,\n directions: directionsWithData,\n })\n }\n\n // Sort routes deterministically, handling mixed numeric/alphanumeric IDs\n const sortedRoutes = [...filteredRoutes].sort((a, b) => {\n const aShort = a.route_short_name ?? ''\n const bShort = b.route_short_name ?? ''\n const aNum = Number.parseInt(aShort, 10)\n const bNum = Number.parseInt(bShort, 10)\n\n if (!Number.isNaN(aNum) && !Number.isNaN(bNum) && aNum !== bNum) {\n return aNum - bNum\n }\n\n if (Number.isNaN(aNum) && !Number.isNaN(bNum)) {\n return 1\n }\n\n if (!Number.isNaN(aNum) && Number.isNaN(bNum)) {\n return -1\n }\n\n return aShort.localeCompare(bShort, undefined, {\n numeric: true,\n sensitivity: 'base',\n })\n })\n\n // Get Parent Station Stops\n const parentStationIds = new Set(stops.map((stop) => stop.parent_station))\n\n const parentStationStops = getStops(\n { stop_id: Array.from(parentStationIds) },\n ['stop_id', 'stop_name', 'stop_code', 'parent_station'],\n )\n\n stops.push(\n ...parentStationStops.map((stop) => ({\n ...stop,\n is_parent_station: true,\n })),\n )\n\n // Sort unique list of stops\n const sortedStops = sortBy(uniqBy(stops, 'stop_id'), 'stop_name')\n\n return {\n routes: arrayOfArrays(removeNulls(sortedRoutes)),\n stops: arrayOfArrays(removeNulls(sortedStops)),\n }\n}\n\n/*\n * Remove null values from array or object\n */\nfunction removeNulls(data: any): any {\n if (Array.isArray(data)) {\n return data\n .map(removeNulls)\n .filter((item) => item !== null && item !== undefined)\n } else if (\n data !== null &&\n typeof data === 'object' &&\n Object.getPrototypeOf(data) === Object.prototype\n ) {\n return Object.entries(data).reduce<Record<string, unknown>>(\n (acc, [key, value]) => {\n const cleanedValue = removeNulls(value)\n if (cleanedValue !== null && cleanedValue !== undefined) {\n acc[key] = cleanedValue\n }\n return acc\n },\n {},\n )\n } else {\n return data\n }\n}\n\n/*\n * Convert an array of objects into an Array-of-arrays JSON: { \"fields\": [...], \"rows\": [[...], ...] }\n */\nfunction arrayOfArrays(array: any[]): { fields: string[]; rows: any[][] } {\n if (array.length === 0) {\n return { fields: [], rows: [] }\n }\n\n const fields: string[] = Array.from(\n array.reduce<Set<string>>((fieldSet, item) => {\n Object.keys(item ?? {}).forEach((key) => fieldSet.add(key))\n return fieldSet\n }, new Set<string>()),\n )\n\n return {\n fields,\n rows: array.map((item) => fields.map((field) => item?.[field] ?? null)),\n }\n}\n\nexport function formatWhereClause(\n key: string,\n value: null | SqlValue | SqlValue[],\n) {\n if (Array.isArray(value)) {\n let whereClause = `${sqlString.escapeId(key)} IN (${value\n .filter((v) => v !== null)\n .map((v) => sqlString.escape(v))\n .join(', ')})`\n\n if (value.includes(null)) {\n whereClause = `(${whereClause} OR ${sqlString.escapeId(key)} IS NULL)`\n }\n\n return whereClause\n }\n\n if (value === null) {\n return `${sqlString.escapeId(key)} IS NULL`\n }\n\n return `${sqlString.escapeId(key)} = ${sqlString.escape(value)}`\n}\n\nexport function formatWhereClauses(query: SqlWhere) {\n if (Object.keys(query).length === 0) {\n return ''\n }\n\n const whereClauses = Object.entries(query).map(([key, value]) =>\n formatWhereClause(key, value),\n )\n return `WHERE ${whereClauses.join(' AND ')}`\n}\n","export const messages = {\n noActiveCalendarsGlobal:\n 'No active calendars found for the configured date range - returning empty routes and stops',\n noActiveCalendarsForRoute: (routeId: string) =>\n `route_id ${routeId} has no active calendars in range - skipping directions`,\n noActiveCalendarsForDirection: (\n routeId: string,\n directionId: string | number,\n ) =>\n `route_id ${routeId} direction ${directionId} has no active calendars in range - skipping stops`,\n routeHasNoDirections: (routeId: string) =>\n `route_id ${routeId} has no directions - skipping`,\n stopNotFound: (\n routeId: string,\n directionId: string | number,\n stopId: string,\n ) =>\n `stop_id ${stopId} for route ${routeId} direction ${directionId} not found - dropping`,\n}\n"],"mappings":";AAAA,OAAO,UAAU;AACjB,SAAS,OAAO,YAAY;AAC5B,SAAS,iBAAiB;AAC1B,SAAS,YAAY,UAAAA,eAAiC;AACtD,OAAO,cAAc;AACrB,OAAO,WAAW;AAClB,OAAOC,gBAAe;;;ACNtB,SAAS,SAAS,MAAM,eAAe;AACvC,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,OAAO,cAAc;AACrB,OAAO,SAAS;AAChB,OAAO,eAAe;AAwCf,SAAS,4BAA4B;AAC1C,QAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;AAGxD,MAAI;AACJ,MAAI,UAAU,SAAS,WAAW,KAAK,UAAU,SAAS,WAAW,GAAG;AAEtE,qBAAiB,QAAQ,WAAW,QAAQ;AAAA,EAC9C,WAAW,UAAU,SAAS,OAAO,GAAG;AAEtC,qBAAiB,QAAQ,WAAW,KAAK;AAAA,EAC3C,OAAO;AAEL,qBAAiB,QAAQ,WAAW,QAAQ;AAAA,EAC9C;AAEA,SAAO;AACT;AAKO,SAAS,qBAAqB,QAAgB;AACnD,MAAI,OAAO,cAAc;AACvB,WAAO,UAAU,OAAO,YAAY;AAAA,EACtC;AAEA,SAAO,KAAK,0BAA0B,GAAG,cAAc;AACzD;AAKA,SAAS,sBAAsB,kBAA0B,QAAgB;AACvE,QAAM,uBACJ,OAAO,WAAW,OACd,GAAG,gBAAgB,cACnB,GAAG,g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OAAO,MAAM,oCAAoC,MAAM;AAC7D,QAAM,UAAU,KAAK,KAAK,YAAY,YAAY,GAAG,IAAI;AAEzD,QAAM,KAAK;AAGX,SAAO;AAAA,IACL,GAAG,SAAS,+CAA+C,UAAU;AAAA,EACvE;AAEA,QAAM,UAAU,KAAK,MAAM,MAAM,KAAK,IAAI,GAAI;AAC9C,SAAO,KAAK,GAAG,SAAS,8BAA8B,OAAO,UAAU;AACzE;AAEA,IAAO,oCAAQ;","names":["openDb","untildify","error","join","join","stoptimes","openDb","untildify"]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|