From 7a3e1e90bdd33858eb5243d4419b69bb2dbe949d Mon Sep 17 00:00:00 2001 From: BluJ Date: Tue, 2 May 2023 15:50:06 -0600 Subject: [PATCH] chore: fix the old spec to build --- lib/test/configBuilder.test.ts | 22 ++++++++++------------ scripts/oldSpecToBuilder.ts | 14 +++++++------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/lib/test/configBuilder.test.ts b/lib/test/configBuilder.test.ts index fa05f4f..cbd56d2 100644 --- a/lib/test/configBuilder.test.ts +++ b/lib/test/configBuilder.test.ts @@ -384,19 +384,17 @@ describe("values", () => { }) }) test("datetime", async () => { - const value = Value.dynamicDatetime<{ test: "a" }>( - async ({ effects, utils }) => { - ;async () => { - ;(await utils.getOwnWrapperData("/test").once()) satisfies "a" - } + const value = Value.dynamicDatetime<{ test: "a" }>(async ({ utils }) => { + ;async () => { + ;(await utils.getOwnWrapperData("/test").once()) satisfies "a" + } - return { - name: "Testing", - required: { default: null }, - inputmode: "date", - } - }, - ) + return { + name: "Testing", + required: { default: null }, + inputmode: "date", + } + }) const validator = value.validator validator.unsafeCast("2021-01-01") validator.unsafeCast(null) diff --git a/scripts/oldSpecToBuilder.ts b/scripts/oldSpecToBuilder.ts index 0c4dc34..46ceda1 100644 --- a/scripts/oldSpecToBuilder.ts +++ b/scripts/oldSpecToBuilder.ts @@ -2,13 +2,12 @@ import * as fs from "fs" // https://stackoverflow.com/questions/2970525/converting-any-string-into-camel-case export function camelCase(value: string) { - return value.replace( - /^([A-Z])|[\s-_](\w)/g, - function (match, p1, p2, offset) { + return value + .replace(/([\(\)\[\]])/g, "") + .replace(/^([A-Z])|[\s-_](\w)/g, function (match, p1, p2, offset) { if (p2) return p2.toUpperCase() return p1.toLowerCase() - }, - ) + }) } export async function oldSpecToBuilder( @@ -41,6 +40,7 @@ export default async function makeFileContentFromOld( import {WrapperData} from '${wrapperData}' `) const data = await inputData + const hammerWrapperData = !nested ? ".withWrapperData()" : "" const namedConsts = new Set(["Config", "Value", "List"]) const configName = newConst( @@ -73,7 +73,7 @@ export default async function makeFileContentFromOld( for (const [key, value] of Object.entries(data)) { const variableName = maybeNewConst(key, convertValueSpec(value)) - answer += `${JSON.stringify(key)}: ${variableName},` + answer += `${JSON.stringify(key)}: ${variableName}${hammerWrapperData},` } return `${answer}}` } @@ -364,7 +364,7 @@ export default async function makeFileContentFromOld( value.name + "_list_config", ` Config.of({ - "union": ${unionValueName} + "union": ${unionValueName}${hammerWrapperData} }) `, )