Skip to content

Commit 5472846

Browse files
ondreianclaude
andauthored
feat: add validate --input option and refactor project structure (#8)
## Major Changes ### Add --input option to validate command - Support validating specific mapdb.json files via --input/-i flag - Maintains backward compatibility with existing tmp dir behavior - Perfect for CI/CD pipelines and automated workflows ### Project Structure Refactor - Rename mapdb/ → src/ (conventional structure) - Rename mapdb.ts → cartographer.ts (matches CLI tool name) - Update all imports and references throughout codebase ### Consistent Branding - CLI now shows "cartographer" instead of "mapdb" in help - Dynamic version reading from package.json - Binary output: dist/cartographer (was dist/mapdb) - GitHub release assets updated to upload dist/cartographer ### Code Cleanup - Consolidate duplicate validation logic into single validateMapdb function - Remove unused validate.ts (replaced by validateMapdb) - All tests passing with updated imports and structure ## Usage Examples ```bash # Validate specific file (new) bunx @elanthia/cartographer validate --input ./mapdb.json # Validate from tmp dir (existing behavior) bunx @elanthia/cartographer validate # Version and help now show proper branding bunx @elanthia/cartographer --version # 0.4.0 bunx @elanthia/cartographer --help # Usage: cartographer [options] ``` This enables the GitHub Actions PR validation workflow in the mapdb repository to validate built mapdb.json files directly without tmp directory conventions. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <[email protected]>
1 parent 1c69f2e commit 5472846

21 files changed

+205
-51
lines changed

.github/workflows/release-please.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ jobs:
5050
env:
5151
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5252
run: |
53-
gh release upload ${{ needs.release-please.outputs.tag_name }} dist/mapdb --clobber
53+
gh release upload ${{ needs.release-please.outputs.tag_name }} dist/cartographer --clobber

mapdb/tasks/validate.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
22
"name": "@elanthia/cartographer",
3-
"module": "mapdb/index.ts",
3+
"module": "src/index.ts",
44
"version": "0.4.0",
55
"files": [
6-
"mapdb/**/*"
6+
"src/**/*"
77
],
88
"type": "module",
99
"scripts": {
10-
"compile": "bun build --compile ./mapdb/mapdb.ts --outfile=dist/mapdb"
10+
"compile": "bun build --compile ./src/cartographer.ts --outfile=dist/cartographer"
1111
},
1212
"bin": {
13-
"mapdb": "./mapdb/mapdb.ts"
13+
"cartographer": "./src/cartographer.ts"
1414
},
1515
"devDependencies": {
1616
"bun-types": "latest"

mapdb/mapdb.ts renamed to src/cartographer.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import ora from "ora"
33
import { program } from "commander"
44
import * as Tasks from "./tasks"
55
import * as Project from "./project"
6+
import packageJson from "../package.json"
7+
8+
program
9+
.name("cartographer")
10+
.version(packageJson.version)
611

712
program.command("download")
813
.alias("dl")
@@ -23,24 +28,29 @@ program.command("download")
2328

2429
program.command("validate")
2530
.alias("v")
26-
.description("validate a mapdb in the local tmp dir")
31+
.description("validate a mapdb file")
2732
.option("--dr", "run in dragonrealms mode", false)
28-
.action(async (args: {dr: boolean})=> {
29-
const project = args.dr ? Project.Dragonrealms : Project.Gemstone
33+
.option("-i, --input <file>", "input mapdb.json file path")
34+
.action(async (args: {dr: boolean, input?: string})=> {
35+
const baseProject = args.dr ? Project.Dragonrealms : Project.Gemstone
3036
const then = performance.now()
3137
const spinner = ora()
32-
spinner.start(`validating mapdb at ${project.route("/map.json")}...`)
33-
const {rooms, errors} = await Tasks.validate({project})
38+
39+
// Use input file or default to tmp directory path
40+
const filePath = args.input || baseProject.route("/map.json")
41+
42+
spinner.start(`validating mapdb at ${filePath}...`)
43+
const {rooms, errors} = await Tasks.validateMapdb({filePath})
3444
const runtime = Math.round(performance.now() - then)
3545

3646
if (errors.length == 0) {
3747
spinner.succeed(`[${runtime}ms] validated ${rooms.length} rooms`)
3848
return process.exit(0)
3949
}
50+
4051
spinner.clear()
4152
console.table(errors)
4253
spinner.fail(`[${runtime}ms] found ${errors.length} issues`)
43-
4454
process.exit(1)
4555
})
4656

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

mapdb/tasks/git.ts renamed to src/tasks/git.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Ora } from "ora";
22
import {type Project} from "../project"
33
import { State, Room } from "../room/room";
44
import { download } from "./download";
5-
import { validate } from "./validate"
5+
import { validateMapdb } from "./validate-mapdb"
66

77
/**
88
* Tracks the results of git operations performed on rooms
@@ -45,7 +45,7 @@ export async function git (config : SeedConfig) {
4545
await config.project.gitSetup()
4646
}
4747

48-
const {errors: validationErrors, rooms} = await validate(config)
48+
const {errors: validationErrors, rooms} = await validateMapdb({filePath: config.project.route("/map.json")})
4949
const operations: Operations = {
5050
updated: 0,
5151
skipped: 0,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { download } from "./download"
2-
import { validate } from "./validate"
32
import { git } from "./git"
43
import { reconstruct } from "./reconstruct"
54
import { validateFiles } from "./validate-files"
6-
export { download, validate, git, reconstruct, validateFiles }
5+
import { validateMapdb } from "./validate-mapdb"
6+
export { download, git, reconstruct, validateFiles, validateMapdb }

0 commit comments

Comments
 (0)