UNPKG

codexen

Version:
41 lines (33 loc) 1.16 kB
var request = require('request'); var fs = require('fs'); var path = './codexen.json'; module.exports = function(){ console.log('\nUpdating codexen.json....') checkCodexenFile(function (check){ // when codexen.json file doesn't exist if(!check) throwCodexenFileNotFound(); fs.readFile(path, {encoding: 'utf-8'}, function(err, data){ if(err) throw err; var deck = JSON.parse(data).deck; fetchDepot(deck.label); }) }); }; var checkCodexenFile = function(callback){ fs.exists(path, callback); }; var throwCodexenFileNotFound = function(){ console.error('\'codexen.json\' is not found.\n'); console.error('use \'cx-config init\' to make codexen.json\n'); process.exit(); }; var fetchDepot = function(deckLabel){ var url = require('./url') + 'decks/' + deckLabel; request.get(url) .on('response', function(response) { //console.log(response.statusCode) //console.log(response.headers['content-type']); console.log('\nSuccessfully Done.\n'); }) .pipe(fs.createWriteStream('codexen.json')) };