Skip to content

Commit

Permalink
fixed policy options generation
Browse files Browse the repository at this point in the history
  • Loading branch information
ntotten committed Oct 5, 2023
1 parent 3ab72e8 commit 167b229
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
7 changes: 7 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"concurrently": "^8.2.0",
"glob": "^8.1.0",
"jsdom": "^22.0.0",
"json-schema": "^0.4.0",
"prettier": "^2.8.8",
"prettier-plugin-organize-imports": "^3.1.1",
"ts-node": "^10.8.2",
Expand Down
22 changes: 13 additions & 9 deletions scripts/update-policies.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { dereference } from "@apidevtools/json-schema-ref-parser";
import { JSONSchema } from "@apidevtools/json-schema-ref-parser/dist/lib/types";
import { render } from "@zuplo/md-tools";
import arg from "arg";
import chalk from "chalk";
import chokidar from "chokidar";
import { existsSync } from "fs";
import { copyFile, mkdir, readdir, readFile, rm, writeFile } from "fs/promises";
import glob from "glob";
import { JSONSchema7 } from "json-schema";
import path from "path";
import prettier from "prettier";
import React from "react";
import { renderToStaticMarkup } from "react-dom/server";

type PolicySchema = JSONSchema & {
type PolicySchema = JSONSchema7 & {
isPreview?: boolean;
isDeprecated?: boolean;
isPaidAddOn?: boolean;
Expand All @@ -21,7 +21,11 @@ type PolicySchema = JSONSchema & {

type PolicyProperties = Record<
string,
{ description: string; properties?: PolicyProperties }
{
default?: boolean | string | number;
description: string;
properties?: PolicyProperties;
}
>;

// NOTE: This component is used to generate policy HTML in the policy script
Expand Down Expand Up @@ -98,7 +102,7 @@ function stringify(obj: any) {
async function processProperties(properties) {
const tasks = Object.keys(properties).map(async (key) => {
if (properties[key].description) {
const html = await render(properties[key].description);
const { html } = await render(properties[key].description);
properties[key].description = html;
}
if (properties[key].properties) {
Expand Down Expand Up @@ -252,10 +256,10 @@ async function run() {
schemaJson
)
);
const handler = schema.properties.handler as any;
const handler = schema.properties.handler as JSONSchema7;
meta.defaultHandler = {
export: handler.properties.export.const,
module: handler.properties.module.const,
export: (handler.properties.export as JSONSchema7).const,
module: (handler.properties.module as JSONSchema7).const,
options: {},
};
}
Expand Down Expand Up @@ -377,10 +381,10 @@ async function getExampleHtml(
throw new Error("Invalid schema");
}

const description = await render(schema.description);
const { html: description } = await render(schema.description);

const properties = (schema.properties.handler as any).properties.options
?.properties;

if (properties && Object.keys(properties).length === 0) {
console.warn(
chalk.yellow(
Expand Down

1 comment on commit 167b229

@vercel
Copy link

@vercel vercel bot commented on 167b229 Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./

docs-git-main.zuplosite.com
docs-site.zuplosite.com
docs.zuplosite.com
docs.zuplopreview.net

Please sign in to comment.