Skip to content

Commit

Permalink
Add tsup and schema typings (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Corb3nik authored Dec 31, 2024
1 parent bc7d436 commit 36de22d
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 35 deletions.
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@caido/plugin-manifest",
"version": "0.2.0",
"version": "0.2.1",
"description": "Validation for the plugin manifest",
"author": "Caido Labs Inc. <[email protected]>",
"license": "MIT",
Expand All @@ -17,10 +17,12 @@
"access": "public"
},
"scripts": {
"build": "rm -rf dist/*; tsc -p tsconfig.build.json",
"build": "tsup",
"generate": "json2ts src/schema.json > src/schema.generated.ts",
"lint": "eslint src/ --fix",
"test": "vitest run",
"typecheck": "tsc --noEmit"
"typecheck": "tsc --noEmit",
"prepublish": "pnpm generate"
},
"dependencies": {
"ajv": "^8.16.0"
Expand All @@ -34,6 +36,8 @@
"eslint-import-resolver-typescript": "3.6.1",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-prettier": "5.1.3",
"json-schema-to-typescript": "^15.0.3",
"tsup": "^8.0.2",
"typescript": "5.4.3",
"vitest": "1.4.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from "fs";

import { describe, expect, it } from "vitest";

import { validateManifest } from "./validator.js";
import { validateManifest } from "./index";

describe("Manifest", () => {
it("validates frontend manifest", () => {
Expand Down
19 changes: 18 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
export { validateManifest } from "./validator.js";
import { Ajv } from "ajv";

import schema from "./schema.json" with { type: "json" };

export * from "./schema.generated";

const ajv = new Ajv();

export function validateManifest(data: unknown): boolean {
console.log("[*] Validating manifest data");
const validate = ajv.compile(schema);
const valid = validate(data);
if (!valid) {
console.log(`[-] Errors: ${JSON.stringify(validate.errors, null, 2)}`);
return false;
}
return true;
}
55 changes: 55 additions & 0 deletions src/schema.generated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* eslint-disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
*/

export type Schema = Manifest;
export type ManifestID = string;
export type ManifestPlugin =
| {
backend?: ManifestFrontendPluginConnection | null;
entrypoint?: string | null;
id: ManifestID;
kind: "frontend";
name?: string | null;
style?: string | null;
[k: string]: unknown;
}
| {
entrypoint: string;
id: ManifestID;
kind: "backend";
name?: string | null;
runtime: ManifestBackendPluginRuntime;
[k: string]: unknown;
}
| {
id: ManifestID;
kind: "workflow";
name?: string;
definition: string;
[k: string]: unknown;
};
export type ManifestBackendPluginRuntime = "javascript";

export interface Manifest {
author?: ManifestAuthor | null;
description?: string | null;
id: ManifestID;
name?: string | null;
plugins: ManifestPlugin[];
version: string;
[k: string]: unknown;
}
export interface ManifestAuthor {
email?: string | null;
name?: string | null;
url?: string | null;
[k: string]: unknown;
}
export interface ManifestFrontendPluginConnection {
id: ManifestID;
[k: string]: unknown;
}
16 changes: 0 additions & 16 deletions src/validator.ts

This file was deleted.

10 changes: 0 additions & 10 deletions tsconfig.build.json

This file was deleted.

6 changes: 2 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
{
"compilerOptions": {
"target": "esnext",
"module": "NodeNext",

"module": "esnext",
"moduleResolution": "bundler",
"noImplicitAny": true,
"noUncheckedIndexedAccess": true,
"strict": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"noUnusedLocals": true,

"moduleResolution": "NodeNext",
"esModuleInterop": true,
"sourceMap": true,
"useDefineForClassFields": true,
Expand Down
10 changes: 10 additions & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'tsup'

export default defineConfig({
entry: ['src/index.ts'],
format: ['esm'],
dts: true,
clean: true,
sourcemap: true,
minify: false,
})

0 comments on commit 36de22d

Please sign in to comment.