Sets up grunt for functioning with the specific add ins/modules and
configuration we provide in this gruntfile.js.
@param {grunt} grunt
164779
function prepareGrunt(grunt) {
    var allFiles = [
        'package.json',
        'Gruntfile.js',
        'lib/**/*.js',
        'spec/**/*',
        '.jshintrc',
        'spec/**/.jshintrc',
        'lib/**/.jshintrc'
    ];

    var allConfigFiles = [
        'Gruntfile.js'
    ];

    var allLibFiles = [
        'Gruntfile.js',
        'lib/**/*.js',
        'index.js'
    ];

    var allSpecFiles = [
        'spec/**/*-spec.js'
    ];

    var allIgnoreFiles = [
        'node_modules/**/*',
        'spec/**/*-disabled.js'
    ];

    // grunt configuration.
    grunt.initConfig({

        // grunt-contrib-jshint
            jshint: {
                // grunt jshint:source
                // will check the source files only
                source: {
                    src: allLibFiles
                },
                // grunt jshint:spec
                // will check the spec files only
                spec: {
                    src: allSpecFiles,
                    // use test specific .jshintrc for spec folder
                    options: {
                        jshintrc: 'spec/.jshintrc'
                    }
                },
                options: {
                    // default to the root .jshintrc
                    jshintrc: '.jshintrc',

                    // ensure we don't waste our time on files we have
                    // explicitly disabled or that we have brought in from
                    // other libraries.
                    ignores: allIgnoreFiles
                }
            },

        // grunt-contrib-watch
            watch: {
                // use with 'grunt watch' from command line ensure we reload
                // our watches when ANY of these files change.
                files: allConfigFiles,
                options: {
                    reload: true
                },
                jshint: {
                    files: allFiles,
                    tasks: ['jshint'],
                    options:{
                        interrupt: true,
                        atBegin: true
                    }
                },
                // grunt watch:mochaTest
                mochaTest: {
                    files: allFiles,
                    tasks: ['coverage'],
                    options:{
                        interrupt: true,
                        atBegin: true
                    }
                }
            },

        // grunt-mocha-test
            mochaTest: {
                // run all tests
                test: {
                    options: {
                        reporter: 'spec',
                        require: 'spec/helper'
                    },
                    src: allSpecFiles
                },
                min: {
                    options: {
                        reporter: 'spec',
                        require: 'spec/helper'
                    },
                    src: allSpecFiles
                }
            },

            'mocha_istanbul': {
                coverage: {
                    src: 'spec',
                    options: {
                        excludes: [
                            'spec/**/*.js'
                        ],
                        mask: '**/*-spec.js',
                        reportFormats: ['html'],
                        mochaOptions: [
                            '--require',
                            'spec/helper'
                        ]
                    }
                }
            }
        });

    // These plugins provide necessary tasks.
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-mocha-test');
    grunt.loadNpmTasks('grunt-mocha-istanbul');
    grunt.loadNpmTasks('grunt-notify');

    // Whenever the "coverage" task is run, run these tasks
    grunt.registerTask('coverage', ['mocha_istanbul:coverage']);

    // Whenever the "test" task is run, run these tasks
    grunt.registerTask('test', ['jshint', 'mochaTest:test']);

    // By default, lint and run all tests.
    grunt.registerTask('default', ['jshint', 'coverage']);
}
760644
function createFiles (num, dir) {
  for (var i = 0; i < num; i++) {
    grunt.file.write(path.join(dir, 'test-' + i + '.js'), 'var test = ' + i + ';');
  }
}
685286
function init() {
	var ugr = rbot.env ? rbot.env.usingGrunt : require.main.filename.indexOf('grunt') >= 0;
	if (!rbot.env) {
		rbot.env = {
			usingGrunt : ugr
		}
	}
	var notr = !rbot.env.taskRunner;
	if (notr) {
		// grunt should pass instance as 1st argument
		rbot.env.taskRunner = ugr ? (arguments[0] ? arguments[0] : require('grunt')) : require('gulp');
	}
	var tr = rbot.env.taskRunner;
	if (notr || !rbot.log) {
		var ugrl = ugr && tr && tr.log;
		rbot.log = {
			verboseEnabled : !ugr || !tr || tr.option('verbose'),
			verbose : ugr && tr && tr.verbose ? tr.verbose.writeln : console.log,
			debug : ugrl ? tr.log.debug : console.log,
			info : console.info || console.log,
			warn : console.warn,
			error : ugrl ? tr.log.error : console.error,
			fail : function fail(e) {
				var tr = rbot.env.taskRunner;
				if (rbot.env.usingGrunt && tr && tr.fail) {
					return tr.fail.fatal(e);
				}
				throw (e instanceof Error ? e : new Error(e));
			},
			dir : ugrl ? tr.log.writeflags : console.dir
		};
	}
	if (notr || !rbot.file) {
		var ugrf = ugr && tr && tr.file;
		rbot.file = {
			read : ugrf ? tr.file.read : null,
			write : ugrf ? tr.file.write : null,
			defaultEncoding : ugrf ? tr.file.defaultEncoding : null,
			readJSON : ugrf ? tr.file.readJSON : null,
			writeJSON : ugrf ? tr.file.writeJSON : null
		};
	}
	if (notr || !rbot.option) {
		rbot.option = ugr && tr && tr.option ? tr.option : null;
	}
}
1191387
function (options, callback) {
        options = extend({}, MODULE_LOADER_DEFAULTS, options)
        var modulesFolder = options.uri

        iterateFiles(modulesFolder, loadModule, callback, isJsFile)

        function loadModule(fileName) {
            if (options.skip && options.skip.test(fileName)) {
                return
            }
            var module = require(fileName)
            var name = path.relative(options.uri, fileName)
            options.core.add(name, module)
        }
    }
