Created
September 17, 2015 20:27
-
-
Save samgiles/496399d0da51f03e308e to your computer and use it in GitHub Desktop.
Polyfill Service config automaticificationifier!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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