<commit_before>/* global module */
var glob = require('glob');
var _ = require('underscore');
var fs = require('fs');
var path = require('path');
//var buildPack = require('./tools/buildPack');

module.exports = function (grunt) {
	'use strict';
	var engineVersion = grunt.option('goo-version') || 'UNOFFICIAL';

	var gooModule = {
		name: 'goo'
	};
	var engineFilename = './out/goo.js';

	// Returns the code to add at the start and end of the minified file
	function getWrapper() {
		var wrapperHead = '';
		var wrapperTail = '';

		wrapperHead +=
			'/* Goo Engine ' + engineVersion + '\n' +
			' * Copyright 2014 Goo Technologies AB\n' +
			' */\n';

		var customRequire = fs.readFileSync('tools/customRequire.js');
		wrapperHead += customRequire;

		wrapperHead += '(function(window) {';

		// Put all calls to define and require in the f function
		wrapperHead +=
			'function f(){';
		wrapperTail +=
			'}' +
			'try{' +
			'if(window.localStorage&&window.localStorage.gooPath){' +
				// We're configured to not use the engine from goo.js.
				// Don't call the f function so the modules won't be defined
				// and require will load them separately instead.
				'window.require.config({' +
					'paths:{goo:localStorage.gooPath}' +
				'})' +
			'}else f()' +
			'}catch(e){f()}';

		wrapperTail += '})(window,undefined)';
		return [wrapperHead, wrapperTail];
	}

	// Project configuration.
	grunt.initConfig({
		pkg: grunt.file.readJSON('package.json'),
		requirejs: {
			build: {
				// Options: https://github.com/jrburke/r.js/blob/master/build/example.build.js
				options: {
					baseUrl: 'src/',
					optimize: 'uglify2',  // uglify, uglify2, closure, closure.keepLines
					preserveLicenseComments: false,
					useStrict: true,
					wrap: false,
					keepBuildDir: true,
					//generateSourceMaps: true,
					dir: 'out/minified/',
					modules: [gooModule],
					paths: {
						'requireLib': '../lib/require'
					}

					// I tried using a wrap block like this, but it has no effect
					// wrap: { ... }
					/*
					uglify2: {
						output: {
							beautify: true
						},
						compress: {
							sequences: false,
							global_defs: {
								DEBUG: false
							}
						},
						warnings: true,
						mangle: false
					}*/
				}
			}
		},
		wrap: {
			build: {
				src: ['out/minified/goo.js'],
				dest: engineFilename,
				options: {
					wrapper: getWrapper()
				}
			}
		},
		clean: {
			build: {
				src: [
					'out/',
					'src/goo.js'
				]
			},
			toc: {
				src: [
					'visual-test/index.html'
				]
			},
			docs: [
				'goojs-jsdoc/',
				'goojs-jsdoc-json/',
				'goojs-jsdoc_*.tar.gz'
			]
		},
		'build-pack': {
			fsmpack: {
				packPath: 'fsmpack',
				outBaseDir: 'out'
			},
			geometrypack: {
				packPath: 'geometrypack',
				outBaseDir: 'out'
			},
			quadpack: {
				packPath: 'quadpack',
				outBaseDir: 'out'
			},
			timelinepack: {
				packPath: 'timelinepack',
				outBaseDir: 'out'
			},
			debugpack: {
				packPath: 'debugpack',
				outBaseDir: 'out'
			},
			scriptpack: {
				packPath: 'scriptpack',
				outBaseDir: 'out'
			},
			p2pack: {
				packPath: 'addons/p2pack',
				outBaseDir: 'out'
			},
			box2dpack: {
				packPath: 'addons/box2dpack',
				outBaseDir: 'out'
			},
			terrainpack: {
				packPath: 'addons/terrainpack',
				outBaseDir: 'out'
			},
			ammopack: {
				packPath: 'addons/ammopack',
			},
			cannonpack: {
				packPath: 'addons/cannonpack',
				outBaseDir: 'out'
			},
			howlerpack: {
				packPath: 'addons/howlerpack',
				outBaseDir: 'out'
			},
			waterpack: {
				packPath: 'addons/waterpack',
				outBaseDir: 'out'
			},
			soundmanager2pack: {
				packPath: 'addons/soundmanager2pack',
				outBaseDir: 'out'
			}
		},
		'build-custom': {
			myBundle: {
				outFile: 'bundle.js'
			}
		},
		karma: {
			unit: {
				configFile: 'test/karma.conf.js',
				singleRun: true,
				browsers: ['Chrome'] // Phantom just doesn't have support for the goodies we've come to know and love
			}
		},
		shell: {
			jsdoc: {
				command: path.resolve('tools', 'generate_jsdoc.sh')
			},
			jsdoc_json: {
				command: path.resolve('tools', 'generate_jsdoc_json.sh')
			}
		},
		/*
	    jsdoc : { // Could replace tools/generate_jsdoc.sh, but still need something that makes the tar.gz docs bundle
	        dist : {
	            src: ['src','tools/jsdoc-template/static/README.md'],
	            options: {
	                destination: 'goojs-jsdoc',
	                template: 'tools/jsdoc-template',
	                'private': false,
	                recurse: true
	            }
	        }
	    },
	    */
		jshint: {
			all: ['src'],
			options: {
				jshintrc: '.jshintrc',
				force: true // Do not fail the task
			}
		}
	});

	grunt.loadNpmTasks('grunt-contrib-uglify');
	grunt.loadNpmTasks('grunt-contrib-requirejs');
	grunt.loadNpmTasks('grunt-wrap');
	grunt.loadNpmTasks('grunt-contrib-clean');
	grunt.loadNpmTasks('grunt-karma');
	//grunt.loadNpmTasks('grunt-jsdoc');
	grunt.loadNpmTasks('grunt-shell');
	grunt.loadNpmTasks('grunt-contrib-jshint');

	grunt.loadTasks('tools/grunt_tasks');

	grunt.registerTask('default',	['minify']);
	grunt.registerTask('docs',		['shell:jsdoc']);
	grunt.registerTask('jsdoc',		['shell:jsdoc']);
	grunt.registerTask('minify',	['main-file', 'requirejs:build', 'wrap', 'build-pack']);
	grunt.registerTask('unittest',	['karma:unit']);
	grunt.registerTask('test',		['unittest']);

	//! AT: no better place to put this
	function extractFilename(path) {
		var index = path.lastIndexOf('/');
		return index === -1 ? path : path.substr(index + 1);
	}

	// Creates src/goo.js that depends on all engine modules
	grunt.registerTask('main-file', function () {
		// prefiltering out files in packs on the 'ground' level
		var sourceFiles = glob.sync('!(*pack)/**/*.js', { cwd: 'src/goo/', nonegate: true });

		// filtering files in packs that are not on the 'ground' level
		var regexp = /.+pack\/.+/;
		sourceFiles = sourceFiles.filter(function (sourceFile) {
			return !regexp.test(sourceFile);
		});

		var allModules = _.map(sourceFiles, function (f) {
			return 'goo/' + f.replace(/\.js/, '');
		});

		var lines = [];
		lines.push('require([');
		lines.push(_.map(allModules, function (m) { return "\t'" + m + "'"; }).join(',\n'));
		lines.push('], function (');

		var fileNames = allModules.map(extractFilename);

		lines.push('\t' + fileNames.join(',\n\t'));
		lines.push(') {');
		lines.push('\tvar goo = window.goo;\n\tif (!goo) { return; }');
		fileNames.forEach(function (fileName) {
			lines.push('\tgoo.' + fileName + ' = ' + fileName + ';');
		});

		lines.push('});');

		fs.writeFileSync('src/goo.js', lines.join('\n'));
	});

	// Creates an HTML list of tests in visual-test/index.html
	grunt.registerTask('visualtoc', function () {
		var toc = require('./visual-test/toc');
		toc.run();
	});

	// Creates an example table of content HTML file: examples/index.html
	grunt.registerTask('examplestoc', function () {
		var toc = require('./examples/toc');
		toc.run();
	});

	// Generates reference screenshots
	grunt.registerTask('refs', function () {
		var done = this.async();
		require('child_process').exec('node test/e2etesting/generate-reference-screenshots', function (error, stdout, stderr) {
		    console.log('stdout: ' + stdout);
		    console.log('stderr: ' + stderr);
		    if (error !== null) {
				console.log('exec error: ' + error);
		    }
		    done();
		});
	});
};
<commit_msg>Fixed the Gruntfile<commit_after>/* global module */
var glob = require('glob');
var _ = require('underscore');
var fs = require('fs');
var path = require('path');
//var buildPack = require('./tools/buildPack');

