gtfs 4.15.5 → 4.15.7

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.
@@ -13,63 +13,6 @@ import { omit, snakeCase } from "lodash-es";
13
13
  import sanitize from "sanitize-filename";
14
14
  import untildify from "untildify";
15
15
  import StreamZip from "node-stream-zip";
16
- async function getConfig(argv2) {
17
- let config;
18
- let data;
19
- if (argv2.configPath) {
20
- try {
21
- data = await readFile(path.resolve(untildify(argv2.configPath)), "utf8");
22
- } catch (error) {
23
- throw new Error(
24
- `Cannot find configuration file at \`${argv2.configPath}\`. Use config-sample.json as a starting point.`
25
- );
26
- }
27
- try {
28
- config = Object.assign(JSON.parse(data), argv2);
29
- } catch (error) {
30
- throw new Error(
31
- `Cannot parse configuration file at \`${argv2.configPath}\`. Check to ensure that it is valid JSON.`
32
- );
33
- }
34
- } else if (argv2.gtfsPath || argv2.gtfsUrl || argv2.sqlitePath) {
35
- const agencies = [];
36
- if (argv2.gtfsPath) {
37
- agencies.push({
38
- path: argv2.gtfsPath
39
- });
40
- }
41
- if (argv2.gtfsUrl) {
42
- agencies.push({
43
- url: argv2.gtfsUrl
44
- });
45
- }
46
- config = {
47
- agencies,
48
- ...omit(argv2, ["path", "url"])
49
- };
50
- } else if (existsSync(path.resolve("./config.json"))) {
51
- try {
52
- data = await readFile(path.resolve("./config.json"), "utf8");
53
- } catch (error) {
54
- throw new Error(
55
- `Cannot open configuration file at \`${path.resolve("./config.json")}\`. Check to ensure that it exists. Use config-sample.json as a starting point.`
56
- );
57
- }
58
- try {
59
- config = Object.assign(JSON.parse(data), argv2);
60
- console.log("Using configuration from ./config.json");
61
- } catch (error) {
62
- throw new Error(
63
- `Cannot parse configuration file at \`${path.resolve("./config.json")}\`. Check to ensure that it is valid JSON.`
64
- );
65
- }
66
- } else {
67
- throw new Error(
68
- "Cannot find configuration file. Use config-sample.json as a starting point, pass --configPath option."
69
- );
70
- }
71
- return config;
72
- }
73
16
 
74
17
  // src/lib/log-utils.ts
75
18
  import { clearLine, cursorTo } from "node:readline";
@@ -82,8 +25,8 @@ function log(config) {
82
25
  if (config.logFunction) {
83
26
  return config.logFunction;
84
27
  }
85
- return (text, overwrite) => {
86
- if (overwrite === true && process.stdout.isTTY) {
28
+ return (text, overwrite = false) => {
29
+ if (overwrite && process.stdout.isTTY) {
87
30
  clearLine(process.stdout, 0);
88
31
  cursorTo(process.stdout, 0);
89
32
  } else {
@@ -113,16 +56,50 @@ ${formatError(text)}
113
56
  };
114
57
  }
115
58
  function formatWarning(text) {
116
- const warningMessage = `${colors.underline("Warning")}: ${text}`;
117
- return colors.yellow(warningMessage);
59
+ return colors.yellow(`${colors.underline("Warning")}: ${text}`);
118
60
  }
119
61
  function formatError(error) {
120
62
  const messageText = error instanceof Error ? error.message : error;
121
- const errorMessage = `${colors.underline("Error")}: ${messageText.replace(
122
- "Error: ",
123
- ""
124
- )}`;
125
- return colors.red(errorMessage);
63
+ const cleanMessage = messageText.replace(/^Error:\s*/i, "");
64
+ return colors.red(`${colors.underline("Error")}: ${cleanMessage}`);
65
+ }
66
+
67
+ // src/lib/file-utils.ts
68
+ async function getConfig(argv2) {
69
+ let config;
70
+ let data;
71
+ try {
72
+ if (argv2.configPath) {
73
+ const configPath = path.resolve(untildify(argv2.configPath));
74
+ data = await readFile(configPath, "utf8");
75
+ config = Object.assign(JSON.parse(data), argv2);
76
+ } else if (argv2.gtfsPath || argv2.gtfsUrl || argv2.sqlitePath) {
77
+ const agencies = [
78
+ ...argv2.gtfsPath ? [{ path: argv2.gtfsPath }] : [],
79
+ ...argv2.gtfsUrl ? [{ url: argv2.gtfsUrl }] : []
80
+ ];
81
+ config = {
82
+ agencies,
83
+ ...omit(argv2, ["path", "url"])
84
+ };
85
+ } else if (existsSync(path.resolve("./config.json"))) {
86
+ data = await readFile(path.resolve("./config.json"), "utf8");
87
+ config = Object.assign(JSON.parse(data), argv2);
88
+ log(config)("Using configuration from ./config.json");
89
+ } else {
90
+ throw new Error(
91
+ "Cannot find configuration file. Use config-sample.json as a starting point, pass --configPath option."
92
+ );
93
+ }
94
+ return config;
95
+ } catch (error) {
96
+ if (error instanceof SyntaxError) {
97
+ throw new Error(
98
+ `Cannot parse configuration file. Check to ensure that it is valid JSON. Error: ${error.message}`
99
+ );
100
+ }
101
+ throw error;
102
+ }
126
103
  }
127
104
 
128
105
  // src/lib/import-gtfs.ts
@@ -614,7 +591,8 @@ function setDefaultConfig(initialConfig) {
614
591
  sqlitePath: ":memory:",
615
592
  ignoreDuplicates: false,
616
593
  ignoreErrors: false,
617
- gtfsRealtimeExpirationSeconds: 0
594
+ gtfsRealtimeExpirationSeconds: 0,
595
+ verbose: true
618
596
  };
619
597
  return {
620
598
  ...defaults,
@@ -623,7 +601,9 @@ function setDefaultConfig(initialConfig) {
623
601
  }
624
602
  function convertLongTimeToDate(longDate) {
625
603
  const { high, low, unsigned } = longDate;
626
- return new Date(new Long(low, high, unsigned).toInt() * 1e3).toISOString();
604
+ return new Date(
605
+ Long.fromBits(low, high, unsigned).toNumber() * 1e3
606
+ ).toISOString();
627
607
  }
628
608
 
629
609
  // src/lib/import-gtfs-realtime.ts