gtfs-to-html 2.9.2 → 2.9.3
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 +26 -18
- package/dist/app/index.js.map +1 -1
- package/dist/bin/gtfs-to-html.js +40 -33
- package/dist/bin/gtfs-to-html.js.map +1 -1
- package/dist/index.js +39 -32
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/views/default/timetablepage.pug +4 -3
- package/views/default/timetablepage_full.pug +2 -2
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var __export = (target, all) => {
|
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
// src/lib/gtfs-to-html.ts
|
|
8
|
-
import
|
|
8
|
+
import path from "node:path";
|
|
9
9
|
import { mkdir as mkdir2, writeFile } from "node:fs/promises";
|
|
10
10
|
import { map } from "lodash-es";
|
|
11
11
|
import { openDb as openDb2, importGtfs } from "gtfs";
|
|
@@ -13,7 +13,7 @@ import sanitize2 from "sanitize-filename";
|
|
|
13
13
|
import Timer from "timer-machine";
|
|
14
14
|
|
|
15
15
|
// src/lib/file-utils.ts
|
|
16
|
-
import
|
|
16
|
+
import { dirname, join, resolve } from "node:path";
|
|
17
17
|
import { createWriteStream } from "node:fs";
|
|
18
18
|
import { fileURLToPath } from "node:url";
|
|
19
19
|
import { access, cp, copyFile, mkdir, readFile, rm } from "node:fs/promises";
|
|
@@ -325,7 +325,7 @@ function formatTripNameForCSV(trip, timetable) {
|
|
|
325
325
|
}
|
|
326
326
|
|
|
327
327
|
// package.json
|
|
328
|
-
var version = "2.9.
|
|
328
|
+
var version = "2.9.2";
|
|
329
329
|
|
|
330
330
|
// src/lib/utils.ts
|
|
331
331
|
var isTimepoint = (stoptime) => {
|
|
@@ -1787,13 +1787,24 @@ function mergeTimetablesWithSameId(timetables) {
|
|
|
1787
1787
|
}
|
|
1788
1788
|
|
|
1789
1789
|
// src/lib/file-utils.ts
|
|
1790
|
-
function
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1790
|
+
function getPathToViewsFolder(config) {
|
|
1791
|
+
if (config.templatePath) {
|
|
1792
|
+
return untildify(config.templatePath);
|
|
1793
|
+
}
|
|
1794
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
1795
|
+
let viewsFolderPath;
|
|
1796
|
+
if (__dirname.endsWith("/dist/bin") || __dirname.endsWith("/dist/app")) {
|
|
1797
|
+
viewsFolderPath = resolve(__dirname, "../../views/default");
|
|
1798
|
+
} else if (__dirname.endsWith("/dist")) {
|
|
1799
|
+
viewsFolderPath = resolve(__dirname, "../views/default");
|
|
1800
|
+
} else {
|
|
1801
|
+
viewsFolderPath = resolve(__dirname, "views/default");
|
|
1794
1802
|
}
|
|
1795
|
-
|
|
1796
|
-
|
|
1803
|
+
return viewsFolderPath;
|
|
1804
|
+
}
|
|
1805
|
+
function getPathToTemplateFile(templateFileName, config) {
|
|
1806
|
+
const fullTemplateFileName = config.noHead !== true ? `${templateFileName}_full.pug` : `${templateFileName}.pug`;
|
|
1807
|
+
return join(getPathToViewsFolder(config), fullTemplateFileName);
|
|
1797
1808
|
}
|
|
1798
1809
|
async function prepDirectory(exportPath) {
|
|
1799
1810
|
await rm(exportPath, { recursive: true, force: true });
|
|
@@ -1809,35 +1820,31 @@ async function prepDirectory(exportPath) {
|
|
|
1809
1820
|
}
|
|
1810
1821
|
}
|
|
1811
1822
|
async function copyStaticAssets(config, exportPath) {
|
|
1812
|
-
const
|
|
1823
|
+
const viewsFolderPath = getPathToViewsFolder(config);
|
|
1813
1824
|
const foldersToCopy = ["css", "js", "img"];
|
|
1814
1825
|
for (const folder of foldersToCopy) {
|
|
1815
|
-
if (await access(
|
|
1816
|
-
await cp(
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
{
|
|
1820
|
-
recursive: true
|
|
1821
|
-
}
|
|
1822
|
-
);
|
|
1826
|
+
if (await access(join(viewsFolderPath, folder)).then(() => true).catch(() => false)) {
|
|
1827
|
+
await cp(join(viewsFolderPath, folder), join(exportPath, folder), {
|
|
1828
|
+
recursive: true
|
|
1829
|
+
});
|
|
1823
1830
|
}
|
|
1824
1831
|
}
|
|
1825
1832
|
if (config.hasGtfsRealtime) {
|
|
1826
1833
|
await copyFile(
|
|
1827
1834
|
"node_modules/pbf/dist/pbf.js",
|
|
1828
|
-
|
|
1835
|
+
join(exportPath, "js/pbf.js")
|
|
1829
1836
|
);
|
|
1830
1837
|
await copyFile(
|
|
1831
1838
|
"node_modules/gtfs-realtime-pbf-js-module/gtfs-realtime.browser.proto.js",
|
|
1832
|
-
|
|
1839
|
+
join(exportPath, "js/gtfs-realtime.browser.proto.js")
|
|
1833
1840
|
);
|
|
1834
1841
|
}
|
|
1835
1842
|
}
|
|
1836
1843
|
function zipFolder(exportPath) {
|
|
1837
|
-
const output = createWriteStream(
|
|
1844
|
+
const output = createWriteStream(join(exportPath, "timetables.zip"));
|
|
1838
1845
|
const archive = archiver("zip");
|
|
1839
|
-
return new Promise((
|
|
1840
|
-
output.on("close",
|
|
1846
|
+
return new Promise((resolve2, reject) => {
|
|
1847
|
+
output.on("close", resolve2);
|
|
1841
1848
|
archive.on("error", reject);
|
|
1842
1849
|
archive.pipe(output);
|
|
1843
1850
|
archive.glob("**/*.{txt,css,js,html}", {
|
|
@@ -1865,7 +1872,7 @@ function generateFolderName(timetablePage) {
|
|
|
1865
1872
|
return sanitize(`${timetable.start_date}-${timetable.end_date}`);
|
|
1866
1873
|
}
|
|
1867
1874
|
async function renderTemplate(templateFileName, templateVars, config) {
|
|
1868
|
-
const templatePath =
|
|
1875
|
+
const templatePath = getPathToTemplateFile(templateFileName, config);
|
|
1869
1876
|
const html = await renderFile(templatePath, {
|
|
1870
1877
|
_,
|
|
1871
1878
|
md: (text) => insane(marked.parseInline(text)),
|
|
@@ -2075,7 +2082,7 @@ var gtfsToHtml = async (initialConfig) => {
|
|
|
2075
2082
|
const agencyKey = config.agencies.map(
|
|
2076
2083
|
(agency) => agency.agencyKey ?? agency.agency_key ?? "unknown"
|
|
2077
2084
|
).join("-");
|
|
2078
|
-
const exportPath =
|
|
2085
|
+
const exportPath = path.join(process.cwd(), "html", sanitize2(agencyKey));
|
|
2079
2086
|
const outputStats = {
|
|
2080
2087
|
timetables: 0,
|
|
2081
2088
|
timetablePages: 0,
|
|
@@ -2119,16 +2126,16 @@ var gtfsToHtml = async (initialConfig) => {
|
|
|
2119
2126
|
outputStats.timetables += timetablePage.consolidatedTimetables.length;
|
|
2120
2127
|
outputStats.timetablePages += 1;
|
|
2121
2128
|
const datePath = generateFolderName(timetablePage);
|
|
2122
|
-
await mkdir2(
|
|
2129
|
+
await mkdir2(path.join(exportPath, datePath), { recursive: true });
|
|
2123
2130
|
config.assetPath = "../";
|
|
2124
|
-
timetablePage.relativePath =
|
|
2131
|
+
timetablePage.relativePath = path.join(
|
|
2125
2132
|
datePath,
|
|
2126
2133
|
sanitize2(timetablePage.filename)
|
|
2127
2134
|
);
|
|
2128
2135
|
if (config.outputFormat === "csv") {
|
|
2129
2136
|
for (const timetable of timetablePage.consolidatedTimetables) {
|
|
2130
2137
|
const csv = await generateTimetableCSV(timetable);
|
|
2131
|
-
const csvPath =
|
|
2138
|
+
const csvPath = path.join(
|
|
2132
2139
|
exportPath,
|
|
2133
2140
|
datePath,
|
|
2134
2141
|
generateFileName(timetable, config, "csv")
|
|
@@ -2137,7 +2144,7 @@ var gtfsToHtml = async (initialConfig) => {
|
|
|
2137
2144
|
}
|
|
2138
2145
|
} else {
|
|
2139
2146
|
const html = await generateTimetableHTML(timetablePage, config);
|
|
2140
|
-
const htmlPath =
|
|
2147
|
+
const htmlPath = path.join(
|
|
2141
2148
|
exportPath,
|
|
2142
2149
|
datePath,
|
|
2143
2150
|
sanitize2(timetablePage.filename)
|
|
@@ -2162,14 +2169,14 @@ var gtfsToHtml = async (initialConfig) => {
|
|
|
2162
2169
|
if (config.outputFormat === "html") {
|
|
2163
2170
|
config.assetPath = "";
|
|
2164
2171
|
const html = await generateOverviewHTML(timetablePages, config);
|
|
2165
|
-
await writeFile(
|
|
2172
|
+
await writeFile(path.join(exportPath, "index.html"), html);
|
|
2166
2173
|
}
|
|
2167
2174
|
const logText = generateLogText(outputStats, config);
|
|
2168
|
-
await writeFile(
|
|
2175
|
+
await writeFile(path.join(exportPath, "log.txt"), logText);
|
|
2169
2176
|
if (config.zipOutput) {
|
|
2170
2177
|
await zipFolder(exportPath);
|
|
2171
2178
|
}
|
|
2172
|
-
const fullExportPath =
|
|
2179
|
+
const fullExportPath = path.join(
|
|
2173
2180
|
exportPath,
|
|
2174
2181
|
config.zipOutput ? "/timetables.zip" : ""
|
|
2175
2182
|
);
|