module.exports = function (grunt) {
	'use strict';
	var engineVersion = grunt.option('goo-version') || 'UNOFFICIAL';

	var gooModule = {
		name: 'goo'
	};
	var engineFilename = './out/goo.js';

	// Returns the code to add at the start and end of the minified file
	function getWrapper() {
		var wrapperHead = '';
		var wrapperTail = '';

		wrapperHead +=
			'/* Goo Engine ' + engineVersion + '\n' +
			' * Copyright 2014 Goo Technologies AB\n' +
			' */\n';

		var customRequire = fs.readFileSync('tools/customRequire.js');
		wrapperHead += customRequire;

		wrapperHead += '(function(window) {';

		// Put all calls to define and require in the f function
		wrapperHead +=
			'function f(){';
		wrapperTail +=
			'}' +
			'try{' +
			'if(window.localStorage&&window.localStorage.gooPath){' +
				// We're configured to not use the engine from goo.js.
				// Don't call the f function so the modules won't be defined
				// and require will load them separately instead.
				'window.require.config({' +
					'paths:{goo:localStorage.gooPath}' +
				'})' +
			'}else f()' +
			'}catch(e){f()}';

		wrapperTail += '})(window,undefined)';
		return [wrapperHead, wrapperTail];
	}

	// Project configuration.
	grunt.initConfig({
		pkg: grunt.file.readJSON('package.json'),
		requirejs: {
			build: {
				// Options: https://github.com/jrburke/r.js/blob/master/build/example.build.js
				options: {
					baseUrl: 'src/',
					optimize: 'uglify2',  // uglify, uglify2, closure, closure.keepLines
					preserveLicenseComments: false,
					useStrict: true,
					wrap: false,
					keepBuildDir: true,
					//generateSourceMaps: true,
					dir: 'out/minified/',
					modules: [gooModule],
					paths: {
						'requireLib': '../lib/require'
					}

					// I tried using a wrap block like this, but it has no effect
					// wrap: { ... }
					/*
					uglify2: {
						output: {
							beautify: true
						},
						compress: {
							sequences: false,
							global_defs: {
								DEBUG: false
							}
						},
						warnings: true,
						mangle: false
					}*/
				}
			}
		},
		wrap: {
			build: {
				src: ['out/minified/goo.js'],
				dest: engineFilename,
				options: {
					wrapper: getWrapper()
				}
			}
		},
		clean: {
			build: {
				src: [
					'out/',
					'src/goo.js'
				]
			},
			toc: {
				src: [
					'visual-test/index.html'
				]
			},
			docs: [
				'goojs-jsdoc/',
				'goojs-jsdoc-json/',
				'goojs-jsdoc_*.tar.gz'
			]
		},
		'build-pack': {
			fsmpack: {
				packPath: 'fsmpack',
				outBaseDir: 'out'
			},
			geometrypack: {
				packPath: 'geometrypack',
				outBaseDir: 'out'
			},
			quadpack: {
				packPath: 'quadpack',
				outBaseDir: 'out'
			},
			timelinepack: {
				packPath: 'timelinepack',
				outBaseDir: 'out'
			},
			debugpack: {
				packPath: 'debugpack',
				outBaseDir: 'out'
			},
			scriptpack: {
				packPath: 'scriptpack',
				outBaseDir: 'out'
			},
			p2pack: {
				packPath: 'addons/p2pack',
				outBaseDir: 'out'
			},
			box2dpack: {
				packPath: 'addons/box2dpack',
				outBaseDir: 'out'
			},
			terrainpack: {
				packPath: 'addons/terrainpack',
				outBaseDir: 'out'
			},
			ammopack: {
				packPath: 'addons/ammopack',
				outBaseDir: 'out'
			},
			cannonpack: {
				packPath: 'addons/cannonpack',
				outBaseDir: 'out'
			},
			howlerpack: {
				packPath: 'addons/howlerpack',
				outBaseDir: 'out'
			},
			waterpack: {
				packPath: 'addons/waterpack',
				outBaseDir: 'out'
			},
			soundmanager2pack: {
				packPath: 'addons/soundmanager2pack',
				outBaseDir: 'out'
			}
		},
		'build-custom': {
			myBundle: {
				outFile: 'bundle.js'
			}
		},
		karma: {
			unit: {
				configFile: 'test/karma.conf.js',
				singleRun: true,
				browsers: ['Chrome'] // Phantom just doesn't have support for the goodies we've come to know and love
			}
		},
		shell: {
			jsdoc: {
				command: path.resolve('tools', 'generate_jsdoc.sh')
			},
			jsdoc_json: {
				command: path.resolve('tools', 'generate_jsdoc_json.sh')
			}
		},
		/*
	    jsdoc : { // Could replace tools/generate_jsdoc.sh, but still need something that makes the tar.gz docs bundle
	        dist : {
	            src: ['src','tools/jsdoc-template/static/README.md'],
	            options: {
	                destination: 'goojs-jsdoc',
	                template: 'tools/jsdoc-template',
	                'private': false,
	                recurse: true
	            }
	        }
	    },
	    */
		jshint: {
			all: ['src'],
			options: {
				jshintrc: '.jshintrc',
				force: true // Do not fail the task
			}
		}
	});

	grunt.loadNpmTasks('grunt-contrib-uglify');
	grunt.loadNpmTasks('grunt-contrib-requirejs');
	grunt.loadNpmTasks('grunt-wrap');
	grunt.loadNpmTasks('grunt-contrib-clean');
	grunt.loadNpmTasks('grunt-karma');
	//grunt.loadNpmTasks('grunt-jsdoc');
	grunt.loadNpmTasks('grunt-shell');
	grunt.loadNpmTasks('grunt-contrib-jshint');

	grunt.loadTasks('tools/grunt_tasks');

	grunt.registerTask('default',	['minify']);
	grunt.registerTask('docs',		['shell:jsdoc']);
	grunt.registerTask('jsdoc',		['shell:jsdoc']);
	grunt.registerTask('minify',	['main-file', 'requirejs:build', 'wrap', 'build-pack']);
	grunt.registerTask('unittest',	['karma:unit']);
	grunt.registerTask('test',		['unittest']);

	//! AT: no better place to put this
	function extractFilename(path) {
		var index = path.lastIndexOf('/');
		return index === -1 ? path : path.substr(index + 1);
	}

	// Creates src/goo.js that depends on all engine modules
	grunt.registerTask('main-file', function () {
		// prefiltering out files in packs on the 'ground' level
		var sourceFiles = glob.sync('!(*pack)/**/*.js', { cwd: 'src/goo/', nonegate: true });

		// filtering files in packs that are not on the 'ground' level
		var regexp = /.+pack\/.+/;
		sourceFiles = sourceFiles.filter(function (sourceFile) {
			return !regexp.test(sourceFile);
		});

		var allModules = _.map(sourceFiles, function (f) {
			return 'goo/' + f.replace(/\.js/, '');
		});

		var lines = [];
		lines.push('require([');
		lines.push(_.map(allModules, function (m) { return "\t'" + m + "'"; }).join(',\n'));
		lines.push('], function (');

		var fileNames = allModules.map(extractFilename);

		lines.push('\t' + fileNames.join(',\n\t'));
		lines.push(') {');
		lines.push('\tvar goo = window.goo;\n\tif (!goo) { return; }');
		fileNames.forEach(function (fileName) {
			lines.push('\tgoo.' + fileName + ' = ' + fileName + ';');
		});

		lines.push('});');

		fs.writeFileSync('src/goo.js', lines.join('\n'));
	});

	// Creates an HTML list of tests in visual-test/index.html
	grunt.registerTask('visualtoc', function () {
		var toc = require('./visual-test/toc');
		toc.run();
	});

	// Creates an example table of content HTML file: examples/index.html
	grunt.registerTask('examplestoc', function () {
		var toc = require('./examples/toc');
		toc.run();
	});

	// Generates reference screenshots
	grunt.registerTask('refs', function () {
		var done = this.async();
		require('child_process').exec('node test/e2etesting/generate-reference-screenshots', function (error, stdout, stderr) {
		    console.log('stdout: ' + stdout);
		    console.log('stderr: ' + stderr);
		    if (error !== null) {
				console.log('exec error: ' + error);
		    }
		    done();
		});
	});
};
<|endoftext|>


<commit_before>module.exports = function(grunt) {

  grunt.loadNpmTasks('grunt-contrib-requirejs');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-bump');
  grunt.loadNpmTasks('grunt-mocha');

  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    license: grunt.file.read('src/copyright.js'),

    clean: ['tmp', 'dist'],

    jshint: {
      all: ['Gruntfile.js', 'src/**/*.js', 'dist/*.js', 'tests/spec/**/*.js'],
      options: {
        curly: true,
        eqeqeq: true,
        eqnull: true,
        browser: true,
        globals: {
          jQuery: true
        },
      },
    },

    requirejs: {
      production: {
        options: {
          optimize: 'none',
          baseUrl: "src",
          name: '../node_modules/almond/almond',
          include: ['main'],
          out: 'tmp/plyfe-widget.js',
          wrap: {
            startFile: 'src/build_frags/start.frag',
            endFile: 'src/build_frags/end.frag'
          }
        }
      }
    },

    uglify: {
      options: {
        banner: '<%= license %>'
      },
      minified: {
        files: {
          'tmp/plyfe-widget.min.js': ['tmp/plyfe-widget.js']
        }
      },
      beautiful: {
        options: {
          compress: false,
          mangle: false,
          preserveComments: false,
          beautify: true,
        },
        files: {
          'tmp/plyfe-widget.js': ['tmp/plyfe-widget.js']
        }
      }
    },

    watch: {
      scripts: {
        files: ['src/**/*.js'],
        tasks: ['test'],
      },
    },

    copy: {
      version: {
        files: [
          {
            src: 'tmp/plyfe-widget.js',
            dest: 'dist/plyfe-widget-<%= pkg.version %>.js'
          },
          {
            src: 'tmp/plyfe-widget.min.js',
            dest: 'dist/plyfe-widget-<%= pkg.version %>.min.js'
          },
        ]
      },
    },

    bump: {
      options: {
        updateConfigs: ['pkg'],
      }
    },

    mocha: {
      options: {
        run: true
      },
      test: {
        src: ['tests/*.html'],
      }
    },

  });

  grunt.registerTask('default', [
    'build',
    'jshint',
    'copy:version',
  ]);

  grunt.registerTask('build', [
    'clean',
    'requirejs',
    'uglify:minified',
    'uglify:beautiful',
  ]);

  grunt.registerTask('test', [
    'build',
    'mocha',
  ]);

  ['', ':patch', ':minor', ':major', ':build', ':git'].forEach(function(task) {
    grunt.registerTask('release' + task, [
      'bump-only:' + task,
      'default',
      'copy:version',
      'bump-commit',
    ]);
  });

};
<commit_msg>Updated Gruntfile to get release process working<commit_after>module.exports = function(grunt) {

  grunt.loadNpmTasks('grunt-contrib-requirejs');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-bump');
  grunt.loadNpmTasks('grunt-mocha');

  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    license: grunt.file.read('src/copyright.js'),

    clean: ['tmp', 'dist'],

    jshint: {
      all: ['Gruntfile.js', 'src/**/*.js', 'dist/*.js', 'tests/spec/**/*.js'],
      options: {
        curly: true,
        eqeqeq: true,
        eqnull: true,
        browser: true,
        globals: {
          jQuery: true
        },
      },
    },

    requirejs: {
      production: {
        options: {
          optimize: 'none',
          baseUrl: "src",
          name: '../node_modules/almond/almond',
          include: ['main'],
          out: 'tmp/plyfe-widget.js',
          wrap: {
            startFile: 'src/build_frags/start.frag',
            endFile: 'src/build_frags/end.frag'
          }
        }
      }
    },

    uglify: {
      options: {
        banner: '<%= license %>'
      },
      minified: {
        files: {
          'tmp/plyfe-widget.min.js': ['tmp/plyfe-widget.js']
        }
      },
      beautiful: {
        options: {
          compress: false,
          mangle: false,
          preserveComments: false,
          beautify: true,
        },
        files: {
          'tmp/plyfe-widget.js': ['tmp/plyfe-widget.js']
        }
      }
    },

    watch: {
      scripts: {
        files: ['src/**/*.js'],
        tasks: ['test'],
      },
    },

    copy: {
      version: {
        files: [
          {
            src: 'tmp/plyfe-widget.js',
            dest: 'dist/plyfe-widget-<%= pkg.version %>.js'
          },
          {
            src: 'tmp/plyfe-widget.min.js',
            dest: 'dist/plyfe-widget-<%= pkg.version %>.min.js'
          },
        ]
      },
    },

    bump: {
      options: {
        updateConfigs: ['pkg'],
        pushTo: 'origin',
        commitFiles: ['package.json', 'dist/'],
      }
    },

    mocha: {
      options: {
        run: true
      },
      test: {
        src: ['tests/*.html'],
      }
    },

  });

  grunt.registerTask('default', [
    'build',
    'jshint',
    'copy:version',
  ]);

  grunt.registerTask('build', [
    'clean',
    'requirejs',
    'uglify:minified',
    'uglify:beautiful',
  ]);

  grunt.registerTask('test', [
    'build',
    'mocha',
  ]);

  ['', ':patch', ':minor', ':major', ':build', ':git'].forEach(function(task) {
    grunt.registerTask('release' + task, [
      'bump-only:' + task,
      'default',
      'copy:version',
      'bump-commit',
    ]);
  });

};
<|endoftext|>


<commit_before>module.exports = function(grunt) {

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        concat: {
            options: {
                separator: ';',
                sourceMap: true
            },
            dist: {
                src: ['src/**/*.js'],
                dest: 'assets/<%= pkg.name %>.js'
            }
        },
        uglify: {
            options: {
                banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n',
                sourceMap: true
            },
            dist: {
                files: {
                    'assets/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>']
                }
            }
        },
        jshint: {
            files: ['Gruntfile.js', 'src/**/*.js'],
            options: {
                // options here to override JSHint defaults
                trailing: true,
                globals: {
                    browser: true,
                    console: true
                }
            }
        },
        watch: {
            files: ['<%= jshint.files %>'],
            tasks: ['jshint', 'concat']
        }
    });

    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-concat');

    grunt.registerTask('default', ['jshint', 'concat', 'uglify']);

};<commit_msg>Set grunt watch use default task to generate .min.js file<commit_after>module.exports = function(grunt) {

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        concat: {
            options: {
                separator: ';',
                sourceMap: true
            },
            dist: {
                src: ['src/**/*.js'],
                dest: 'assets/<%= pkg.name %>.js'
            }
        },
        uglify: {
            options: {
                banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n',
                sourceMap: true
            },
            dist: {
                files: {
                    'assets/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>']
                }
            }
        },
        jshint: {
            files: ['Gruntfile.js', 'src/**/*.js'],
            options: {
                // options here to override JSHint defaults
                trailing: true,
                globals: {
                    browser: true,
                    console: true
                }
            }
        },
        watch: {
            files: ['<%= jshint.files %>'],
            tasks: ['default']
        }
    });

    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-concat');

    grunt.registerTask('default', ['jshint', 'concat', 'uglify']);

};<|endoftext|>


