Last active
July 27, 2017 01:10
-
-
Save andrejewski/67426eee5e48c74c0039350867dafe26 to your computer and use it in GitHub Desktop.
Super mod: update Travis Firefox version
This file contains hidden or 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
| var fs = require('fs') | |
| var path = require('path') | |
| module.exports = { | |
| getOptions: function () { | |
| return [{ | |
| name: 'version', | |
| type: 'input', | |
| default: '51.0', | |
| message: 'New Firefox version:' | |
| }] | |
| }, | |
| run: function (directory, options) { | |
| var version = options.version | |
| version = version.trim() | |
| var filepath = path.join(directory, '.travis.yml') | |
| if (!fs.existsSync(filepath)) { | |
| console.error('"' + filepath + '" was not found, cannot update Firefox version') | |
| return Promise.resolve() | |
| } | |
| return new Promise(function (resolve, reject) { | |
| fs.readFile(filepath, {encoding: 'utf8'}, function (error, text) { | |
| error ? reject(error) : resolve(text) | |
| }) | |
| }).then(function (text) { | |
| var newFirefox = 'firefox: "' + version + '"' | |
| var newText = text.replace(/firefox: "(.*)"/, newFirefox) | |
| if (newText === text) { | |
| console.error('Firefox version not previously specified, unable to update.') | |
| } | |
| return newText | |
| }).then(function (newText) { | |
| return new Promise(function (resolve, reject) { | |
| fs.writeFile(filepath, newText, function (error) { | |
| error ? reject(error) : resolve() | |
| }) | |
| }) | |
| }) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment