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

feat(cli): add commands/search

This commit is contained in:
Divlo
2023-01-05 18:29:07 +01:00
parent 70564f174a
commit c8a7a6dcd4
3 changed files with 73 additions and 2 deletions

View File

@ -15,6 +15,7 @@ export interface GenerateChallengeOptions extends ChallengeOptions {
}
export class Challenge implements ChallengeOptions {
public static BASE_URL = new URL('../../challenges/', import.meta.url)
public name: string
public path: string
@ -22,11 +23,18 @@ export class Challenge implements ChallengeOptions {
const { name } = options
this.name = name
this.path = fileURLToPath(
new URL(`../../challenges/${name}`, import.meta.url)
new URL(`./${name}`, Challenge.BASE_URL)
)
}
static async generate(options: GenerateChallengeOptions): Promise<Challenge> {
public static async getChallenges(): Promise<Challenge[]> {
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> {
const { name, githubUser } = options
const challenge = new Challenge({ name })
if (await isExistingPath(challenge.path)) {