<commit_before>'use strict';

// # Globbing
// for performance reasons we're only matching one level down:
// '<%= config.src %>/templates/pages/{,*/}*.hbs'
// use this if you want to match all subfolders:
// '<%= config.src %>/templates/pages/**/*.hbs'

const yaml = require('js-yaml');
const fs = require('fs').promises;
const fse = require('fs-extra');
const pkg = require('./package.json');

module.exports = function(grunt) {
  require('time-grunt')(grunt);
  require('load-grunt-tasks')(grunt);

  // Project configuration. actual tasks
  grunt.initConfig({
    banner: '/* p5js.org */',
    config: {
      src: 'src',
      dist: 'dist'
    },
    exec: {
      build_examples: 'node <%= config.src %>/data/examples/build_examples/build.js <%= config.src %>/templates/pages/examples/',
      build_libraries: 'node <%= config.src %>/data/libraries/build.js <%= config.src %>/templates/pages/libraries/',
      build_learn: 'node <%= config.src %>/data/learn/build.js <%= config.src %>/templates/pages/learn/'
    },
    watch: {
      assemble: {
        files: '<%= config.src %>/{content,data,templates}/**/*.{md,hbs,yml,json}',
        tasks: ['assemble']
      },
      css: {
        files: '<%= config.src %>/assets/css/*.css',
        tasks: [
          'concat:dist',
          'postcss'
        ]
      },
      imagemin: {
        files: '<%= config.src %>/assets/img/*.{png,jpg,jpeg,gif,svg,ico}',
        tasks: ['newer:imagemin']
      },
      livereload: {
        options: {
          livereload: '<%= connect.options.livereload %>'
        },
        files: [
          '<%= config.dist %>/{,*/}*.html',
          '<%= config.dist %>/assets/css/*.css',
          '<%= config.dist %>/assets/js/*.js',
          '<%= config.dist %>/assets/img/*.{png,jpg,jpeg,gif,webp,svg,ico}',
          '<%= config.dist %>/assets/p5_featured/{,*/}*.*',
          '<%= config.dist %>/assets/learn/{,*/}*.*',
          '<%= config.dist %>/assets/contributor-docs/*.*'
        ]
      }
    },

    // Local server:
    connect: {
      options: {
        port: 9000,
        livereload: 35729,
        // change this to '0.0.0.0' to access the server from outside
        hostname: 'localhost'
      },
      livereload: {
        options: {
          open: true,
          base: [
            '<%= config.dist %>'
          ]
        }
      }
    },

    // HTML:
    assemble: {
      pages: {
        options: {
          expand: true,
          flatten: true,
          assets: '<%= config.dist %>/assets',
          helpers: ['helpers/translation.js', 'helpers/cache-busting.js'],
          layout: '<%= config.src %>/templates/layouts/default.hbs',
          data: [
            '<%= config.src %>/data/**/*.{json,yml}',
            '!<%= config.src %>/data/reference/*.json'
          ],
          partials: '<%= config.src %>/templates/partials/*.hbs',
          plugins: [
            'assemble-contrib-permalinks',
            'assemble-contrib-i18n'
          ],
          i18n: {
            languages: pkg.languages,
            templates: [
              '<%= config.src %>/templates/pages/**/*.hbs',
            ]
          },
          permalinks: {
            structure: ':lang/:slug/:base:ext',
            patterns: [
              {
                pattern: ':lang',
                replacement: function() {
                  return this.language.toLowerCase() === 'en' ? '' : this.language;
                }
              },
              {
                pattern: ':base',
                replacement: function () {
                  var check = this.basename.lastIndexOf(this.language.toLowerCase());
                  if (check > -1) {
                    return this.basename.substring(0, check - 1);
                  } else return this.basename;
                }
              }
            ]
          }
        },
        dest: '<%= config.dist %>',
        src: '!*.*'
      }
    },

    requirejs: {
      yuidoc_theme: {
        options: {
          baseUrl: '<%= config.src %>/yuidoc-p5-theme-src/scripts/',
          mainConfigFile: '<%= config.src %>/yuidoc-p5-theme-src/scripts/config.js',
          name: 'main',
          out: '<%= config.src %>/assets/js/reference.js',
          optimize: 'none',
          generateSourceMaps: false,
          findNestedDependencies: true,
          wrap: true,
          paths: {
            jquery: 'empty:'
          }
        }
      }
    },

    // Images:
    imagemin: {
      images: {
        options: {
          optimizationLevel: 2
        },
        files: [{
          expand: true,
          cwd: '<%= config.src %>/assets/img',
          src: ['**/*.{png,jpg,gif,svg,ico}'],
          dest: '<%= config.dist %>/assets/img/'
        }]
      }
    },

    // CSS:
    concat: {
      options: {
        separator: ';'
      },
      dist: {
        src: [
          '<%= config.src %>/assets/css/normalize.css',
          '<%= config.src %>/assets/css/main.css',
          '<%= config.src %>/assets/css/prism.css'
        ],
        dest: '<%= config.dist %>/assets/css/all.css'
      }
    },
    postcss: {
      options: {
        map: {
          inline: false,
          annotation: '<%= config.dist %>/assets/css/maps/'
        },
        processors: [
          require('autoprefixer')({browsers: [
            'Android 2.3',
            'Android >= 4',
            'Chrome >= 20',
            'Firefox >= 24',
            'Explorer >= 8',
            'iOS >= 6',
            'Opera >= 12',
            'Safari >= 6'
          ]}),
          require('cssnano')()
        ]
      },
      dist: {
        src: '<%= config.dist %>/assets/css/all.css'
      }
    },

    // Data handling:
    copy: {
      js: {
        expand: true,
        cwd: '<%= config.src %>/assets/js',
        src: '**',
        dest: '<%= config.dist %>/assets/js/'
      },
      fonts: {
        expand: true,
        cwd: '<%= config.src %>/assets/css/fonts',
        src: '**',
        dest: '<%= config.dist %>/assets/css/fonts'
      },
      learn: {
        expand: true,
        cwd: '<%= config.src %>/assets/learn',
        src: '**',
        dest: '<%= config.dist %>/assets/learn'
      },
      p5_featured: {
        expand: true,
        cwd: '<%= config.src %>/assets/p5_featured',
        src: '**',
        dest: '<%= config.dist %>/assets/p5_featured'
      },
      examples: {
        expand: true,
        cwd: '<%= config.src %>/data/examples',
        src: ['**', '!build_examples/**'],
        dest: '<%= config.dist %>/assets/examples'
      },
      contributor_docs: {
        expand: true,
        cwd: '<%= config.src %>/assets/contributor-docs',
        src: '**',
        dest: '<%= config.dist %>/contributor-docs'
      },
      reference: {
        expand: true,
        cwd: '<%= config.src %>/data/reference',
        src: ['**'],
        dest: '<%= config.dist %>/assets/reference'
      },
      reference_assets: {
        files: (function() {
          const cp = [];
          pkg.languages.forEach(language => {
            if (language === 'en') {
              cp.push({
                expand: true,
                cwd: '<%= config.src %>/templates/pages/reference/',
                src: ['**/!(*.hbs)'],
                dest: '<%= config.dist %>/reference/'
              });
            } else {
              cp.push({
                expand: true,
                cwd: '<%= config.src %>/templates/pages/reference/',
                src: ['**/!(*.hbs)'],
                dest: `<%= config.dist %>/${language}/reference/`
              });
            }
          });

          return cp;
        })()
      },
      offlineReference: {
        files: [
          {
            expand: true,
            cwd: '<%= config.dist %>/reference',
            src: 'assets/**/*',
            dest: '<%= config.src %>/offline-reference/'
          },
          {
            expand: true,
            cwd: '<%= config.src %>/assets',
            src: 'js/**/*',
            dest: '<%= config.src %>/offline-reference/'
          },
          {
            expand: true,
            cwd: '<%= config.dist %>/assets',
            src: 'css/all.css',
            dest: '<%= config.src %>/offline-reference/'
          },
          {
            expand: true,
            cwd: 'offline-reference/extra',
            src: '**',
            dest: '<%= config.src %>/offline-reference/'
          }
        ]
      }
    },

    // Before generating any new files,
    // remove any previously-created files.
    clean: {
      assets: [
        '<%= config.dist %>/**/*.*',
        '!<%= config.dist %>/download/release.php',
        '!<%= config.dist %>/git-pull.php',
        '!<%= config.dist %>/books/media.zip',
        '!<%= config.dist %>/learn/books/media.zip',
        '<%= config.src %>/offline-reference/**/*.*'
      ]
    },

    file_append: {
      default_options: {
        files: [
          {
            prepend: 'referenceData = ',
            input: '<%= config.src %>/templates/pages/reference/data.json',
            output: '<%= config.src %>/offline-reference/js/data.js'
          }
        ]
      }
    },

    compress: {
      main: {
        options: {
          archive: '<%= config.dist %>/offline-reference/p5-reference.zip'
        },
        expand: true,
        cwd: '<%= config.src %>/offline-reference',
        src: ['**/*'],
        dest: 'p5-reference/'
      }
    },
    htmllint: {
      all: {
        src: [
          '<%= config.dist %>/**/*.html',
          '!<%= config.dist %>/**/CHANGES.html',
          '!<%= config.dist %>/**/README.html',
          '!<%= config.dist %>/**/p5_featured/**/*.html',
          '!<%= config.dist %>/**/learn/*.html',
          '!<%= config.dist %>/**/examples/*.html',
          '!<%= config.dist %>/**/reference/assets/index.html'
        ],
        options: {
          ignore: [
            /^This document appears to be written in English/,
            /^Bad value “https:/,
            /^Consider adding a “lang” attribute to the “html”/
          ]
        }
      }
    },
    shell: {
      make_tmp_dir: {
        command: 'mkdir -p tmp/p5.js'
      },
      clone_p5js_repo: {
        command: 'git clone https://github.com/processing/p5.js .',
        options: {
          execOptions: {
            cwd: 'tmp/p5.js'
          }
        }
      },
      generate_dataJSON: {
        command: 'npm i && npm run grunt yui',
        options: {
          execOptions: {
            cwd: 'tmp/p5.js'
          }
        }
      }
    }
  });

  grunt.registerTask('update-version', function() {
    const done = this.async();

    const version = require('./src/templates/pages/reference/data.json').project.version;

    fs.readFile('./src/data/data.yml').then((str) => {
      const data = yaml.safeLoad(str);
      data.version = version;

      const dump = yaml.safeDump(data);

      return fs.writeFile('./src/data/data.yml', dump);
    }).then(() => {
      done();
    });
  });

  grunt.loadNpmTasks('grunt-exec');
  grunt.loadNpmTasks('grunt-assemble');
  grunt.loadNpmTasks('grunt-file-append');
  grunt.loadNpmTasks('grunt-contrib-compress');
  grunt.loadNpmTasks('grunt-contrib-requirejs');
  grunt.loadNpmTasks('grunt-html');

  grunt.registerTask('clone_p5js', [
    'shell:make_tmp_dir',
    'shell:clone_p5js_repo'
  ]);

  grunt.registerTask('generate_dataJSON', ['shell:generate_dataJSON']);

  grunt.registerTask('move_dataJSON', function() {
    const dataJSON_p5js = 'tmp/p5.js/docs/reference/data.json';
    const dataJSON_p5jswebsite = 'src/templates/pages/reference/data.json';
    // move the data.json from the cloned p5.js repository to the p5.js-website repository
    fse.moveSync(dataJSON_p5js, dataJSON_p5jswebsite, { overwrite: true });
    // delete the tmp folder that contained the p5.js repository
    fse.removeSync('tmp/');
  });

  grunt.registerTask('generate_enJSON', function() {
    const getenJSON = require('./getenJSON.js');
    // generate and save the en.json
    getenJSON();
  });

  grunt.registerTask('update-enJSON', [
    'clone_p5js',
    'generate_dataJSON',
    'move_dataJSON',
    'generate_enJSON'
  ]);

  // multi-tasks: collections of other tasks
  grunt.registerTask('server', [
    'build',
    'connect:livereload',
    'watch'
  ]);

  grunt.registerTask('run', [
    'connect:livereload',
    'watch'
  ]);

  // optimize assets
  grunt.registerTask('optimize', [
    'newer:imagemin',
    'concat:dist',
    'postcss'
  ]);

  // i18n tracking task
  grunt.registerTask('i18n', function() {
    var done = this.async();
    require('./i18n.js')(done);
  });

  // runs tasks in order
  grunt.registerTask('build', [
    'update-version',
    'exec',
    'clean',
    'requirejs:yuidoc_theme',
    'requirejs',
    'copy',
    'optimize',
    'assemble',
    'file_append',
    'compress',
    'i18n',
    'htmllint'
  ]);

  // runs with just grunt command
  grunt.registerTask('default', ['build']);
};<commit_msg>Use fs-extra instead of grunt-shell<commit_after>'use strict';

