Skip to content

Commit

Permalink
Merge pull request #174 from bluecadet/zod
Browse files Browse the repository at this point in the history
Zod
  • Loading branch information
claytercek authored Nov 13, 2024
2 parents 224f368 + 7a1c78b commit 4056528
Show file tree
Hide file tree
Showing 42 changed files with 691 additions and 458 deletions.
8 changes: 8 additions & 0 deletions .changeset/itchy-ties-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@bluecadet/launchpad-content": minor
"@bluecadet/launchpad-monitor": minor
"@bluecadet/launchpad-utils": minor
"@bluecadet/launchpad-cli": minor
---

convert configs to zod validators
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
- name: lint
run: npm run lint

- name: lint dependency versions
run: npx sherif

- name: Validate types
run: npm run build

Expand Down
154 changes: 128 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "launchpad",
"private": "true",
"private": true,
"version": "0.0.1",
"description": "monorepo for @bluecadet/launchpad and friends",
"scripts": {
Expand Down Expand Up @@ -32,10 +32,12 @@
"@changesets/changelog-github": "^0.4.6",
"@changesets/cli": "^2.23.0",
"@types/node": "^20.3.1",
"sherif": "^1.0.1",
"typescript": "^5.1.3",
"vitest": "^2.1.4"
},
"engines": {
"node": ">=18"
}
},
"packageManager": "[email protected]"
}
3 changes: 2 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"chalk": "^5.0.0",
"dotenv": "^16.4.5",
"neverthrow": "^8.1.1",
"yargs": "^17.7.2"
"yargs": "^17.7.2",
"zod": "^3.23.8"
},
"optionalDependencies": {
"@bluecadet/launchpad-content": "~2.0.0-next.2",
Expand Down
8 changes: 5 additions & 3 deletions packages/cli/src/commands/content.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { ResultAsync, err, ok } from "neverthrow";
import type { LaunchpadArgv } from "../cli.js";
import { ImportError } from "../errors.js";
import { ConfigError, ImportError } from "../errors.js";
import { handleFatalError, initializeLogger, loadConfigAndEnv } from "../utils/command-utils.js";

export function content(argv: LaunchpadArgv) {
return loadConfigAndEnv(argv)
.mapErr((error) => handleFatalError(error, console))
.andThen(initializeLogger)
.andThen(({ config, rootLogger }) => {
return importLaunchpadContent()
.andThen(({ default: LaunchpadContent }) => {
if (!config.content) {
return err(new Error("No content config found in your config file."));
return err(new ConfigError("No content config found in your config file."));
}

const contentInstance = new LaunchpadContent(config.content, rootLogger);
Expand All @@ -23,9 +24,10 @@ export function content(argv: LaunchpadArgv) {
export function importLaunchpadContent() {
return ResultAsync.fromPromise(
import("@bluecadet/launchpad-content"),
() =>
(e) =>
new ImportError(
'Could not find module "@bluecadet/launchpad-content". Make sure you have installed it.',
{ cause: e },
),
);
}
9 changes: 5 additions & 4 deletions packages/cli/src/commands/monitor.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { ResultAsync, err, ok } from "neverthrow";
import type { LaunchpadArgv } from "../cli.js";
import { ImportError, MonitorError } from "../errors.js";
import { ConfigError, ImportError, MonitorError } from "../errors.js";
import { handleFatalError, initializeLogger, loadConfigAndEnv } from "../utils/command-utils.js";

export function monitor(argv: LaunchpadArgv) {
return loadConfigAndEnv(argv)
.mapErr((error) => handleFatalError(error, console))
.andThen(initializeLogger)
.andThen(({ config, rootLogger }) => {
return importLaunchpadMonitor()
.andThen(({ default: LaunchpadMonitor }) => {
if (!config.monitor) {
return err(new Error("No monitor config found in your config file."));
return err(new ConfigError("No monitor config found in your config file."));
}

const monitorInstance = new LaunchpadMonitor(config.monitor, rootLogger);
Expand All @@ -19,13 +20,13 @@ export function monitor(argv: LaunchpadArgv) {
.andThrough((monitorInstance) => {
return ResultAsync.fromPromise(
monitorInstance.connect(),
() => new MonitorError("Failed to connect to monitor"),
(e) => new MonitorError("Failed to connect to monitor", { cause: e }),
);
})
.andThrough((monitorInstance) => {
return ResultAsync.fromPromise(
monitorInstance.start(),
() => new MonitorError("Failed to start monitor"),
(e) => new MonitorError("Failed to start monitor", { cause: e }),
);
})
.orElse((error) => handleFatalError(error, rootLogger));
Expand Down
Loading

0 comments on commit 4056528

Please sign in to comment.