[web] Add CPP templates

This commit is contained in:
orosmatthew 2024-01-31 21:09:32 -05:00
parent face74b314
commit df916b2622
2 changed files with 40 additions and 0 deletions

View File

@ -7,6 +7,9 @@ import {
templateCSharpGitIgnore, templateCSharpGitIgnore,
templateCSharpProblem, templateCSharpProblem,
templateCSharpProblemProj, templateCSharpProblemProj,
templateCppCMakeLists,
templateCppGitIgnore,
templateCppProblem,
templateJavaProblem templateJavaProblem
} from './templates'; } from './templates';
@ -42,6 +45,23 @@ async function addProblemsCSharp(opts: OptsAddProblems) {
}); });
} }
async function addProblemsCPP(opts: OptsAddProblems) {
let cmakeLists = templateCppCMakeLists;
opts.contest.problems.forEach((problem) => {
cmakeLists += `add_executable(${problem.pascalName} ${problem.pascalName}/${problem.pascalName}.cpp)`;
});
opts.fs.writeFileSync(join(opts.dir, 'CMakeLists.txt'), cmakeLists);
opts.contest.problems.forEach((problem) => {
opts.fs.mkdirSync(join(opts.dir, problem.pascalName));
const filledTemplate = templateCppProblem.replaceAll('%%pascalName%%', problem.pascalName);
opts.fs.writeFileSync(
join(opts.dir, problem.pascalName, `${problem.pascalName}.cpp`),
filledTemplate
);
});
}
export async function createRepos(contestId: number) { export async function createRepos(contestId: number) {
const vol = new memfs.Volume(); const vol = new memfs.Volume();
const fs = createFsFromVolume(vol); const fs = createFsFromVolume(vol);
@ -63,6 +83,9 @@ export async function createRepos(contestId: number) {
} else if (team.language === 'CSharp') { } else if (team.language === 'CSharp') {
addProblemsCSharp({ fs, dir: team.id.toString(), contest }); addProblemsCSharp({ fs, dir: team.id.toString(), contest });
fs.writeFileSync(join(team.id.toString(), '.gitignore'), templateCSharpGitIgnore); fs.writeFileSync(join(team.id.toString(), '.gitignore'), templateCSharpGitIgnore);
} else if (team.language === 'CPP') {
addProblemsCPP({ fs, dir: team.id.toString(), contest });
fs.writeFileSync(join(team.id.toString(), '.gitignore'), templateCppGitIgnore);
} else { } else {
console.error('Language not supported'); console.error('Language not supported');
return; return;

View File

@ -26,3 +26,20 @@ export const templateCSharpProblemProj = `<Project Sdk="Microsoft.NET.Sdk">
</PropertyGroup> </PropertyGroup>
</Project>`; </Project>`;
export const templateCppCMakeLists = `cmake_minimum_required(VERSION 3.5)
project(bwcontest)
`;
export const templateCppProblem = `#include <iostream>
int main()
{
std::cout << "Hello %%pascalName%%!" << std::endl;
return 0;
}`;
export const templateCppGitIgnore = `/build
`;