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 <derryk@redmantech.com>
This commit is contained in:
Derryk Boyd
2022-10-11 12:42:08 -06:00
committed by GitHub
parent 2f6530325d
commit d380f13172
2 changed files with 18 additions and 18 deletions

View File

@@ -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>${head}</head>${embedSource({ source: contents })}`;
return `<head>${head}</head>${embedSource({ source: contents }) || ''}`;
}

View File

@@ -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 }
};
}