Skip to content

Instantly share code, notes, and snippets.

@rchavarria
Last active July 24, 2017 18:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rchavarria/ffcfd44c9cb00497a460f8b0e29f0fd3 to your computer and use it in GitHub Desktop.
Transform your track's `config.json` into a CSV to be imported into a spreadsheet
/*
You'll need NodeJS installed to run this script.
Place this script in your track's root folder:
track/
+ config.json
+ json2csv.js <-----
+ exercises/
+ hello_world
+ bob
+ ...
Simply run the command:
$ node json2csv.js
You'll get a file named `core.csv` in the same folder.
*/
const fs = require('fs');
// read `config.json` file
const jsonContent = fs.readFileSync('./config.json');
// get the array of exercises
const exercises = JSON.parse(jsonContent.toString()).exercises;
// create the header and generate a line by each exercise
const header = 'Slug,Core,Unlocked by';
const csvLines = exercises.map(exercise => `${exercise.slug},${exercise.core},${exercise.unlocked_by}`);
// write a CSV file named `core.csv`, easy to import on a spreadsheet
const csvContent = [header].concat(csvLines).join('\n');
fs.writeFileSync('core.csv', csvContent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment