scratch-www/bin/get-localized-urls
chrisgarrity 74e315dc71 Add new Tips page (#1357)
New of tips page, uses cards from new resources server (s3)

* added get-localized-urls script to get the generated json from the s3 bucket
* added /tips route
* correct localized-urls for other pages
* remove thingstotry
* redirect /go
* fix up /info/cards view to use resources (s3).
* redirect /go to /tips
* change /hoc redirect from /go to /tips
* Add full set of cards pdf download to tips localization
* removed cards and guides from static PDFs, they are all coming from resources.scratch.mit.edu now.
* removed things to try view

Corrections for reviews:
* decided to pretty print the localized URLs
* replaced console.errors with process.stdout and fail with exit(1)
* formatted localized-urls to make it easier to read
* moved link outside  `<Button…` makes whole button clickable instead of just text
* fixed up css styles, removed unnecessary classes
* corrected “unused” resource links
2017-06-21 16:20:18 -04:00

48 lines
1.3 KiB
JavaScript
Executable file

#!/usr/bin/env node
/*
Get localized-urls.json from resources.scratch.mit.edu
*/
var https = require('https');
var fs = require('fs');
var path = require('path');
var urlData = '';
var args = process.argv.slice(2);
if (!args.length) {
process.stdout.write('A output filename must be specified.\n');
process.exit(1);
}
var filename = path.resolve(__dirname, 'lib', args.shift());
https.get('https://resources.scratch.mit.edu/localized-urls.json', (res) => {
var statusCode = res && res.statusCode;
var error;
if (statusCode !== 200) {
error = new Error('Request Failed.\n' +
`Status Code: ${statusCode}`);
}
if (error) {
process.stdout.write(`${error.message}\n`);
// consume response data to free up memory
res.resume();
return;
}
res.setEncoding('utf8');
res.on('data', (chunk) => { urlData += chunk; });
res.on('end', () => {
try {
var urlJson = JSON.parse(urlData);
fs.writeFile(filename, JSON.stringify(urlJson, null, ' '));
} catch (e) {
process.stdout.write(`Failed parsing url data: ${e.message}\n`);
process.exit(1);
}
});
}).on('error', (e) => {
process.stdout.write(`Got error: ${e.message}\n`);
process.exit(1);
});