// # Globbing
// for performance reasons we're only matching one level down:
// '<%= config.src %>/templates/pages/{,*/}*.hbs'
// use this if you want to match all subfolders:
// '<%= config.src %>/templates/pages/**/*.hbs'

const yaml = require('js-yaml');
const fs = require('fs').promises;
const fse = require('fs-extra');
const pkg = require('./package.json');

module.exports = function(grunt) {
  require('time-grunt')(grunt);
  require('load-grunt-tasks')(grunt);

  // Project configuration. actual tasks
  grunt.initConfig({
    banner: '/* p5js.org */',
    config: {
      src: 'src',
      dist: 'dist'
    },
    exec: {
      build_examples: 'node <%= config.src %>/data/examples/build_examples/build.js <%= config.src %>/templates/pages/examples/',
      build_libraries: 'node <%= config.src %>/data/libraries/build.js <%= config.src %>/templates/pages/libraries/',
      build_learn: 'node <%= config.src %>/data/learn/build.js <%= config.src %>/templates/pages/learn/'
    },
    watch: {
      assemble: {
        files: '<%= config.src %>/{content,data,templates}/**/*.{md,hbs,yml,json}',
        tasks: ['assemble']
      },
      css: {
        files: '<%= config.src %>/assets/css/*.css',
        tasks: [
          'concat:dist',
          'postcss'
        ]
      },
      imagemin: {
        files: '<%= config.src %>/assets/img/*.{png,jpg,jpeg,gif,svg,ico}',
        tasks: ['newer:imagemin']
      },
      livereload: {
        options: {
          livereload: '<%= connect.options.livereload %>'
        },
        files: [
          '<%= config.dist %>/{,*/}*.html',
          '<%= config.dist %>/assets/css/*.css',
          '<%= config.dist %>/assets/js/*.js',
          '<%= config.dist %>/assets/img/*.{png,jpg,jpeg,gif,webp,svg,ico}',
          '<%= config.dist %>/assets/p5_featured/{,*/}*.*',
          '<%= config.dist %>/assets/learn/{,*/}*.*',
          '<%= config.dist %>/assets/contributor-docs/*.*'
        ]
      }
    },

    // Local server:
    connect: {
      options: {
        port: 9000,
        livereload: 35729,
        // change this to '0.0.0.0' to access the server from outside
        hostname: 'localhost'
      },
      livereload: {
        options: {
          open: true,
          base: [
            '<%= config.dist %>'
          ]
        }
      }
    },

    // HTML:
    assemble: {
      pages: {
        options: {
          expand: true,
          flatten: true,
          assets: '<%= config.dist %>/assets',
          helpers: ['helpers/translation.js', 'helpers/cache-busting.js'],
          layout: '<%= config.src %>/templates/layouts/default.hbs',
          data: [
            '<%= config.src %>/data/**/*.{json,yml}',
            '!<%= config.src %>/data/reference/*.json'
          ],
          partials: '<%= config.src %>/templates/partials/*.hbs',
          plugins: [
            'assemble-contrib-permalinks',
            'assemble-contrib-i18n'
          ],
          i18n: {
            languages: pkg.languages,
            templates: [
              '<%= config.src %>/templates/pages/**/*.hbs',
            ]
          },
          permalinks: {
            structure: ':lang/:slug/:base:ext',
            patterns: [
              {
                pattern: ':lang',
                replacement: function() {
                  return this.language.toLowerCase() === 'en' ? '' : this.language;
                }
              },
              {
                pattern: ':base',
                replacement: function () {
                  var check = this.basename.lastIndexOf(this.language.toLowerCase());
                  if (check > -1) {
                    return this.basename.substring(0, check - 1);
                  } else return this.basename;
                }
              }
            ]
          }
        },
        dest: '<%= config.dist %>',
        src: '!*.*'
      }
    },

    requirejs: {
      yuidoc_theme: {
        options: {
          baseUrl: '<%= config.src %>/yuidoc-p5-theme-src/scripts/',
          mainConfigFile: '<%= config.src %>/yuidoc-p5-theme-src/scripts/config.js',
          name: 'main',
          out: '<%= config.src %>/assets/js/reference.js',
          optimize: 'none',
          generateSourceMaps: false,
          findNestedDependencies: true,
          wrap: true,
          paths: {
            jquery: 'empty:'
          }
        }
      }
    },

    // Images:
    imagemin: {
      images: {
        options: {
          optimizationLevel: 2
        },
        files: [{
          expand: true,
          cwd: '<%= config.src %>/assets/img',
          src: ['**/*.{png,jpg,gif,svg,ico}'],
          dest: '<%= config.dist %>/assets/img/'
        }]
      }
    },

    // CSS:
    concat: {
      options: {
        separator: ';'
      },
      dist: {
        src: [
          '<%= config.src %>/assets/css/normalize.css',
          '<%= config.src %>/assets/css/main.css',
          '<%= config.src %>/assets/css/prism.css'
        ],
        dest: '<%= config.dist %>/assets/css/all.css'
      }
    },
    postcss: {
      options: {
        map: {
          inline: false,
          annotation: '<%= config.dist %>/assets/css/maps/'
        },
        processors: [
          require('autoprefixer')({browsers: [
            'Android 2.3',
            'Android >= 4',
            'Chrome >= 20',
            'Firefox >= 24',
            'Explorer >= 8',
            'iOS >= 6',
            'Opera >= 12',
            'Safari >= 6'
          ]}),
          require('cssnano')()
        ]
      },
      dist: {
        src: '<%= config.dist %>/assets/css/all.css'
      }
    },

    // Data handling:
    copy: {
      js: {
        expand: true,
        cwd: '<%= config.src %>/assets/js',
        src: '**',
        dest: '<%= config.dist %>/assets/js/'
      },
      fonts: {
        expand: true,
        cwd: '<%= config.src %>/assets/css/fonts',
        src: '**',
        dest: '<%= config.dist %>/assets/css/fonts'
      },
      learn: {
        expand: true,
        cwd: '<%= config.src %>/assets/learn',
        src: '**',
        dest: '<%= config.dist %>/assets/learn'
      },
      p5_featured: {
        expand: true,
        cwd: '<%= config.src %>/assets/p5_featured',
        src: '**',
        dest: '<%= config.dist %>/assets/p5_featured'
      },
      examples: {
        expand: true,
        cwd: '<%= config.src %>/data/examples',
        src: ['**', '!build_examples/**'],
        dest: '<%= config.dist %>/assets/examples'
      },
      contributor_docs: {
        expand: true,
        cwd: '<%= config.src %>/assets/contributor-docs',
        src: '**',
        dest: '<%= config.dist %>/contributor-docs'
      },
      reference: {
        expand: true,
        cwd: '<%= config.src %>/data/reference',
        src: ['**'],
        dest: '<%= config.dist %>/assets/reference'
      },
      reference_assets: {
        files: (function() {
          const cp = [];
          pkg.languages.forEach(language => {
            if (language === 'en') {
              cp.push({
                expand: true,
                cwd: '<%= config.src %>/templates/pages/reference/',
                src: ['**/!(*.hbs)'],
                dest: '<%= config.dist %>/reference/'
              });
            } else {
              cp.push({
                expand: true,
                cwd: '<%= config.src %>/templates/pages/reference/',
                src: ['**/!(*.hbs)'],
                dest: `<%= config.dist %>/${language}/reference/`
              });
            }
          });

          return cp;
        })()
      },
      offlineReference: {
        files: [
          {
            expand: true,
            cwd: '<%= config.dist %>/reference',
            src: 'assets/**/*',
            dest: '<%= config.src %>/offline-reference/'
          },
          {
            expand: true,
            cwd: '<%= config.src %>/assets',
            src: 'js/**/*',
            dest: '<%= config.src %>/offline-reference/'
          },
          {
            expand: true,
            cwd: '<%= config.dist %>/assets',
            src: 'css/all.css',
            dest: '<%= config.src %>/offline-reference/'
          },
          {
            expand: true,
            cwd: 'offline-reference/extra',
            src: '**',
            dest: '<%= config.src %>/offline-reference/'
          }
        ]
      }
    },

    // Before generating any new files,
    // remove any previously-created files.
    clean: {
      assets: [
        '<%= config.dist %>/**/*.*',
        '!<%= config.dist %>/download/release.php',
        '!<%= config.dist %>/git-pull.php',
        '!<%= config.dist %>/books/media.zip',
        '!<%= config.dist %>/learn/books/media.zip',
        '<%= config.src %>/offline-reference/**/*.*'
      ]
    },

    file_append: {
      default_options: {
        files: [
          {
            prepend: 'referenceData = ',
            input: '<%= config.src %>/templates/pages/reference/data.json',
            output: '<%= config.src %>/offline-reference/js/data.js'
          }
        ]
      }
    },

    compress: {
      main: {
        options: {
          archive: '<%= config.dist %>/offline-reference/p5-reference.zip'
        },
        expand: true,
        cwd: '<%= config.src %>/offline-reference',
        src: ['**/*'],
        dest: 'p5-reference/'
      }
    },
    htmllint: {
      all: {
        src: [
          '<%= config.dist %>/**/*.html',
          '!<%= config.dist %>/**/CHANGES.html',
          '!<%= config.dist %>/**/README.html',
          '!<%= config.dist %>/**/p5_featured/**/*.html',
          '!<%= config.dist %>/**/learn/*.html',
          '!<%= config.dist %>/**/examples/*.html',
          '!<%= config.dist %>/**/reference/assets/index.html'
        ],
        options: {
          ignore: [
            /^This document appears to be written in English/,
            /^Bad value “https:/,
            /^Consider adding a “lang” attribute to the “html”/
          ]
        }
      }
    },
    shell: {
      clone_p5js_repo: {
        command: 'git clone https://github.com/processing/p5.js .',
        options: {
          execOptions: {
            cwd: 'tmp/p5.js'
          }
        }
      },
      generate_dataJSON: {
        command: 'npm i && npm run grunt yui',
        options: {
          execOptions: {
            cwd: 'tmp/p5.js'
          }
        }
      }
    }
  });

  grunt.registerTask('update-version', function() {
    const done = this.async();

    const version = require('./src/templates/pages/reference/data.json').project.version;

    fs.readFile('./src/data/data.yml').then((str) => {
      const data = yaml.safeLoad(str);
      data.version = version;

      const dump = yaml.safeDump(data);

      return fs.writeFile('./src/data/data.yml', dump);
    }).then(() => {
      done();
    });
  });

  grunt.loadNpmTasks('grunt-exec');
  grunt.loadNpmTasks('grunt-assemble');
  grunt.loadNpmTasks('grunt-file-append');
  grunt.loadNpmTasks('grunt-contrib-compress');
  grunt.loadNpmTasks('grunt-contrib-requirejs');
  grunt.loadNpmTasks('grunt-html');

  grunt.registerTask('make_tmp_dir', function() {
    const tmp_path = 'tmp/p5.js';
    fse.mkdirpSync(tmp_path);
  });

  grunt.registerTask('clone_p5js_repo', ['shell:clone_p5js_repo']);

  grunt.registerTask('generate_dataJSON', ['shell:generate_dataJSON']);

  grunt.registerTask('move_dataJSON', function() {
    const dataJSON_p5js = 'tmp/p5.js/docs/reference/data.json';
    const dataJSON_p5jswebsite = 'src/templates/pages/reference/data.json';
    // move the data.json from the cloned p5.js repository to the p5.js-website repository
    fse.moveSync(dataJSON_p5js, dataJSON_p5jswebsite, { overwrite: true });
    // delete the tmp folder that contained the p5.js repository
    fse.removeSync('tmp/');
  });

  grunt.registerTask('generate_enJSON', function() {
    const getenJSON = require('./getenJSON.js');
    // generate and save the en.json
    getenJSON();
  });

  grunt.registerTask('update-enJSON', [
    'make_tmp_dir',
    'clone_p5js_repo',
    'generate_dataJSON',
    'move_dataJSON',
    'generate_enJSON'
  ]);

  // multi-tasks: collections of other tasks
  grunt.registerTask('server', [
    'build',
    'connect:livereload',
    'watch'
  ]);

  grunt.registerTask('run', [
    'connect:livereload',
    'watch'
  ]);

  // optimize assets
  grunt.registerTask('optimize', [
    'newer:imagemin',
    'concat:dist',
    'postcss'
  ]);

  // i18n tracking task
  grunt.registerTask('i18n', function() {
    var done = this.async();
    require('./i18n.js')(done);
  });

  // runs tasks in order
  grunt.registerTask('build', [
    'update-version',
    'exec',
    'clean',
    'requirejs:yuidoc_theme',
    'requirejs',
    'copy',
    'optimize',
    'assemble',
    'file_append',
    'compress',
    'i18n',
    'htmllint'
  ]);

  // runs with just grunt command
  grunt.registerTask('default', ['build']);
};<|endoftext|>


