transit-departures-widget 2.4.0 → 2.4.2

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/CHANGELOG.md DELETED
@@ -1,206 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ## [2.4.0] - 2024-07-03
9
-
10
- ## Updated
11
-
12
- - Store routes and stops in separate JSON file
13
- - Dependency updates
14
-
15
- ## Fixed
16
-
17
- - Copy img folder
18
-
19
- ## [2.3.0] - 2024-04-22
20
-
21
- ## Fixed
22
-
23
- - Better removing of last stoptime of trip
24
-
25
- ## [2.2.1] - 2024-04-08
26
-
27
- ## Fixed
28
-
29
- - allow query param in config gtfsRtTripupdatesUrl
30
-
31
- ## Updated
32
-
33
- - Dependency updates
34
-
35
- ## [2.2.0] - 2024-03-07
36
-
37
- ## Added
38
-
39
- - startDate and endDate config params
40
-
41
- ## Updated
42
-
43
- - Dependency updates
44
-
45
- ## [2.1.1] - 2023-12-04
46
-
47
- ## Fixed
48
-
49
- - Fix for routes with no directions
50
-
51
- ## Updated
52
-
53
- - Dependency updates
54
-
55
- ## [2.1.0] - 2023-09-13
56
-
57
- ## Changed
58
-
59
- - Remove last stop of each route
60
- - Improved autocomplete sorting
61
- - Use stop_code as value in autocomplete
62
- - Populate route dropdown on page load
63
-
64
- ## Fixed
65
-
66
- - Fix for grouping child stops
67
- - Handle case with no departures
68
-
69
- ## Updated
70
-
71
- - Dependency updates
72
-
73
- ## [2.0.0] - 2023-09-14
74
-
75
- ## Changed
76
-
77
- - Renamed to transit-departures-widget
78
- - Renamed all styles and functions to use departures instead of arrivals
79
-
80
- ## Fixed
81
-
82
- - Handle empty direction_id in GTFS
83
- - Hide overflow in route circle
84
- - Better route sorting
85
- - Fix for hidden arrival times after none available
86
-
87
- ## Updated
88
-
89
- - Reword input to "stop" and "Stop code"
90
- - Add support for GTFS without stop codes
91
- - Hide departures more than 1 minute in the past
92
-
93
- ## [1.2.1] - 2023-08-14
94
-
95
- ## Fixed
96
-
97
- - Error in logging functions
98
-
99
- ## Updated
100
-
101
- - Use lint-staged instead of pretty-quick
102
- - Dependency updates
103
-
104
- ## [1.2.0] - 2023-05-22
105
-
106
- ## Fixed
107
-
108
- - Deduplicate stops in a row
109
-
110
- ## Updated
111
-
112
- - Update to node-gtfs v4
113
- - Dependency updates
114
-
115
- ## [1.1.0] - 2022-06-29
116
-
117
- ## Added
118
-
119
- - Added a refresh button
120
- - Updated filter to hide departure times at last stop of each trip
121
-
122
- ## Updated
123
-
124
- - Dependency updates
125
-
126
- ## [1.0.2] - 2022-03-17
127
-
128
- ## Changed
129
-
130
- - Move text out of JS into template
131
- - Add i18n and support for locale translation file
132
-
133
- ## Fixed
134
-
135
- - Fix issue with initial arrivals load
136
- - Fix for routes with no colors defined
137
- - Fix HTML escape for headsign in dropdown
138
-
139
- ## Updated
140
-
141
- - Dependency updates
142
-
143
- ## [1.0.1] - 2021-10-17
144
-
145
- ## Updated
146
-
147
- - node-gtfs library
148
-
149
- ## Added
150
-
151
- - Husky and Prettier
152
-
153
- ## [1.0.0] - 2021-10-15
154
-
155
- ### Breaking Changes
156
-
157
- - Converted to ES6 Module
158
-
159
- ### Added
160
-
161
- - Support for other languages using languageCode config variable
162
- - Polish translations
163
- - Support for 24-hour time using timeFormat config variable
164
-
165
- ### Updated
166
-
167
- - Dependency updates
168
- - Support for release-it
169
-
170
- ## [0.1.4] - 2021-04-20
171
-
172
- ### Updated
173
-
174
- - Dependency updates
175
- - Readme updates
176
-
177
- ## [0.1.3] - 2021-01-12
178
-
179
- ### Fixed
180
-
181
- - Fallback for cyclic routes when finding stop order
182
-
183
- ### Updated
184
-
185
- - Dependency updates
186
-
187
- ## [0.1.2] - 2020-11-13
188
-
189
- ### Updated
190
-
191
- - default to lookup by stop id
192
- - better direction names
193
-
194
- ## [0.1.1] - 2020-11-10
195
-
196
- ### Added
197
-
198
- - beautify option
199
- - templatePath option
200
- - noHead option
201
-
202
- ## [0.1.0] - 2020-11-10
203
-
204
- ### Added
205
-
206
- - Initial Release
package/app/index.js DELETED
@@ -1,95 +0,0 @@
1
- import path from 'node:path'
2
- import { fileURLToPath } from 'node:url'
3
- import { readFileSync } from 'node:fs'
4
- import yargs from 'yargs'
5
- import { openDb } from 'gtfs'
6
-
7
- import express from 'express'
8
- import logger from 'morgan'
9
-
10
- import {
11
- setDefaultConfig,
12
- generateTransitDeparturesWidgetHtml,
13
- generateTransitDeparturesWidgetJson,
14
- } from '../lib/utils.js'
15
-
16
- const { argv } = yargs(process.argv).option('c', {
17
- alias: 'configPath',
18
- describe: 'Path to config file',
19
- default: './config.json',
20
- type: 'string',
21
- })
22
-
23
- const app = express()
24
- const router = new express.Router()
25
-
26
- const configPath = argv.configPath || new URL('../config.json', import.meta.url)
27
- const selectedConfig = JSON.parse(readFileSync(configPath))
28
-
29
- const config = setDefaultConfig(selectedConfig)
30
- // Override noHead config option so full HTML pages are generated
31
- config.noHead = false
32
- config.assetPath = '/'
33
- config.log = console.log
34
- config.logWarning = console.warn
35
- config.logError = console.error
36
-
37
- try {
38
- openDb(config)
39
- } catch (error) {
40
- if (error instanceof Error && error.code === 'SQLITE_CANTOPEN') {
41
- config.logError(
42
- `Unable to open sqlite database "${config.sqlitePath}" defined as \`sqlitePath\` config.json. Ensure the parent directory exists or remove \`sqlitePath\` from config.json.`,
43
- )
44
- }
45
-
46
- throw error
47
- }
48
-
49
- /*
50
- * Show the transit departures widget
51
- */
52
- router.get('/', async (request, response, next) => {
53
- try {
54
- const html = await generateTransitDeparturesWidgetHtml(config)
55
- response.send(html)
56
- } catch (error) {
57
- next(error)
58
- }
59
- })
60
-
61
- /*
62
- * Provide data
63
- */
64
- router.get('/data/routes.json', async (request, response, next) => {
65
- try {
66
- const { routes } = await generateTransitDeparturesWidgetJson(config)
67
- response.json(routes)
68
- } catch (error) {
69
- next(error)
70
- }
71
- })
72
-
73
- router.get('/data/stops.json', async (request, response, next) => {
74
- try {
75
- const { stops } = await generateTransitDeparturesWidgetJson(config)
76
- response.json(stops)
77
- } catch (error) {
78
- next(error)
79
- }
80
- })
81
-
82
- app.set('views', path.join(fileURLToPath(import.meta.url), '../../views'))
83
- app.set('view engine', 'pug')
84
-
85
- app.use(logger('dev'))
86
- app.use(
87
- express.static(path.join(fileURLToPath(import.meta.url), '../../public')),
88
- )
89
-
90
- app.use('/', router)
91
- app.set('port', process.env.PORT || 3000)
92
-
93
- const server = app.listen(app.get('port'), () => {
94
- console.log(`Express server listening on port ${server.address().port}`)
95
- })
@@ -1,38 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import yargs from 'yargs'
4
- import { hideBin } from 'yargs/helpers'
5
- import { getConfig } from '../lib/file-utils.js'
6
- import { formatError } from '../lib/log-utils.js'
7
- import transitDeparturesWidget from '../index.js'
8
-
9
- const { argv } = yargs(hideBin(process.argv))
10
- .usage('Usage: $0 --config ./config.json')
11
- .help()
12
- .option('c', {
13
- alias: 'configPath',
14
- describe: 'Path to config file',
15
- default: './config.json',
16
- type: 'string',
17
- })
18
- .option('s', {
19
- alias: 'skipImport',
20
- describe: 'Don’t import GTFS file.',
21
- type: 'boolean',
22
- })
23
- .default('skipImport', undefined)
24
-
25
- const handleError = (error) => {
26
- const text = error || 'Unknown Error'
27
- process.stdout.write(`\n${formatError(text)}\n`)
28
- console.error(error)
29
- process.exit(1)
30
- }
31
-
32
- const setupImport = async () => {
33
- const config = await getConfig(argv)
34
- await transitDeparturesWidget(config)
35
- process.exit()
36
- }
37
-
38
- setupImport().catch(handleError)
@@ -1,15 +0,0 @@
1
- {
2
- "agency": {
3
- "agency_key": "youragency",
4
- "gtfs_static_url": "https://marintransit.org/data/google_transit.zip",
5
- "gtfs_rt_tripupdates_url": "https://marintransit.net/gtfs-rt/tripupdates"
6
- },
7
- "beautify": true,
8
- "endDate": "20240331",
9
- "locale": "en",
10
- "noHead": false,
11
- "refreshIntervalSeconds": 20,
12
- "templatePath": "views/widget",
13
- "timeFormat": "12hour",
14
- "startDate": "20240301"
15
- }
@@ -1,18 +0,0 @@
1
- <svg width="280" height="311" viewBox="0 0 280 311" fill="none" xmlns="http://www.w3.org/2000/svg">
2
- <path fill-rule="evenodd" clip-rule="evenodd" d="M279.142 216.458V95.0263C279.142 82.9559 272.684 71.822 262.162 65.7868L156.951 5.01874C146.43 -1.01645 133.617 -1.01645 123.096 5.01874L17.8843 65.6828C7.36316 71.718 0.904633 82.8518 0.904633 95.0263V216.458C0.904633 228.529 7.36316 239.663 17.8843 245.698L123.096 306.362C133.617 312.397 146.43 312.397 156.951 306.362L262.267 245.594C272.684 239.663 279.142 228.529 279.142 216.458Z" fill="#FF8038"/>
3
- <path fill-rule="evenodd" clip-rule="evenodd" d="M140.075 292.21C137.471 292.21 134.867 291.482 132.471 290.233L27.2596 229.465C22.5719 226.76 19.6552 221.765 19.6552 216.354V95.0263C19.6552 89.6154 22.5719 84.6208 27.1554 81.9154L132.471 21.1473C134.763 19.7945 137.367 19.1702 140.075 19.1702C142.784 19.1702 145.284 19.8986 147.68 21.1473L252.995 81.9154C257.683 84.6208 260.6 89.6154 260.6 95.0263V216.458C260.6 221.869 257.683 226.864 252.995 229.569L147.68 290.337C145.284 291.482 142.68 292.21 140.075 292.21Z" fill="#9CFC61"/>
4
- <mask id="mask0_4_3" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="10" y="133" width="259" height="61">
5
- <path d="M10.6457 133.301H268.646V193.301H10.6457V133.301Z" fill="white"/>
6
- </mask>
7
- <g mask="url(#mask0_4_3)">
8
- <path fill-rule="evenodd" clip-rule="evenodd" d="M10.6457 34.2317H268.646V292.232H10.6457V34.2317Z" fill="#FF8038"/>
9
- </g>
10
- <mask id="mask1_4_3" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="122" y="244" width="36" height="35">
11
- <path d="M122 244H157.139V278.037H122V244Z" fill="white"/>
12
- </mask>
13
- <g mask="url(#mask1_4_3)">
14
- <path fill-rule="evenodd" clip-rule="evenodd" d="M144.917 255.167L157.139 256.912L148.335 265.657L150.471 277.948L139.523 272.186L128.621 278.037L130.658 265.73L121.785 257.056L133.993 255.212L139.41 244L144.917 255.167Z" fill="white"/>
15
- </g>
16
- <path fill-rule="evenodd" clip-rule="evenodd" d="M178.87 65.8803C178.87 64.6713 178.312 63.7413 177.289 63.0903C177.103 62.9973 176.824 62.8113 176.638 62.7183C176.638 59.6494 176.545 56.4875 176.359 53.3256C175.987 46.0718 172.174 42.5378 165.013 42.4448C158.782 42.4448 152.551 42.4448 146.32 42.4448C136.183 42.4448 126.139 42.3518 116.002 42.5378C106.702 42.7238 102.982 46.6297 102.982 55.9295C102.982 58.1614 102.982 60.3934 102.982 62.7183C102.424 62.9043 101.959 63.3693 101.587 63.8343C100.936 64.3923 100.75 65.2293 100.75 66.1592C100.75 70.4371 100.75 74.715 100.75 79.0859C100.75 80.3879 101.215 81.4109 102.331 82.0618C102.61 82.2478 102.796 82.3408 103.075 82.4338C103.075 91.6406 103.075 100.754 103.075 109.961C103.075 111.263 102.889 112.751 103.54 113.867C104.935 116.099 104.656 118.517 104.749 120.935C104.842 123.911 106.795 125.957 109.771 126.05C111.91 126.143 114.049 126.143 116.188 126.05C119.257 125.957 121.21 124.19 121.303 121.121C121.396 119.819 121.582 119.354 123.07 119.354C134.23 119.447 145.483 119.447 156.643 119.354C158.038 119.354 158.41 119.726 158.41 121.121C158.503 124.376 160.456 126.05 163.711 126.05C165.571 126.05 167.431 126.05 169.291 126.05C173.104 126.05 174.964 124.097 175.057 120.284C175.057 118.796 174.592 117.122 175.429 115.727C176.452 113.867 176.731 112.007 176.731 109.961C176.731 101.312 176.731 92.6636 176.731 82.4338C177.382 82.3408 177.94 81.7829 178.312 81.2249C178.777 80.6669 178.963 79.9229 178.963 79.1789C178.87 74.808 178.87 70.3441 178.87 65.8803ZM124.279 49.1407C129.859 49.1407 135.439 49.1407 140.926 49.1407C146.32 49.1407 151.714 49.1407 157.201 49.1407C159.619 49.1407 159.898 49.5127 159.991 52.3026C159.991 55.3715 159.712 55.8365 157.387 55.8365C146.32 55.8365 135.253 55.8365 124.279 55.8365C121.861 55.8365 121.396 55.2785 121.396 52.4886C121.303 49.6987 121.768 49.1407 124.279 49.1407ZM117.304 111.077C114.049 111.077 111.352 108.38 111.352 105.125C111.445 101.963 114.142 99.3594 117.211 99.3594C120.466 99.3594 122.884 101.87 122.884 105.218C122.977 108.473 120.466 111.077 117.304 111.077ZM116.467 90.9896C112.933 90.9896 111.352 89.3157 111.352 85.6888C111.352 79.1789 111.352 72.6691 111.352 66.1592C111.352 62.5323 112.84 61.0444 116.467 61.0444C124.279 61.0444 131.998 61.0444 139.81 61.0444C147.436 61.0444 155.062 61.0444 162.688 61.0444C166.78 61.0444 168.175 62.4393 168.175 66.4382C168.175 72.6691 168.175 78.8999 168.175 85.1308C168.175 88.8507 166.129 90.8966 162.409 90.9896C147.157 90.9896 131.812 90.9896 116.467 90.9896ZM162.409 111.077C159.247 111.077 156.736 108.566 156.643 105.311C156.643 101.963 159.061 99.4524 162.316 99.4524C165.571 99.4524 168.268 102.149 168.268 105.404C168.175 108.38 165.571 111.077 162.409 111.077Z" fill="white"/>
17
- <path d="M22.6277 153.8H19.5227V151.1H28.7027V153.8H25.5977V170H22.6277V153.8ZM30.1407 151.1H34.5417C36.0717 151.1 37.1877 151.46 37.8897 152.18C38.5917 152.882 38.9427 153.971 38.9427 155.447V156.608C38.9427 158.57 38.2947 159.812 36.9987 160.334V160.388C37.7187 160.604 38.2227 161.045 38.5107 161.711C38.8167 162.377 38.9697 163.268 38.9697 164.384V167.705C38.9697 168.245 38.9877 168.686 39.0237 169.028C39.0597 169.352 39.1497 169.676 39.2937 170H36.2697C36.1617 169.694 36.0897 169.406 36.0537 169.136C36.0177 168.866 35.9997 168.38 35.9997 167.678V164.222C35.9997 163.358 35.8557 162.755 35.5677 162.413C35.2977 162.071 34.8207 161.9 34.1367 161.9H33.1107V170H30.1407V151.1ZM34.1907 159.2C34.7847 159.2 35.2257 159.047 35.5137 158.741C35.8197 158.435 35.9727 157.922 35.9727 157.202V155.744C35.9727 155.06 35.8467 154.565 35.5947 154.259C35.3607 153.953 34.9827 153.8 34.4607 153.8H33.1107V159.2H34.1907ZM43.3253 151.1H47.3483L50.4263 170H47.4563L46.9163 166.247V166.301H43.5413L43.0013 170H40.2473L43.3253 151.1ZM46.5653 163.736L45.2423 154.394H45.1883L43.8923 163.736H46.5653ZM51.8673 151.1H55.5933L58.4823 162.413H58.5363V151.1H61.1823V170H58.1313L54.5673 156.203H54.5133V170H51.8673V151.1ZM67.2507 170.27C65.8107 170.27 64.7217 169.865 63.9837 169.055C63.2457 168.227 62.8767 167.048 62.8767 165.518V164.438H65.6847V165.734C65.6847 166.958 66.1977 167.57 67.2237 167.57C67.7277 167.57 68.1057 167.426 68.3577 167.138C68.6277 166.832 68.7627 166.346 68.7627 165.68C68.7627 164.888 68.5827 164.195 68.2227 163.601C67.8627 162.989 67.1967 162.26 66.2247 161.414C65.0007 160.334 64.1457 159.362 63.6597 158.498C63.1737 157.616 62.9307 156.626 62.9307 155.528C62.9307 154.034 63.3087 152.882 64.0647 152.072C64.8207 151.244 65.9187 150.83 67.3587 150.83C68.7807 150.83 69.8517 151.244 70.5717 152.072C71.3097 152.882 71.6787 154.052 71.6787 155.582V156.365H68.8707V155.393C68.8707 154.745 68.7447 154.277 68.4927 153.989C68.2407 153.683 67.8717 153.53 67.3857 153.53C66.3957 153.53 65.9007 154.133 65.9007 155.339C65.9007 156.023 66.0807 156.662 66.4407 157.256C66.8187 157.85 67.4937 158.57 68.4657 159.416C69.7077 160.496 70.5627 161.477 71.0307 162.359C71.4987 163.241 71.7327 164.276 71.7327 165.464C71.7327 167.012 71.3457 168.2 70.5717 169.028C69.8157 169.856 68.7087 170.27 67.2507 170.27ZM73.4356 151.1H76.4056V170H73.4356V151.1ZM80.9519 153.8H77.8469V151.1H87.0269V153.8H83.9219V170H80.9519V153.8ZM92.7891 151.1H97.3251C98.8011 151.1 99.9081 151.496 100.646 152.288C101.384 153.08 101.753 154.241 101.753 155.771V165.329C101.753 166.859 101.384 168.02 100.646 168.812C99.9081 169.604 98.8011 170 97.3251 170H92.7891V151.1ZM97.2711 167.3C97.7571 167.3 98.1261 167.156 98.3781 166.868C98.6481 166.58 98.7831 166.112 98.7831 165.464V155.636C98.7831 154.988 98.6481 154.52 98.3781 154.232C98.1261 153.944 97.7571 153.8 97.2711 153.8H95.7591V167.3H97.2711ZM103.758 151.1H111.858V153.8H106.728V158.795H110.805V161.495H106.728V167.3H111.858V170H103.758V151.1ZM113.566 151.1H117.94C119.416 151.1 120.523 151.496 121.261 152.288C121.999 153.08 122.368 154.241 122.368 155.771V157.634C122.368 159.164 121.999 160.325 121.261 161.117C120.523 161.909 119.416 162.305 117.94 162.305H116.536V170H113.566V151.1ZM117.94 159.605C118.426 159.605 118.786 159.47 119.02 159.2C119.272 158.93 119.398 158.471 119.398 157.823V155.582C119.398 154.934 119.272 154.475 119.02 154.205C118.786 153.935 118.426 153.8 117.94 153.8H116.536V159.605H117.94ZM125.327 151.1H129.35L132.428 170H129.458L128.918 166.247V166.301H125.543L125.003 170H122.249L125.327 151.1ZM128.567 163.736L127.244 154.394H127.19L125.894 163.736H128.567ZM133.869 151.1H138.27C139.8 151.1 140.916 151.46 141.618 152.18C142.32 152.882 142.671 153.971 142.671 155.447V156.608C142.671 158.57 142.023 159.812 140.727 160.334V160.388C141.447 160.604 141.951 161.045 142.239 161.711C142.545 162.377 142.698 163.268 142.698 164.384V167.705C142.698 168.245 142.716 168.686 142.752 169.028C142.788 169.352 142.878 169.676 143.022 170H139.998C139.89 169.694 139.818 169.406 139.782 169.136C139.746 168.866 139.728 168.38 139.728 167.678V164.222C139.728 163.358 139.584 162.755 139.296 162.413C139.026 162.071 138.549 161.9 137.865 161.9H136.839V170H133.869V151.1ZM137.919 159.2C138.513 159.2 138.954 159.047 139.242 158.741C139.548 158.435 139.701 157.922 139.701 157.202V155.744C139.701 155.06 139.575 154.565 139.323 154.259C139.089 153.953 138.711 153.8 138.189 153.8H136.839V159.2H137.919ZM147.028 153.8H143.923V151.1H153.103V153.8H149.998V170H147.028V153.8ZM158.861 170.27C157.421 170.27 156.323 169.865 155.567 169.055C154.811 168.227 154.433 167.048 154.433 165.518V151.1H157.403V165.734C157.403 166.382 157.529 166.85 157.781 167.138C158.051 167.426 158.429 167.57 158.915 167.57C159.401 167.57 159.77 167.426 160.022 167.138C160.292 166.85 160.427 166.382 160.427 165.734V151.1H163.289V165.518C163.289 167.048 162.911 168.227 162.155 169.055C161.399 169.865 160.301 170.27 158.861 170.27ZM165.404 151.1H169.805C171.335 151.1 172.451 151.46 173.153 152.18C173.855 152.882 174.206 153.971 174.206 155.447V156.608C174.206 158.57 173.558 159.812 172.262 160.334V160.388C172.982 160.604 173.486 161.045 173.774 161.711C174.08 162.377 174.233 163.268 174.233 164.384V167.705C174.233 168.245 174.251 168.686 174.287 169.028C174.323 169.352 174.413 169.676 174.557 170H171.533C171.425 169.694 171.353 169.406 171.317 169.136C171.281 168.866 171.263 168.38 171.263 167.678V164.222C171.263 163.358 171.119 162.755 170.831 162.413C170.561 162.071 170.084 161.9 169.4 161.9H168.374V170H165.404V151.1ZM169.454 159.2C170.048 159.2 170.489 159.047 170.777 158.741C171.083 158.435 171.236 157.922 171.236 157.202V155.744C171.236 155.06 171.11 154.565 170.858 154.259C170.624 153.953 170.246 153.8 169.724 153.8H168.374V159.2H169.454ZM176.294 151.1H184.394V153.8H179.264V158.795H183.341V161.495H179.264V167.3H184.394V170H176.294V151.1ZM190.016 170.27C188.576 170.27 187.487 169.865 186.749 169.055C186.011 168.227 185.642 167.048 185.642 165.518V164.438H188.45V165.734C188.45 166.958 188.963 167.57 189.989 167.57C190.493 167.57 190.871 167.426 191.123 167.138C191.393 166.832 191.528 166.346 191.528 165.68C191.528 164.888 191.348 164.195 190.988 163.601C190.628 162.989 189.962 162.26 188.99 161.414C187.766 160.334 186.911 159.362 186.425 158.498C185.939 157.616 185.696 156.626 185.696 155.528C185.696 154.034 186.074 152.882 186.83 152.072C187.586 151.244 188.684 150.83 190.124 150.83C191.546 150.83 192.617 151.244 193.337 152.072C194.075 152.882 194.444 154.052 194.444 155.582V156.365H191.636V155.393C191.636 154.745 191.51 154.277 191.258 153.989C191.006 153.683 190.637 153.53 190.151 153.53C189.161 153.53 188.666 154.133 188.666 155.339C188.666 156.023 188.846 156.662 189.206 157.256C189.584 157.85 190.259 158.57 191.231 159.416C192.473 160.496 193.328 161.477 193.796 162.359C194.264 163.241 194.498 164.276 194.498 165.464C194.498 167.012 194.111 168.2 193.337 169.028C192.581 169.856 191.474 170.27 190.016 170.27ZM199.823 151.1H202.685L204.008 165.626H204.062L205.466 151.1H208.706L210.11 165.626H210.164L211.487 151.1H214.052L212.135 170H208.436L207.086 157.256H207.032L205.682 170H201.74L199.823 151.1ZM215.555 151.1H218.525V170H215.555V151.1ZM220.749 151.1H225.285C226.761 151.1 227.868 151.496 228.606 152.288C229.344 153.08 229.713 154.241 229.713 155.771V165.329C229.713 166.859 229.344 168.02 228.606 168.812C227.868 169.604 226.761 170 225.285 170H220.749V151.1ZM225.231 167.3C225.717 167.3 226.086 167.156 226.338 166.868C226.608 166.58 226.743 166.112 226.743 165.464V155.636C226.743 154.988 226.608 154.52 226.338 154.232C226.086 153.944 225.717 153.8 225.231 153.8H223.719V167.3H225.231ZM235.93 170.27C234.49 170.27 233.392 169.865 232.636 169.055C231.88 168.227 231.502 167.048 231.502 165.518V155.582C231.502 154.052 231.88 152.882 232.636 152.072C233.392 151.244 234.49 150.83 235.93 150.83C237.37 150.83 238.468 151.244 239.224 152.072C239.98 152.882 240.358 154.052 240.358 155.582V157.202H237.55V155.393C237.55 154.151 237.037 153.53 236.011 153.53C234.985 153.53 234.472 154.151 234.472 155.393V165.734C234.472 166.958 234.985 167.57 236.011 167.57C237.037 167.57 237.55 166.958 237.55 165.734V162.035H236.065V159.335H240.358V165.518C240.358 167.048 239.98 168.227 239.224 169.055C238.468 169.865 237.37 170.27 235.93 170.27ZM242.265 151.1H250.365V153.8H245.235V158.795H249.312V161.495H245.235V167.3H250.365V170H242.265V151.1ZM254.395 153.8H251.29V151.1H260.47V153.8H257.365V170H254.395V153.8Z" fill="white"/>
18
- </svg>
package/index.js DELETED
@@ -1 +0,0 @@
1
- export { default } from './lib/transit-departures-widget.js'
package/lib/file-utils.js DELETED
@@ -1,110 +0,0 @@
1
- import path from 'path'
2
- import { fileURLToPath } from 'node:url'
3
- import { readFile, rm, mkdir } from 'node:fs/promises'
4
- import copydir from 'copy-dir'
5
- import beautify from 'js-beautify'
6
- import pug from 'pug'
7
- import untildify from 'untildify'
8
-
9
- /*
10
- * Attempt to parse the specified config JSON file.
11
- */
12
- export async function getConfig(argv) {
13
- try {
14
- const data = await readFile(
15
- path.resolve(untildify(argv.configPath)),
16
- 'utf8',
17
- ).catch((error) => {
18
- console.error(
19
- new Error(
20
- `Cannot find configuration file at \`${argv.configPath}\`. Use config-sample.json as a starting point, pass --configPath option`,
21
- ),
22
- )
23
- throw error
24
- })
25
- const config = JSON.parse(data)
26
-
27
- if (argv.skipImport === true) {
28
- config.skipImport = argv.skipImport
29
- }
30
-
31
- return config
32
- } catch (error) {
33
- console.error(
34
- new Error(
35
- `Cannot parse configuration file at \`${argv.configPath}\`. Check to ensure that it is valid JSON.`,
36
- ),
37
- )
38
- throw error
39
- }
40
- }
41
-
42
- /*
43
- * Get the full path of the template file for generating transit departures widget based on
44
- * config.
45
- */
46
- function getTemplatePath(templateFileName, config) {
47
- let fullTemplateFileName = templateFileName
48
- if (config.noHead !== true) {
49
- fullTemplateFileName += '_full'
50
- }
51
-
52
- if (config.templatePath !== undefined) {
53
- return path.join(
54
- untildify(config.templatePath),
55
- `${fullTemplateFileName}.pug`,
56
- )
57
- }
58
-
59
- return path.join(
60
- fileURLToPath(import.meta.url),
61
- '../../views/widget',
62
- `${fullTemplateFileName}.pug`,
63
- )
64
- }
65
-
66
- /*
67
- * Prepare the specified directory for saving HTML widget by deleting everything.
68
- */
69
- export async function prepDirectory(exportPath) {
70
- await rm(exportPath, { recursive: true, force: true })
71
- try {
72
- await mkdir(exportPath, { recursive: true })
73
- } catch (error) {
74
- if (error.code === 'ENOENT') {
75
- throw new Error(
76
- `Unable to write to ${exportPath}. Try running this command from a writable directory.`,
77
- )
78
- }
79
-
80
- throw error
81
- }
82
- }
83
-
84
- /*
85
- * Copy needed CSS and JS to export path.
86
- */
87
- export function copyStaticAssets(exportPath) {
88
- const staticAssetPath = path.join(
89
- fileURLToPath(import.meta.url),
90
- '../../public',
91
- )
92
- copydir.sync(path.join(staticAssetPath, 'img'), path.join(exportPath, 'img'))
93
- copydir.sync(path.join(staticAssetPath, 'css'), path.join(exportPath, 'css'))
94
- copydir.sync(path.join(staticAssetPath, 'js'), path.join(exportPath, 'js'))
95
- }
96
-
97
- /*
98
- * Render the HTML based on the config.
99
- */
100
- export async function renderFile(templateFileName, templateVars, config) {
101
- const templatePath = getTemplatePath(templateFileName, config)
102
- const html = await pug.renderFile(templatePath, templateVars)
103
-
104
- // Beautify HTML if setting is set
105
- if (config.beautify === true) {
106
- return beautify.html_beautify(html, { indent_size: 2 })
107
- }
108
-
109
- return html
110
- }
package/lib/log-utils.js DELETED
@@ -1,77 +0,0 @@
1
- import readline from 'readline';
2
- import PrettyError from 'pretty-error';
3
- import { noop } from 'lodash-es';
4
- import * as colors from 'yoctocolors';
5
-
6
- const pe = new PrettyError();
7
- pe.start();
8
-
9
- /*
10
- * Returns a log function based on config settings
11
- */
12
- export function log(config) {
13
- if (config.verbose === false) {
14
- return noop;
15
- }
16
-
17
- if (config.logFunction) {
18
- return config.logFunction;
19
- }
20
-
21
- return (text, overwrite) => {
22
- if (overwrite === true) {
23
- readline.clearLine(process.stdout, 0);
24
- readline.cursorTo(process.stdout, 0);
25
- } else {
26
- process.stdout.write('\n');
27
- }
28
-
29
- process.stdout.write(text);
30
- };
31
- }
32
-
33
- /*
34
- * Returns an warning log function based on config settings
35
- */
36
- export function logWarning(config) {
37
- if (config.logFunction) {
38
- return config.logFunction;
39
- }
40
-
41
- return (text) => {
42
- process.stdout.write(`\n${formatWarning(text)}\n`);
43
- };
44
- }
45
-
46
- /*
47
- * Returns an error log function based on config settings
48
- */
49
- export function logError(config) {
50
- if (config.logFunction) {
51
- return config.logFunction;
52
- }
53
-
54
- return (text) => {
55
- process.stdout.write(`\n${formatError(text)}\n`);
56
- };
57
- }
58
-
59
- /*
60
- * Format console warning text
61
- */
62
- export function formatWarning(text) {
63
- const warningMessage = `${colors.underline('Warning')}: ${text}`;
64
- return colors.yellow(warningMessage);
65
- }
66
-
67
- /*
68
- * Format console error text
69
- */
70
- export function formatError(error) {
71
- const messageText = error instanceof Error ? error.message : error;
72
- const errorMessage = `${colors.underline('Error')}: ${messageText.replace(
73
- 'Error: ',
74
- '',
75
- )}`;
76
- return colors.red(errorMessage);
77
- }
@@ -1,97 +0,0 @@
1
- import path from 'path'
2
- import { clone, omit } from 'lodash-es'
3
- import { writeFile } from 'node:fs/promises'
4
- import { importGtfs, openDb } from 'gtfs'
5
- import sanitize from 'sanitize-filename'
6
- import Timer from 'timer-machine'
7
-
8
- import { copyStaticAssets, prepDirectory } from './file-utils.js'
9
- import { log, logWarning, logError } from './log-utils.js'
10
- import {
11
- generateTransitDeparturesWidgetHtml,
12
- generateTransitDeparturesWidgetJson,
13
- setDefaultConfig,
14
- } from './utils.js'
15
-
16
- /*
17
- * Generate transit departures widget HTML from GTFS.
18
- */
19
- async function transitDeparturesWidget(initialConfig) {
20
- const config = setDefaultConfig(initialConfig)
21
- config.log = log(config)
22
- config.logWarning = logWarning(config)
23
- config.logError = logError(config)
24
-
25
- try {
26
- openDb(config)
27
- } catch (error) {
28
- if (error instanceof Error && error.code === 'SQLITE_CANTOPEN') {
29
- config.logError(
30
- `Unable to open sqlite database "${config.sqlitePath}" defined as \`sqlitePath\` config.json. Ensure the parent directory exists or remove \`sqlitePath\` from config.json.`,
31
- )
32
- }
33
-
34
- throw error
35
- }
36
-
37
- if (!config.agency) {
38
- throw new Error('No agency defined in `config.json`')
39
- }
40
-
41
- const timer = new Timer()
42
- const agencyKey = config.agency.agency_key
43
- const exportPath = path.join(process.cwd(), 'html', sanitize(agencyKey))
44
-
45
- timer.start()
46
-
47
- if (!config.skipImport) {
48
- // Import GTFS
49
- const gtfsImportConfig = clone(omit(config, 'agency'))
50
- gtfsImportConfig.agencies = [
51
- {
52
- agency_key: config.agency.agency_key,
53
- path: config.agency.gtfs_static_path,
54
- url: config.agency.gtfs_static_url,
55
- },
56
- ]
57
-
58
- await importGtfs(gtfsImportConfig)
59
- }
60
-
61
- await prepDirectory(exportPath)
62
- await prepDirectory(path.join(exportPath, 'data'))
63
-
64
- if (config.noHead !== true) {
65
- copyStaticAssets(exportPath)
66
- }
67
-
68
- config.log(`${agencyKey}: Generating Transit Departures Widget HTML`)
69
-
70
- config.assetPath = ''
71
-
72
- // Generate JSON of routes and stops
73
- const { routes, stops } = generateTransitDeparturesWidgetJson(config)
74
- await writeFile(
75
- path.join(exportPath, 'data', 'routes.json'),
76
- JSON.stringify(routes, null, 2),
77
- )
78
- await writeFile(
79
- path.join(exportPath, 'data', 'stops.json'),
80
- JSON.stringify(stops, null, 2),
81
- )
82
-
83
- const html = await generateTransitDeparturesWidgetHtml(config)
84
- await writeFile(path.join(exportPath, 'index.html'), html)
85
-
86
- timer.stop()
87
-
88
- // Print stats
89
- config.log(
90
- `${agencyKey}: Transit Departures Widget HTML created at ${exportPath}`,
91
- )
92
-
93
- const seconds = Math.round(timer.time() / 1000)
94
- config.log(`${agencyKey}: HTML generation required ${seconds} seconds`)
95
- }
96
-
97
- export default transitDeparturesWidget