878081
protected void addModuleArg(String jsFile, String moduleName, List<String> args, StringBuilder moduleArg) {
		int argIdx = 0;
		for (Iterator<String> iterArg = args.iterator(); iterArg.hasNext(); argIdx++) {
			String arg = iterArg.next();
			if (arg.equals(JS_ARG)) {
				iterArg.next();
				arg = iterArg.next();
				argIdx += 2;
			}
			if (arg.equals(MODULE_ARG)) {
				arg = iterArg.next();
				argIdx++;
				Matcher matcher = MODULE_ARG_PATTERN.matcher(arg);
				if (matcher.find()) {
					String dep = matcher.group(1);
					if (dep != null) {
						List<String> moduleDependencies = Arrays.asList(dep.split(MODULE_DEPENDENCIES_SEPARATOR));
						if (moduleDependencies.contains(moduleName)) {
							break;
						}
					}
				} else {
					throw new BundlingProcessException(
							"There were an error in the generation of the module dependencies.");
				}
			}
		}

		args.add(argIdx++, JS_ARG);
		args.add(argIdx++, jsFile);
		args.add(argIdx++, MODULE_ARG);
		args.add(argIdx++, moduleArg.toString());
	}
395647
function configureGrunt(docs, ghpages) {
  console.log(chalk.gray("Compiling the grunt template file..."));

  let templateFilePath = `${config.path.templates}/grunt`;
  
  let gruntfileName = 'Gruntfile.js';
  let gruntfileFiles = [
    `"${templateFilePath}/Gruntfile_header.js"`,
    `"${templateFilePath}/Gruntfile_${ghpages}.js"`,
    `"${templateFilePath}/Gruntfile_${docs}.js"`,
    `"${templateFilePath}/Gruntfile_middle.js"`,
    `"${templateFilePath}/Gruntfile_${ghpages}_npm.js"`,
    `"${templateFilePath}/Gruntfile_${docs}_npm.js"`,
    `"${templateFilePath}/Gruntfile_footer.js"`
  ];

  let gruntfileExists = fs.readdirSync('./').some((file, index, array) => {
    return file.toLowerCase() == gruntfileName.toLowerCase();
  });

  if (gruntfileExists === true) {
    console.log(chalk.yellow("Gruntfile.js already exists. Creating a temporary file instead..."));
    gruntfileName = `${gruntfileName}.tmp`;
  }

  execSync(`cat ${gruntfileFiles.join(' ')} > ${gruntfileName}`);
}
818424
function (value)
		{
			if (value != undefined && fs.statSync(value).isDirectory())
			{
				this.modulePath = value;
				this.setConfig('modulePath',value);
			}
			return this;
		}
