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 fs from 'fs';
import moment from "moment"; import moment from 'moment';
import jinja from "jinja-js"; import jinja from 'jinja-js';
import yaml from "yaml"; import yaml from 'yaml';
import _ from "lodash"; import _ from 'lodash';
interface Member { interface Member {
name: string; name: string;
...@@ -27,12 +27,14 @@ interface RenderData { ...@@ -27,12 +27,14 @@ interface RenderData {
duels: Member[][]; 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[]) { function shuffle(arr: any[]) {
for (let i=arr.length-1; i>=0; i--) { for (let i = arr.length - 1; i >= 0; i--) {
let rIndex = Math.floor(Math.random()*(i+1)); const rIndex = Math.floor(Math.random() * (i + 1));
let temp = arr[rIndex]; const temp = arr[rIndex];
arr[rIndex] = arr[i]; arr[rIndex] = arr[i];
arr[i] = temp; arr[i] = temp;
} }
...@@ -44,28 +46,34 @@ function makeMatch(team1: Team, team2: Team): RenderData { ...@@ -44,28 +46,34 @@ function makeMatch(team1: Team, team2: Team): RenderData {
throw `Team ${team1.name} and ${team2.name} has different member size.`; throw `Team ${team1.name} and ${team2.name} has different member size.`;
} }
const len = team1.members.length; const len = team1.members.length;
const memberLists: Member[][] = ([team1, team2]).map(team => { const memberLists: Member[][] = [team1, team2].map((team) => {
const list = _.clone(team.members); const list = _.clone(team.members);
shuffle(list); shuffle(list);
return list; return list;
}); });
const duels: Member[][] = []; 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]]); duels.push([memberLists[0][i], memberLists[1][i]]);
} }
return { return {
teamNames: [team1.name, team2.name].map(n => n.toUpperCase()), teamNames: [team1.name, team2.name].map((n) => n.toUpperCase()),
timeString: moment().format("YYYY.MM.DD"), timeString: moment().format('YYYY.MM.DD'),
duels duels,
} };
} }
const missingTeams: string[] = []; const missingTeams: string[] = [];
for (let match of config.matches) { for (const match of config.matches) {
const team1 = _.find(config.teams, t => t.name.toUpperCase() === match.team1.toUpperCase()); const team1 = _.find(
config.teams,
(t) => t.name.toUpperCase() === match.team1.toUpperCase(),
);
if (!team1) { if (!team1) {
missingTeams.push(match.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) { if (!team2) {
missingTeams.push(match.team2); missingTeams.push(match.team2);
} }
...@@ -75,8 +83,8 @@ for (let match of config.matches) { ...@@ -75,8 +83,8 @@ for (let match of config.matches) {
const data = makeMatch(team1, team2); const data = makeMatch(team1, team2);
const renderedData = jinja.render(config.template, data); const renderedData = jinja.render(config.template, data);
console.log(renderedData); console.log(renderedData);
console.log(""); console.log('');
} }
for (let missingName of missingTeams) { for (const missingName of missingTeams) {
console.error(`Missing team ${missingName.toUpperCase()}.`); 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