<commit_before>module.exports = function(grunt) {

grunt.initConfig({
  pkg: '<json:package.json>',
  meta: {
    banner: '/*!\n' +
            ' * <%= pkg.name %> v<%= pkg.version %>\n' +
            ' *\n' +
            ' * Copyright (c) <%= grunt.template.today(\'yyyy\') %> smori <shinichiro.mori.19833@gmail.com>\n' +
            ' * Dual licensed under the MIT or GPL-2.0 licenses.\n' +
            ' *\n' +
            ' * Date <%= grunt.template.today(\'yyyy-mm-dd HH:MM:ss\') %>\n' +
            ' */',
  },
  eslint: {
    target: ['src/smodules/*.js', 'test/smodules/*.js'],
  },
  connect: {
    qunit: {
      options: {
        port: 8888,
        base: '.',
      },
    },
    keepalive: {
      options: {
        keepalive: true,
        port: 8000,
        base: '.',
      },
    },
  },
  qunit: {
    all: {
      options: {
        urls: [
          'http://localhost:8888/test/test.html',
        ],
      },
    },
  },
  concat: {
    all: {
      src: [
        '<banner:meta.banner>',
        'src/smodules/HEAD.js',
        'src/smodules/a.js',
        'src/smodules/data.HEAD.js',
        'src/smodules/data.*.js',
        'src/smodules/mod.HEAD.js',
        'src/smodules/mod.*.js',
        'src/smodules/ui.HEAD.js',
        'src/smodules/ui.*.js',
        'src/smodules/util.HEAD.js',
        'src/smodules/util.*.js',
        'src/smodules/*.js',
      ],
      dest: 'dist/smodules-<%= pkg.version %>.js',
    },
  },
  watch: {
    scripts: {
      files: ['src/smodules/*.js', 'test/smodules/*.js'],
      tasks: ['eslint', 'connect:qunit', 'qunit'],
      options: {
        event: ['all'],
      },
    },
  },
});

grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-eslint');

grunt.registerTask('default', ['eslint', 'concat']);
grunt.registerTask('lint', ['eslint']);
grunt.registerTask('unit', ['connect:qunit', 'qunit']);

};
<commit_msg>remove ui from Grunt concat task<commit_after>module.exports = function(grunt) {

grunt.initConfig({
  pkg: '<json:package.json>',
  meta: {
    banner: '/*!\n' +
            ' * <%= pkg.name %> v<%= pkg.version %>\n' +
            ' *\n' +
            ' * Copyright (c) <%= grunt.template.today(\'yyyy\') %> smori <shinichiro.mori.19833@gmail.com>\n' +
            ' * Dual licensed under the MIT or GPL-2.0 licenses.\n' +
            ' *\n' +
            ' * Date <%= grunt.template.today(\'yyyy-mm-dd HH:MM:ss\') %>\n' +
            ' */',
  },
  eslint: {
    target: ['src/smodules/*.js', 'test/smodules/*.js'],
  },
  connect: {
    qunit: {
      options: {
        port: 8888,
        base: '.',
      },
    },
    keepalive: {
      options: {
        keepalive: true,
        port: 8000,
        base: '.',
      },
    },
  },
  qunit: {
    all: {
      options: {
        urls: [
          'http://localhost:8888/test/test.html',
        ],
      },
    },
  },
  concat: {
    all: {
      src: [
        '<banner:meta.banner>',
        'src/smodules/HEAD.js',
        'src/smodules/a.js',
        'src/smodules/data.HEAD.js',
        'src/smodules/data.*.js',
        'src/smodules/mod.HEAD.js',
        'src/smodules/mod.*.js',
        'src/smodules/util.HEAD.js',
        'src/smodules/util.*.js',
        'src/smodules/*.js',
      ],
      dest: 'dist/smodules-<%= pkg.version %>.js',
    },
  },
  watch: {
    scripts: {
      files: ['src/smodules/*.js', 'test/smodules/*.js'],
      tasks: ['eslint', 'connect:qunit', 'qunit'],
      options: {
        event: ['all'],
      },
    },
  },
});

grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-eslint');

grunt.registerTask('default', ['eslint', 'concat']);
grunt.registerTask('lint', ['eslint']);
grunt.registerTask('unit', ['connect:qunit', 'qunit']);

};
<|endoftext|>


<commit_before>'use strict';

function branchDocumentationTasks(packageInfo, target) {
    target = target || packageInfo.version;
    const path = `doc/generated/versions/${target}`;
    return {
        jsdoc: {
            src: ['lib/'],
            options: {
                configure: 'doc/jsdoc.json',
                recurse: true,
                encoding: 'utf8',
                destination: path,
                package: 'package.json',
                template : 'node_modules/ink-docstrap/template',
                readme: 'README.md'
            }
        },
        pages: {
            options: {
                base: 'doc/generated',
                only: ['doc/generated', '!doc/generated/versions', path]
            },
            src: ['**']
        },
        copy: {
            cwd: `${path}/${packageInfo.name}/${packageInfo.version}`,
            expand: true,
            src: "**",
            dest: path,
        },
        clean: ['doc/placeholder.jsdoc', `${path}/${packageInfo.name}/`],
    };
}

module.exports = function(grunt) {
    const packageInfo = grunt.file.readJSON('package.json');
    grunt.loadNpmTasks('grunt-mocha-test');
    grunt.loadNpmTasks('grunt-jsdoc');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-touch');
    grunt.loadNpmTasks('grunt-gh-pages');
    grunt.loadNpmTasks('grunt-contrib-copy');

    grunt.initConfig({
        pkg: packageInfo,
        clean: {
          'doc-all': ['doc/generated'],
          'doc-current-version': branchDocumentationTasks(packageInfo).clean,
          'doc-master':  branchDocumentationTasks(packageInfo, 'master').clean,
        },
        touch: {
            'doc-placeholder': {
                src: 'doc/placeholder.jsdoc'
            }
        },
        copy: {
            'doc-master': branchDocumentationTasks(packageInfo, 'master').copy,
            'doc-current-version': branchDocumentationTasks(packageInfo).copy
        },
        jsdoc: {
            master: branchDocumentationTasks(packageInfo, 'master').jsdoc,
            'current-version': branchDocumentationTasks(packageInfo).jsdoc,
            index: {
                src: ['doc/placeholder.jsdoc'],
                options: {
                    configure: 'doc/jsdoc.json',
                    recurse: false,
                    encoding: 'utf8',
                    destination: 'doc/generated',
                    template : 'node_modules/ink-docstrap/template',
                    readme: 'doc/VersionIndex.md'
                }
            }
        },
        'gh-pages': {
            master: branchDocumentationTasks(packageInfo, 'master').pages,
            'current-version': branchDocumentationTasks(packageInfo).pages
        },
        mochaTest: {
            options: {
                reporter: 'spec',
                // Clear the require cache, since we enable/disable integrations via require.
                clearRequireCache: true,
            },
            unit: {
                options: {
                    require: function() {
                        delete global._ZB_INTEGRATION_TEST;
                    }
                },
                src: ['test/**/*.js']
            },
            integration: {
                options: {
                    require: function() {
                        global._ZB_INTEGRATION_TEST = true;
                    }
                },
                src: ['test/**/*.js']
            }
        }
    });

    grunt.registerTask('doc:index', ['clean:doc-all', 'touch:doc-placeholder', 'jsdoc:index']);
    grunt.registerTask('doc:master', ['doc:index', 'jsdoc:master', 'copy:doc-master', 'clean:doc-master']);
    grunt.registerTask('doc:current-version', ['doc:index', 'jsdoc:current-version', 'copy:doc-current-version', 'clean:doc-current-version']);
    grunt.registerTask('doc:master:push', ['doc:master', 'gh-pages:master']);
    grunt.registerTask('doc:current-version:push', ['doc:current-version', 'gh-pages:current-version']);
    grunt.registerTask('default', 'mochaTest:unit');
};<commit_msg>Stop clobbing other versions' documentation in pages<commit_after>'use strict';

function branchDocumentationTasks(packageInfo, target) {
    target = target || packageInfo.version;
    const path = `doc/generated/versions/${target}`;
    return {
        jsdoc: {
            src: ['lib/'],
            options: {
                configure: 'doc/jsdoc.json',
                recurse: true,
                encoding: 'utf8',
                destination: path,
                package: 'package.json',
                template : 'node_modules/ink-docstrap/template',
                readme: 'README.md'
            }
        },
        pages: {
            options: {
                base: 'doc/generated',
                add: true
            },
            src: ['**']
        },
        copy: {
            cwd: `${path}/${packageInfo.name}/${packageInfo.version}`,
            expand: true,
            src: "**",
            dest: path,
        },
        clean: ['doc/placeholder.jsdoc', `${path}/${packageInfo.name}/`],
    };
}

