Skip to content

Instantly share code, notes, and snippets.

@samgiles
Created September 17, 2015 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samgiles/496399d0da51f03e308e to your computer and use it in GitHub Desktop.
Save samgiles/496399d0da51f03e308e to your computer and use it in GitHub Desktop.
Polyfill Service config automaticificationifier!
// vim: set ts=4 sw=4 tw=78 noet :
const latest = require('./lib/sources').latest;
const path = require('path');
const fs = require('fs');
latest.listPolyfills().then(function(polyfills) {
return Promise.all(polyfills.map(function(polyfill) {
return latest.getPolyfill(polyfill).then(function(polyfill) {
const config = path.join(polyfill.baseDir, 'config.json');
return new Promise(function(resolve, reject) {
fs.readFile(config, function(err, fileContents) {
if (err) { reject(err); return; }
resolve({ configPath: config, config: JSON.parse(fileContents) });
});
});
});
}));
}).then(function(polyfillConfigs) {
polyfillConfigs.forEach(function(polyfillConfig) {
if (polyfillConfig.config.browsers && polyfillConfig.config.browsers.firefox) {
polyfillConfig.config.browsers.firefox_mob = polyfillConfig.config.browsers.firefox;
} else {
return;
}
fs.writeFile(polyfillConfig.configPath, JSON.stringify(polyfillConfig.config, null, " "), function(err) {
if (err) { console.error("Failed to write config out to: ", polyfillConfig.configPath); return; }
console.log("Successfully updated config: ", polyfillConfig.configPath);
});
});
}).catch(function(error) {
console.error(error);
console.error(error.stack);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment