Skip to content

Instantly share code, notes, and snippets.

@rchavarria
Last active Jul 24, 2017
Embed
What would you like to do?
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