From 3b917d0d1d4b3719974f97fa4f9c0d864c9575ba Mon Sep 17 00:00:00 2001 From: Callum Locke Date: Tue, 17 Nov 2015 15:18:18 +0000 Subject: [PATCH] add "download-data" task --- .gitignore | 2 ++ gulpfile.babel.js | 23 +++++++++++++++++++++++ package.json | 2 ++ 3 files changed, 27 insertions(+) mode change 100755 => 100644 package.json diff --git a/.gitignore b/.gitignore index 656dd18..c3041ef 100755 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ /dist/ /.tmp/ /.sass-cache/ +/.env +/data.json diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 4f7571d..c49480f 100755 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -1,6 +1,9 @@ import browserify from 'browserify'; import browserSync from 'browser-sync'; import del from 'del'; +import dotenv from 'dotenv'; +import fetch from 'node-fetch'; +import fs from 'fs'; import gulp from 'gulp'; import igdeploy from 'igdeploy'; import mergeStream from 'merge-stream'; @@ -12,6 +15,8 @@ import vinylBuffer from 'vinyl-buffer'; import watchify from 'watchify'; const $ = require('auto-plug')('gulp'); +dotenv.load(); + const AUTOPREFIXER_BROWSERS = [ 'ie >= 8', 'ff >= 30', @@ -234,3 +239,21 @@ gulp.task('deploy', done => { console.log(`Deployed to http://ig.ft.com/${DEPLOY_TARGET}/`); }); }); + +gulp.task('download-data', () => fetch(`https://bertha.ig.ft.com/republish/publish/gss/${process.env.SPREADSHEET_KEY}/data`) + .then(res => res.json()) + .then(spreadsheet => { + const data = {}; + + for (const word of spreadsheet) { + data[word.slug] = data[word.slug] || []; + data[word.slug].push(word); + + if (data[word.slug].length > 1) { + console.log('Multiple definitions for this slug:', word.slug); + } + } + + fs.writeFileSync('data.json', JSON.stringify(data, null, 2)); + }) +); diff --git a/package.json b/package.json old mode 100755 new mode 100644 index 12b2868..f6eef24 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "browserify": "^12.0.1", "debowerify": "^1.3.1", "del": "^2.0.2", + "dotenv": "^1.2.0", "eslint": "^1.9.0", "eslint-config-xo": "^0.8.0", "fastclick": "^1.0.6", @@ -29,6 +30,7 @@ "gulp-util": "^3.0.7", "igdeploy": "^0.1.0", "merge-stream": "^1.0.0", + "node-fetch": "^1.3.3", "nodemon": "^1.8.1", "run-sequence": "^1.1.4", "subdir": "0.0.3",