Skip to content

Commit

Permalink
wip: nextjs migration
Browse files Browse the repository at this point in the history
  • Loading branch information
esemyonov committed Nov 28, 2023
1 parent fb360d8 commit f97b9ee
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions scripts/update-policies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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 { glob } from "glob";
import { JSONSchema7 } from "json-schema";
import { Heading as AstHeading } from "mdast";
import { toString } from "mdast-util-to-string";
Expand Down Expand Up @@ -163,7 +163,7 @@ async function render(markdown: string): Promise<RenderResult> {
};
}

async function processProperties(properties) {
async function processProperties(properties: any) {
const tasks = Object.keys(properties).map(async (key) => {
if (properties[key].description) {
const { html } = await render(properties[key].description);
Expand All @@ -176,7 +176,7 @@ async function processProperties(properties) {
return Promise.all(tasks);
}

function getPolicyFilePaths(policyId) {
function getPolicyFilePaths(policyId: string) {
return {
iconSvg: path.join(policiesDir, policyId, "icon.svg"),
introMd: path.join(policiesDir, policyId, "intro.md"),
Expand Down Expand Up @@ -298,23 +298,11 @@ export async function run() {
);
const policyConfig = JSON.parse(policyConfigJson);

const matches: string[] = await new Promise((resolve, reject) => {
glob(
"**/schema.json",
{
cwd: policiesDir,
},
(err, result) => {
if (err) {
reject(err);
} else {
resolve(result);
}
},
);
const matches: string[] = await glob("**/schema.json", {
cwd: policiesDir,
});

const policies = [];
const policies: any = [];
const tasks = matches.map(async (match) => {
const policyId = match.replace("/schema.json", "");
const schemaPath = path.join(policiesDir, match);
Expand Down Expand Up @@ -364,10 +352,10 @@ export async function run() {
schemaJson,
),
);
const handler = schema.properties.handler as JSONSchema7;
const handler = schema.properties!.handler as JSONSchema7;
meta.defaultHandler = {
export: (handler.properties.export as JSONSchema7).const,
module: (handler.properties.module as JSONSchema7).const,
export: (handler.properties!.export as JSONSchema7).const,
module: (handler.properties!.module as JSONSchema7).const,
options: {},
};
}
Expand Down Expand Up @@ -466,7 +454,7 @@ async function getExampleHtml(

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

const properties = (schema.properties.handler as any).properties.options
const properties = (schema.properties!.handler as any).properties.options
?.properties;
if (!properties) {
return;
Expand Down Expand Up @@ -502,7 +490,7 @@ export async function watch() {
ignoreInitial: true,
});

function changed(path) {
function changed() {
run().catch(console.error);
}

Expand Down

0 comments on commit f97b9ee

Please sign in to comment.