Commit 5d4c00c2 authored by nanahira's avatar nanahira

eslint

parent 2268c634
Pipeline #4771 failed with stages
in 6 minutes and 57 seconds
/dist
/build
import fs from "fs";
import moment from "moment";
import jinja from "jinja-js";
import yaml from "yaml";
import _ from "lodash";
import fs from 'fs';
import moment from 'moment';
import jinja from 'jinja-js';
import yaml from 'yaml';
import _ from 'lodash';
interface Member {
name: string;
......@@ -27,12 +27,14 @@ interface RenderData {
duels: Member[][];
}
const config: Config = yaml.parse(fs.readFileSync(process.argv[2] || "./config.yaml", "utf-8"));
const config: Config = yaml.parse(
fs.readFileSync(process.argv[2] || './config.yaml', 'utf-8'),
);
function shuffle(arr: any[]) {
for (let i=arr.length-1; i>=0; i--) {
let rIndex = Math.floor(Math.random()*(i+1));
let temp = arr[rIndex];
for (let i = arr.length - 1; i >= 0; i--) {
const rIndex = Math.floor(Math.random() * (i + 1));
const temp = arr[rIndex];
arr[rIndex] = arr[i];
arr[i] = temp;
}
......@@ -44,28 +46,34 @@ function makeMatch(team1: Team, team2: Team): RenderData {
throw `Team ${team1.name} and ${team2.name} has different member size.`;
}
const len = team1.members.length;
const memberLists: Member[][] = ([team1, team2]).map(team => {
const memberLists: Member[][] = [team1, team2].map((team) => {
const list = _.clone(team.members);
shuffle(list);
return list;
});
const duels: Member[][] = [];
for (let i = 0; i < len; ++i){
for (let i = 0; i < len; ++i) {
duels.push([memberLists[0][i], memberLists[1][i]]);
}
return {
teamNames: [team1.name, team2.name].map(n => n.toUpperCase()),
timeString: moment().format("YYYY.MM.DD"),
duels
}
teamNames: [team1.name, team2.name].map((n) => n.toUpperCase()),
timeString: moment().format('YYYY.MM.DD'),
duels,
};
}
const missingTeams: string[] = [];
for (let match of config.matches) {
const team1 = _.find(config.teams, t => t.name.toUpperCase() === match.team1.toUpperCase());
for (const match of config.matches) {
const team1 = _.find(
config.teams,
(t) => t.name.toUpperCase() === match.team1.toUpperCase(),
);
if (!team1) {
missingTeams.push(match.team1);
}
const team2 = _.find(config.teams, t => t.name.toUpperCase() === match.team2.toUpperCase());
const team2 = _.find(
config.teams,
(t) => t.name.toUpperCase() === match.team2.toUpperCase(),
);
if (!team2) {
missingTeams.push(match.team2);
}
......@@ -75,8 +83,8 @@ for (let match of config.matches) {
const data = makeMatch(team1, team2);
const renderedData = jinja.render(config.template, data);
console.log(renderedData);
console.log("");
console.log('');
}
for (let missingName of missingTeams) {
for (const missingName of missingTeams) {
console.error(`Missing team ${missingName.toUpperCase()}.`);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment