gtfs 4.15.5 → 4.15.6

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.
@@ -21,65 +21,47 @@ import StreamZip from "node-stream-zip";
21
21
  async function getConfig(argv2) {
22
22
  let config;
23
23
  let data;
24
- if (argv2.configPath) {
25
- try {
26
- data = await readFile(path.resolve(untildify(argv2.configPath)), "utf8");
27
- } catch (error) {
28
- throw new Error(
29
- `Cannot find configuration file at \`${argv2.configPath}\`. Use config-sample.json as a starting point.`
30
- );
31
- }
32
- try {
24
+ try {
25
+ if (argv2.configPath) {
26
+ const configPath = path.resolve(untildify(argv2.configPath));
27
+ data = await readFile(configPath, "utf8");
33
28
  config = Object.assign(JSON.parse(data), argv2);
34
- } catch (error) {
35
- throw new Error(
36
- `Cannot parse configuration file at \`${argv2.configPath}\`. Check to ensure that it is valid JSON.`
37
- );
38
- }
39
- } else if (argv2.gtfsPath || argv2.gtfsUrl || argv2.sqlitePath) {
40
- const agencies = [];
41
- if (argv2.gtfsPath) {
42
- agencies.push({
43
- path: argv2.gtfsPath
44
- });
45
- }
46
- if (argv2.gtfsUrl) {
47
- agencies.push({
48
- url: argv2.gtfsUrl
49
- });
50
- }
51
- config = {
52
- agencies,
53
- ...omit(argv2, ["path", "url"])
54
- };
55
- } else if (existsSync(path.resolve("./config.json"))) {
56
- try {
29
+ } else if (argv2.gtfsPath || argv2.gtfsUrl || argv2.sqlitePath) {
30
+ const agencies = [
31
+ ...argv2.gtfsPath ? [{ path: argv2.gtfsPath }] : [],
32
+ ...argv2.gtfsUrl ? [{ url: argv2.gtfsUrl }] : []
33
+ ];
34
+ config = {
35
+ agencies,
36
+ ...omit(argv2, ["path", "url"])
37
+ };
38
+ } else if (existsSync(path.resolve("./config.json"))) {
57
39
  data = await readFile(path.resolve("./config.json"), "utf8");
58
- } catch (error) {
40
+ config = Object.assign(JSON.parse(data), argv2);
41
+ console.log("Using configuration from ./config.json");
42
+ } else {
59
43
  throw new Error(
60
- `Cannot open configuration file at \`${path.resolve("./config.json")}\`. Check to ensure that it exists. Use config-sample.json as a starting point.`
44
+ "Cannot find configuration file. Use config-sample.json as a starting point, pass --configPath option."
61
45
  );
62
46
  }
63
- try {
64
- config = Object.assign(JSON.parse(data), argv2);
65
- console.log("Using configuration from ./config.json");
66
- } catch (error) {
47
+ return config;
48
+ } catch (error) {
49
+ if (error instanceof SyntaxError) {
67
50
  throw new Error(
68
- `Cannot parse configuration file at \`${path.resolve("./config.json")}\`. Check to ensure that it is valid JSON.`
51
+ `Cannot parse configuration file. Check to ensure that it is valid JSON. Error: ${error.message}`
69
52
  );
70
53
  }
71
- } else {
72
- throw new Error(
73
- "Cannot find configuration file. Use config-sample.json as a starting point, pass --configPath option."
74
- );
54
+ throw error;
75
55
  }
76
- return config;
77
56
  }
78
57
  async function prepDirectory(exportPath) {
79
58
  await rm(exportPath, { recursive: true, force: true });
80
59
  await mkdir(exportPath, { recursive: true });
81
60
  }
82
61
  function generateFolderName(folderName) {
62
+ if (!folderName || typeof folderName !== "string") {
63
+ throw new Error("Folder name must be a non-empty string");
64
+ }
83
65
  return snakeCase(sanitize(folderName));
84
66
  }
85
67
 
@@ -88,14 +70,14 @@ import { clearLine, cursorTo } from "node:readline";
88
70
  import { noop } from "lodash-es";
89
71
  import * as colors from "yoctocolors";
90
72
  function log(config) {
91
- if (config.verbose === false) {
73
+ if (!config.verbose) {
92
74
  return noop;
93
75
  }
94
76
  if (config.logFunction) {
95
77
  return config.logFunction;
96
78
  }
97
- return (text, overwrite) => {
98
- if (overwrite === true && process.stdout.isTTY) {
79
+ return (text, overwrite = false) => {
80
+ if (overwrite && process.stdout.isTTY) {
99
81
  clearLine(process.stdout, 0);
100
82
  cursorTo(process.stdout, 0);
101
83
  } else {
@@ -115,16 +97,12 @@ ${formatWarning(text)}
115
97
  };
116
98
  }
117
99
  function formatWarning(text) {
118
- const warningMessage = `${colors.underline("Warning")}: ${text}`;
119
- return colors.yellow(warningMessage);
100
+ return colors.yellow(`${colors.underline("Warning")}: ${text}`);
120
101
  }
121
102
  function formatError(error) {
122
103
  const messageText = error instanceof Error ? error.message : error;
123
- const errorMessage = `${colors.underline("Error")}: ${messageText.replace(
124
- "Error: ",
125
- ""
126
- )}`;
127
- return colors.red(errorMessage);
104
+ const cleanMessage = messageText.replace(/^Error:\s*/i, "");
105
+ return colors.red(`${colors.underline("Error")}: ${cleanMessage}`);
128
106
  }
129
107
 
130
108
  // src/lib/import-gtfs.ts