startProtractor: function(config, done){ var sauceUser = grunt.option('sauceUser'); var sauceKey = grunt.option('sauceKey'); var tunnelIdentifier = grunt.option('capabilities.tunnel-identifier'); var sauceBuild = grunt.option('capabilities.build'); var browser = grunt.option('browser'); var args = ['node_modules/protractor/bin/protractor', config]; if (sauceUser) args.push('--sauceUser='******'--sauceKey=' + sauceKey); if (tunnelIdentifier) args.push('--capabilities.tunnel-identifier=' + tunnelIdentifier); if (sauceBuild) args.push('--capabilities.build=' + sauceBuild); if (browser) { args.push('--browser=' + browser); args.push('--params.browser=' + browser); } var p = spawn('node', args); p.stdout.pipe(process.stdout); p.stderr.pipe(process.stderr); p.on('exit', function(code){ if(code !== 0) grunt.fail.warn('Protractor test(s) failed. Exit code: ' + code); done(); }); },
versions.forEach(function (version) { // .. then create a karma config for it! var karmaConfigName = 'angular-' + grunt.config.escape(version); if (grunt.option('core') || grunt.option('fast')){ grunt.config('karma.' + karmaConfigName, { options: { files: util.testDependencies.unit .concat(util.angularFiles(version) .concat(util.testFiles.core_unit)) } }); } else if ( grunt.option('feature') ){ grunt.config('karma.' + karmaConfigName, { options: { files: util.testDependencies.unit .concat(util.angularFiles(version) .concat(util.testFilesFeature(grunt.option('feature')).unit)) } }); } else { grunt.config('karma.' + karmaConfigName, { options: { files: util.testDependencies.unit .concat(util.angularFiles(version) .concat(util.testFiles.unit)) } }); } });
actions.copy = function copy(source, destination, options) { source = this.isPathAbsolute(source) ? source : path.join(this.sourceRoot(), source); grunt.option('verbose', true); grunt.file.copy(source, destination, options); grunt.option('verbose', false); return this; };
// Just fooling around (not used) function runTaskDirect(task, path, callback) { //reload grunt module require.uncache('grunt'); var grunt = require("grunt"); grunt.option('gruntfile', path + "Gruntfile.js"); grunt.option('verbose', "true"); grunt.task.init([]); grunt.task.run(task); grunt.task.start(); }
enable: function (test) { test.expect(1); grunt.loadTasks('use-the-force'); grunt.option('force', false); grunt.task.run('use-the-force'); test.equal(grunt.option('force'), true, 'should have the force flag as true'); test.done(); },
function licenseBanner(){ var currentYear = '' + new Date(Date.now()).getFullYear(); return grunt.template.process( grunt.file.read('grunt/templates/licenseBanner.js.jst') ,{ data: { currentYear: currentYear ,name: grunt.option('name') ,author: grunt.option('author') } } ); }
createKarmangularConfig: function() { var versions; if (grunt.option('fast')){ versions = [util.latestAngular()]; } else { // For each file found, make sure it's a directory... versions = grunt.option('angular') ? grunt.option('angular').split(/,/) : null || util.angulars(); } if (grunt.option('angular')) { if (grunt.option('angular') === 'latest') { versions = [util.latestAngular()]; } grunt.log.writeln("Using angular " + grunt.util.pluralize(versions, "version/versions") + ": " + versions.join(', ')); } versions.forEach(function (version) { // .. then create a karma config for it! var karmaConfigName = 'angular-' + grunt.config.escape(version); if (grunt.option('core') || grunt.option('fast')){ grunt.config('karma.' + karmaConfigName, { options: { files: util.testDependencies.unit .concat(util.angularFiles(version) .concat(util.testFiles.core_unit)) } }); } else if ( grunt.option('feature') ){ grunt.config('karma.' + karmaConfigName, { options: { files: util.testDependencies.unit .concat(util.angularFiles(version) .concat(util.testFilesFeature(grunt.option('feature')).unit)) } }); } else { grunt.config('karma.' + karmaConfigName, { options: { files: util.testDependencies.unit .concat(util.angularFiles(version) .concat(util.testFiles.unit)) } }); } }); },
function createBuildConfig(absPathToConfigFolder) { var loadDeveloperConfig; if (grunt.option('devConfig') !== undefined) { grunt.verbose.writeln('detected command line argument: --devConfig=' + grunt.option('devConfig')); loadDeveloperConfig = grunt.option('devConfig'); } else { loadDeveloperConfig = true; } var configs = []; var systemConfig = './system.config.js'; configs.push(systemConfig); var projectConfig = path.normalize(absPathToConfigFolder + path.sep + '/project.config.js'); configs.push(projectConfig); if (loadDeveloperConfig) { // developer config don't have to exist because the build system defines a template only. // Perhaps the developer created a developer config based on this template, perhaps he doesn't. try { var developerConfig = path.normalize(absPathToConfigFolder + path.sep + 'developer.config.js'); // try to load require(developerConfig); // if no exception configs.push(developerConfig); } catch (e) { grunt.log.writeln('No developer config found!'); } } var buildConfig = loadAndMergeConfigs(configs); /* for easier usage within the task configuration * we concatenate the output dir and the build / compile dir to a new property outdir */ buildConfig.build.prepare.outdir = buildConfig.build.output.dir + '/' + buildConfig.build.prepare.dir; buildConfig.build.compile.outdir = buildConfig.build.output.dir + '/' + buildConfig.build.compile.dir; buildConfig.build.dist.e2e.outdir = buildConfig.build.output.dir + '/' + buildConfig.build.dist.e2e.dir; buildConfig.app.files.html.forEach(function (htmlFile) { buildConfig.app.files.templates.push('!' + htmlFile); }); return buildConfig; }
grunt.registerTask('test', function(target) { var taskEnv = target || 'development'; if (_.isUndefined(target)) { taskEnv = 'ci'; } grunt.task.run('env:test'); var tasks = _.map(grunt.config.getRaw('config.sharedTasks'), function(task) { if (task === 'browserify:<%= env %>') { return ['browserify:development', 'browserify:test']; } return grunt.template.process(task, { data: { env: 'test' } }); }); if (taskEnv === 'serve') { tasks.push('connect:test:keepalive'); } else { if (testServerRunning) { tasks.push('karma:' + taskEnv + ':run'); } else { tasks.push('connect:test', 'karma:' + taskEnv); } testServerRunning = true; } grunt.option('force', true); // do not quit grunt if it encounters errors in tasks grunt.task.run(_.flatten(tasks)); });
debugOption: function (test) { test.expect(1); var files = path.join(fixtures, 'pass.scss'), muted = grunt.log.muted, stdoutMsg = ''; grunt.log.muted = false; hooker.hook(process.stdout, 'write', { pre: function (result) { stdoutMsg += grunt.log.uncolor(result); return hooker.preempt(); } }); grunt.option('debug', true); scsslint.lint(files, defaultOptions, function () { grunt.option('debug', undefined); hooker.unhook(process.stdout, 'write'); grunt.log.muted = muted; test.ok(stdoutMsg.indexOf('Run command: scss-lint -c') !== -1, 'Show debug information'); test.done(); }); },
processUrlFormat: function(test) { var actual, expected, dataSet; dataSet = { template: 'example.tpl', templateDir: 'templates', dest: 'tmp', urlDateFormat: 'yyyy-mm-dd', urlFormat: 'PREFIX-SLUG/article.link.txt' }; grunt.option('title', 'This is the title'); test.expect(2); actual = textfile.processUrlFormat(dataSet); expected = '1-this-is-the-title/article.link.txt'; test.equal(actual, expected, 'Should generate the right filepath.'); dataSet.urlFormat = 'DATE-SLUG.md'; actual = textfile.processUrlFormat(dataSet); expected = grunt.template.today(dataSet.urlDateFormat) + '-this-is-the-title.md'; test.equal(actual, expected, 'Should generate the right filepath.'); test.done(); },
function resolveInFile (fname){ var source = null; if (self.resolveSource) { source = self.resolveSource(fname, lfile.dir, lfile.name, block.dest, searchPath); if (source) { if (!fs.existsSync(source)) { throw new Error(_.template('usemin: resolveSource() returned non-existent path "<%= source %>" for source "<%= fname %>".', {source: source, fname: fname})); } return source; } } if (source !== false) { for (var i=0; i<searchPath.length; ++i) { source = path.join(searchPath[i], fname); if (fs.existsSync(source)) { return source; } } } if (self.warnMissing) { var msg = _.template('usemin: can\'t resolve source reference "<%= fname %>" (file "<%= filepath %>", block "<%= block.dest %>").', {fname: fname, block: block, filepath: path.join(lfile.dir, lfile.name)}); if (grunt.option('force')) { grunt.fail.warn(msg); }else{ throw new Error(msg); } } // we know it's not there, but return placeholder to match old behavior. return path.join(searchPath[0], fname); }
.finally(function(){ if (grunt.option('webdriver-keep-open')) { return; } grunt.verbose.writeln('Closing the browser window. To keep it open, pass the --webdriver-keep-open flag to grunt.'); return browser.quit(); })
scsslint.lint(files, defaultOptions, function () { grunt.option('debug', undefined); hooker.unhook(process.stdout, 'write'); grunt.log.muted = muted; test.ok(stdoutMsg.indexOf('Run command: scss-lint -c') !== -1, 'Show debug information'); test.done(); });
startKarma: function(config, singleRun, done){ var browsers = grunt.option('browsers'); var reporters = grunt.option('reporters'); var noColor = grunt.option('no-colors'); var p = spawn('node', ['node_modules/karma/bin/karma', 'start', config, singleRun ? '--single-run=true' : '', reporters ? '--reporters=' + reporters : '', browsers ? '--browsers=' + browsers : '', noColor ? '--no-colors' : '' ]); p.stdout.pipe(process.stdout); p.stderr.pipe(process.stderr); p.on('exit', function(code){ if(code !== 0) grunt.fail.warn("Test(s) failed"); done(); }); },
grunt.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 = allInit ? null : grunt.option('gruntfile') || grunt.file.findup('Gruntfile.{js,coffee}', {nocase: true}); var msg = 'Reading "' + (gruntfile ? path.basename(gruntfile) : '???') + '" Gruntfile...'; /*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') || []).forEach(task.loadNpmTasks); // Load all user-specified --tasks. (grunt.option('tasks') || []).forEach(task.loadTasks); };
startKarma: function(config, singleRun, done) { var browsers = grunt.option('browsers'); var reporters = grunt.option('reporters'); var noColor = grunt.option('no-colors'); var port = grunt.option('port'); var p = spawn('karma', ['start', config, singleRun ? '--single-run=true' : '', reporters ? '--reporters=' + reporters : '', browsers ? '--browsers=' + browsers : '', noColor ? '--no-colors' : '', port ? '--port=' + port : '' ]); p.stdout.pipe(process.stdout); p.stderr.pipe(process.stderr); p.on('exit', function(code) { if (code !== 0) grunt.fail.warn('Karma test(s) failed. Exit code: ' + code); done(); }); },
(function (exports) { 'use strict'; var grunt = require('grunt'); var initialValue = grunt.option('initial-value') || 0; var timeout = grunt.option('timeout') || 1; // Create a promise for increasing the value. exports.increase = function (value) { return new Promise(function (resolve) { setTimeout(function () { value++; grunt.log.writeln('addition:value', value); resolve(value); }, timeout); }); }; // Create a promise for multiplying the value. exports.multiply = function (value) { return new Promise(function (resolve) { setTimeout(function () { value *= 10; grunt.log.writeln('multiplication:value', value); resolve(value); }, timeout); }); }; // An "add" promise. exports.add = function () { return this.increase(initialValue) // Expected value: 1 .then(exports.increase) // Expected value: 2 .then(exports.increase) // Expected value: 3 .then(exports.increase) // Expected value: 4 .then(exports.increase) // Expected value: 5 ; }; })(module.exports);
// helpers function runCli(name, gruntfile) { var fn; if (typeof gruntfile === 'function') { fn = gruntfile; } else { fn = require(path.resolve(gruntfile)); } if (typeof fn === 'function') { fn.call(grunt, grunt); if (grunt.task._tasks[name]) { grunt.option('gruntfile', gruntfile); grunt.option('base', process.cwd()); grunt.task.init([name]); grunt.task.run(name); grunt.task.start(); return true; } } return false; }
module.exports.register = function (Handlebars, options, params) { "use strict"; var grunt = require("grunt") var basePath = require("path").dirname(grunt.option("gruntfile")); var gruntFileConfig = basePath + "/gruntfileConfig.json"; var config = grunt.file.readJSON(gruntFileConfig); Handlebars.registerHelper("cssFileName", function() { return config.css.fileName + ".css"; }) };
function runCli(name, gruntfile) { var fn; if (typeof gruntfile === 'function') { fn = gruntfile; } else { fn = require(path.resolve(gruntfile)); } if (typeof fn === 'function') { fn.call(grunt, grunt); if (grunt.task._tasks[name]) { grunt.option('gruntfile', gruntfile); grunt.option('base', process.cwd()); var task = grunt.task; var fail = grunt.fail; var uncaughtHandler = function(e) { fail.fatal(e, fail.code.TASK_FAILURE); }; process.on('uncaughtException', uncaughtHandler); task.options({ error: function(e) { fail.warn(e, fail.code.TASK_FAILURE); }, done: function() { process.removeListener('uncaughtException', uncaughtHandler); fail.report(); process.exit(0); } }); task.init([name]); task.run(name); task.start(); return true; } } return false; }
scsslint.lint(files, testOptions, function (results) { grunt.option('debug', undefined); hooker.unhook(process.stdout, 'write'); grunt.log.muted = muted; test.ok(results, 'Should return results.'); test.ok( stdout[1].indexOf('scss-lint failed, but was run in force mode') !== -1, 'Should log forcing.' ); test.done(); });
it('should work with a real-world grunt-crx run', function (done) { // load the task as if done by grunt var task = require('../tasks/crx.js'); task(grunt); grunt.option('options.silently', true); // run it as if done by grunt (just no log output) grunt.log.muted = true; grunt.tasks(['crx:standard'], {}, function() { expect(grunt.file.expand('test/data/files/test.crx')).to.have.lengthOf(1); grunt.log.muted = false; done(); }); });
getGruntConfig: function () { /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Load the build configuration. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ var fabsBuildConfig = configuration.getConfig(); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Load the task configuration, the object Grunt uses to give each task its instructions and apply the build * configuration -> replace all variables like '<%= build.output.dir %>' within task configuration with the * value from build configuration. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ grunt.verbose.writeln('reading tasks configuration'); var tasksConfig = require('./tasks/config.js'); grunt.verbose.writeln('tasks configuration read'); var gruntConfig = _.extend(tasksConfig, fabsBuildConfig); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Load composite and custom tasks. No need to do anything else than require the modules. They register the * tasks themselves. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ grunt.verbose.writeln('registering tasks'); require('./tasks/def.npm.js'); require('./tasks/def.composite.js'); require('./tasks/def.custom.js'); grunt.verbose.writeln('tasks registered'); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Dump configuration to console (e.g. for debugging the build system) * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ if (grunt.option('dump')) { var asterisk = grunt.util.repeat(60, '* '); grunt.log.writeln(asterisk); grunt.log.writeln('Build configuration: ' + JSON.stringify(buildConfig, null, ' ')); grunt.log.writeln(asterisk); grunt.log.writeln('Tasks configuration: ' + JSON.stringify(tasksConfig, null, ' ')); grunt.log.writeln(asterisk); } return gruntConfig; },
var makeOptions = function (options) { var baseOptions = { base: null, prefix: 'grunt-', verbose: false }; if (options) { for (var key in options) { baseOptions[key] = options[key]; if(key != 'base' && key != 'prefix'){ grunt.option(key, options[key]); } } } return baseOptions; };
module.exports = (function() { var grunt = require("grunt"); var DEBUG = !!grunt.option('dbg'); return { options: { outputStyle: DEBUG ? 'expanded' : 'compressed', includePaths: [ 'vendor/susy/sass/susy' ] }, files: [ {dest: '<%= buildDestination %>.css', src: 'src/scss/showcar-ui.scss'}, {dest: 'docs/css/documentation.css', src: 'docs/css/documentation.scss'}, { expand: true, cwd: 'examples/', src: ['**/*.scss'], dest: './examples', ext: '.css' } ] } })();
function getTasks(gruntfilePath) { var key; if (!fs.existsSync(gruntfilePath + "Gruntfile.js")) { domain.emitEvent("grunt", "change", 'No gruntfile found at: "' + gruntfilePath + '"<br>'); return; } //reload grunt module require.uncache('grunt'); var grunt = require("grunt"); grunt.option('gruntfile', gruntfilePath + "Gruntfile.js"); grunt.task.init([]); var tasks = []; for (key in grunt.task._tasks) { var task = {}; task.name = key; task.isAlias = (grunt.task._tasks[key].info && grunt.task._tasks[key].info.indexOf("Alias for ") > -1); task.isDefault = (key === "default"); tasks.push(task); } return tasks.sort(function (a, b) { if ((a.isAlias && b.isAlias) || (!a.isAlias && !b.isAlias)) { return a.name === b.name ? 0 : (a.name < b.name ? -1 : 1); } else if (a.isAlias) { return -1; } else { return 1; } }); }
parallelTask: function(args, options) { var task = { grunt: true, args: args, stream: options && options.stream }; args.push('--port=' + this.sauceLabsAvailablePorts.pop()); if (args.indexOf('test:e2e') !== -1 && grunt.option('e2e-browsers')) { args.push('--browsers=' + grunt.option('e2e-browsers')); } else if (grunt.option('browsers')) { args.push('--browsers=' + grunt.option('browsers')); } if (grunt.option('reporters')) { args.push('--reporters=' + grunt.option('reporters')); } return task; },
fail= { fatal: function (m) { var e= new Error(m); e.fail= true; throw(e); } }, _= grunt.util._, async= grunt.util.async, mem= function () { return util.inspect(process.memoryUsage()); }; grunt.option('verbose',_.contains(process.argv,'--verbose')); grunt.option('debug',_.contains(process.argv,'--debug')); grunt.option('stack',_.contains(process.argv,'--stack')); cheerio.prototype.odd = function() { var odds = []; this.each(function(index, item) { if (index % 2 == 1) { odds.push(item); } }); return cheerio(odds); };
var grunt = require('grunt'); module.exports = { demo: { options: { source: 'demo/static/css/', destination: 'demo/', template: 'node_modules/cf-component-demo/' + ( grunt.option('tpl') || 'raw' ) + '/', templateData: { ltIE9AltSource: '<%= opt.ltIE9AltSource %>', ltIE8Source: '<%= opt.ltIE8Source %>', ie8FontFaceHack: '<%= opt.ie8FontFaceHack %>', html5Shiv: '<%= opt.html5Shiv %>', modernizr: '<%= opt.modernizr %>', jsBody: '<%= opt.jsBody %>', family: '<%= pkg.name %>', title: '<%= pkg.name %> demo', repo: '<%= pkg.homepage %>', custom: '<%= grunt.file.read("demo/custom.html") %>' } } }, docs: { options: { source: 'docs/static/css/', destination: 'docs/', template: 'node_modules/cf-component-demo/' + ( grunt.option('tpl') || 'docs' ) + '/', templateData: { modernizr: '<%= opt.modernizr %>', jsBody: '<%= opt.jsBody %>', family: '<%= pkg.name %>',