module.exports = function(grunt) {
    const packageInfo = grunt.file.readJSON('package.json');
    grunt.loadNpmTasks('grunt-mocha-test');
    grunt.loadNpmTasks('grunt-jsdoc');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-touch');
    grunt.loadNpmTasks('grunt-gh-pages');
    grunt.loadNpmTasks('grunt-contrib-copy');

    grunt.initConfig({
        pkg: packageInfo,
        clean: {
          'doc-all': ['doc/generated'],
          'doc-current-version': branchDocumentationTasks(packageInfo).clean,
          'doc-master':  branchDocumentationTasks(packageInfo, 'master').clean,
        },
        touch: {
            'doc-placeholder': {
                src: 'doc/placeholder.jsdoc'
            }
        },
        copy: {
            'doc-master': branchDocumentationTasks(packageInfo, 'master').copy,
            'doc-current-version': branchDocumentationTasks(packageInfo).copy
        },
        jsdoc: {
            master: branchDocumentationTasks(packageInfo, 'master').jsdoc,
            'current-version': branchDocumentationTasks(packageInfo).jsdoc,
            index: {
                src: ['doc/placeholder.jsdoc'],
                options: {
                    configure: 'doc/jsdoc.json',
                    recurse: false,
                    encoding: 'utf8',
                    destination: 'doc/generated',
                    template : 'node_modules/ink-docstrap/template',
                    readme: 'doc/VersionIndex.md'
                }
            }
        },
        'gh-pages': {
            master: branchDocumentationTasks(packageInfo, 'master').pages,
            'current-version': branchDocumentationTasks(packageInfo).pages
        },
        mochaTest: {
            options: {
                reporter: 'spec',
                // Clear the require cache, since we enable/disable integrations via require.
                clearRequireCache: true,
            },
            unit: {
                options: {
                    require: function() {
                        delete global._ZB_INTEGRATION_TEST;
                    }
                },
                src: ['test/**/*.js']
            },
            integration: {
                options: {
                    require: function() {
                        global._ZB_INTEGRATION_TEST = true;
                    }
                },
                src: ['test/**/*.js']
            }
        }
    });

    grunt.registerTask('doc:index', ['clean:doc-all', 'touch:doc-placeholder', 'jsdoc:index']);
    grunt.registerTask('doc:master', ['doc:index', 'jsdoc:master', 'copy:doc-master', 'clean:doc-master']);
    grunt.registerTask('doc:current-version', ['doc:index', 'jsdoc:current-version', 'copy:doc-current-version', 'clean:doc-current-version']);
    grunt.registerTask('doc:master:push', ['doc:master', 'gh-pages:master']);
    grunt.registerTask('doc:current-version:push', ['doc:current-version', 'gh-pages:current-version']);
    grunt.registerTask('default', 'mochaTest:unit');
};<|endoftext|>


<commit_before>module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    jasmine: {
      freedom: {
        src: ['src/libs/*.js', 'src/*.js', 'src/proxy/*.js', 'interface/*.js',
              'providers/core.unprivileged.js', 'providers/echo.unprivileged.js'],
        options: {
          specs: ['spec/*Spec.js', 'spec/providers/*Spec.js']
        }
      }
    },
    jshint: {
      beforeconcat: [
          'src/libs/*.js',
          'src/*.js',
          'src/proxy/*.js',
          'providers/*.js',
          'interface/*.js',
      ],
      afterconcat: ['freedom.js'],
      files: [
          'src/libs/*.js',
          'src/*.js',
          'src/proxy/*.js',
          'providers/*.js',
          'interface/*.js',
      ],
      options: {
        '-W069': true
      }
    },
    concat: {
      dist: {
        options: {
          process: function(src) {
            return src.replace(/\/\*jslint/g,'/*');
          }
        },
        src: [
          'src/libs/*.js',
          'src/util/preamble.js',
          'src/*.js',
          'src/proxy/*.js',
          'providers/*.js',
          'interface/*.js',
          'src/util/postamble.js'
        ],
        dest: 'freedom.js'
      }
    },
    uglify: {
      options: {
        mangle: { except: ['global'] }
      },
      freedom: {
        files: {
          'freedom.min.js': ['freedom.js']
        }
      }
    },
    clean: ['freedom.js', 'freedom.min.js'],
    yuidoc: {
      compile: {
        name: '<%= pkg.name %>',
        description: '<%= pkg.description %>',
        version: '<%= pkg.version %>',
        options: {
          paths: 'src/',
          outdir: 'tools/doc/'
        }
      }
    }
  });

  // Load tasks.
  grunt.loadNpmTasks('grunt-contrib-jasmine');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-yuidoc');
  grunt.loadNpmTasks('grunt-contrib-uglify');

  // Default tasks.
  grunt.registerTask('freedom', [
    'jshint:beforeconcat',
    'concat',
    'jasmine',
    'jshint:afterconcat',
    'uglify'
  ]);
  grunt.registerTask('default', ['freedom']);
};
<commit_msg>Added Grunt task for ChromeTestRunner.sh<commit_after>module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    jasmine: {
      freedom: {
        src: ['src/libs/*.js', 'src/*.js', 'src/proxy/*.js', 'interface/*.js',
              'providers/core.unprivileged.js', 'providers/echo.unprivileged.js'],
        options: {
          specs: ['spec/*Spec.js', 'spec/providers/*Spec.js']
        }
      }
    },
    jshint: {
      beforeconcat: [
          'src/libs/*.js',
          'src/*.js',
          'src/proxy/*.js',
          'providers/*.js',
          'interface/*.js',
      ],
      afterconcat: ['freedom.js'],
      files: [
          'src/libs/*.js',
          'src/*.js',
          'src/proxy/*.js',
          'providers/*.js',
          'interface/*.js',
      ],
      options: {
        '-W069': true
      }
    },
    concat: {
      dist: {
        options: {
          process: function(src) {
            return src.replace(/\/\*jslint/g,'/*');
          }
        },
        src: [
          'src/libs/*.js',
          'src/util/preamble.js',
          'src/*.js',
          'src/proxy/*.js',
          'providers/*.js',
          'interface/*.js',
          'src/util/postamble.js'
        ],
        dest: 'freedom.js'
      }
    },
    uglify: {
      options: {
        mangle: { except: ['global'] }
      },
      freedom: {
        files: {
          'freedom.min.js': ['freedom.js']
        }
      }
    },
    clean: ['freedom.js', 'freedom.min.js'],
    yuidoc: {
      compile: {
        name: '<%= pkg.name %>',
        description: '<%= pkg.description %>',
        version: '<%= pkg.version %>',
        options: {
          paths: 'src/',
          outdir: 'tools/doc/'
        }
      }
    }
  });

  // Load tasks.
  grunt.loadNpmTasks('grunt-contrib-jasmine');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-yuidoc');
  grunt.loadNpmTasks('grunt-contrib-uglify');

  // Custom Task for Chrome Test Runner
  grunt.registerTask('chromeTestRunner', "Runs tests in a Chrome App", function(){
    grunt.util.spawn({
      cmd: 'bash',
      args: ['tools/chromeTestRunner.sh'],
    }, function done(error, result, code) {
      grunt.log.ok('Failed to execute shell script:'+
        "\n\t"+error+
        "\n\tResult: "+result+
        "\n\tCode: "+code);
    });
  });

  // Default tasks.
  grunt.registerTask('freedom', [
    'jshint:beforeconcat',
    'concat',
    'jasmine',
    'jshint:afterconcat',
    'uglify'
  ]);
  grunt.registerTask('default', ['freedom']);
};
<|endoftext|>


