function parse (result) { var instances = _.pluck(result.Reservations, 'Instances'); var flat = _.flatten(instances); if (flat.length > 1) { grunt.fatal('Found more than one instance tagged ' + chalk.magenta(name)); } else if (flat.length === 0) { grunt.fatal('There are no instances tagged ' + chalk.magenta(name)); } done(flat[0]); }
task.init = function(tasks, options) { if (!options) { options = {}; } // Were only init tasks specified? var allInit = tasks.length > 0 && tasks.every(function(name) { var obj = task._taskPlusArgs(name).task; return obj && obj.init; }); // Get any local Gruntfile or tasks that might exist. Use --gruntfile override // if specified, otherwise search the current directory or any parent. var gruntfile, msg; if (allInit || options.gruntfile === false) { gruntfile = null; } else { gruntfile = grunt.option('gruntfile') || grunt.file.findup('Gruntfile.{js,coffee}', {nocase: true}); msg = 'Reading "' + (gruntfile ? path.basename(gruntfile) : '???') + '" Gruntfile...'; } if (options.gruntfile === false) { // Grunt was run as a lib with {gruntfile: false}. } else if (gruntfile && grunt.file.exists(gruntfile)) { grunt.verbose.writeln().write(msg).ok(); // Change working directory so that all paths are relative to the // Gruntfile's location (or the --base option, if specified). process.chdir(grunt.option('base') || path.dirname(gruntfile)); // Load local tasks, if the file exists. loadTasksMessage('Gruntfile'); loadTask(gruntfile); } else if (options.help || allInit) { // Don't complain about missing Gruntfile. } else if (grunt.option('gruntfile')) { // If --config override was specified and it doesn't exist, complain. grunt.log.writeln().write(msg).error(); grunt.fatal('Unable to find "' + gruntfile + '" Gruntfile.', grunt.fail.code.MISSING_GRUNTFILE); } else if (!grunt.option('help')) { grunt.verbose.writeln().write(msg).error(); grunt.log.writelns( 'A valid Gruntfile could not be found. Please see the getting ' + 'started guide for more information on how to configure grunt: ' + 'http://gruntjs.com/getting-started' ); grunt.fatal('Unable to find Gruntfile.', grunt.fail.code.MISSING_GRUNTFILE); } // Load all user-specified --npm tasks. (grunt.option('npm') || []).map(String).forEach(task.loadNpmTasks); // Load all user-specified --tasks. (grunt.option('tasks') || []).map(String).forEach(task.loadTasks); };
sshCredentials(name, function (c) { if (!c) { grunt.fatal('This instance is refusing SSH connections for now'); } var verbosity = conf('VERBOSITY_RSYNC'); var user = conf('AWS_RSYNC_USER'); var include = clud(opts.includes, 'include'); var includeFrom = cludFrom(opts.includeFrom, 'include'); var exclude = clud(opts.excludes, 'exclude'); var excludeFrom = cludFrom(opts.excludeFrom, 'exclude'); grunt.log.writeln('Deploying %s to %s using rsync over ssh...', chalk.blue(opts.name), chalk.cyan(c.id)); var args = ['a', 'z']; var eo = {}; if (verbosity) { eo.buffer = 20000 * 1024; args.push(verbosity); } exec('rsync -%s --stats --delete %s -e "C:\\rsync\\bin\\ssh -o StrictHostKeyChecking=no -i %s" %s %s@%s:%s', [ args.join(''), include + includeFrom + exclude + excludeFrom, c.privateKeyFile, opts.local, user, c.host, opts.remote ], eo, done); });
function run() { var self = this, options = self.options, phantomjs = self.phantomjs, markTaskComplete = self.async(), inject = []; if (!self.filesSrc) { grunt.fatal('Path to test page(s) was not specified, please use the "src" grunt parameter.'); } inject.push(path.join(__dirname, '../includes', 'html-inspector.js')); if (options.bridge) { inject.push(options.bridge); } else { inject.push(path.join(__dirname, '../includes', 'bridge.js')); } options.phantomOptions.inject = inject; if (options.parameters) { self.src += (self.src.indexOf('?') === -1 ? '?' : '&') + options.parameters; } phantomjs.on('htmlinspector.done', onComplete.bind(self)); phantomjs.on('fail.load', onFailLoad.bind(self)); phantomjs.on('fail.timeout', onFailTimeout.bind(self)); grunt.util.async.forEachSeries(self.filesSrc, function spawnPhantomJs(url, next) { grunt.log.writeln('Testing ' + url + ' '); phantomjs.spawn(url, (function defineOptions() { function done(er) { if (er) { markTaskComplete(false); } else { next(); } } return { options: options.phantomOptions, done: done }; }())); }, function allFilesTested(er) { if (er) { markTaskComplete(false); } else { markTaskComplete(); } }); }
sshCredentials(options.name, function (credentials) { if (!credentials) { grunt.fatal('This instance is refusing SSH connections for now'); } c.connect(credentials); });
cachedAngularFiles.forEach(function(f) { var filePath = path.join('lib', 'test', 'angular', version, f); if (! fs.existsSync(filePath)) { grunt.fatal("Angular file " + filePath + " doesn't exist"); } retFiles.push(filePath); });
self._runPhantom(fileCreatedPath, function(err, results) { if(err) { grunt.fatal(err.message); } if(results.passed !== results.total) { grunt.warn("Some tests failed"); } done(); });
Config.prototype.get = function (key) { if (this._ === void 0) { grunt.fatal('Attempted to get configuration value before initializing.'); } if (key === void 0) { return this._; } return this._[key]; };
function ready (err, stream) { if (err) { grunt.fatal('Connection error.\n\n', err); } grunt.log.ok('Connection established! Use ctrl+c twice to exit ssh session'); shell = stream; shell.on('data', read.bind(null, options.chalk)); shell.on('error', fatal); shell.on('exit', exitCommand); resume(); }
async.forEachLimit(files, this.options.spawnLimit, lintFile, function(err) { if(err) { return grunt.fatal(err); } // Let the reporter handle finish message. self.options.reporter.finish(files); // Proceed if we have no errors, or we set the force option var proceed = self.origTask.errorCount < 1 && !force; done(proceed); });
module.exports = function() { var task = this; var shouldStayAliveForever = task.flags.keepalive; var SAUCE_ACCESS_KEY = process.env.SAUCE_ACCESS_KEY || '339d32ca-d594-4570-a3c2-94c50a91919b'; if (!SAUCE_ACCESS_KEY) { grunt.fatal('Requires the environment variable SAUCE_ACCESS_KEY to be set'); } var SAUCE_USERNAME = process.env.SAUCE_USERNAME || 'React'; if (!SAUCE_USERNAME) { grunt.fatal('Requires the environment variable SAUCE_USERNAME to be set'); } var IDENTIFIER = process.env.TRAVIS_JOB_NUMBER || 'my awesome tunnel'; var taskCompletedSuccessfully = task.async(); var stunnel = new SauceTunnel(SAUCE_USERNAME, SAUCE_ACCESS_KEY, IDENTIFIER, /*tunneled*/true, /*tunnelTimeout*/5); process.on('exit', stunnel.stop.bind(stunnel, function() {})); stunnel.on('log:error', grunt.log.error.bind(grunt.log)); stunnel.on('log:writeln', grunt.log.writeln.bind(grunt.log)); stunnel.on('verbose:ok', grunt.verbose.ok.bind(grunt.verbose)); stunnel.on('verbose:error', grunt.verbose.error.bind(grunt.verbose)); stunnel.on('verbose:debug', grunt.verbose.debug.bind(grunt.verbose)); stunnel.on('verbose:writeln', grunt.verbose.writeln.bind(grunt.verbose)); stunnel.openTunnel(function(isOpen) { if (shouldStayAliveForever && isOpen) { grunt.verbose.writeln('Keeping the sauce-tunnel open forever because you used the keepalive flag `' + task.nameArgs + '`'); return; } grunt.verbose.writeln('To keep the sauce-tunnel open forever, use the grunt task `' + task.nameArgs + ':keepalive`'); taskCompletedSuccessfully(isOpen); }); };
http.get(url, function(response) { grunt.verbose.writeln('Received status code ' + response.statusCode + ' for \'' + url + '\''); if (response.statusCode !== 200) { if (response.headers.location) { get(response.headers.location, targetFilePath); return; } else { grunt.fatal('Nothing else to do.'); completedSuccessfully(false); return; } } grunt.verbose.writeln('Writing url to \'' + targetFilePath + '\''); response.pipe(fs.createWriteStream(targetFilePath)) .on('close', function() { completedSuccessfully(true); }); });
.pipe(require('coverify/parse')(function(error, results){ if (error) { grunt.fatal(error); } Object.keys(results) .sort(function(a, b){ return results[a].length - results[b].length; }) .reverse() .forEach(function(path){ if (results[path].length === 0) { return; } var relativePath = path.replace(ROOT, ''); uncoveredExpressionCount += results[path].length; grunt.log.error(results[path].length + ' expressions not covered ' + relativePath); results[path].forEach(function(c){ uncoveredLineCount += c.code.split('\n').length; console.log('txmt://open?url=' + encodeURIComponent('file://' + path) + '&line=' + (c.lineNum+1) + '&column=' + (c.column[0]+2)); }); console.log(''); }) ; Object.keys(results).sort().forEach(function(path){ if (results[path].length > 0) { return; } var relativePath = path.replace(ROOT, ''); grunt.log.ok('100% coverage ' + relativePath); }); if (uncoveredExpressionCount > 0) { grunt.log.error(uncoveredExpressionCount + ' expressions not covered'); } if (uncoveredLineCount > 0) { grunt.log.error(uncoveredLineCount + ' lines not covered'); } done(); }));
self._build(function(err, fileCreatedPath) { if(err) { grunt.fatal(err.message); return done(); } if(self.options.buildOnly) { grunt.log.writeln(fileCreatedPath); return done(); } if (self.options.connectUrl) { // Trim trailing slashes if (self.options.connectUrl.slice(-1) === '/') { self.options.connectUrl = self.options.connectUrl.slice(0, -1); } // Build up the url from the tmp dir name and file name fileCreatedPath = [ self.options.connectUrl, path.basename(path.dirname(fileCreatedPath)), path.basename(fileCreatedPath) ].join('/'); } self._runPhantom(fileCreatedPath, function(err, results) { if(err) { grunt.fatal(err.message); } if(results.passed !== results.total) { grunt.warn("Some tests failed"); } done(); }); });
function fatal (err) { grunt.fatal('Connection error.\n\n', err); }
onError: function(error){ grunt.fatal(error); }
onComplete: function(passed){ if (!passed){ grunt.fatal("tests failed"); } },
// helper for creating assertTasks for testing tasks in child processes function assertTask(task, options) { var spawn = require('child_process').spawn; task = task || 'default'; options = options || {}; // Find the grunt bin var gruntBin = grunt.util._.find([ path.resolve(process.cwd(), 'node_modules', '.bin', 'grunt'), path.resolve(path.dirname(process.execPath), 'grunt'), path.resolve(__dirname, '..', '..', 'node_modules', '.bin', 'grunt'), ], function(bin) { return grunt.file.exists(bin); }); if (process.platform === 'win32') { gruntBin += '.cmd'; } if (!grunt.file.exists(gruntBin)) { grunt.fatal('The Grunt binary could not be found.'); } // get next/kill process trigger var trigger = options.trigger || 'Waiting...'; delete options.trigger; // CWD to spawn var cwd = options.cwd || process.cwd(); delete options.cwd; // turn options into spawn options var spawnOptions = []; grunt.util._.each(options, function(val, key) { spawnOptions.push('--' + key); spawnOptions.push(val); }); spawnOptions.push(task); // Return an interface for testing this task function returnFunc(runs, done) { var spawnGrunt = spawn(gruntBin, spawnOptions, {cwd:cwd}); var out = ''; if (!grunt.util._.isArray(runs)) { runs = [runs]; } // Append a last function to kill spawnGrunt runs.push(function() { spawnGrunt.kill('SIGINT'); }); // After watch starts waiting, run our commands then exit spawnGrunt.stdout.on('data', function(data) { data = grunt.log.uncolor(String(data)); out += data; // If we should run the next function var shouldRun = true; // If our trigger has been found if (trigger !== false) { shouldRun = (grunt.util._.indexOf(data.split("\n"), trigger) !== -1); } // Run the function if (shouldRun) { setTimeout(function() { var run = runs.shift(); if (typeof run === 'function') { run(); } }, 500); } }); // Throw errors for better testing spawnGrunt.stderr.on('data', function(data) { throw new Error(data); }); // On process exit return what has been outputted spawnGrunt.on('exit', function() { done(out); }); } returnFunc.options = options; return returnFunc; }
child.on('error', function(error) { grunt.verbose.writeln('phantomjs ERROR'); grunt.fatal(error); });
child.on('exit', function(code) { grunt.verbose.writeln('phantomjs END'); if (code) grunt.fatal('phantomjs FAIL'); });