[web] Create CSharp repos
This commit is contained in:
parent
509c9bcdda
commit
7f2e4c815c
@ -7,6 +7,52 @@ import { dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import http from 'isomorphic-git/http/node';
|
||||
|
||||
async function addProblemsJava(opts: {
|
||||
fs: memfs.IFs;
|
||||
templateDir: string;
|
||||
dir: string;
|
||||
contest: { problems: { pascalName: string }[] };
|
||||
}) {
|
||||
const template = hostFs
|
||||
.readFileSync(join(opts.templateDir, 'java/problem/problem.java'))
|
||||
.toString();
|
||||
|
||||
opts.contest.problems.forEach((problem) => {
|
||||
opts.fs.mkdirSync(join(opts.dir, problem.pascalName));
|
||||
const filledTemplate = template.replaceAll('%%pascalName%%', problem.pascalName);
|
||||
opts.fs.writeFileSync(
|
||||
join(opts.dir, problem.pascalName, `${problem.pascalName}.java`),
|
||||
filledTemplate
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async function addProblemsCSharp(opts: {
|
||||
fs: memfs.IFs;
|
||||
templateDir: string;
|
||||
dir: string;
|
||||
contest: { problems: { pascalName: string }[] };
|
||||
}) {
|
||||
const project = hostFs
|
||||
.readFileSync(join(opts.templateDir, 'csharp/problem/problem.csproj'))
|
||||
.toString();
|
||||
const template = hostFs
|
||||
.readFileSync(join(opts.templateDir, 'csharp/problem/problem.cs'))
|
||||
.toString();
|
||||
opts.contest.problems.forEach((problem) => {
|
||||
opts.fs.mkdirSync(join(opts.dir, problem.pascalName));
|
||||
opts.fs.writeFileSync(
|
||||
join(opts.dir, problem.pascalName, `${problem.pascalName}.csproj`),
|
||||
project
|
||||
);
|
||||
const filledTemplate = template.replaceAll('%%pascalName%%', problem.pascalName);
|
||||
opts.fs.writeFileSync(
|
||||
join(opts.dir, problem.pascalName, `${problem.pascalName}.cs`),
|
||||
filledTemplate
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export async function createRepos(contestId: number) {
|
||||
const vol = new memfs.Volume();
|
||||
const fs = createFsFromVolume(vol);
|
||||
@ -22,19 +68,19 @@ export async function createRepos(contestId: number) {
|
||||
|
||||
const templateDir = join(dirname(fileURLToPath(import.meta.url)), '../../../../templates');
|
||||
|
||||
const template = hostFs.readFileSync(join(templateDir, 'java/problem/Main.java')).toString();
|
||||
|
||||
contest.teams.forEach(async (team) => {
|
||||
fs.mkdirSync(team.id.toString(), { recursive: true });
|
||||
await git.init({ fs: fs, bare: false, defaultBranch: 'master', dir: team.id.toString() });
|
||||
contest.problems.forEach((problem) => {
|
||||
fs.mkdirSync(join(team.id.toString(), problem.pascalName));
|
||||
const filledTemplate = template.replaceAll('%%pascalName%%', problem.pascalName);
|
||||
fs.writeFileSync(
|
||||
join(team.id.toString(), problem.pascalName, `${problem.pascalName}.java`),
|
||||
filledTemplate
|
||||
);
|
||||
});
|
||||
if (team.language === 'Java') {
|
||||
addProblemsJava({ fs, templateDir, dir: team.id.toString(), contest });
|
||||
} else if (team.language === 'CSharp') {
|
||||
addProblemsCSharp({ fs, templateDir, dir: team.id.toString(), contest });
|
||||
const gitignore = hostFs.readFileSync(join(templateDir, 'csharp/.gitignore')).toString();
|
||||
fs.writeFileSync(join(team.id.toString(), '.gitignore'), gitignore);
|
||||
} else {
|
||||
console.error('Language not supported');
|
||||
return;
|
||||
}
|
||||
await git.add({ fs: fs, dir: team.id.toString(), filepath: '.' });
|
||||
await git.commit({
|
||||
fs: fs,
|
||||
|
3
web/templates/csharp/.gitignore
vendored
Normal file
3
web/templates/csharp/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
*.sln
|
||||
**/bin
|
||||
**/obj
|
7
web/templates/csharp/problem/problem.cs
Normal file
7
web/templates/csharp/problem/problem.cs
Normal file
@ -0,0 +1,7 @@
|
||||
public class %%pascalName%%
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello %%pascalName%%!");
|
||||
}
|
||||
}
|
10
web/templates/csharp/problem/problem.csproj
Normal file
10
web/templates/csharp/problem/problem.csproj
Normal file
@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user