1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2025-05-18 12:02:53 +02:00

build(deps): update latest

This commit is contained in:
Divlo
2023-01-10 23:15:36 +01:00
parent 1a12e0db0c
commit bc6ad699fc
20 changed files with 536 additions and 9974 deletions

View File

@ -22,19 +22,19 @@ export class Challenge implements ChallengeOptions {
constructor(options: ChallengeOptions) {
const { name } = options
this.name = name
this.path = fileURLToPath(
new URL(`./${name}`, Challenge.BASE_URL)
)
this.path = fileURLToPath(new URL(`./${name}`, Challenge.BASE_URL))
}
public static async getChallenges(): Promise<Challenge[]> {
const challengeNames = await fs.promises.readdir( Challenge.BASE_URL)
const challengeNames = await fs.promises.readdir(Challenge.BASE_URL)
return challengeNames.map((challengeName) => {
return new Challenge({ name: challengeName })
})
}
public static async generate(options: GenerateChallengeOptions): Promise<Challenge> {
public static async generate(
options: GenerateChallengeOptions
): Promise<Challenge> {
const { name, githubUser } = options
const challenge = new Challenge({ name })
if (await isExistingPath(challenge.path)) {

View File

@ -70,6 +70,9 @@ export class GitAffected implements GitAffectedOptions {
const [, , programmingLanguageName] = filePath
.replaceAll('\\', '/')
.split('/')
if (programmingLanguageName == null) {
throw new Error('programmingLanguageName is null')
}
return programmingLanguageName
})
const affectedInputOutput = files.filter((filePath) => {
@ -78,6 +81,9 @@ export class GitAffected implements GitAffectedOptions {
const affectedChallengesFromInputOutput = affectedInputOutput.map(
(filePath) => {
const [, challengeName] = filePath.replaceAll('\\', '/').split('/')
if (challengeName == null) {
throw new Error('challengeName is null')
}
return new Challenge({ name: challengeName })
}
)

View File

@ -63,9 +63,7 @@ export class Solution implements SolutionOptions {
try {
await docker.build(this.temporaryFolder.id)
} catch (error: any) {
throw new Error(
`solution: ${this.path}\n${error.message as string}\n`
)
throw new Error(`solution: ${this.path}\n${error.message as string}\n`)
}
}
@ -90,9 +88,7 @@ export class Solution implements SolutionOptions {
}
} catch (error: any) {
loader.fail()
throw new Error(
`solution: ${this.path}\n${error.message as string}\n`
)
throw new Error(`solution: ${this.path}\n${error.message as string}\n`)
}
}
@ -199,6 +195,15 @@ export class Solution implements SolutionOptions {
return solutions.map((solution) => {
const [, challengeName, , programmingLanguageName, solutionName] =
solution.replaceAll('\\', '/').split('/')
if (
challengeName == null ||
programmingLanguageName == null ||
solutionName == null
) {
throw new Error(`Invalid solution path: ${solution}`)
}
return new Solution({
challenge: new Challenge({
name: challengeName

View File

@ -37,7 +37,8 @@ export class SolutionTestsResult implements SolutionTestsResultOptions {
}
public print(options: SolutionTestsResultPrintOptions = {}): void {
const { shouldPrintBenchmark = false, shouldPrintTableResult = false } = options
const { shouldPrintBenchmark = false, shouldPrintTableResult = false } =
options
const name = `${this.solution.challenge.name}/${this.solution.programmingLanguageName}/${this.solution.name}`
console.log(`${chalk.bold('Name:')} ${name}\n`)
const tableResult = [

View File

@ -109,7 +109,9 @@ class Template {
public async getProgrammingLanguages(): Promise<string[]> {
const languages = await fs.promises.readdir(TEMPLATE_SOLUTION_PATH)
return languages.filter((language) => {return language !== 'base'})
return languages.filter((language) => {
return language !== 'base'
})
}
public async verifySupportedProgrammingLanguage(

View File

@ -23,7 +23,9 @@ export class TemporaryFolder {
public static async cleanAll(): Promise<void> {
try {
const temporaryPath = fileURLToPath(new URL('../../temp', import.meta.url))
const temporaryPath = fileURLToPath(
new URL('../../temp', import.meta.url)
)
await fs.promises.rm(temporaryPath, { recursive: true, force: true })
await docker.removeImages()
} catch {}

View File

@ -4,9 +4,7 @@ import { performance } from 'node:perf_hooks'
import type { Solution } from './Solution.js'
import { docker } from './Docker.js'
import {
SolutionTestsResult
} from './SolutionTestsResult.js'
import { SolutionTestsResult } from './SolutionTestsResult.js'
import { TemporaryFolder } from './TemporaryFolder.js'
export interface InputOutput {
@ -74,9 +72,7 @@ export class Test implements TestOptions {
return { input, output }
}
static async runManyWithSolutions(
solutions: Solution[]
): Promise<number> {
static async runManyWithSolutions(solutions: Solution[]): Promise<number> {
const solutionTestsResultsPromises: Array<Promise<SolutionTestsResult>> = []
let isSolutionSuccess = true
for (const solution of solutions) {