1146657
function checkFile( path ) {
            if ( typeof path === "undefined" || ! grunt.file.exists( path ) ) {
                grunt.log.error( "Source file \"" + path + "\" not found." );
                return false;
            }

            return true;
        }
1139566
function registerTask( task ) {
		grunt.registerMultiTask( task.name, task.help, function () {
			var done = this.async();
			if ( ensureSketchtool() ) {
				var options = this.options();

				var commands = [];
				this.files.forEach( function( file ) {
					file.src.filter( function ( src ) {
						var command = createCommand( task, src, file.dest, options );
						if ( command ) {
							commands.push( command );
						}
					} );
				});
				
				async.eachLimit( commands, numCPUs, function ( command, next ) {
					executeCommand( command, next );
				}, done );
			} else {
				done(false);
			}
		} );
	}
1125843
function() {
        var that = this;
        var args = slice.call(arguments);

        each(args, function(arg) {
            var id = that.alias(arg);
            var type = fileType(id);
            var isComp = fileComponents(id);
            var res = {
                id: id
            };
            type = type === 'css' && isComp ? 'compcss' : (type === 'js' && isComp ? 'compjs' : type);

            that.push.apply(that, settings.deps[id]);

            if ((type === 'css') || (type === 'js') || (type === 'compcss') || (type === 'compjs')) {
                (that.depends[type] || (that.depends[type] = [])).push(res);
                ++that.length;
            }
        });
    }
534397
function (cb) {
    // check if we have a custom index file set
    if (settings.index) {
      // generate the real index file path
      var indexFile = process.cwd() + '/' + settings.index;

      // check if the file exists, throw an error otherwise
      if (!grunt.file.exists(indexFile)) {
        grunt.log.error('Index file: "' + indexFile + '" not found');
        cb('Index file: "' + indexFile + '" not found');
        return;
      }

      // load the file contents
      sourceFile = grunt.file.read(indexFile);
    }

    // modify the sourcefile css according to the settings
    var css = settings.css.map(function (file) {   
      if (settings.snapshot && file.search('http://') !== -1) {
        return '<link rel="stylesheet" type="text/css" href="' + path.basename(file) + '"/>';
      } else {
        return '<link rel="stylesheet" type="text/css" href="' + file + '"/>';
      }
    });
    sourceFile = sourceFile.replace('{{css}}', css.join(''));

    // spit out the default sourcefile
    cb(sourceFile);
  }
507674
function addFiles(sources, dest, options) {
      var opt = _.extend({}, defaultOptions, options || {});

      if(_.isString(sources)) {
        sources = [sources];
      }

      if(!inCwd(dest) || _.any(sources, function(src) {
        return !inCwd(src);
      })) {
        grunt.verbose.writeln('Ignore %s to %s: not in CWD.');
        return;
      }

      return addToQueueCopy(sources, dest, opt);
    }
406898
function (taskName, taskFiles) {
  grunt.log.writeln("Versioning files from " + taskName + " task.");
  this.taskName = taskName;

  this.taskConfig = this.getTaskConfig();

  if (!this.taskConfig) {
    grunt.fail.warn("Task '" + this.taskName + "' doesn't exist or doesn't have any configuration.", 1);
  }

  this.taskFiles = taskFiles || this.getFiles();
  if (!this.taskFiles || this.taskFiles.length === 0) {
    grunt.fail.warn("Task '" + this.taskName + "' doesn't have any src-dest file mappings.", 1);
  }

}
648763
function(module) {
			if (!module) {
				return;
			}

			var file = fileByModules(module);
			Array.prototype.push.apply(seen, file.modules);
			file.requires.forEach(function(module) {
				// Ignore resoled modules and dependencies in own file
				if((_.indexOf(resolved, module) < 0) &&
				   (_.indexOf(file.modules, module) < 0)) {
					// Catch circular dependencies
					if(_.indexOf(seen, module) < 0) {
						resolve(module);
					}
					else {
						grunt.fail.fatal('Circular dependency detected:\n\t' +
						                 file.modules.join(', ') + ' depend on ' +
						                 module, 1);
					}
				}
			});
			Array.prototype.push.apply(resolved, file.modules);
		}
