@qualified/ccc-files
Provides a function to map ClassicCodeChallenge fields to files.
type FileWithSource = {
path: string;
contents: string;
source: "solution" | "tests" | "preloaded" | "generated";
};
type ClassicCodeChallenge = {
preloaded?: string;
solution: string;
tests: string;
language: string;
languageVersion?: string;
testFramework: string;
preset?: string;
};
type Options = {
fallback?: boolean;
};
const toFiles: (ccc: ClassicCodeChallenge, opts?: Options) => FileWithSource[];
Supported Languages
- C#
- Dart
- Java
- JavaScript
- Python
- Ruby
- TypeScript
Usage
import { toFiles } from "@qualified/ccc-files";
const preloaded = `
package example;
public class Preloaded {}
`;
const solution = `
package example;
public class Example {}
`;
const tests = `
package example;
class ExampleTests {}
`;
toFiles({
preloaded,
solution,
tests,
language: "java",
languageVersion: "17",
testFramework: "junit",
});
[
{
path: "src/test/java/example/ExampleTests.java",
contents: "...",
source: "tests",
},
{
path: "src/main/java/example/Example.java",
contents: "...",
source: "solution",
},
{
path: "src/main/java/example/Preloaded.java",
contents: "...",
source: "preloaded",
},
];