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

feat(cli): add --all option to run test command

This commit is contained in:
Divlo
2021-10-13 21:43:45 +02:00
parent aeff95e691
commit 0a27b9e1a1
47 changed files with 1657 additions and 1773 deletions

View File

@ -1,8 +1,6 @@
import execa from 'execa'
import { Challenge } from './Challenge'
import { Solution } from './Solution'
import { isExistingPath } from '../utils/isExistingPath'
const solutionsRegex = new RegExp(
/challenges\/[\s\S]*\/solutions\/(c|cpp|cs|dart|java|javascript|python|rust|typescript)\/[\s\S]*\/(solution|Solution).(c|cpp|cs|dart|java|js|py|rs|ts)/
@ -72,22 +70,6 @@ export class GitAffected implements GitAffectedOptions {
const affectedSolutionsPaths = files.filter((filePath) => {
return solutionsRegex.test(filePath)
})
const solutions: string[] = []
for (const path of affectedSolutionsPaths) {
if (await isExistingPath(path)) {
solutions.push(path)
}
}
return solutions.map((solution) => {
const [, challengeName, , programmingLanguageName, solutionName] =
solution.split('/')
return new Solution({
challenge: new Challenge({
name: challengeName
}),
name: solutionName,
programmingLanguageName
})
})
return await Solution.getManyByPaths(affectedSolutionsPaths)
}
}

View File

@ -101,4 +101,29 @@ export class Solution implements SolutionOptions {
}
return solution
}
/**
* Get Solutions by relative paths.
* @param paths relative to `challenges` (e.g: `challenges/hello-world/solutions/c/function`)
* @returns
*/
static async getManyByPaths (paths: string[]): Promise<Solution[]> {
const solutions: string[] = []
for (const path of paths) {
if (await isExistingPath(path)) {
solutions.push(path)
}
}
return solutions.map((solution) => {
const [, challengeName, , programmingLanguageName, solutionName] =
solution.split('/')
return new Solution({
challenge: new Challenge({
name: challengeName
}),
name: solutionName,
programmingLanguageName
})
})
}
}

View File

@ -73,9 +73,7 @@ class Template {
public async solution (options: TemplateSolutionOptions): Promise<void> {
const { destination, githubUser, name, challengeName, programmingLanguageName } = options
const templateLanguagePath = path.join(TEMPLATE_SOLUTION_PATH, programmingLanguageName)
if (!(await isExistingPath(templateLanguagePath))) {
throw new Error('This programming language is not supported yet.')
}
await this.verifySupportedProgrammingLanguage(programmingLanguageName)
await fs.promises.mkdir(destination, { recursive: true })
await copyDirectory(templateLanguagePath, destination)
await copyDirectory(TEMPLATE_SOLUTION_BASE_PATH, destination)
@ -95,6 +93,13 @@ class Template {
destination
})
}
public async verifySupportedProgrammingLanguage (language: string): Promise<void> {
const templateLanguagePath = path.join(TEMPLATE_SOLUTION_PATH, language)
if (!(await isExistingPath(templateLanguagePath))) {
throw new Error('This programming language is not supported yet.')
}
}
}
export const template = new Template()