1068577
function () {
			/** A stateful object to hold items till they are added to the compiler */
			var pkg = {
				exec          : [],
				aliases       : {},
				dependAliases : [],
				ignore        : [],
				publish       : [],
				externals     : [],
				modules       : [],
				noParse       : []
			};

			// process modules to ignore
			var ignore = task.data.ignore;
			if ( !sys.isEmpty( ignore ) && !sys.isEmpty( ignore.src ) ) {
				grunt.verbose.writeln( "Adding ignores" );

				pkg.ignore = sys.map( grunt.file.expand( ignore, ignore.src ), function ( item ) {
					return resolvePath( item );
				} );
			}

			// process modules that won't be parsed
			var noParse = task.data.noParse;
			if ( !sys.isEmpty( noParse ) && !sys.isEmpty( noParse.src ) ) {
				grunt.verbose.writeln( "Adding ignores" );

				pkg.noParse = sys.map( grunt.file.expand( noParse, noParse.src ), function ( item ) {
					return resolvePath( item );
				} );
			}

			// process executable modules
			var exec = task.data.exec;
			if ( !sys.isEmpty( exec ) && !sys.isEmpty( exec.src ) ) {
				grunt.verbose.writeln( "Adding executable modules" );

				pkg.exec = sys.map( grunt.file.expand( exec, exec.src ), function ( item ) {
					return resolvePath( item );
				} );
			}

			// process module entries
			var modules = task.data.modules;
			if ( !sys.isEmpty( modules ) && !sys.isEmpty( modules.src ) ) {
				grunt.verbose.writeln( "Adding modules" );

				pkg.modules = sys.map( grunt.file.expand( modules, modules.src ), function ( item ) {
					return resolvePath( item );
				} );
			}

			// process modules to be published
			var publish = task.data.publish;
			if ( !sys.isEmpty( publish ) && !sys.isEmpty( publish.src ) ) {
				grunt.verbose.writeln( "Adding published modules" );

				pkg.publish = sys.map( grunt.file.expand( publish, publish.src ), function ( item ) {
					return resolvePath( item );
				} );
			}

			// process externals entries
			var externals = task.data.externals;
			if ( !sys.isEmpty( externals ) && !sys.isEmpty( externals.src ) ) {
				grunt.log.writeln( "Adding external modules" );

				pkg.externals = sys.map( grunt.file.expand( externals, externals.src ), function ( item ) {
					return resolvePath( item );
				} );
			}

			// get all task aliases
			sys.extend( pkg.aliases, getTaskAliases( task.target, options ) );
			if ( !sys.isEmpty( task.data.depends ) ) {
				sys.each( task.data.depends, function ( depends ) {
					var dependents = getTaskAliases( depends, options );

					sys.each( dependents, function ( val, key ) {
						pkg.dependAliases.push( key );
					} );
				} );
			}

			// get dependencies definitions and add them to this as external
			if ( options.autoExternals && !sys.isEmpty( task.data.depends ) ) {
				sys.each( task.data.depends, function ( depends ) {
					pkg.externals = pkg.externals.concat( getTaskSources( depends ) );
				} );
			}

			return pkg;
		}
1066755
function(stage) {
      var fileStart = options.dir + '/' + stage;
      for (var ext in input) {
        if (grunt.file.exists(fileStart + '.' + ext)) {
          return true;
        }
      }
      return false;
    }
446097
function setBanner() {
        if (grunt.config.get('app_plugins_mode_release')) {
            var moduleName = grunt.config.get('app_plugins_work_script_name') + '.js';
            var version = grunt.config.get('app_plugins_work_version');
            var src = path.join(
                grunt.config.get('app_plugins_root_dir'),
                grunt.config.get('app_plugins_work_id'),
                grunt.config.get('plugins_www'),
                grunt.config.get('app_plugins_work_script_name') + '.js'
            );

            var info = {
                src: src,
                moduleName: moduleName,
                version: version,
            };

            grunt.config.set('banner_info', info);
            grunt.task.run('banner_setup');
        }
    }