diff --git a/package.json b/package.json index 1646004..44ae52e 100644 --- a/package.json +++ b/package.json @@ -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. ", "license": "MIT", @@ -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" @@ -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" }, diff --git a/src/index.spec.ts b/src/index.spec.ts index 2a28ce1..187d8d3 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -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", () => { diff --git a/src/index.ts b/src/index.ts index b2410e2..650637c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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; +} diff --git a/src/schema.generated.ts b/src/schema.generated.ts new file mode 100644 index 0000000..8c02f16 --- /dev/null +++ b/src/schema.generated.ts @@ -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; +} diff --git a/src/validator.ts b/src/validator.ts deleted file mode 100644 index 260db71..0000000 --- a/src/validator.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { Ajv } from "ajv"; - -import schema from "./schema.json" with { type: "json" }; - -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; -} diff --git a/tsconfig.build.json b/tsconfig.build.json deleted file mode 100644 index 9633675..0000000 --- a/tsconfig.build.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "declaration": true, - "outDir": "./dist", - "noEmit": false, - "allowJs": true - }, - "exclude": ["./src/**/*.spec.ts"] -} diff --git a/tsconfig.json b/tsconfig.json index 541de9d..8a51450 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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, diff --git a/tsup.config.ts b/tsup.config.ts new file mode 100644 index 0000000..0c85f62 --- /dev/null +++ b/tsup.config.ts @@ -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, +}) \ No newline at end of file