gtfs-to-html 2.9.12 → 2.9.14

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.
@@ -20,9 +20,10 @@ import {
20
20
  copyFile,
21
21
  mkdir,
22
22
  readdir,
23
- readFile
23
+ readFile,
24
+ rm
24
25
  } from "node:fs/promises";
25
- import _ from "lodash-es";
26
+ import * as _ from "lodash-es";
26
27
  import archiver from "archiver";
27
28
  import beautify from "js-beautify";
28
29
  import { renderFile } from "pug";
@@ -330,7 +331,7 @@ function formatTripNameForCSV(trip, timetable) {
330
331
  }
331
332
 
332
333
  // package.json
333
- var version = "2.9.12";
334
+ var version = "2.9.14";
334
335
 
335
336
  // src/lib/utils.ts
336
337
  var isTimepoint = (stoptime) => {
@@ -1282,6 +1283,7 @@ function setDefaultConfig(initialConfig) {
1282
1283
  noServiceSymbol: "-",
1283
1284
  noServiceText: "No service at this stop",
1284
1285
  outputFormat: "html",
1286
+ overwriteExistingFiles: true,
1285
1287
  requestDropoffSymbol: "\u2020",
1286
1288
  requestDropoffText: "Must request drop off",
1287
1289
  requestPickupSymbol: "***",
@@ -1868,7 +1870,7 @@ function getPathToTemplateFile(templateFileName, config) {
1868
1870
  const fullTemplateFileName = config.noHead !== true ? `${templateFileName}_full.pug` : `${templateFileName}.pug`;
1869
1871
  return join(getPathToViewsFolder(config), fullTemplateFileName);
1870
1872
  }
1871
- async function prepDirectory(outputPath) {
1873
+ async function prepDirectory(outputPath, config) {
1872
1874
  try {
1873
1875
  await access(outputPath);
1874
1876
  } catch (error) {
@@ -1884,11 +1886,14 @@ async function prepDirectory(outputPath) {
1884
1886
  }
1885
1887
  }
1886
1888
  const files = await readdir(outputPath);
1887
- if (files.length > 0) {
1889
+ if (config.overwriteExistingFiles === false && files.length > 0) {
1888
1890
  throw new Error(
1889
1891
  `Output directory ${outputPath} is not empty. Please specify an empty directory.`
1890
1892
  );
1891
1893
  }
1894
+ if (config.overwriteExistingFiles === true) {
1895
+ await rm(join(outputPath, "*"), { recursive: true, force: true });
1896
+ }
1892
1897
  }
1893
1898
  async function copyStaticAssets(config, outputPath) {
1894
1899
  const viewsFolderPath = getPathToViewsFolder(config);
@@ -2146,7 +2151,12 @@ var gtfsToHtml = async (initialConfig) => {
2146
2151
  config.log = log(config);
2147
2152
  config.logWarning = logWarning(config);
2148
2153
  config.logError = logError(config);
2154
+ const agencyKey = config.agencies.map(
2155
+ (agency) => agency.agencyKey ?? agency.agency_key ?? "unknown"
2156
+ ).join("-");
2157
+ const outputPath = config.outputPath ? untildify2(config.outputPath) : path.join(process.cwd(), "html", sanitize2(agencyKey));
2149
2158
  timer.start();
2159
+ await prepDirectory(outputPath, config);
2150
2160
  try {
2151
2161
  openDb2(config);
2152
2162
  } catch (error) {
@@ -2163,10 +2173,6 @@ var gtfsToHtml = async (initialConfig) => {
2163
2173
  if (!config.skipImport) {
2164
2174
  await importGtfs(config);
2165
2175
  }
2166
- const agencyKey = config.agencies.map(
2167
- (agency) => agency.agencyKey ?? agency.agency_key ?? "unknown"
2168
- ).join("-");
2169
- const outputPath = config.outputPath ? untildify2(config.outputPath) : path.join(process.cwd(), "html", sanitize2(agencyKey));
2170
2176
  const stats = {
2171
2177
  timetables: 0,
2172
2178
  timetablePages: 0,
@@ -2181,7 +2187,6 @@ var gtfsToHtml = async (initialConfig) => {
2181
2187
  getTimetablePagesForAgency(config),
2182
2188
  "timetable_page_id"
2183
2189
  );
2184
- await prepDirectory(outputPath);
2185
2190
  if (config.noHead !== true && ["html", "pdf"].includes(config.outputFormat)) {
2186
2191
  await copyStaticAssets(config, outputPath);
2187
2192
  }