<commit_before>module.exports = function (grunt) {
    'use strict';

    var globalConfig = {
        src: 'src',
        dest: 'dist',
        timestamp: Date.now(),
        jsVendorHeaderFiles: [
            '<%= globalConfig.src %>/js/vendor/header/*.js'
        ],
        jsVendorFooterFiles: [
            '<%= globalConfig.src %>/js/vendor/footer/jquery.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/transition.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/alert.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/button.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/carousel.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/collapse.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/dropdown.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/modal.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/tooltip.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/popover.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/scrollspy.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/tab.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/affix.js',
            '<%= globalConfig.src %>/js/vendor/footer/*.js' // include all other files from vendor directory
        ]
    };

    grunt.initConfig({
        globalConfig: globalConfig,
        pkg: grunt.file.readJSON('package.json'),

        jshint: {
            options: {
                jshintrc: '.jshintrc'
            },
            files: [
                '<%= globalConfig.src %>/js/*.js',
                'Gruntfile.js'
            ]
        },
        clean: {
            pages: ['<%= globalConfig.dest %>/pages/**/*.html'],
            js: ['<%= globalConfig.dest %>/js/**/*.js', '<%= globalConfig.dest %>/js/**/*.map'],
            css: ['<%= globalConfig.dest %>/css/**/*.css', '<%= globalConfig.dest %>/css/**/*.map'],
            images: ['<%= globalConfig.dest %>/images/**/*.{png,jpg,gif}', '<%= globalConfig.dest %>/images-content/**/*.{png,jpg,gif}']
        },
        assemble: {
            options: {
                layoutdir: '<%= globalConfig.src %>/templates/layouts',
                flatten: true,
                layout: 'default.hbs',
                partials: '<%= globalConfig.src %>/templates/partials/*.hbs'
            },
            page: {
                files: {
                    '<%= globalConfig.dest %>/pages/': ['<%= globalConfig.src %>/templates/pages/*.hbs']
                }
            }
        },
        concat: {
            options: {
                sourceMap: true
            },
            vendor: {
                files: {
                    '<%= globalConfig.dest %>/js/vendors.header.lib.js': globalConfig.jsVendorHeaderFiles,
                    '<%= globalConfig.dest %>/js/vendors.footer.lib.js': globalConfig.jsVendorFooterFiles
                }
            },
            app: {
                files: {
                    '<%= globalConfig.dest %>/js/app.js': ['<%= globalConfig.src %>/js/*.js']
                }
            }
        },
        uglify: {
            dist: {
                options: {
                    mangle: false,
                    beautify: false,
                    preserveComments: /^!|@preserve|@license|@cc_on/i,
                    sourceMap: true
                },
                files: {
                    '<%= globalConfig.dest %>/js/vendors.header.lib.js': globalConfig.jsVendorHeaderFiles,
                    '<%= globalConfig.dest %>/js/vendors.footer.lib.js': globalConfig.jsVendorFooterFiles,
                    '<%= globalConfig.dest %>/js/app.js': '<%= globalConfig.src %>/js/*.js'
                }
            }
        },
        sass: {
            dev: {
                options: {
                    sourceMap: true,
                    outputStyle: 'expanded'
                },
                files: [
                    {
                        expand: true,
                        cwd: '<%= globalConfig.src %>/sass',
                        src: ['**/*.scss'],
                        dest: '<%= globalConfig.dest %>/css',
                        ext: '.css'
                    }
                ]
            },
            dist: {
                options: {
                    sourceMap: true,
                    outputStyle: 'compressed'
                },
                files: [
                    {
                        expand: true,
                        cwd: '<%= globalConfig.src %>/sass',
                        src: ['**/*.scss'],
                        dest: '<%= globalConfig.dest %>/css',
                        ext: '.css'
                    }
                ]
            }
        },
        imagemin: {
            images: {
                options: {
                    optimizationLevel: 3
                },
                files: [{
                    expand: true,
                    cwd: '<%= globalConfig.src %>/images',
                    src: ['**/*.{png,jpg,gif}'],
                    dest: '<%= globalConfig.dest %>/images/'
                }]
            },
            'images-content': {
                options: {
                    optimizationLevel: 3
                },
                files: [{
                    expand: true,
                    cwd: '<%= globalConfig.src %>/images-content',
                    src: ['**/*.{png,jpg,gif}'],
                    dest: '<%= globalConfig.dest %>/images-content/'
                }]
            }
        },
        sprite: {
            all: {
                src: '<%= globalConfig.dest %>/images/sprites/*.{png,jpg,gif}',
                destCss: '<%= globalConfig.src %>/sass/_base/_sprites.scss',
                dest: '<%= globalConfig.dest %>/images/sprites.png',
                imgPath: '../images/sprites.png?v=<%= globalConfig.timestamp %>',
                'cssVarMap': function (sprite) {
                    var str = sprite.name,
                        res = str.split("_"),
                        spritePrefix = 'sprite-';

                    if (res[res.length - 1] === 'hover') {
                        sprite.name = spritePrefix + res.slice(0, -1).join("_") + '.sprite--active';
                    } else {
                        sprite.name = spritePrefix + sprite.name;
                    }
                }
            }
        },
        postcss: {
            options: {
                map: {
                    inline: false // save all sourcemaps as separate files
                },
                processors: [
                    require('autoprefixer')({browsers: ['> 1%', 'last 2 versions', 'Firefox ESR'], remove: false})
                ]
            },
            dist: {
                src: '<%= globalConfig.dest %>/css/**/*.css'
            }
        },
        watch: {
            options: {
                spawn: false
            },
            assemble: {
                files: ['<%= globalConfig.src %>/templates/**/*.hbs'],
                tasks: ['clean:pages', 'assemble']
            },
            images: {
                files: ['<%= globalConfig.src %>/images/**/*.{png,jpg,gif}', '<%= globalConfig.src %>/images-content/**/*.{png,jpg,gif}'],
                tasks: ['clean:images', 'imagemin', 'sprite', 'sass:dev', 'postcss']
            },
            'concat-app': {
                files: ['<%= globalConfig.src %>/js/*.js'],
                tasks: ['jshint', 'concat:app']
            },
            'concat-vendor': {
                files: ['<%= globalConfig.src %>/js/vendor/**/*.js'],
                tasks: ['concat:vendor']
            },
            sass: {
                files: ['<%= globalConfig.src %>/sass/**/*.scss'],
                tasks: ['clean:css', 'sass:dev', 'postcss']
            }
        },
        browserSync: {
            bsFiles: {
                src : [
                    '<%= globalConfig.dest %>/css/*.css',
                    '<%= globalConfig.dest %>/js/*.js',
                    '<%= globalConfig.dest %>/pages/*.html'
                ]
            },
            options: {
                watchTask: true,
                server: {
                    baseDir: "<%= globalConfig.dest %>"
                }
            }
        }
    });

    /* load every plugin in package.json */
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('assemble');
    grunt.loadNpmTasks('grunt-sass');
    grunt.loadNpmTasks('grunt-spritesmith');
    grunt.loadNpmTasks('grunt-contrib-imagemin');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-postcss');
    grunt.loadNpmTasks('grunt-browser-sync');

    /* grunt tasks */
    grunt.registerTask('default', [
        'jshint',
        'clean',
        'assemble',
        'concat',
        'imagemin',
        'sprite',
        'sass:dev',
        'postcss',
        'browserSync',
        'watch'
    ]);
    grunt.registerTask('build', [
        'jshint',
        'clean',
        'assemble',
        'uglify:dist',
        'imagemin',
        'sprite',
        'sass:dist',
        'postcss'
    ]);

};<commit_msg>Fix baseDir path<commit_after>module.exports = function (grunt) {
    'use strict';

    var globalConfig = {
        src: 'src',
        dest: 'dist',
        timestamp: Date.now(),
        jsVendorHeaderFiles: [
            '<%= globalConfig.src %>/js/vendor/header/*.js'
        ],
        jsVendorFooterFiles: [
            '<%= globalConfig.src %>/js/vendor/footer/jquery.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/transition.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/alert.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/button.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/carousel.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/collapse.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/dropdown.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/modal.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/tooltip.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/popover.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/scrollspy.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/tab.js',
            //'<%= globalConfig.src %>/js/vendor/footer/bootstrap/affix.js',
            '<%= globalConfig.src %>/js/vendor/footer/*.js' // include all other files from vendor directory
        ]
    };

    grunt.initConfig({
        globalConfig: globalConfig,
        pkg: grunt.file.readJSON('package.json'),

        jshint: {
            options: {
                jshintrc: '.jshintrc'
            },
            files: [
                '<%= globalConfig.src %>/js/*.js',
                'Gruntfile.js'
            ]
        },
        clean: {
            pages: ['<%= globalConfig.dest %>/pages/**/*.html'],
            js: ['<%= globalConfig.dest %>/js/**/*.js', '<%= globalConfig.dest %>/js/**/*.map'],
            css: ['<%= globalConfig.dest %>/css/**/*.css', '<%= globalConfig.dest %>/css/**/*.map'],
            images: ['<%= globalConfig.dest %>/images/**/*.{png,jpg,gif}', '<%= globalConfig.dest %>/images-content/**/*.{png,jpg,gif}']
        },
        assemble: {
            options: {
                layoutdir: '<%= globalConfig.src %>/templates/layouts',
                flatten: true,
                layout: 'default.hbs',
                partials: '<%= globalConfig.src %>/templates/partials/*.hbs'
            },
            page: {
                files: {
                    '<%= globalConfig.dest %>/pages/': ['<%= globalConfig.src %>/templates/pages/*.hbs']
                }
            }
        },
        concat: {
            options: {
                sourceMap: true
            },
            vendor: {
                files: {
                    '<%= globalConfig.dest %>/js/vendors.header.lib.js': globalConfig.jsVendorHeaderFiles,
                    '<%= globalConfig.dest %>/js/vendors.footer.lib.js': globalConfig.jsVendorFooterFiles
                }
            },
            app: {
                files: {
                    '<%= globalConfig.dest %>/js/app.js': ['<%= globalConfig.src %>/js/*.js']
                }
            }
        },
        uglify: {
            dist: {
                options: {
                    mangle: false,
                    beautify: false,
                    preserveComments: /^!|@preserve|@license|@cc_on/i,
                    sourceMap: true
                },
                files: {
                    '<%= globalConfig.dest %>/js/vendors.header.lib.js': globalConfig.jsVendorHeaderFiles,
                    '<%= globalConfig.dest %>/js/vendors.footer.lib.js': globalConfig.jsVendorFooterFiles,
                    '<%= globalConfig.dest %>/js/app.js': '<%= globalConfig.src %>/js/*.js'
                }
            }
        },
        sass: {
            dev: {
                options: {
                    sourceMap: true,
                    outputStyle: 'expanded'
                },
                files: [
                    {
                        expand: true,
                        cwd: '<%= globalConfig.src %>/sass',
                        src: ['**/*.scss'],
                        dest: '<%= globalConfig.dest %>/css',
                        ext: '.css'
                    }
                ]
            },
            dist: {
                options: {
                    sourceMap: true,
                    outputStyle: 'compressed'
                },
                files: [
                    {
                        expand: true,
                        cwd: '<%= globalConfig.src %>/sass',
                        src: ['**/*.scss'],
                        dest: '<%= globalConfig.dest %>/css',
                        ext: '.css'
                    }
                ]
            }
        },
        imagemin: {
            images: {
                options: {
                    optimizationLevel: 3
                },
                files: [{
                    expand: true,
                    cwd: '<%= globalConfig.src %>/images',
                    src: ['**/*.{png,jpg,gif}'],
                    dest: '<%= globalConfig.dest %>/images/'
                }]
            },
            'images-content': {
                options: {
                    optimizationLevel: 3
                },
                files: [{
                    expand: true,
                    cwd: '<%= globalConfig.src %>/images-content',
                    src: ['**/*.{png,jpg,gif}'],
                    dest: '<%= globalConfig.dest %>/images-content/'
                }]
            }
        },
        sprite: {
            all: {
                src: '<%= globalConfig.dest %>/images/sprites/*.{png,jpg,gif}',
                destCss: '<%= globalConfig.src %>/sass/_base/_sprites.scss',
                dest: '<%= globalConfig.dest %>/images/sprites.png',
                imgPath: '../images/sprites.png?v=<%= globalConfig.timestamp %>',
                'cssVarMap': function (sprite) {
                    var str = sprite.name,
                        res = str.split("_"),
                        spritePrefix = 'sprite-';

                    if (res[res.length - 1] === 'hover') {
                        sprite.name = spritePrefix + res.slice(0, -1).join("_") + '.sprite--active';
                    } else {
                        sprite.name = spritePrefix + sprite.name;
                    }
                }
            }
        },
        postcss: {
            options: {
                map: {
                    inline: false // save all sourcemaps as separate files
                },
                processors: [
                    require('autoprefixer')({browsers: ['> 1%', 'last 2 versions', 'Firefox ESR'], remove: false})
                ]
            },
            dist: {
                src: '<%= globalConfig.dest %>/css/**/*.css'
            }
        },
        watch: {
            options: {
                spawn: false
            },
            assemble: {
                files: ['<%= globalConfig.src %>/templates/**/*.hbs'],
                tasks: ['clean:pages', 'assemble']
            },
            images: {
                files: ['<%= globalConfig.src %>/images/**/*.{png,jpg,gif}', '<%= globalConfig.src %>/images-content/**/*.{png,jpg,gif}'],
                tasks: ['clean:images', 'imagemin', 'sprite', 'sass:dev', 'postcss']
            },
            'concat-app': {
                files: ['<%= globalConfig.src %>/js/*.js'],
                tasks: ['jshint', 'concat:app']
            },
            'concat-vendor': {
                files: ['<%= globalConfig.src %>/js/vendor/**/*.js'],
                tasks: ['concat:vendor']
            },
            sass: {
                files: ['<%= globalConfig.src %>/sass/**/*.scss'],
                tasks: ['clean:css', 'sass:dev', 'postcss']
            }
        },
        browserSync: {
            bsFiles: {
                src : [
                    '<%= globalConfig.dest %>/css/*.css',
                    '<%= globalConfig.dest %>/js/*.js',
                    '<%= globalConfig.dest %>/pages/*.html'
                ]
            },
            options: {
                watchTask: true,
                server: {
                    baseDir: "./"
                }
            }
        }
    });

    /* load every plugin in package.json */
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('assemble');
    grunt.loadNpmTasks('grunt-sass');
    grunt.loadNpmTasks('grunt-spritesmith');
    grunt.loadNpmTasks('grunt-contrib-imagemin');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-postcss');
    grunt.loadNpmTasks('grunt-browser-sync');

    /* grunt tasks */
    grunt.registerTask('default', [
        'jshint',
        'clean',
        'assemble',
        'concat',
        'imagemin',
        'sprite',
        'sass:dev',
        'postcss',
        'browserSync',
        'watch'
    ]);
    grunt.registerTask('build', [
        'jshint',
        'clean',
        'assemble',
        'uglify:dist',
        'imagemin',
        'sprite',
        'sass:dist',
        'postcss'
    ]);

};<|endoftext|>


