From d380f131729aaea51a377d042f6f519dcd2dc0bb Mon Sep 17 00:00:00 2001 From: Derryk Boyd Date: Tue, 11 Oct 2022 12:42:08 -0600 Subject: [PATCH] chore(client): ts migrate builders.js (#47813) * Rename builders.js > builderst.ts * Chore: Migrate builders.js to typescript * Replace _concatHtml with concatHtml Co-authored-by: Derryk Boyd --- .../rechallenge/{builders.js => builders.ts} | 18 +++++++++++++++--- client/src/templates/Challenges/utils/build.ts | 18 +++--------------- 2 files changed, 18 insertions(+), 18 deletions(-) rename client/src/templates/Challenges/rechallenge/{builders.js => builders.ts} (60%) diff --git a/client/src/templates/Challenges/rechallenge/builders.js b/client/src/templates/Challenges/rechallenge/builders.ts similarity index 60% rename from client/src/templates/Challenges/rechallenge/builders.js rename to client/src/templates/Challenges/rechallenge/builders.ts index 67eee543427..9b0fd91f86e 100644 --- a/client/src/templates/Challenges/rechallenge/builders.js +++ b/client/src/templates/Challenges/rechallenge/builders.ts @@ -1,7 +1,19 @@ import { template as _template } from 'lodash-es'; -export function concatHtml({ required = [], template, contents } = {}) { - const embedSource = template ? _template(template) : ({ source }) => source; +interface ConcatHTMLOptions { + required: { src: string; link?: string }[]; + template?: string; + contents?: string; +} + +export function concatHtml({ + required = [], + template, + contents +}: ConcatHTMLOptions) { + const embedSource = template + ? _template(template) + : ({ source }: { source: ConcatHTMLOptions['contents'] }) => source; const head = required .map(({ link, src }) => { if (link && src) { @@ -19,5 +31,5 @@ A required file can not have both a src and a link: src = ${src}, link = ${link} }) .join('\n'); - return `${head}${embedSource({ source: contents })}`; + return `${head}${embedSource({ source: contents }) || ''}`; } diff --git a/client/src/templates/Challenges/utils/build.ts b/client/src/templates/Challenges/utils/build.ts index fb0d77fe25e..b902c8b635d 100644 --- a/client/src/templates/Challenges/utils/build.ts +++ b/client/src/templates/Challenges/utils/build.ts @@ -5,7 +5,7 @@ import { ChallengeFile as PropTypesChallengeFile, ChallengeMeta } from '../../../redux/prop-types'; -import { concatHtml } from '../rechallenge/builders.js'; +import { concatHtml } from '../rechallenge/builders'; import { getTransformers, embedFilesInHtml } from '../rechallenge/transformers'; import { createTestFramer, @@ -19,18 +19,6 @@ import { } from './frame'; import createWorker from './worker-executor'; -const _concatHtml = ({ - required, - template, - contents -}: { - required: { src: string }[]; - template?: string; - contents?: string; -}): string => { - return concatHtml({ required, template, contents }); -}; - interface ChallengeFile extends PropTypesChallengeFile { source: string; index: string; @@ -222,7 +210,7 @@ export function buildDOMChallenge( return { challengeType: challengeTypes.html || challengeTypes.multifileCertProject, - build: _concatHtml({ + build: concatHtml({ required: finalRequires, template, contents @@ -265,7 +253,7 @@ export function buildJSChallenge( export function buildBackendChallenge({ url }: BuildChallengeData) { return { challengeType: challengeTypes.backend, - build: _concatHtml({ required: frameRunner }), + build: concatHtml({ required: frameRunner }), sources: { url } }; }