I have been trying to get myself more familiar with Typescript in the past few weeks using a few side projects as well as professionally with the Clasp tool.

So I spent a little bit of time trying to create a way to generate challenges to test myself with. There is a great resource on the r/dailyprogrammer subreddit that has challenges.

So I wrote a fairly simple node script using a library called inquirer to do that heavy lifting for me.

const inquirer = require('inquirer');
const fetchDaily = require('./fetchDaily');
const createCustom = require('./newChallenge');

const questions = [
  {
    type: 'list',
    name: 'language',
    message: 'Which language will you be doing the challenge in?',
    choices: ['Typescript', 'Go'],
    default: 'Typescript',
    filter(answer) {
      return answer.toLowerCase();
    },
  },
  {
    type: 'list',
    name: 'source',
    message: 'Where do you want to create the challenge from?',
    choices: ['r/DailyProgrammer', 'Custom'],
  },
  {
    type: 'input',
    name: 'title',
    message: 'Title of your challenge',
    when(answers) {
      return answers.source === 'Custom';
    },
  },
  {
    type: 'input',
    name: 'description',
    message: 'Challenge description',
    when(answers) {
      return answers.source === 'Custom' && answers.title !== null;
    },
  },
];

function createChallenge() {
  inquirer.prompt(questions).then(answers => {
    if (answers.source === 'r/DailyProgrammer') {
      fetchDaily(answers.language);
    }

    if (answers.source === 'Custom') {
      createCustom(answers);
    }
  });
}

createChallenge();

I pushed my tinkering into a repository on github. It also made me realize that I am in store for a major Github cleanup effort… but that is a story for another day.