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/bin/gtfs-to-html.js
CHANGED
|
@@ -11,7 +11,7 @@ import { hideBin } from "yargs/helpers";
|
|
|
11
11
|
import PrettyError from "pretty-error";
|
|
12
12
|
|
|
13
13
|
// src/lib/file-utils.ts
|
|
14
|
-
import
|
|
14
|
+
import { dirname, join, resolve } from "node:path";
|
|
15
15
|
import { createWriteStream } from "node:fs";
|
|
16
16
|
import { fileURLToPath } from "node:url";
|
|
17
17
|
import { access, cp, copyFile, mkdir, readFile, rm } from "node:fs/promises";
|
|
@@ -323,7 +323,7 @@ function formatTripNameForCSV(trip, timetable) {
|
|
|
323
323
|
}
|
|
324
324
|
|
|
325
325
|
// package.json
|
|
326
|
-
var version = "2.9.
|
|
326
|
+
var version = "2.9.2";
|
|
327
327
|
|
|
328
328
|
// src/lib/utils.ts
|
|
329
329
|
var isTimepoint = (stoptime) => {
|
|
@@ -1789,7 +1789,7 @@ async function getConfig(argv2) {
|
|
|
1789
1789
|
let data;
|
|
1790
1790
|
let config;
|
|
1791
1791
|
try {
|
|
1792
|
-
data = await readFile(
|
|
1792
|
+
data = await readFile(resolve(untildify(argv2.configPath)), "utf8");
|
|
1793
1793
|
} catch (error) {
|
|
1794
1794
|
throw new Error(
|
|
1795
1795
|
`Cannot find configuration file at \`${argv2.configPath}\`. Use config-sample.json as a starting point, pass --configPath option`
|
|
@@ -1810,13 +1810,24 @@ async function getConfig(argv2) {
|
|
|
1810
1810
|
}
|
|
1811
1811
|
return config;
|
|
1812
1812
|
}
|
|
1813
|
-
function
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1813
|
+
function getPathToViewsFolder(config) {
|
|
1814
|
+
if (config.templatePath) {
|
|
1815
|
+
return untildify(config.templatePath);
|
|
1816
|
+
}
|
|
1817
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
1818
|
+
let viewsFolderPath;
|
|
1819
|
+
if (__dirname.endsWith("/dist/bin") || __dirname.endsWith("/dist/app")) {
|
|
1820
|
+
viewsFolderPath = resolve(__dirname, "../../views/default");
|
|
1821
|
+
} else if (__dirname.endsWith("/dist")) {
|
|
1822
|
+
viewsFolderPath = resolve(__dirname, "../views/default");
|
|
1823
|
+
} else {
|
|
1824
|
+
viewsFolderPath = resolve(__dirname, "views/default");
|
|
1817
1825
|
}
|
|
1818
|
-
|
|
1819
|
-
|
|
1826
|
+
return viewsFolderPath;
|
|
1827
|
+
}
|
|
1828
|
+
function getPathToTemplateFile(templateFileName, config) {
|
|
1829
|
+
const fullTemplateFileName = config.noHead !== true ? `${templateFileName}_full.pug` : `${templateFileName}.pug`;
|
|
1830
|
+
return join(getPathToViewsFolder(config), fullTemplateFileName);
|
|
1820
1831
|
}
|
|
1821
1832
|
async function prepDirectory(exportPath) {
|
|
1822
1833
|
await rm(exportPath, { recursive: true, force: true });
|
|
@@ -1832,35 +1843,31 @@ async function prepDirectory(exportPath) {
|
|
|
1832
1843
|
}
|
|
1833
1844
|
}
|
|
1834
1845
|
async function copyStaticAssets(config, exportPath) {
|
|
1835
|
-
const
|
|
1846
|
+
const viewsFolderPath = getPathToViewsFolder(config);
|
|
1836
1847
|
const foldersToCopy = ["css", "js", "img"];
|
|
1837
1848
|
for (const folder of foldersToCopy) {
|
|
1838
|
-
if (await access(
|
|
1839
|
-
await cp(
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
{
|
|
1843
|
-
recursive: true
|
|
1844
|
-
}
|
|
1845
|
-
);
|
|
1849
|
+
if (await access(join(viewsFolderPath, folder)).then(() => true).catch(() => false)) {
|
|
1850
|
+
await cp(join(viewsFolderPath, folder), join(exportPath, folder), {
|
|
1851
|
+
recursive: true
|
|
1852
|
+
});
|
|
1846
1853
|
}
|
|
1847
1854
|
}
|
|
1848
1855
|
if (config.hasGtfsRealtime) {
|
|
1849
1856
|
await copyFile(
|
|
1850
1857
|
"node_modules/pbf/dist/pbf.js",
|
|
1851
|
-
|
|
1858
|
+
join(exportPath, "js/pbf.js")
|
|
1852
1859
|
);
|
|
1853
1860
|
await copyFile(
|
|
1854
1861
|
"node_modules/gtfs-realtime-pbf-js-module/gtfs-realtime.browser.proto.js",
|
|
1855
|
-
|
|
1862
|
+
join(exportPath, "js/gtfs-realtime.browser.proto.js")
|
|
1856
1863
|
);
|
|
1857
1864
|
}
|
|
1858
1865
|
}
|
|
1859
1866
|
function zipFolder(exportPath) {
|
|
1860
|
-
const output = createWriteStream(
|
|
1867
|
+
const output = createWriteStream(join(exportPath, "timetables.zip"));
|
|
1861
1868
|
const archive = archiver("zip");
|
|
1862
|
-
return new Promise((
|
|
1863
|
-
output.on("close",
|
|
1869
|
+
return new Promise((resolve2, reject) => {
|
|
1870
|
+
output.on("close", resolve2);
|
|
1864
1871
|
archive.on("error", reject);
|
|
1865
1872
|
archive.pipe(output);
|
|
1866
1873
|
archive.glob("**/*.{txt,css,js,html}", {
|
|
@@ -1888,7 +1895,7 @@ function generateFolderName(timetablePage) {
|
|
|
1888
1895
|
return sanitize(`${timetable.start_date}-${timetable.end_date}`);
|
|
1889
1896
|
}
|
|
1890
1897
|
async function renderTemplate(templateFileName, templateVars, config) {
|
|
1891
|
-
const templatePath =
|
|
1898
|
+
const templatePath = getPathToTemplateFile(templateFileName, config);
|
|
1892
1899
|
const html = await renderFile(templatePath, {
|
|
1893
1900
|
_,
|
|
1894
1901
|
md: (text) => insane(marked.parseInline(text)),
|
|
@@ -2072,7 +2079,7 @@ function progressBar(formatString, barTotal, config) {
|
|
|
2072
2079
|
}
|
|
2073
2080
|
|
|
2074
2081
|
// src/lib/gtfs-to-html.ts
|
|
2075
|
-
import
|
|
2082
|
+
import path from "node:path";
|
|
2076
2083
|
import { mkdir as mkdir2, writeFile } from "node:fs/promises";
|
|
2077
2084
|
import { map } from "lodash-es";
|
|
2078
2085
|
import { openDb as openDb2, importGtfs } from "gtfs";
|
|
@@ -2104,7 +2111,7 @@ var gtfsToHtml = async (initialConfig) => {
|
|
|
2104
2111
|
const agencyKey = config.agencies.map(
|
|
2105
2112
|
(agency) => agency.agencyKey ?? agency.agency_key ?? "unknown"
|
|
2106
2113
|
).join("-");
|
|
2107
|
-
const exportPath =
|
|
2114
|
+
const exportPath = path.join(process.cwd(), "html", sanitize2(agencyKey));
|
|
2108
2115
|
const outputStats = {
|
|
2109
2116
|
timetables: 0,
|
|
2110
2117
|
timetablePages: 0,
|
|
@@ -2148,16 +2155,16 @@ var gtfsToHtml = async (initialConfig) => {
|
|
|
2148
2155
|
outputStats.timetables += timetablePage.consolidatedTimetables.length;
|
|
2149
2156
|
outputStats.timetablePages += 1;
|
|
2150
2157
|
const datePath = generateFolderName(timetablePage);
|
|
2151
|
-
await mkdir2(
|
|
2158
|
+
await mkdir2(path.join(exportPath, datePath), { recursive: true });
|
|
2152
2159
|
config.assetPath = "../";
|
|
2153
|
-
timetablePage.relativePath =
|
|
2160
|
+
timetablePage.relativePath = path.join(
|
|
2154
2161
|
datePath,
|
|
2155
2162
|
sanitize2(timetablePage.filename)
|
|
2156
2163
|
);
|
|
2157
2164
|
if (config.outputFormat === "csv") {
|
|
2158
2165
|
for (const timetable of timetablePage.consolidatedTimetables) {
|
|
2159
2166
|
const csv = await generateTimetableCSV(timetable);
|
|
2160
|
-
const csvPath =
|
|
2167
|
+
const csvPath = path.join(
|
|
2161
2168
|
exportPath,
|
|
2162
2169
|
datePath,
|
|
2163
2170
|
generateFileName(timetable, config, "csv")
|
|
@@ -2166,7 +2173,7 @@ var gtfsToHtml = async (initialConfig) => {
|
|
|
2166
2173
|
}
|
|
2167
2174
|
} else {
|
|
2168
2175
|
const html = await generateTimetableHTML(timetablePage, config);
|
|
2169
|
-
const htmlPath =
|
|
2176
|
+
const htmlPath = path.join(
|
|
2170
2177
|
exportPath,
|
|
2171
2178
|
datePath,
|
|
2172
2179
|
sanitize2(timetablePage.filename)
|
|
@@ -2191,14 +2198,14 @@ var gtfsToHtml = async (initialConfig) => {
|
|
|
2191
2198
|
if (config.outputFormat === "html") {
|
|
2192
2199
|
config.assetPath = "";
|
|
2193
2200
|
const html = await generateOverviewHTML(timetablePages, config);
|
|
2194
|
-
await writeFile(
|
|
2201
|
+
await writeFile(path.join(exportPath, "index.html"), html);
|
|
2195
2202
|
}
|
|
2196
2203
|
const logText = generateLogText(outputStats, config);
|
|
2197
|
-
await writeFile(
|
|
2204
|
+
await writeFile(path.join(exportPath, "log.txt"), logText);
|
|
2198
2205
|
if (config.zipOutput) {
|
|
2199
2206
|
await zipFolder(exportPath);
|
|
2200
2207
|
}
|
|
2201
|
-
const fullExportPath =
|
|
2208
|
+
const fullExportPath = path.join(
|
|
2202
2209
|
exportPath,
|
|
2203
2210
|
config.zipOutput ? "/timetables.zip" : ""
|
|
2204
2211
|
);
|