@nyc-transit-kit/cli 0.1.0
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/LICENSE +21 -0
- package/README.md +5 -0
- package/bin/ntk +3 -0
- package/bin/nyc-transit +3 -0
- package/package.json +58 -0
- package/scripts/build-binary.ts +113 -0
- package/scripts/build.ts +1 -0
- package/src/build-info.ts +2 -0
- package/src/commands/catalog.ts +59 -0
- package/src/commands/mta.ts +610 -0
- package/src/commands/nyc-dot.ts +212 -0
- package/src/commands/nyc-open-data.ts +243 -0
- package/src/commands/root.ts +38 -0
- package/src/commands/shared.ts +144 -0
- package/src/commands/socrata.ts +206 -0
- package/src/commands/soda3-shared.ts +103 -0
- package/src/commands/types.ts +33 -0
- package/src/config.ts +21 -0
- package/src/files.ts +27 -0
- package/src/index.ts +2 -0
- package/src/main.ts +205 -0
- package/src/output.ts +39 -0
- package/src/runtime.ts +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 nyc-transit-kit contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/bin/ntk
ADDED
package/bin/nyc-transit
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nyc-transit-kit/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"bin": {
|
|
7
|
+
"ntk": "./bin/ntk",
|
|
8
|
+
"nyc-transit": "./bin/nyc-transit"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./src/index.ts"
|
|
12
|
+
},
|
|
13
|
+
"types": "./src/index.ts",
|
|
14
|
+
"files": [
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"README.md",
|
|
17
|
+
"bin",
|
|
18
|
+
"scripts",
|
|
19
|
+
"src"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc -b",
|
|
23
|
+
"test": "bun test ./test"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@effect/platform-bun": "4.0.0-beta.83",
|
|
27
|
+
"@nyc-transit-kit/contracts": "0.1.0",
|
|
28
|
+
"@nyc-transit-kit/mta": "0.1.0",
|
|
29
|
+
"@nyc-transit-kit/nyc-dot": "0.1.0",
|
|
30
|
+
"@nyc-transit-kit/nyc-open-data": "0.1.0",
|
|
31
|
+
"@nyc-transit-kit/soda3": "0.1.0",
|
|
32
|
+
"effect": "4.0.0-beta.83"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/mannyc2/nyc-transit-kit.git",
|
|
41
|
+
"directory": "packages/cli"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/mannyc2/nyc-transit-kit#readme",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/mannyc2/nyc-transit-kit/issues"
|
|
46
|
+
},
|
|
47
|
+
"keywords": [
|
|
48
|
+
"bun",
|
|
49
|
+
"effect",
|
|
50
|
+
"mta",
|
|
51
|
+
"nyc",
|
|
52
|
+
"socrata",
|
|
53
|
+
"transit"
|
|
54
|
+
],
|
|
55
|
+
"engines": {
|
|
56
|
+
"bun": ">=1.3.14"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { mkdir } from "node:fs/promises"
|
|
2
|
+
import { join } from "node:path"
|
|
3
|
+
import { pathToFileURL } from "node:url"
|
|
4
|
+
import { releaseVersion, schemaVersion } from "@nyc-transit-kit/contracts/metadata"
|
|
5
|
+
import { CliReleaseArtifact, CliReleaseManifest } from "@nyc-transit-kit/contracts/release"
|
|
6
|
+
import * as Schema from "effect/Schema"
|
|
7
|
+
|
|
8
|
+
const binaryPath = "dist/ntk"
|
|
9
|
+
const manifestPath = "dist/ntk-release-manifest.json"
|
|
10
|
+
|
|
11
|
+
const releasePlatform = () => {
|
|
12
|
+
switch (process.platform) {
|
|
13
|
+
case "darwin":
|
|
14
|
+
return "darwin"
|
|
15
|
+
case "linux":
|
|
16
|
+
return "linux"
|
|
17
|
+
case "win32":
|
|
18
|
+
return "win32"
|
|
19
|
+
default:
|
|
20
|
+
return undefined
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const releaseArchitecture = () => {
|
|
25
|
+
switch (process.arch) {
|
|
26
|
+
case "arm64":
|
|
27
|
+
return "arm64"
|
|
28
|
+
case "x64":
|
|
29
|
+
return "x64"
|
|
30
|
+
default:
|
|
31
|
+
return undefined
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const currentCommit = () => {
|
|
36
|
+
const result = Bun.spawnSync(["git", "rev-parse", "HEAD"], {
|
|
37
|
+
stderr: "pipe",
|
|
38
|
+
stdout: "pipe"
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
if (!result.success) {
|
|
42
|
+
return "unknown"
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return result.stdout.toString().trim()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const sha256 = async (path: string) => {
|
|
49
|
+
const digest = await crypto.subtle.digest("SHA-256", await Bun.file(path).arrayBuffer())
|
|
50
|
+
return Array.from(new Uint8Array(digest))
|
|
51
|
+
.map((byte) => byte.toString(16).padStart(2, "0"))
|
|
52
|
+
.join("")
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await mkdir("dist", { recursive: true })
|
|
56
|
+
|
|
57
|
+
const platform = releasePlatform()
|
|
58
|
+
const arch = releaseArchitecture()
|
|
59
|
+
|
|
60
|
+
if (platform === undefined || arch === undefined) {
|
|
61
|
+
console.error(`Unsupported release target: ${process.platform}/${process.arch}`)
|
|
62
|
+
process.exit(1)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const commit = currentCommit()
|
|
66
|
+
const buildTarget = `${platform}-${arch}`
|
|
67
|
+
const result = await Bun.build({
|
|
68
|
+
entrypoints: ["packages/cli/src/main.ts"],
|
|
69
|
+
define: {
|
|
70
|
+
"process.env.NTK_BUILD_COMMIT": JSON.stringify(commit),
|
|
71
|
+
"process.env.NTK_BUILD_TARGET": JSON.stringify(buildTarget)
|
|
72
|
+
},
|
|
73
|
+
compile: {
|
|
74
|
+
outfile: binaryPath
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
if (!result.success) {
|
|
79
|
+
for (const log of result.logs) {
|
|
80
|
+
console.error(log)
|
|
81
|
+
}
|
|
82
|
+
process.exit(1)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const manifest = CliReleaseManifest.make({
|
|
86
|
+
manifestVersion: 1,
|
|
87
|
+
packageName: "@nyc-transit-kit/cli",
|
|
88
|
+
version: releaseVersion,
|
|
89
|
+
schemaVersion,
|
|
90
|
+
schemaCommit: commit,
|
|
91
|
+
generatedSourceCommit: commit,
|
|
92
|
+
builtAt: new Date().toISOString(),
|
|
93
|
+
artifacts: [
|
|
94
|
+
CliReleaseArtifact.make({
|
|
95
|
+
platform,
|
|
96
|
+
arch,
|
|
97
|
+
url: pathToFileURL(join(process.cwd(), binaryPath)).href,
|
|
98
|
+
sha256: await sha256(binaryPath),
|
|
99
|
+
size: Bun.file(binaryPath).size,
|
|
100
|
+
signed: false
|
|
101
|
+
})
|
|
102
|
+
]
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
if (!Schema.is(CliReleaseManifest)(manifest)) {
|
|
106
|
+
console.error("Generated CLI release manifest failed schema validation.")
|
|
107
|
+
process.exit(1)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
await Bun.write(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`)
|
|
111
|
+
|
|
112
|
+
console.log(`Built ${binaryPath}`)
|
|
113
|
+
console.log(`Wrote ${manifestPath}`)
|
package/scripts/build.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
console.log("CLI build plan is scaffolded. Binary build implementation is deferred.")
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { buildCatalogSearchUrl, catalogSearch } from "@nyc-transit-kit/soda3/catalog"
|
|
2
|
+
import * as Effect from "effect/Effect"
|
|
3
|
+
import * as Command from "effect/unstable/cli/Command"
|
|
4
|
+
import * as Flag from "effect/unstable/cli/Flag"
|
|
5
|
+
import { runEffect, writeSuccess } from "./shared"
|
|
6
|
+
import { CliCommandContext } from "./types"
|
|
7
|
+
|
|
8
|
+
export const catalogCommandPaths: ReadonlyArray<ReadonlyArray<string>> = [["catalog", "search"]]
|
|
9
|
+
|
|
10
|
+
export const handleCatalogSearch = (config: {
|
|
11
|
+
readonly domain: string
|
|
12
|
+
readonly query: string
|
|
13
|
+
readonly dryRun: boolean
|
|
14
|
+
}) =>
|
|
15
|
+
Effect.gen(function* () {
|
|
16
|
+
const context = yield* CliCommandContext
|
|
17
|
+
const tokens = ["catalog", "search"]
|
|
18
|
+
const request = {
|
|
19
|
+
domain: config.domain,
|
|
20
|
+
query: config.query
|
|
21
|
+
}
|
|
22
|
+
const url = yield* buildCatalogSearchUrl(request)
|
|
23
|
+
|
|
24
|
+
if (config.dryRun) {
|
|
25
|
+
return yield* writeSuccess(context, "socrata", {
|
|
26
|
+
dryRun: true,
|
|
27
|
+
method: "GET",
|
|
28
|
+
url: url.toString()
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return yield* runEffect(
|
|
33
|
+
context,
|
|
34
|
+
"socrata",
|
|
35
|
+
tokens,
|
|
36
|
+
catalogSearch(request).pipe(Effect.provide(context.runtime.soda3Layer))
|
|
37
|
+
)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const catalogSearchCommand = Command.make(
|
|
41
|
+
"search",
|
|
42
|
+
{
|
|
43
|
+
domain: Flag.string("domain").pipe(
|
|
44
|
+
Flag.withDescription("Socrata domain without protocol, such as data.cityofnewyork.us.")
|
|
45
|
+
),
|
|
46
|
+
query: Flag.string("query").pipe(
|
|
47
|
+
Flag.withDescription("Search text for Socrata Discovery API.")
|
|
48
|
+
),
|
|
49
|
+
dryRun: Flag.boolean("dry-run").pipe(
|
|
50
|
+
Flag.withDescription("Print the planned request without contacting the provider.")
|
|
51
|
+
)
|
|
52
|
+
},
|
|
53
|
+
handleCatalogSearch
|
|
54
|
+
).pipe(Command.withShortDescription("Search a Socrata catalog."))
|
|
55
|
+
|
|
56
|
+
export const catalogCommand = Command.make("catalog").pipe(
|
|
57
|
+
Command.withShortDescription("Socrata catalog commands."),
|
|
58
|
+
Command.withSubcommands([catalogSearchCommand])
|
|
59
|
+
)
|