<commit_before>/*global module:false*/
module.exports = function(grunt) {

  var TRACKER_FILENAME = 'w.js',
      CDN_URL = 'http://static.woopra.com/';

  // Project configuration.
  grunt.config.init({
    pkg: grunt.file.readJSON('package.json'),
    options: {
      testFiles: ['<%= pkg.name %>.v<%= pkg.version %>.min.js'],
      specFiles: ['test/spec/*.js']
    },
    connect: {
        dev: {
            options: {
                port: 4242,
                hostname: '0.0.0.0',
                keepalive: true
            }
        },
        test: {
            options: {
                port: 4141,
                hostname: '0.0.0.0'
            }
        },
    },

    meta: {
      banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
        '<%= grunt.template.today("yyyy-mm-dd") %>\\n' +
        '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
        '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
        ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */'
    },
    watch: {
      files: '<config:lint.files>',
      tasks: 'lint min',
      test: {
        files: ['<%= options.testFiles>', '<%= options.specFiles %>', 'test/TestRunner.html'],
        tasks: 'mocha'
      }
    },
    jshint: {
      options: {
        curly: true,
        eqeqeq: true,
        immed: true,
        latedef: true,
        newcap: true,
        noarg: true,
        sub: true,
        undef: true,
        boss: true,
        eqnull: true,
        browser: true,
        unused: true,
        globals: {
          exports: true,
          jQuery: true
        }
      },
      main: {
          files: [{
              src: ['grunt.js', '<%= pkg.name %>.js']
          }]
      },
      tests: {
          options: {
              globals: {
                  exports: true,
                  '$': true,
                  describe: true,
                  expect: true,
                  before: true,
                  beforeEach: true,
                  after: true,
                  afterEach: true,
                  sinon: true,
                  Woopra: true,
                  WoopraTracker: true,
                  it: true
              }
          },
          files: [{
              src: ['<%= options.specFiles %>']
          }]
      }
    },
    uglify: {
        options: {
            compressor: {
                warnings: false
            },
            mangle: true,
            compress: true
        },
        main: {
          options: {
          },
            src: ['<%= pkg.name %>.js'],
            dest: '<%= pkg.name %>.min.js'
        },
        snippet: {
            src: ['snippet.js'],
            dest: 'snippet-min.js'
        }
    },
    upload: {
        tracker: {
            type: 'scp',
            host: 'woopra-cdn',
            cdnRoot: '/var/www/html',
            tasks: [{
                src: [
                    '<%= uglify.main.dest %>'
                ],
                dest: '<%= upload.tracker.cdnRoot %>/js/' + TRACKER_FILENAME
            }]
        }
    },
    mocha: {
      tracker: {
        src: ['test/TestRunner.html'],
        options: {
          mocha: {
            globals: ['woopra', 'newTracker', 'pingTracker', 'w1', 'w2', 'w3'],
            ignoreLeaks: false
          },
          reporter: 'Spec',
          run: true,
          log: true
        }
      },
      snippet: {
        src: ['test/snippet.html'],
        options: {
          mocha: {
            globals: ['woopraLoaded', '_w', 'WoopraTracker', 'woopraTracker', 'WoopraLoadScript', 'Woopra', 'woopra', 'woopra_c1', 'woopra_c2', 'woopra_c3'],
            ignoreLeaks: false
          },
          reporter: 'Spec',
          run: true,
          log: false
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-mocha');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-connect');
  grunt.loadNpmTasks('grunt-contrib-watch');

  // Default task.
  grunt.registerTask('default', ['jshint', 'test', 'uglify']);

  grunt.task.registerTask('test', ['connect:test', 'mocha']);

  grunt.registerTask('deploy', function() {
      grunt.task.run(['jshint', 'test', 'uglify']);
      grunt.task.run('upload:tracker');
      grunt.task.run('purge');
  });

  grunt.registerTask('purge', 'Call EdgeCast API to purge CDN cache', function() {
      var done = this.async(),
          request = require('request'),
          data = {
              MediaPath: CDN_URL + 'js/' + TRACKER_FILENAME,
              MediaType: 8
          };

      request.put({
          url: 'https://api.edgecast.com/v2/mcc/customers/' + process.env.EDGECAST_ACCOUNT_NUMBER + '/edge/purge',
          json: true,
          body: data,
          headers: {
              Authorization: 'TOK:' + process.env.EDGECAST_ACCESS_TOKEN,
              Accept: 'application/json'
          }
      }, function(e, r, body) {
          var json;
          if (!e) {
              if (body.Id) {
                  done();
                  grunt.log.writeln('Request sent, id = ' + body.Id);
              }
              else {
                  grunt.log.error('Error purging CDN cache.');
              }
          }
          else {
              grunt.log.error('Error purging CDN cache.');
          }
      });

  });

  grunt.registerMultiTask('upload', 'Uploads to CDN', function() {
      var self = this;
      var done = this.async();
      var tasks = {
          scp: function() {
              var scp = require('scp');

              this.data.tasks.forEach(function(task) {
                  task.src.forEach(function(src) {
                      scp.send({
                          host: self.data.host,
                          path: task.dest,
                          file: __dirname + '/' + src
                      }, function(err, stdout, stderr) {
                          grunt.log.writeln(err, stdout, stderr);
                          if (err) done(false);
                          else done();
                      });
                  });
              });
          }
      };

      tasks[this.data.type].apply(this);
  });

};
<commit_msg>WIP: Versioning with gruntfile<commit_after>/*global module:false*/
var spawn = require('child_process').spawn;

module.exports = function(grunt) {

  var TRACKER_FILENAME = 'w.js',
      CDN_URL = 'http://static.woopra.com/';

  var getVersion = function(version) {
    var data = {};
    var match, major, minor, patch;

    match = version.match(/^([0-9]+)\.([0-9]+)\.([0-9]+).*/);

    if (match) {
      data.major = match[1];
      data.minor = match[2];
      data.patch = match[3];
    }

    return data;
  };

  // Project configuration.
  grunt.config.init({
    pkg: grunt.file.readJSON('package.json'),
    options: {
      testFiles: ['<%= pkg.name %>.v<%= pkg.version %>.min.js'],
      specFiles: ['test/spec/*.js']
    },
    connect: {
        dev: {
            options: {
                port: 4242,
                hostname: '0.0.0.0',
                keepalive: true
            }
        },
        test: {
            options: {
                port: 4141,
                hostname: '0.0.0.0'
            }
        },
    },

    meta: {
      banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
        '<%= grunt.template.today("yyyy-mm-dd") %>\\n' +
        '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
        '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
        ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */'
    },
    watch: {
      files: '<config:lint.files>',
      tasks: 'lint min',
      test: {
        files: ['<%= options.testFiles>', '<%= options.specFiles %>', 'test/TestRunner.html'],
        tasks: 'mocha'
      }
    },
    jshint: {
      options: {
        curly: true,
        eqeqeq: true,
        immed: true,
        latedef: true,
        newcap: true,
        noarg: true,
        sub: true,
        undef: true,
        boss: true,
        eqnull: true,
        browser: true,
        unused: true,
        globals: {
          exports: true,
          jQuery: true
        }
      },
      main: {
          files: [{
              src: ['grunt.js', '<%= pkg.name %>.js']
          }]
      },
      tests: {
          options: {
              globals: {
                  exports: true,
                  '$': true,
                  describe: true,
                  expect: true,
                  before: true,
                  beforeEach: true,
                  after: true,
                  afterEach: true,
                  sinon: true,
                  Woopra: true,
                  WoopraTracker: true,
                  it: true
              }
          },
          files: [{
              src: ['<%= options.specFiles %>']
          }]
      }
    },
    uglify: {
        options: {
            compressor: {
                warnings: false
            },
            mangle: true,
            compress: true
        },
        main: {
          options: {
          },
            src: ['<%= pkg.name %>.js'],
            dest: '<%= pkg.name %>.min.js'
        },
        snippet: {
            src: ['snippet.js'],
            dest: 'snippet-min.js'
        }
    },
    upload: {
        tracker: {
            type: 'scp',
            host: 'woopra-cdn',
            cdnRoot: '/var/www/html',
            tasks: [{
                src: [
                    '<%= uglify.main.dest %>'
                ],
                dest: '<%= upload.tracker.cdnRoot %>/js/' + TRACKER_FILENAME
            }]
        },
        dev: {
            type: 'scp',
            host: 'woopra-cdn',
            cdnRoot: '/var/www/html',
            tasks: [{
                src: [
                    '<%= uglify.main.dest %>'
                ],
                dest: '<%= upload.tracker.cdnRoot %>/js/t/' + TRACKER_FILENAME
            }]

        }
    },
    mocha: {
      tracker: {
        src: ['test/TestRunner.html'],
        options: {
          mocha: {
            globals: ['woopra', 'newTracker', 'pingTracker', 'w1', 'w2', 'w3'],
            ignoreLeaks: false
          },
          reporter: 'Spec',
          run: true,
          log: true
        }
      },
      snippet: {
        src: ['test/snippet.html'],
        options: {
          mocha: {
            globals: ['woopraLoaded', '_w', 'WoopraTracker', 'woopraTracker', 'WoopraLoadScript', 'Woopra', 'woopra', 'woopra_c1', 'woopra_c2', 'woopra_c3'],
            ignoreLeaks: false
          },
          reporter: 'Spec',
          run: true,
          log: false
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-mocha');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-connect');
  grunt.loadNpmTasks('grunt-contrib-watch');

  // Default task.
  grunt.registerTask('default', ['jshint', 'test', 'uglify']);

  grunt.task.registerTask('test', ['connect:test', 'mocha']);

  grunt.registerTask('deploy', function() {
      grunt.task.run(['jshint', 'test', 'uglify']);
      grunt.task.run('upload:tracker');
      grunt.task.run('purge');
  });

  grunt.registerTask('version', function() {
    var done = this.async();
    var version = grunt.option('version') || 'patch';
    var child;

    child = spawn('npm', ['version', version]);

    child.stdout.on('data', function(data) {
      grunt.log.writeln(data);
    });
    child.stderr.on('data', function(data) {
      grunt.log.error(data);
    });

    child.on('close', function(code) {
      if (code === 0) {
        grunt.log.writeln('Done updating version (' + version + ')');
        grunt.config('pkg', grunt.file.readJSON('package.json'));
      }
      else {
        grunt.log.error('Error updating version (' + version + ')');
      }
      done();
    });
  });

  grunt.registerTask('purge', 'Call EdgeCast API to purge CDN cache', function() {
      var done = this.async(),
          request = require('request'),
          data = {
              MediaPath: CDN_URL + 'js/' + TRACKER_FILENAME,
              MediaType: 8
          };

      request.put({
          url: 'https://api.edgecast.com/v2/mcc/customers/' + process.env.EDGECAST_ACCOUNT_NUMBER + '/edge/purge',
          json: true,
          body: data,
          headers: {
              Authorization: 'TOK:' + process.env.EDGECAST_ACCESS_TOKEN,
              Accept: 'application/json'
          }
      }, function(e, r, body) {
          var json;
          if (!e) {
              if (body.Id) {
                  done();
                  grunt.log.writeln('Request sent, id = ' + body.Id);
              }
              else {
                  grunt.log.error('Error purging CDN cache.');
              }
          }
          else {
              grunt.log.error('Error purging CDN cache.');
          }
      });

  });

  grunt.registerMultiTask('upload', 'Uploads to CDN', function() {
      var self = this;
      var done = this.async();
      var tasks = {
          scp: function() {
              var scp = require('scp');

              this.data.tasks.forEach(function(task) {
                  task.src.forEach(function(src) {
                      scp.send({
                          host: self.data.host,
                          path: task.dest,
                          file: __dirname + '/' + src
                      }, function(err, stdout, stderr) {
                          grunt.log.writeln(err, stdout, stderr);
                          if (err) done(false);
                          else done();
                      });
                  });
              });
          }
      };

      tasks[this.data.type].apply(this);
  });

};
<|endoftext|>