(
{
challengeFiles,
required = [],
template = '',
challengeType
}: BuildChallengeData,
options?: BuildOptions
)
| 212 | // abstraction (function, class, whatever) and then create the various functions |
| 213 | // out of it. |
| 214 | async function buildDOMChallenge( |
| 215 | { |
| 216 | challengeFiles, |
| 217 | required = [], |
| 218 | template = '', |
| 219 | challengeType |
| 220 | }: BuildChallengeData, |
| 221 | options?: BuildOptions |
| 222 | ): Promise<BuildResult> { |
| 223 | // TODO: make this required in the schema. |
| 224 | if (!challengeFiles) throw Error('No challenge files provided'); |
| 225 | const hasJsx = challengeFiles.some( |
| 226 | challengeFile => challengeFile.ext === 'jsx' || challengeFile.ext === 'tsx' |
| 227 | ); |
| 228 | |
| 229 | await configureTSCompiler(challengeFiles); |
| 230 | const sourceFiles = challengeFiles.filter(file => !isTSConfig(file)); |
| 231 | const isMultifile = sourceFiles.length > 1; |
| 232 | // I'm reasonably sure this is fine, but we need to migrate transformers to |
| 233 | // TypeScript to be sure. |
| 234 | const transformers: ApplyFunctionProps[] = (isMultifile && hasJsx |
| 235 | ? getMultifileJSXTransformers(options) |
| 236 | : getTransformers(options)) as unknown as ApplyFunctionProps[]; |
| 237 | |
| 238 | const pipeLine = composeFunctions(...transformers); |
| 239 | const finalFiles = await Promise.all(sourceFiles.map(pipeLine)); |
| 240 | const error = finalFiles.find(({ error }) => error)?.error; |
| 241 | const contents = (await embedFilesInHtml(finalFiles)) as string; |
| 242 | |
| 243 | // if there is an error, we just build the test runner so that it can be |
| 244 | // used to run tests against the code without actually running the code. |
| 245 | const toBuild = error |
| 246 | ? {} |
| 247 | : { |
| 248 | required, |
| 249 | template, |
| 250 | contents |
| 251 | }; |
| 252 | |
| 253 | const requiresReact16 = required.some(({ src }) => |
| 254 | src?.includes('https://cdnjs.cloudflare.com/ajax/libs/react/16.') |
| 255 | ); |
| 256 | |
| 257 | return { |
| 258 | challengeType, |
| 259 | build: concatHtml(toBuild), |
| 260 | sources: buildSourceMap(finalFiles), |
| 261 | loadEnzyme: requiresReact16, |
| 262 | error |
| 263 | }; |
| 264 | } |
| 265 | |
| 266 | async function buildJSChallenge( |
| 267 | { |
nothing calls this directly
no test coverage detected