<commit_before>module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    pkgMeta: grunt.file.readJSON('pkg/meta.json'),
    dest: 'dist',
    package_dir: 'pkg',
    package_temp_dir: '<%= package_dir %>/tmp/',

    watch: {
      less: {
        files: ['app/less/*.less', 'lib/**/*.less'],
        tasks: ['less:build'],
        options: {
          spawn: false
        }
      },

      js: {
        files: ['app/**/*.js', 'lib/**/*.js'],
        tasks: ['concat', 'jshint'],
        options: {
          spawn: false
        }
      },

      dev: {
        files: ['app/**'],
        tasks: ['deploy'],
        options: {
          spawn: false
        }
      }
    },

    jshint: {
      options: {
        jshintrc: '.jshintrc'
      },
      src: {
        src: ['app/**/*.js', 'lib/**/*.js']
      }
    },

    less: {
      build: {
        options: {
          paths: ["app/less", "lib/less", "vendor"],
        },
        files: {
          '<%= dest %>/css/archetype.css': 'app/less/archetype.less',
        }
      }
    },

    concat: {
      options: {
        stripBanners: false
      },
      application: {
        src: [
          'app/controllers/controller.js',
          'app/controllers/config.controller.js',
          'app/directives/archetypeproperty.js',
          'app/resources/propertyeditor.js'
        ],
        dest: '<%= dest %>/js/archetype.js'
      }
    },

    nugetpack: {
    	dist: {
    		src: '<%= package_temp_dir %>/nuget/package.nuspec',
    		dest: '<%= package_dir %>'
    	}
    },

    template: {
    	'nuget_manifest': {
			'options': {
    			'data': {
            name: '<%= pkgMeta.name %>',
    				version: '<%= pkgMeta.version %>',
            url: '<%= pkgMeta.url %>',
            license: '<%= pkgMeta.license %>',
            licenseUrl: '<%= pkgMeta.licenseUrl %>',
            author: '<%= pkgMeta.author %>',
            authorUrl: '<%= pkgMeta.authorUrl %>',

    				files: [{ path: '..\\..\\..\\<%= dest %>\\**', target: 'content\\App_Plugins\\Archetype'}]
	    		}
    		},
    		'files': {
    			'<%= package_temp_dir %>/nuget/package.nuspec': ['<%= package_dir %>/nuget/package.nuspec']
    		}
    	}
    },

    clean: {
  		build: ['<%= dest %>']
    },

    copy: {
      build: {
       files: [
        {expand: true, cwd: 'app/', src: ['package.manifest'], dest: '<%= dest %>', flatten: true},
        {expand: true, cwd: 'app/views/', src: ['archetype.html', 'archetype.config.html'], dest: '<%= dest %>/views', flatten: true},
        {expand: true, cwd: 'app/config/', src: ['propertyEditors.views.js'], dest: '<%= dest %>/js', flatten: true},
        {expand: true, cwd: 'app/Umbraco/Umbraco.Archetype/bin/Debug/', src: ['Archetype.dll'], dest: '<%= dest %>/bin', flatten: true}
        ]
      },
      deploy: {
        files: [
          {expand: true, cwd: '<%= dest %>/', src: ['**/*', '!bin/*'], dest: '<%= grunt.option("target") %>\\App_Plugins\\Archetype', flatten: false},
          {expand: true, cwd: '<%= dest %>/', src: ['bin/*'], dest: '<%= grunt.option("target") %>\\bin', flatten: false},
        ]
      },
      nuget_prepare: {
        files: [
          {expand: true, cwd: '<%= dest %>/', src: ['**/*', '!bin/*'], dest: '<%= package_temp_dir %>/nuget/content/', flatten: false},
          {expand: true, cwd: '<%= dest %>/', src: ['bin/*'], dest: '<%= package_temp_dir %>/nuget/lib/net40/', flatten: false}
        ]
      },
      umbracopackage: {
        files: [
          {expand: true, cwd: '<%= dest %>/', src: ['**/*', "!bin/*"], dest: 'pkg/tmp/umbraco/App_Plugins/Archetype', flatten: false},
          {expand: true, cwd: '<%= dest %>/', src: ['bin/*'], dest: 'pkg/tmp/umbraco', flatten: false}
        ]
      }
    },

    touch: {
      options: {},
      webconfig: {
        src: ['<%= grunt.option("target") %>\\Web.config']
      }
    },

    umbracoPackage: {
      options: {
        name: "<%= pkgMeta.name %>",
        version: '<%= pkgMeta.version %>',
        url: '<%= pkgMeta.url %>',
        license: '<%= pkgMeta.license %>',
        licenseUrl: '<%= pkgMeta.licenseUrl %>',
        author: '<%= pkgMeta.author %>',
        authorUrl: '<%= pkgMeta.authorUrl %>',
        manifest: 'pkg/umbraco/package.xml',
        readme: 'pkg/umbraco/readme.txt',
        sourceDir: 'pkg/tmp/umbraco',
        outputDir: 'pkg',
      }
    },

    clean: {
      build: ['<%= dest %>'],
      package_temp: ['pkg/tmp'],
      package_artifacts: ['pkg/*.zip', 'pkg/*.nupkg'],
    },

    msbuild: {
        dev: {
            src: ['app/Umbraco/Umbraco.Archetype/Archetype.Umbraco.csproj'],
            options: {
                projectConfiguration: 'Debug',
                targets: ['Clean', 'Rebuild'],
                stdout: true,
                maxCpuCount: 4,
                buildParameters: {
                    WarningLevel: 2
                },
                verbosity: 'quiet'
            }
        }
    }

  });

  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-less');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-nuget');
  grunt.loadNpmTasks('grunt-template');
  grunt.loadNpmTasks('grunt-touch');
  grunt.loadNpmTasks('grunt-msbuild');
  grunt.loadTasks('tasks');

  grunt.registerTask('package', ['default', 'package:nuget', 'package:umbraco']);
  grunt.registerTask('package:nuget', ['clean:package_artifacts', 'copy:nuget_prepare', 'template:nuget_manifest', 'nugetpack', 'clean:package_temp']);
  grunt.registerTask('package:umbraco', ['clean:package_artifacts', 'copy:umbracopackage', 'umbracoPackage', 'clean:package_temp']);
  grunt.registerTask('touchwebconfigifenabled', function() { if (grunt.option("touch")) grunt.task.run("touch:webconfig") });
  grunt.registerTask('deploy', ['default', 'copy:deploy', 'touchwebconfigifenabled']);
  grunt.registerTask('css:build', ['less']);
  grunt.registerTask('js:build', ['concat']);
  grunt.registerTask('default', ['clean', 'css:build', 'js:build', 'copy:build', 'msbuild:dev']);
};

<commit_msg>Only clean on main task<commit_after>module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    pkgMeta: grunt.file.readJSON('pkg/meta.json'),
    dest: 'dist',
    package_dir: 'pkg',
    package_temp_dir: '<%= package_dir %>/tmp/',

    watch: {
      less: {
        files: ['app/less/*.less', 'lib/**/*.less'],
        tasks: ['less:build'],
        options: {
          spawn: false
        }
      },

      js: {
        files: ['app/**/*.js', 'lib/**/*.js'],
        tasks: ['concat', 'jshint'],
        options: {
          spawn: false
        }
      },

      dev: {
        files: ['app/**'],
        tasks: ['deploy'],
        options: {
          spawn: false
        }
      }
    },

    jshint: {
      options: {
        jshintrc: '.jshintrc'
      },
      src: {
        src: ['app/**/*.js', 'lib/**/*.js']
      }
    },

    less: {
      build: {
        options: {
          paths: ["app/less", "lib/less", "vendor"],
        },
        files: {
          '<%= dest %>/css/archetype.css': 'app/less/archetype.less',
        }
      }
    },

    concat: {
      options: {
        stripBanners: false
      },
      application: {
        src: [
          'app/controllers/controller.js',
          'app/controllers/config.controller.js',
          'app/directives/archetypeproperty.js',
          'app/resources/propertyeditor.js'
        ],
        dest: '<%= dest %>/js/archetype.js'
      }
    },

    nugetpack: {
    	dist: {
    		src: '<%= package_temp_dir %>/nuget/package.nuspec',
    		dest: '<%= package_dir %>'
    	}
    },

    template: {
    	'nuget_manifest': {
			'options': {
    			'data': {
            name: '<%= pkgMeta.name %>',
    				version: '<%= pkgMeta.version %>',
            url: '<%= pkgMeta.url %>',
            license: '<%= pkgMeta.license %>',
            licenseUrl: '<%= pkgMeta.licenseUrl %>',
            author: '<%= pkgMeta.author %>',
            authorUrl: '<%= pkgMeta.authorUrl %>',

    				files: [{ path: '..\\..\\..\\<%= dest %>\\**', target: 'content\\App_Plugins\\Archetype'}]
	    		}
    		},
    		'files': {
    			'<%= package_temp_dir %>/nuget/package.nuspec': ['<%= package_dir %>/nuget/package.nuspec']
    		}
    	}
    },

    clean: {
  		build: ['<%= dest %>']
    },

    copy: {
      build: {
       files: [
        {expand: true, cwd: 'app/', src: ['package.manifest'], dest: '<%= dest %>', flatten: true},
        {expand: true, cwd: 'app/views/', src: ['archetype.html', 'archetype.config.html'], dest: '<%= dest %>/views', flatten: true},
        {expand: true, cwd: 'app/config/', src: ['propertyEditors.views.js'], dest: '<%= dest %>/js', flatten: true},
        {expand: true, cwd: 'app/Umbraco/Umbraco.Archetype/bin/Debug/', src: ['Archetype.dll'], dest: '<%= dest %>/bin', flatten: true}
        ]
      },
      deploy: {
        files: [
          {expand: true, cwd: '<%= dest %>/', src: ['**/*', '!bin/*'], dest: '<%= grunt.option("target") %>\\App_Plugins\\Archetype', flatten: false},
          {expand: true, cwd: '<%= dest %>/', src: ['bin/*'], dest: '<%= grunt.option("target") %>\\bin', flatten: false},
        ]
      },
      nuget_prepare: {
        files: [
          {expand: true, cwd: '<%= dest %>/', src: ['**/*', '!bin/*'], dest: '<%= package_temp_dir %>/nuget/content/', flatten: false},
          {expand: true, cwd: '<%= dest %>/', src: ['bin/*'], dest: '<%= package_temp_dir %>/nuget/lib/net40/', flatten: false}
        ]
      },
      umbracopackage: {
        files: [
          {expand: true, cwd: '<%= dest %>/', src: ['**/*', "!bin/*"], dest: 'pkg/tmp/umbraco/App_Plugins/Archetype', flatten: false},
          {expand: true, cwd: '<%= dest %>/', src: ['bin/*'], dest: 'pkg/tmp/umbraco', flatten: false}
        ]
      }
    },

    touch: {
      options: {},
      webconfig: {
        src: ['<%= grunt.option("target") %>\\Web.config']
      }
    },

    umbracoPackage: {
      options: {
        name: "<%= pkgMeta.name %>",
        version: '<%= pkgMeta.version %>',
        url: '<%= pkgMeta.url %>',
        license: '<%= pkgMeta.license %>',
        licenseUrl: '<%= pkgMeta.licenseUrl %>',
        author: '<%= pkgMeta.author %>',
        authorUrl: '<%= pkgMeta.authorUrl %>',
        manifest: 'pkg/umbraco/package.xml',
        readme: 'pkg/umbraco/readme.txt',
        sourceDir: 'pkg/tmp/umbraco',
        outputDir: 'pkg',
      }
    },

    clean: {
      build: ['<%= dest %>'],
      package_temp: ['pkg/tmp'],
      package_artifacts: ['pkg/*.zip', 'pkg/*.nupkg'],
    },

    msbuild: {
        dev: {
            src: ['app/Umbraco/Umbraco.Archetype/Archetype.Umbraco.csproj'],
            options: {
                projectConfiguration: 'Debug',
                targets: ['Clean', 'Rebuild'],
                stdout: true,
                maxCpuCount: 4,
                buildParameters: {
                    WarningLevel: 2
                },
                verbosity: 'quiet'
            }
        }
    }

  });

  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-less');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-nuget');
  grunt.loadNpmTasks('grunt-template');
  grunt.loadNpmTasks('grunt-touch');
  grunt.loadNpmTasks('grunt-msbuild');
  grunt.loadTasks('tasks');

  grunt.registerTask('package', ['clean:package_artifacts', 'default', 'package:nuget', 'package:umbraco']);
  grunt.registerTask('package:nuget', ['copy:nuget_prepare', 'template:nuget_manifest', 'nugetpack', 'clean:package_temp']);
  grunt.registerTask('package:umbraco', ['copy:umbracopackage', 'umbracoPackage', 'clean:package_temp']);
  grunt.registerTask('touchwebconfigifenabled', function() { if (grunt.option("touch")) grunt.task.run("touch:webconfig") });
  grunt.registerTask('deploy', ['default', 'copy:deploy', 'touchwebconfigifenabled']);
  grunt.registerTask('css:build', ['less']);
  grunt.registerTask('js:build', ['concat']);
  grunt.registerTask('default', ['clean', 'css:build', 'js:build', 'copy:build', 'msbuild:dev']);
};

<|endoftext|>


<commit_before>(function(e){if(typeof module!=="undefined"&&module&&module.exports){module.exports=e()}else if(typeof define==="function"&&define.amd){define(e)}else{P=e()}})(function(){"use strict";var e=v(typeof process)&&process!=null&&{}.toString.call(process)==="[object process]",n=typeof setImmediate==="function",t=v(typeof MutationObserver)&&MutationObserver||v(typeof WebKitMutationObserver)&&WebKitMutationObserver,i=new p,r=i,o=false,u=e?w:t?g(_):x(_),a=[],s=x(h),l,f,c=v.call,d=v.apply;r.next=i;function p(){this.task=null;this.domain=null;this.a=null;this.b=null;this.next=null}function v(e){return e==="object"||e==="function"}function h(){if(a.length){throw a.shift()}}function _(){while(i!==r){i=i.next;var e=i.task;if(M.countFreeTaskNodes>=1024){r.next=r.next.next}else{++M.countFreeTaskNodes}if(i.domain){y(i.domain,e,i.a,i.b,void 0);i.domain=null}else{e(i.a,i.b)}i.task=null;i.a=null;i.b=null}o=false}function m(){i.task=null;i.domain=null;i.a=null;i.b=null;u()}function y(e,n,t,i,r){if(e._disposed){return}e.enter();n(t,i,r);e.exit()}function b(n,t,a,s){var l=r.next;if(l===i){l=new p;r.next=l;l.next=i}else{--M.countFreeTaskNodes}r=l;l.task=t;l.a=a;l.b=s;if(n&&e){l.domain=process.domain}if(!o){o=true;u()}}function w(){var e=process.domain;if(e){if(!f)f=(1,require)("domain");f.active=process.domain=null}if(o&&n){setImmediate(_)}else{process.nextTick(_)}if(e){f.active=process.domain=e}}function g(e){var n=1;var i=document.createTextNode("");var r=new t(e);r.observe(i,{characterData:true});return function(){n=-n;i.data=n}}function x(e){return function(){var n=setTimeout(i,0);var t=setInterval(i,50);function i(){clearTimeout(n);clearInterval(t);e()}}}if(e){l=function(e){m();throw e}}else{l=function(e){a.push(e);s()}}function T(e,n){try{e.call()}catch(t){n(t)}}function k(e){b(true,T,e,l)}function j(e,n){for(var t=0,i=e.length;t<i;++t){if(t in e){n(e[t],t)}}}function N(e){k(function(){if(M.onerror){M.onerror.call(null,e)}else{throw e}})}var O=0;var F=1;var I=2;function M(e){return e instanceof C?e:K(new C,e,false)}M.countFreeTaskNodes=0;function E(n,t,i){if(n._state){return n}n._state=t;n._value=i;if(t===I&&e){n._domain=process.domain}if(n._pending){W(n)}return n}function A(e,n){if(n._state){return n}n._state=e._state;n._value=e._value;n._domain=e._domain;if(n._pending){W(n)}return n}function K(e,n,t){if(e._state){return e}if(n instanceof C){if(n===e){E(e,I,new TypeError("You can't resolve a promise with itself"))}else if(n._state){A(n,e)}else{q(e,n)}}else if(n!==Object(n)){E(e,F,n)}else if(t){S(e,n)}else{b(true,S,e,n)}return e}function S(e,n){var t,i;try{i=n.then}catch(r){E(e,I,r);return}if(typeof i==="function"){t=Y(e);try{c.call(i,n,t.resolve,t.reject)}catch(o){t.reject(o)}}else{E(e,F,n)}}function W(e){var n=e._pending;e._pending=null;if(n instanceof C){b(false,D,e,n);return}for(var t=0,i=n.length;t<i;++t){b(false,D,e,n[t])}}function q(e,n){if(!n._pending){n._pending=e}else if(n._pending instanceof C){n._pending=[n._pending,e]}else{n._pending.push(e)}}function D(e,n){var t=e._state===F?n._cb:n._eb;n._cb=null;n._eb=null;if(!t){A(e,n);return}var i=e._domain||n._domain;if(i){n._domain=null;y(i,P,t,n,e._value)}else{P(t,n,e._value)}}function P(e,n,t){var i;try{i=e(t)}catch(r){E(n,I,r);return}K(n,i,true)}function Y(e){var n=false;return{promise:e,resolve:function(t){if(!n){n=true;K(e,t,false)}},reject:function(t){if(!n){n=true;E(e,I,t)}}}}M.defer=z;function z(){return Y(new C)}M.reject=B;function B(e){return E(new C,I,e)}function C(){this._state=0;this._value=void 0;this._domain=null;this._cb=null;this._eb=null;this._pending=null}C.prototype.then=function(n,t){var i=new C;i._cb=typeof n==="function"?n:null;i._eb=typeof t==="function"?t:null;i._domain=e?process.domain:null;if(this._state===O){q(i,this)}else{b(false,D,this,i)}return i};C.prototype.done=function(e,n){var t=this;if(e||n){t=t.then(e,n)}t.then(null,N)};C.prototype.fail=function(e){return this.then(null,e)};C.prototype._always=function(e){return this.then(e,e)};C.prototype.spread=function(e,n){return this.then(e&&function(t){return H(t).then(function(n){return d.call(e,void 0,n)},n)},n)};C.prototype.timeout=function(e,n){var t=this;var i=new C;if(t._state!==O){A(t,i)}else{var r=setTimeout(function(){E(i,I,new Error(n||"Timed out after "+e+" ms"))},e);t._always(function(){clearTimeout(r);A(t,i)})}return i};C.prototype.delay=function(e){var n=z();this.then(function(t){setTimeout(function(){n.resolve(t)},e)},n.reject);return n.promise};C.prototype.inspect=function(){switch(this._state){case O:return{state:"pending"};case F:return{state:"fulfilled",value:this._value};case I:return{state:"rejected",reason:this._value};default:throw new TypeError("invalid state")}};M.allSettled=G;function G(e){var n=0;var t=new C;var i=new Array(e.length);j(e,function(e,r){var o=M(e);if(o._state===O){++n;o._always(function(){i[r]=o.inspect();if(--n===0){E(t,F,i)}})}else{i[r]=o.inspect()}});if(n===0){E(t,F,i)}return t}M.all=H;function H(e){var n=0;var t=z();var i=new Array(e.length);j(e,function(e,r){var o=M(e);if(o._state===F){i[r]=o._value}else{++n;o.then(function(e){i[r]=e;if(--n===0){t.resolve(i)}},t.reject)}});if(n===0){t.resolve(i)}return t.promise}M.promised=J;function J(e){function n(n){return d.apply(e,n)}return function(){return H([this,H(arguments)]).then(n)}}M.onerror=null;M.nextTick=k;return M});<commit_msg>Minify<commit_after>(function(e){if(typeof module!=="undefined"&&module&&module.exports){module.exports=e()}else if(typeof define==="function"&&define.amd){define(e)}else{P=e()}})(function(){"use strict";var e=h(typeof process)&&process!=null&&{}.toString.call(process)==="[object process]",n=typeof setImmediate==="function",t=h(typeof MutationObserver)&&MutationObserver||h(typeof WebKitMutationObserver)&&WebKitMutationObserver,i=new v,r=i,o=false,u=0,a=e?g:t?x(m):T(m),l=[],s=T(_),f,c,p=h.call,d=h.apply;r.next=i;function v(){this.task=null;this.domain=null;this.a=null;this.b=null;this.next=null}function h(e){return e==="object"||e==="function"}function _(){if(l.length){throw l.shift()}}function m(){while(i!==r){i=i.next;var e=i.task;if(u>=1024){r.next=r.next.next}else{++u}if(i.domain){b(i.domain,e,i.a,i.b,void 0);i.domain=null}else{e(i.a,i.b)}i.task=null;i.a=null;i.b=null}o=false}function y(){i.task=null;i.domain=null;i.a=null;i.b=null;a()}function b(e,n,t,i,r){if(e._disposed){return}e.enter();n(t,i,r);e.exit()}function w(n,t,l,s){var f=r.next;if(f===i){f=new v;r.next=f;f.next=i}else{--u}r=f;f.task=t;f.a=l;f.b=s;if(n&&e){f.domain=process.domain}if(!o){o=true;a()}}function g(){var e=process.domain;if(e){if(!c)c=(1,require)("domain");c.active=process.domain=null}if(o&&n){setImmediate(m)}else{process.nextTick(m)}if(e){c.active=process.domain=e}}function x(e){var n=1;var i=document.createTextNode("");var r=new t(e);r.observe(i,{characterData:true});return function(){n=-n;i.data=n}}function T(e){return function(){var n=setTimeout(i,0);var t=setInterval(i,50);function i(){clearTimeout(n);clearInterval(t);e()}}}if(e){f=function(e){y();throw e}}else{f=function(e){l.push(e);s()}}function j(e,n){try{e.call()}catch(t){n(t)}}function k(e){w(true,j,e,f)}function O(e,n){for(var t=0,i=e.length;t<i;++t){if(t in e){n(e[t],t)}}}function I(e){k(function(){if(K.onerror){K.onerror.call(null,e)}else{throw e}})}var M=0;var E=1;var A=2;function K(e){return e instanceof G?e:q(new G,e,false)}function S(n,t,i){if(n._state){return n}n._state=t;n._value=i;if(t===A&&e){n._domain=process.domain}if(n._pending){N(n)}return n}function W(e,n){if(n._state){return n}n._state=e._state;n._value=e._value;n._domain=e._domain;if(n._pending){N(n)}return n}function q(e,n,t){if(e._state){return e}if(n instanceof G){if(n===e){S(e,A,new TypeError("You can't resolve a promise with itself"))}else if(n._state){W(n,e)}else{P(e,n)}}else if(n!==Object(n)){S(e,E,n)}else if(t){D(e,n)}else{w(true,D,e,n)}return e}function D(e,n){var t,i;try{i=n.then}catch(r){S(e,A,r);return}if(typeof i==="function"){t=B(e);try{p.call(i,n,t.resolve,t.reject)}catch(o){t.reject(o)}}else{S(e,E,n)}}function N(e){var n=e._pending;e._pending=null;if(n instanceof G){w(false,Y,e,n);return}for(var t=0,i=n.length;t<i;++t){w(false,Y,e,n[t])}}function P(e,n){if(!n._pending){n._pending=e}else if(n._pending instanceof G){n._pending=[n._pending,e]}else{n._pending.push(e)}}function Y(e,n){var t=e._state===E?n._cb:n._eb;n._cb=null;n._eb=null;if(!t){W(e,n);return}var i=e._domain||n._domain;if(i){n._domain=null;b(i,z,t,n,e._value)}else{z(t,n,e._value)}}function z(e,n,t){var i;try{i=e(t)}catch(r){S(n,A,r);return}q(n,i,true)}function B(e){var n=false;return{promise:e,resolve:function(t){if(!n){n=true;q(e,t,false)}},reject:function(t){if(!n){n=true;S(e,A,t)}}}}K.defer=C;function C(){return B(new G)}K.reject=F;function F(e){return S(new G,A,e)}function G(){this._state=0;this._value=void 0;this._domain=null;this._cb=null;this._eb=null;this._pending=null}G.prototype.then=function(n,t){var i=new G;i._cb=typeof n==="function"?n:null;i._eb=typeof t==="function"?t:null;i._domain=e?process.domain:null;if(this._state===M){P(i,this)}else{w(false,Y,this,i)}return i};G.prototype.done=function(e,n){var t=this;if(e||n){t=t.then(e,n)}t.then(null,I)};G.prototype.fail=function(e){return this.then(null,e)};G.prototype._always=function(e){return this.then(e,e)};G.prototype.spread=function(e,n){return this.then(e&&function(t){return J(t).then(function(n){return d.call(e,void 0,n)},n)},n)};G.prototype.timeout=function(e,n){var t=this;var i=new G;if(t._state!==M){W(t,i)}else{var r=setTimeout(function(){S(i,A,new Error(n||"Timed out after "+e+" ms"))},e);t._always(function(){clearTimeout(r);W(t,i)})}return i};G.prototype.delay=function(e){var n=C();this.then(function(t){setTimeout(function(){n.resolve(t)},e)},n.reject);return n.promise};G.prototype.inspect=function(){switch(this._state){case M:return{state:"pending"};case E:return{state:"fulfilled",value:this._value};case A:return{state:"rejected",reason:this._value};default:throw new TypeError("invalid state")}};K.allSettled=H;function H(e){var n=0;var t=new G;var i=new Array(e.length);O(e,function(e,r){var o=K(e);if(o._state===M){++n;o._always(function(){i[r]=o.inspect();if(--n===0){S(t,E,i)}})}else{i[r]=o.inspect()}});if(n===0){S(t,E,i)}return t}K.all=J;function J(e){var n=0;var t=C();var i=new Array(e.length);O(e,function(e,r){var o=K(e);if(o._state===E){i[r]=o._value}else{++n;o.then(function(e){i[r]=e;if(--n===0){t.resolve(i)}},t.reject)}});if(n===0){t.resolve(i)}return t.promise}K.promised=L;function L(e){function n(n){return d.apply(e,n)}return function(){return J([this,J(arguments)]).then(n)}}K.onerror=null;K.nextTick=k;return K});<|endoftext|>


<commit_before>'use strict';
var LIVERELOAD_PORT = 35729;
var SERVER_PORT = 9000;
var lrSnippet = require('connect-livereload')({port: LIVERELOAD_PORT});
var mountFolder = function (connect, dir) {
    return connect.static(require('path').resolve(dir));
};

// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to match all subfolders:
// 'test/spec/**/*.js'
// templateFramework: 'lodash'

module.exports = function (grunt) {
    // show elapsed time at the end
    require('time-grunt')(grunt);
    // load all grunt tasks
    require('load-grunt-tasks')(grunt);

    // configurable paths
    var yeomanConfig = {
        app: 'app',
        dist: 'dist'
    };

    grunt.initConfig({
        yeoman: yeomanConfig,
        watch: {
            options: {
                nospawn: true,
                livereload: LIVERELOAD_PORT
            },
            sass: {
                files: ['<%= yeoman.app %>/styles/**/*.{scss,sass}'],
                tasks: ['sass:server']
            },
            livereload: {
                options: {
                    livereload: grunt.option('livereloadport') || LIVERELOAD_PORT
                },
                files: [
                    '<%= yeoman.app %>/*.html',
                    //'{.tmp,<%= yeoman.app %>/styles/{,*/}*.{scss,sass}',
                    '{.tmp,<%= yeoman.app %>}/styles/**/*.css',
                    '{.tmp,<%= yeoman.app %>}/scripts/{,*/}*.js',
                    '<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp}',
                    '<%= yeoman.app %>/scripts/templates/*.{ejs,mustache,hbs}',
                    'test/spec/**/*.js'
                ]
            },
            jst: {
                files: [
                    '<%= yeoman.app %>/scripts/templates/*.ejs'
                ],
                tasks: ['jst']
            },
            test: {
                files: ['<%= yeoman.app %>/scripts/{,*/}*.js', 'test/spec/**/*.js'],
                tasks: ['test:true']
            }
        },
        connect: {
            /*
            options: {
                port: grunt.option('port') || SERVER_PORT,
                // change this to '0.0.0.0' to access the server from outside
                hostname: 'localhost'
            },
            */
            //server: {
                options: {
                    port: grunt.option('port') || SERVER_PORT,
                    hostname: 'localhost',
                    base: '<%= yeoman.app %>',
                    open: true,
                    middleware: function (connect, options) {
                            var mw = [];
                            /* rewrite the path as a hash after the index for the app to parse and strip trailing slash
                             don't match if route contains '#' since that means we've already redirected
                             don't match if route contains '.' since we don’t want to redirect files */
                            var expressions = [
                                    '^\/(.*)/$ /$1 [R]',
                                    '^\/([^#.?]+)(\\?.*)?$ /$2#$1 [R,L]'
                            ];
                            // https://www.npmjs.com/package/connect-modrewrite
                            mw.push(require('connect-modrewrite')(expressions));
                            for (var i = 0, l = options.base.length; i < l; i++) {
                                    mw.push(connect.static(options.base[i]));
                            }

                            return mw;
                    }
            //    }
            },
            livereload: {
                options: {
                    middleware: function (connect) {
                        return [
                            lrSnippet,
                            mountFolder(connect, '.tmp'),
                            mountFolder(connect, yeomanConfig.app)
                        ];
                    }
                }
            },
            test: {
                options: {
                    port: 9001,
                    middleware: function (connect) {
                        return [
                            mountFolder(connect, 'test'),
                            lrSnippet,
                            mountFolder(connect, '.tmp'),
                            mountFolder(connect, yeomanConfig.app)
                        ];
                    }
                }
            },
            dist: {
                options: {
                    middleware: function (connect) {
                        return [
                            mountFolder(connect, yeomanConfig.dist)
                        ];
                    }
                }
            }
        },
        open: {
            server: {
                path: 'http://localhost:<%= connect.options.port %>'
            },
            test: {
                path: 'http://localhost:<%= connect.test.options.port %>'
            }
        },
        clean: {
            dist: {
                src: ['.tmp/**/*','dist/**/*'],
                filter: function(filepath) {
                    if (!grunt.file.isDir(filepath)) { return true; }
                    return (fs.readdirSync(filepath).length === 0);
                }
            },
            server: {
                src: ['.tmp/**/*'],
                filter: function(filepath) {
                    if (!grunt.file.isDir(filepath)) { return true; }
                    return (fs.readdirSync(filepath).length === 0);
                }
            }
        },
        jshint: {
            options: {
                jshintrc: '.jshintrc',
                reporter: require('jshint-stylish')
            },
            all: [
                'Gruntfile.js',
                '<%= yeoman.app %>/scripts/{,*/}*.js',
                '!<%= yeoman.app %>/scripts/vendor/*',
                'test/spec/{,*/}*.js'
            ]
        },
        mocha: {
            all: {
                options: {
                    run: true,
                    urls: ['http://localhost:<%= connect.test.options.port %>/index.html']
                }
            }
        },
        sass: {
          options: {
            sourceMap: true,
            includePaths: ['app/bower_components']
            },
          dist: {
            files: [{
              expand: true,
              cwd: '<%= yeoman.app %>/styles',
              src: ['**/*.{scss,sass}'],
              dest: '.tmp/styles',
              ext: '.css'
            }]
          },
          server: {
            files: [{
              expand: true,
              cwd: '<%= yeoman.app %>/styles',
              src: ['**/*.{scss,sass}'],
              dest: '.tmp/styles',
              ext: '.css'
            }]
          }
        },
        // not enabled since usemin task does concat and uglify
        // check index.html to edit your build targets
        // enable this task if you prefer defining your build targets here
        /*uglify: {
            dist: {}
        },*/
        useminPrepare: {
            html: '<%= yeoman.app %>/index.html',
            options: {
                dest: '<%= yeoman.dist %>'
            }
        },
        usemin: {
            html: ['<%= yeoman.dist %>/{,*/}*.html'],
            css: ['<%= yeoman.dist %>/styles/**/*.css'],
            options: {
                basedir: '<%= yeoman.app %>',
                dirs: ['<%= yeoman.app %>','<%= yeoman.dist %>']
            }
        },
        imagemin: {
            dist: {
                files: [{
                    expand: true,
                    cwd: '<%= yeoman.app %>/images',
                    src: '{,*/}*.{png,jpg,jpeg}',
                    dest: '<%= yeoman.dist %>/images'
                }]
            }
        },
        cssmin: {
            dist: {
                files: {
                    '<%= yeoman.dist %>/styles/main.css': [
                        '.tmp/styles/{,*/}*.css',
                        '<%= yeoman.app %>/styles/{,*/}*.css'
                    ]
                }
            }
        },
        htmlmin: {
            dist: {
                options: {
                    /*removeCommentsFromCDATA: true,
                    // https://github.com/yeoman/grunt-usemin/issues/44
                    //collapseWhitespace: true,
                    collapseBooleanAttributes: true,
                    removeAttributeQuotes: true,
                    removeRedundantAttributes: true,
                    useShortDoctype: true,
                    removeEmptyAttributes: true,
                    removeOptionalTags: true*/
                },
                files: [{
                    expand: true,
                    cwd: '<%= yeoman.app %>',
                    src: '*.html',
                    dest: '<%= yeoman.dist %>'
                }]
            }
        },
        copy: {
            dist: {
                files: [{
                    expand: true,
                    dot: true,
                    cwd: '<%= yeoman.app %>',
                    dest: '<%= yeoman.dist %>',
                    src: [
                        '*.{ico,txt}',
                        'images/{,*/}*.{webp,gif}',
                        'styles/fonts/{,*/}*.*',
                        'bower_components/bootstrap-sass-official/assets/fonts/bootstrap/*.*'
                    ]
                }, {
                    src: 'node_modules/apache-server-configs/dist/.htaccess',
                    dest: '<%= yeoman.dist %>/.htaccess'
                }]
            }
        },
        jst: {
            compile: {
                files: {
                    '.tmp/scripts/templates.js': ['<%= yeoman.app %>/scripts/templates/*.ejs']
                }
            }
        },
        rev: {
            dist: {
                files: {
                    src: [
                        '<%= yeoman.dist %>/scripts/{,*/}*.js',
                        '<%= yeoman.dist %>/styles/{,*/}*.css',
                        '<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp}',
                        '/styles/fonts/{,*/}*.*',
                        'bower_components/bootstrap-sass-official/assets/fonts/bootstrap/*.*'
                    ]
                }
            }
        }
    });

    //grunt.loadNpmTasks('grunt-contrib-compass');

    //grunt.registerTask('build',['compass:prod']);
    //grunt.registerTask('default',['watch']);

    grunt.registerTask('createDefaultTemplate', function () {
        grunt.file.write('.tmp/scripts/templates.js', 'this.JST = this.JST || {};');
    });

    grunt.registerTask('server', function (target) {
        grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
        grunt.task.run(['serve' + (target ? ':' + target : '')]);
    });

    grunt.registerTask('serve', function (target) {
        if (target === 'dist') {
            return grunt.task.run(['build', 'open:server', 'connect:dist:keepalive']);
        }

        if (target === 'test') {
            return grunt.task.run([
                'clean:server',
                'createDefaultTemplate',
                'jst',
                'sass:server',
                'connect:test',
                'open:test',
                'watch'
            ]);
        }

        grunt.task.run([
            'clean:server',
            'createDefaultTemplate',
            'jst',
            'sass:server',
            'connect:livereload',
            'open:server',
            'watch'
        ]);
    });

    grunt.registerTask('test', function (isConnected) {
        isConnected = Boolean(isConnected);
        var testTasks = [
                'clean:server',
                'createDefaultTemplate',
                'jst',
                'sass',
                'connect:test',
                'mocha',
            ];

        if(!isConnected) {
            return grunt.task.run(testTasks);
        } else {
            // already connected so not going to connect again, remove the connect:test task
            testTasks.splice(testTasks.indexOf('connect:test'), 1);
            return grunt.task.run(testTasks);
        }
    });

    grunt.registerTask('build', [
        'clean:dist',
        'createDefaultTemplate',
        'jst',
        'sass:dist',
        'useminPrepare',
        'imagemin',
        'htmlmin',
        'concat',
        'cssmin',
        'uglify',
        'copy',
        'rev',
        'usemin'
    ]);

    grunt.registerTask('default', [
        'jshint',
        'test',
        'build'
    ]);
};
<commit_msg>Routing full support in grunt serve<commit_after>'use strict';
var LIVERELOAD_PORT = 35729;
var SERVER_PORT = 9000;
var lrSnippet = require('connect-livereload')({port: LIVERELOAD_PORT});
var mountFolder = function (connect, dir) {
    return connect.static(require('path').resolve(dir));
};

// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to match all subfolders:
// 'test/spec/**/*.js'
// templateFramework: 'lodash'

module.exports = function (grunt) {
    // show elapsed time at the end
    require('time-grunt')(grunt);
    // load all grunt tasks
    require('load-grunt-tasks')(grunt);

    // configurable paths
    var yeomanConfig = {
        app: 'app',
        dist: 'dist'
    };

    grunt.initConfig({
        yeoman: yeomanConfig,
        watch: {
            options: {
                nospawn: true,
                livereload: LIVERELOAD_PORT
            },
            sass: {
                files: ['<%= yeoman.app %>/styles/**/*.{scss,sass}'],
                tasks: ['sass:server']
            },
            livereload: {
                options: {
                    livereload: grunt.option('livereloadport') || LIVERELOAD_PORT
                },
                files: [
                    '<%= yeoman.app %>/*.html',
                    //'{.tmp,<%= yeoman.app %>/styles/{,*/}*.{scss,sass}',
                    '{.tmp,<%= yeoman.app %>}/styles/**/*.css',
                    '{.tmp,<%= yeoman.app %>}/scripts/{,*/}*.js',
                    '<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp}',
                    '<%= yeoman.app %>/scripts/templates/*.{ejs,mustache,hbs}',
                    'test/spec/**/*.js'
                ]
            },
            jst: {
                files: [
                    '<%= yeoman.app %>/scripts/templates/*.ejs'
                ],
                tasks: ['jst']
            },
            test: {
                files: ['<%= yeoman.app %>/scripts/{,*/}*.js', 'test/spec/**/*.js'],
                tasks: ['test:true']
            }
        },
        connect: {
            options: {
                port: grunt.option('port') || SERVER_PORT,
                hostname: 'localhost',
                base: '<%= yeoman.app %>',
                open: true,
                middleware: function (connect, options, mw) {
                    //var mw = [];
                    /* rewrite the path as a hash after the index for the app to parse and strip trailing slash
                     don't match if route contains '#' since that means we've already redirected
                     don't match if route contains '.' since we don’t want to redirect files */
                    var expressions = [
                        '^\/(.*)/$ /$1 [R]',
                        '^\/([^#.?]+)(\\?.*)?$ /$2#$1 [R,L]'
                    ];
                    // https://www.npmjs.com/package/connect-modrewrite
                    mw.push(require('connect-modrewrite')(expressions));
                    for (var i = 0, l = options.base.length; i < l; i++) {
                        mw.push(connect.static(options.base[i]));
                    }

                    return mw;
                }
            },
            livereload: {
                options: {
                    middleware: function (connect, options, mw) {
                        var expressions = [
                            '^\/(.*)/$ /$1 [R]',
                            '^\/([^#.?]+)(\\?.*)?$ /$2#$1 [R,L]'
                        ];
                        // https://www.npmjs.com/package/connect-modrewrite
                        mw.push(require('connect-modrewrite')(expressions));
                        for (var i = 0, l = options.base.length; i < l; i++) {
                            mw.push(connect.static(options.base[i]));
                        }

                        return mw.concat([
                            lrSnippet,
                            mountFolder(connect, '.tmp'),
                            mountFolder(connect, yeomanConfig.app)
                        ]);
                    }
                }
            },
            test: {
                options: {
                    port: 9001,
                    middleware: function (connect, options, mw) {
                        var expressions = [
                            '^\/(.*)/$ /$1 [R]',
                            '^\/([^#.?]+)(\\?.*)?$ /$2#$1 [R,L]'
                        ];
                        // https://www.npmjs.com/package/connect-modrewrite
                        mw.push(require('connect-modrewrite')(expressions));
                        for (var i = 0, l = options.base.length; i < l; i++) {
                            mw.push(connect.static(options.base[i]));
                        }

                        return mw.concat([
                            mountFolder(connect, 'test'),
                            lrSnippet,
                            mountFolder(connect, '.tmp'),
                            mountFolder(connect, yeomanConfig.app)
                        ]);
                    }
                }
            },
            dist: {
                options: {
                    middleware: function (connect, options, mw) {
                        var expressions = [
                            '^\/(.*)/$ /$1 [R]',
                            '^\/([^#.?]+)(\\?.*)?$ /$2#$1 [R,L]'
                        ];
                        // https://www.npmjs.com/package/connect-modrewrite
                        mw.push(require('connect-modrewrite')(expressions));
                        for (var i = 0, l = options.base.length; i < l; i++) {
                            mw.push(connect.static(options.base[i]));
                        }

                        return mw.concat([
                            mountFolder(connect, yeomanConfig.dist)
                        ]);
                    }
                }
            }
        },
        open: {
            server: {
                path: 'http://localhost:<%= connect.options.port %>'
            },
            test: {
                path: 'http://localhost:<%= connect.test.options.port %>'
            }
        },
        clean: {
            dist: {
                src: ['.tmp/**/*','dist/**/*'],
                filter: function(filepath) {
                    if (!grunt.file.isDir(filepath)) { return true; }
                    return (fs.readdirSync(filepath).length === 0);
                }
            },
            server: {
                src: ['.tmp/**/*'],
                filter: function(filepath) {
                    if (!grunt.file.isDir(filepath)) { return true; }
                    return (fs.readdirSync(filepath).length === 0);
                }
            }
        },
        jshint: {
            options: {
                jshintrc: '.jshintrc',
                reporter: require('jshint-stylish')
            },
            all: [
                'Gruntfile.js',
                '<%= yeoman.app %>/scripts/{,*/}*.js',
                '!<%= yeoman.app %>/scripts/vendor/*',
                'test/spec/{,*/}*.js'
            ]
        },
        mocha: {
            all: {
                options: {
                    run: true,
                    urls: ['http://localhost:<%= connect.test.options.port %>/index.html']
                }
            }
        },
        sass: {
          options: {
            sourceMap: true,
            includePaths: ['app/bower_components']
            },
          dist: {
            files: [{
              expand: true,
              cwd: '<%= yeoman.app %>/styles',
              src: ['**/*.{scss,sass}'],
              dest: '.tmp/styles',
              ext: '.css'
            }]
          },
          server: {
            files: [{
              expand: true,
              cwd: '<%= yeoman.app %>/styles',
              src: ['**/*.{scss,sass}'],
              dest: '.tmp/styles',
              ext: '.css'
            }]
          }
        },
        // not enabled since usemin task does concat and uglify
        // check index.html to edit your build targets
        // enable this task if you prefer defining your build targets here
        /*uglify: {
            dist: {}
        },*/
        useminPrepare: {
            html: '<%= yeoman.app %>/index.html',
            options: {
                dest: '<%= yeoman.dist %>'
            }
        },
        usemin: {
            html: ['<%= yeoman.dist %>/{,*/}*.html'],
            css: ['<%= yeoman.dist %>/styles/**/*.css'],
            options: {
                basedir: '<%= yeoman.app %>',
                dirs: ['<%= yeoman.app %>','<%= yeoman.dist %>']
            }
        },
        imagemin: {
            dist: {
                files: [{
                    expand: true,
                    cwd: '<%= yeoman.app %>/images',
                    src: '{,*/}*.{png,jpg,jpeg}',
                    dest: '<%= yeoman.dist %>/images'
                }]
            }
        },
        cssmin: {
            dist: {
                files: {
                    '<%= yeoman.dist %>/styles/main.css': [
                        '.tmp/styles/{,*/}*.css',
                        '<%= yeoman.app %>/styles/{,*/}*.css'
                    ]
                }
            }
        },
        htmlmin: {
            dist: {
                options: {
                    /*removeCommentsFromCDATA: true,
                    // https://github.com/yeoman/grunt-usemin/issues/44
                    //collapseWhitespace: true,
                    collapseBooleanAttributes: true,
                    removeAttributeQuotes: true,
                    removeRedundantAttributes: true,
                    useShortDoctype: true,
                    removeEmptyAttributes: true,
                    removeOptionalTags: true*/
                },
                files: [{
                    expand: true,
                    cwd: '<%= yeoman.app %>',
                    src: '*.html',
                    dest: '<%= yeoman.dist %>'
                }]
            }
        },
        copy: {
            dist: {
                files: [{
                    expand: true,
                    dot: true,
                    cwd: '<%= yeoman.app %>',
                    dest: '<%= yeoman.dist %>',
                    src: [
                        '*.{ico,txt}',
                        'images/{,*/}*.{webp,gif}',
                        'styles/fonts/{,*/}*.*',
                        'bower_components/bootstrap-sass-official/assets/fonts/bootstrap/*.*'
                    ]
                }, {
                    src: 'node_modules/apache-server-configs/dist/.htaccess',
                    dest: '<%= yeoman.dist %>/.htaccess'
                }]
            }
        },
        jst: {
            compile: {
                files: {
                    '.tmp/scripts/templates.js': ['<%= yeoman.app %>/scripts/templates/*.ejs']
                }
            }
        },
        rev: {
            dist: {
                files: {
                    src: [
                        '<%= yeoman.dist %>/scripts/{,*/}*.js',
                        '<%= yeoman.dist %>/styles/{,*/}*.css',
                        '<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp}',
                        '/styles/fonts/{,*/}*.*',
                        'bower_components/bootstrap-sass-official/assets/fonts/bootstrap/*.*'
                    ]
                }
            }
        }
    });

    //grunt.loadNpmTasks('grunt-contrib-compass');

    //grunt.registerTask('build',['compass:prod']);
    //grunt.registerTask('default',['watch']);

    grunt.registerTask('createDefaultTemplate', function () {
        grunt.file.write('.tmp/scripts/templates.js', 'this.JST = this.JST || {};');
    });

    grunt.registerTask('server', function (target) {
        grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
        grunt.task.run(['serve' + (target ? ':' + target : '')]);
    });

    grunt.registerTask('serve', function (target) {
        if (target === 'dist') {
            return grunt.task.run(['build', 'open:server', 'connect:dist:keepalive']);
        }

        if (target === 'test') {
            return grunt.task.run([
                'clean:server',
                'createDefaultTemplate',
                'jst',
                'sass:server',
                'connect:test',
                'open:test',
                'watch'
            ]);
        }

        grunt.task.run([
            'clean:server',
            'createDefaultTemplate',
            'jst',
            'sass:server',
            'connect:livereload',
            'open:server',
            'watch'
        ]);
    });

    grunt.registerTask('test', function (isConnected) {
        isConnected = Boolean(isConnected);
        var testTasks = [
                'clean:server',
                'createDefaultTemplate',
                'jst',
                'sass',
                'connect:test',
                'mocha',
            ];

        if(!isConnected) {
            return grunt.task.run(testTasks);
        } else {
            // already connected so not going to connect again, remove the connect:test task
            testTasks.splice(testTasks.indexOf('connect:test'), 1);
            return grunt.task.run(testTasks);
        }
    });

    grunt.registerTask('build', [
        'clean:dist',
        'createDefaultTemplate',
        'jst',
        'sass:dist',
        'useminPrepare',
        'imagemin',
        'htmlmin',
        'concat',
        'cssmin',
        'uglify',
        'copy',
        'rev',
        'usemin'
    ]);

    grunt.registerTask('default', [
        'jshint',
        'test',
        'build'
    ]);
};
<|endoftext|>


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

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    aws: grunt.file.readJSON('aws-credentials.json'),

    aws_s3: {
      options: {
        accessKeyId: '<%= aws.AWSAccessKeyId %>', // Use the variables
        secretAccessKey: '<%= aws.AWSSecretKey %>', // You can also use env variables
        region: 'ap-southeast-2',
        uploadConcurrency: 5, // 5 simultaneous uploads
        downloadConcurrency: 5 // 5 simultaneous downloads
      },
      production: {
        options: {
          bucket: 'www.growth.ren',
          params: {
            CacheControl: 'max-age=604800'
          }
        },
        files: [
          {expand: true, cwd: 'www/advancedQuiz/', src: ['**'], dest: 'advancedQuiz/', action: 'upload'},
          {expand: true, cwd: 'www/article/', src: ['**'], dest: 'article/', action: 'upload', params: {ContentType: 'text/plain'}},
          {expand: true, cwd: 'www/assets/', src: ['**'], dest: 'assets/', action: 'upload'},
          {expand: true, cwd: 'www/css/', src: ['**'], dest: 'css/', action: 'upload'},
          {expand: true, cwd: 'www/img/', src: ['**'], dest: 'img/', action: 'upload'},
          {expand: true, cwd: 'www/js/', src: ['**'], dest: 'js/', action: 'upload'},
          {expand: true, cwd: 'www/lib/', src: ['**'], dest: 'lib/', action: 'upload'},
          {expand: true, cwd: 'www/quiz/', src: ['**'], dest: 'quiz/', action: 'upload'},
          {expand: true, cwd: 'www/review/', src: ['**'], dest: 'review/', action: 'upload'},
          {expand: true, cwd: 'www/templates/', src: ['**'], dest: 'templates/', action: 'upload'},
          {expand: true, cwd: 'www/', src: ['manifest.json'], dest: './', action: 'upload'},
          {expand: true, cwd: 'platforms/android/build/outputs/apk', src: ['growth.apk'], dest: './', action: 'upload'},
          {
            expand: true,
            cwd: './www/',
            src: ['index.html'],
            dest: './',
            action: 'upload',
            params: {CacheControl: 'max-age=30', ContentType: 'text/html'}
          }
          // CacheControl only applied to the assets folder
          // LICENCE inside that folder will have ContentType equal to 'text/plain'
        ]
      },
      clean_production: {
        options: {
          bucket: 'www.growth.ren',
          debug: true // Doesn't actually delete but shows log
        },
        files: [
          {dest: 'css/', src: ['**'],  action: 'delete'},
          {dest: 'img/', src: ['**'],  action: 'delete'},
          {dest: 'js/', src: ['**'],  action: 'delete'},
          {dest: 'lib/', src: ['**'],  action: 'delete'},
          {dest: 'templates/', src: ['**'],  action: 'delete'},
          {dest: 'article/', src: ['**'],  action: 'delete'},
          {dest: './', src: ['index.html'], action: 'delete'}
          //{dest: 'assets/', exclude: "**/*.tgz", action: 'delete'}, // will not delete the tgz
          //{dest: 'assets/large/', exclude: "**/*copy*", flipExclude: true, action: 'delete'}, // will delete everything that has copy in the name
        ]
      }
    }
  });

  grunt.loadNpmTasks('grunt-aws-s3');
  grunt.registerTask('deploy', ['aws_s3:clean_production', 'aws_s3:production']);

};
<commit_msg>upload version to s3<commit_after>module.exports = function (grunt) {

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    aws: grunt.file.readJSON('aws-credentials.json'),

    aws_s3: {
      options: {
        accessKeyId: '<%= aws.AWSAccessKeyId %>', // Use the variables
        secretAccessKey: '<%= aws.AWSSecretKey %>', // You can also use env variables
        region: 'ap-southeast-2',
        uploadConcurrency: 5, // 5 simultaneous uploads
        downloadConcurrency: 5 // 5 simultaneous downloads
      },
      production: {
        options: {
          bucket: 'www.growth.ren',
          params: {
            CacheControl: 'max-age=604800'
          }
        },
        files: [
          {expand: true, cwd: 'www/advancedQuiz/', src: ['**'], dest: 'advancedQuiz/', action: 'upload'},
          {expand: true, cwd: 'www/article/', src: ['**'], dest: 'article/', action: 'upload', params: {ContentType: 'text/plain'}},
          {expand: true, cwd: 'www/assets/', src: ['**'], dest: 'assets/', action: 'upload'},
          {expand: true, cwd: 'www/css/', src: ['**'], dest: 'css/', action: 'upload'},
          {expand: true, cwd: 'www/img/', src: ['**'], dest: 'img/', action: 'upload'},
          {expand: true, cwd: 'www/js/', src: ['**'], dest: 'js/', action: 'upload'},
          {expand: true, cwd: 'www/lib/', src: ['**'], dest: 'lib/', action: 'upload'},
          {expand: true, cwd: 'www/quiz/', src: ['**'], dest: 'quiz/', action: 'upload'},
          {expand: true, cwd: 'www/review/', src: ['**'], dest: 'review/', action: 'upload'},
          {expand: true, cwd: 'www/templates/', src: ['**'], dest: 'templates/', action: 'upload'},
          {expand: true, cwd: 'www/', src: ['manifest.json'], dest: './', action: 'upload'},
          {expand: true, cwd: 'www/', src: ['version.json'], dest: './', action: 'upload'},
          {expand: true, cwd: 'platforms/android/build/outputs/apk', src: ['growth.apk'], dest: './', action: 'upload'},
          {
            expand: true,
            cwd: './www/',
            src: ['index.html'],
            dest: './',
            action: 'upload',
            params: {CacheControl: 'max-age=30', ContentType: 'text/html'}
          }
          // CacheControl only applied to the assets folder
          // LICENCE inside that folder will have ContentType equal to 'text/plain'
        ]
      },
      clean_production: {
        options: {
          bucket: 'www.growth.ren',
          debug: true // Doesn't actually delete but shows log
        },
        files: [
          {dest: 'css/', src: ['**'],  action: 'delete'},
          {dest: 'img/', src: ['**'],  action: 'delete'},
          {dest: 'js/', src: ['**'],  action: 'delete'},
          {dest: 'lib/', src: ['**'],  action: 'delete'},
          {dest: 'templates/', src: ['**'],  action: 'delete'},
          {dest: 'article/', src: ['**'],  action: 'delete'},
          {dest: './', src: ['index.html'], action: 'delete'}
          //{dest: 'assets/', exclude: "**/*.tgz", action: 'delete'}, // will not delete the tgz
          //{dest: 'assets/large/', exclude: "**/*copy*", flipExclude: true, action: 'delete'}, // will delete everything that has copy in the name
        ]
      }
    }
  });

  grunt.loadNpmTasks('grunt-aws-s3');
  grunt.registerTask('deploy', ['aws_s3:clean_production', 'aws_s3:production']);

};
<|endoftext|>


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

	// Project configuration.
	grunt.initConfig({
		pkg: grunt.file.readJSON("package.json"),

		jshint: {
			src: [
				"**/*.js",
				"!{node_modules,dijit,form,layout,mobile}/**/*.js",

				// Note: skip this file since it gives a JSHint error about a character being silently deleted.
				// It will have to be fixed by the translators.
				"!nls/he/loading.js"
			],
			options: {
				jshintrc: ".jshintrc"
			}
		},

		// Task for compiling less files into CSS files
		less : {

			// Compile theme independent files
			transitions: {
				expand: true,
				cwd: "themes/common/transitions",
				src: ["*.less"],
				dest: "themes/common/transitions",
				ext: ".css"
			},

			// Infrastructure per-theme files
			common : {
				files: [
					{
						expand: true,
						src: ["themes/*/*.less", "!themes/common/*.less", "!**/variables.less", "!**/common.less"],
						ext: ".css"
					}
				]
			},

			// Compile less code for each widget
			widgets : {
				files: [
					{
						expand: true,
						src: [
							"*/themes/*/*.less",
							"samples/ExampleWidget/themes/*/*.less",
							"!{dijit,mobile}/themes/*/*.less"
						],
						ext: ".css"
					}
				]
			}
		},

		// Convert CSS files to JS files
		cssToJs : {
			// convert CSS files generated from LESS files
			intermediate: {
				src: [
					// infrastructure
					"themes/*/*.css",
					"!themes/common/*.css",
					"themes/common/transitions/*.css",

					// widgets
					"*/themes/*/*.css",
					"samples/ExampleWidget/themes/*/*.css",
					"!{dijit,mobile}/themes/*/*.css"
				],
				options: {
					remove: true
				}
			},

			// convert files originally authored as CSS, without removing the original CSS files
			original: {
				src: [ "tests/unit/css/*.css" ]
			}
		},

		// Copied from grunt web site but not tested
		uglify: {
			options: {
				banner: "/*! <%= pkg.name %> <%= grunt.template.today('yyyy-mm-dd') %> */\n"
			},
			build: {
				src: "src/<%= pkg.name %>.js",
				dest: "build/<%= pkg.name %>.min.js"
			}
		},
		intern: {
			local: {
				options: {
					runType: "runner",
					config: "tests/intern.local",
					reporters: ["runner"]
				}
			},
			remote: {
				options: {
					runType: "runner",
					config: "tests/intern",
					reporters: ["runner"]
				}
			}
		},
		"jsdoc-amddcl": {
			delite: {
				files: [
					{
						src: [
							".",
							"./README.md",
							"./package.json"
						]
					},
					{
						args: [
							"-X"
						],
						src: [
							".",
							"./README.md",
							"./package.json"
						],
						dest: "./out/doclets.json"
					}
				]
			}
		}
	});

	// Load plugins
	grunt.loadNpmTasks("intern");
	grunt.loadNpmTasks("grunt-contrib-jshint");
	grunt.loadNpmTasks("grunt-contrib-less");
	grunt.loadNpmTasks("grunt-contrib-uglify");
	grunt.loadNpmTasks("jsdoc-amddcl");
	grunt.loadTasks("themes/tasks");// Custom cssToJs task to convert CSS to JS

	// Aliases
	grunt.registerTask("css", ["less", "cssToJs"]);
	grunt.registerTask("jsdoc", "jsdoc-amddcl");

	// Testing.
	// Always specify the target e.g. grunt test:remote, grunt test:remote
	// then add on any other flags afterwards e.g. console, lcovhtml.
	var testTaskDescription = "Run this task instead of the intern task directly! \n" +
		"Always specify the test target e.g. \n" +
		"grunt test:local\n" +
		"grunt test:remote\n\n" +
		"Add any optional reporters via a flag e.g. \n" +
		"grunt test:local:console\n" +
		"grunt test:local:lcovhtml\n" +
		"grunt test:local:console:lcovhtml";
	grunt.registerTask("test", testTaskDescription, function (target) {
		function addReporter(reporter) {
			var property = "intern." + target + ".options.reporters",
				value = grunt.config.get(property);
			if (value.indexOf(reporter) !== -1) {
				return;
			}
			value.push(reporter);
			grunt.config.set(property, value);
		}

		if (this.flags.lcovhtml) {
			addReporter("lcovhtml");
		}

		if (this.flags.console) {
			addReporter("console");
		}
		grunt.task.run("intern:" + target);
	});
};<commit_msg>Cleanup Grunt config for jsdoc.<commit_after>/*global module */
module.exports = function (grunt) {

	// Project configuration.
	grunt.initConfig({
		pkg: grunt.file.readJSON("package.json"),

		jshint: {
			src: [
				"**/*.js",
				"!{node_modules,dijit,form,layout,mobile}/**/*.js",

				// Note: skip this file since it gives a JSHint error about a character being silently deleted.
				// It will have to be fixed by the translators.
				"!nls/he/loading.js"
			],
			options: {
				jshintrc: ".jshintrc"
			}
		},

		// Task for compiling less files into CSS files
		less : {

			// Compile theme independent files
			transitions: {
				expand: true,
				cwd: "themes/common/transitions",
				src: ["*.less"],
				dest: "themes/common/transitions",
				ext: ".css"
			},

			// Infrastructure per-theme files
			common : {
				files: [
					{
						expand: true,
						src: ["themes/*/*.less", "!themes/common/*.less", "!**/variables.less", "!**/common.less"],
						ext: ".css"
					}
				]
			},

			// Compile less code for each widget
			widgets : {
				files: [
					{
						expand: true,
						src: [
							"*/themes/*/*.less",
							"samples/ExampleWidget/themes/*/*.less",
							"!{dijit,mobile}/themes/*/*.less"
						],
						ext: ".css"
					}
				]
			}
		},

		// Convert CSS files to JS files
		cssToJs : {
			// convert CSS files generated from LESS files
			intermediate: {
				src: [
					// infrastructure
					"themes/*/*.css",
					"!themes/common/*.css",
					"themes/common/transitions/*.css",

					// widgets
					"*/themes/*/*.css",
					"samples/ExampleWidget/themes/*/*.css",
					"!{dijit,mobile}/themes/*/*.css"
				],
				options: {
					remove: true
				}
			},

			// convert files originally authored as CSS, without removing the original CSS files
			original: {
				src: [ "tests/unit/css/*.css" ]
			}
		},

		// Copied from grunt web site but not tested
		uglify: {
			options: {
				banner: "/*! <%= pkg.name %> <%= grunt.template.today('yyyy-mm-dd') %> */\n"
			},
			build: {
				src: "src/<%= pkg.name %>.js",
				dest: "build/<%= pkg.name %>.min.js"
			}
		},
		intern: {
			local: {
				options: {
					runType: "runner",
					config: "tests/intern.local",
					reporters: ["runner"]
				}
			},
			remote: {
				options: {
					runType: "runner",
					config: "tests/intern",
					reporters: ["runner"]
				}
			}
		},
		"jsdoc-amddcl": {
			docs: {
				files: [
					{
						src: [
							".",
							"./README.md",
							"./package.json"
						]
					}
				]
			},
			export: {
				files: [
					{
						args: [
							"-X"
						],
						src: [
							".",
							"./README.md",
							"./package.json"
						],
						dest: "./out/doclets.json"
					}
				]
			}
		}
	});

	// Load plugins
	grunt.loadNpmTasks("intern");
	grunt.loadNpmTasks("grunt-contrib-jshint");
	grunt.loadNpmTasks("grunt-contrib-less");
	grunt.loadNpmTasks("grunt-contrib-uglify");
	grunt.loadNpmTasks("jsdoc-amddcl");
	grunt.loadTasks("themes/tasks");// Custom cssToJs task to convert CSS to JS

	// Aliases
	grunt.registerTask("css", ["less", "cssToJs"]);
	grunt.registerTask("jsdoc", "jsdoc-amddcl");

	// Testing.
	// Always specify the target e.g. grunt test:remote, grunt test:remote
	// then add on any other flags afterwards e.g. console, lcovhtml.
	var testTaskDescription = "Run this task instead of the intern task directly! \n" +
		"Always specify the test target e.g. \n" +
		"grunt test:local\n" +
		"grunt test:remote\n\n" +
		"Add any optional reporters via a flag e.g. \n" +
		"grunt test:local:console\n" +
		"grunt test:local:lcovhtml\n" +
		"grunt test:local:console:lcovhtml";
	grunt.registerTask("test", testTaskDescription, function (target) {
		function addReporter(reporter) {
			var property = "intern." + target + ".options.reporters",
				value = grunt.config.get(property);
			if (value.indexOf(reporter) !== -1) {
				return;
			}
			value.push(reporter);
			grunt.config.set(property, value);
		}

		if (this.flags.lcovhtml) {
			addReporter("lcovhtml");
		}

		if (this.flags.console) {
			addReporter("console");
		}
		grunt.task.run("intern:" + target);
	});
};<|endoftext|>


<commit_before>'use strict';

var mongodb = require('mongodb');
var connection = null;
var MongoClient = mongodb.MongoClient;
var mongo = {};

function init (env, cb, forceNewConnection) {

  function maybe_connect (cb) {

    if (connection != null && !forceNewConnection) {
      console.log('Reusing MongoDB connection handler');
      // If there is a valid callback, then return the Mongo-object
      mongo.db = connection;

      if (cb && cb.call) {
        cb(null, mongo);
      }
    } else {
      if (!env.storageURI) {
        throw new Error('MongoDB connection string is missing. Please set MONGODB_URI environment variable');
      }

      console.log('Setting up new connection to MongoDB');
      var timeout = 30 * 1000;
      var options = {
        reconnectInterval: 10000
        , reconnectTries: 500
        , connectTimeoutMS: timeout
        , socketTimeoutMS: timeout
        , useNewUrlParser: true
      };

      var connect_with_retry = function(i) {

        MongoClient.connect(env.storageURI, options)
          .then(client => {
            console.log('Successfully established a connected to MongoDB');

            var dbName = env.storageURI.split('/').pop().split('?');
            dbName = dbName[0]; // drop Connection Options
            mongo.db = client.db(dbName);
            connection = mongo.db;
            mongo.client = client;

            mongo.db.command({ connectionStatus: 1 }).then(
              result => {
                const roles = result.authInfo.authenticatedUserRoles;
                if (roles.length > 0 && roles[0].role == 'readAnyDatabase') {
                  console.error('Mongo user is read only');
                  cb(new Error('MongoDB connection is in read only mode! Go back to MongoDB configuration and check your database user has read and write access.'), null);
                }

                console.log('Mongo user role seems ok:', roles);

                // If there is a valid callback, then invoke the function to perform the callback
                if (cb && cb.call) {
                  cb(null, mongo);
                }
              }
            );
          })
          .catch(err => {
            if (err.message && err.message.includes('AuthenticationFailed')) {
              console.log('Authentication to Mongo failed');
              cb(new Error('MongoDB authentication failed! Double check the URL has the right username and password in MONGODB_URI.'), null);
              return;
            }

            if (err.name && err.name === "MongoNetworkError") {
              var timeout = (i > 15) ? 60000 : i * 3000;
              console.log('Error connecting to MongoDB: %j - retrying in ' + timeout / 1000 + ' sec', err);
              setTimeout(connect_with_retry, timeout, i + 1);
              if (i == 1) cb(new Error('MongoDB connection failed! Double check the MONGODB_URI setting in Heroku.'), null);
            } else {
              cb(new Error('MONGODB_URI ' + env.storageURI + ' seems invalid: ' + err.message));
            }
          });

      };

      return connect_with_retry(1);

    }
  }

  mongo.collection = function get_collection (name) {
    return connection.collection(name);
  };

  mongo.ensureIndexes = function ensureIndexes (collection, fields) {
    fields.forEach(function(field) {
      console.info('ensuring index for: ' + field);
      collection.createIndex(field, { 'background': true }, function(err) {
        if (err) {
          console.error('unable to ensureIndex for: ' + field + ' - ' + err);
        }
      });
    });
  };

  return maybe_connect(cb);
}

module.exports = init;
<commit_msg>Refactor `mongo-storage.js`  (#6589)<commit_after>'use strict';

const MongoClient = require('mongodb').MongoClient;

const mongo = {
  client: null,
  db: null,
};

function init(env, cb, forceNewConnection) {

  function maybe_connect(cb) {

    if (mongo.db != null && !forceNewConnection) {
      console.log('Reusing MongoDB connection handler');
      // If there is a valid callback, then return the Mongo-object

      if (cb && cb.call) {
        cb(null, mongo);
      }
    } else {
      if (!env.storageURI) {
        throw new Error('MongoDB connection string is missing. Please set MONGODB_URI environment variable');
      }

      console.log('Setting up new connection to MongoDB');
      const timeout = 10 * 1000;
      const options = {
        connectTimeoutMS: timeout,
        socketTimeoutMS: timeout,
        useNewUrlParser: true,
        useUnifiedTopology: true,
      };

      const connect_with_retry = async function (i) {

        mongo.client = new MongoClient(env.storageURI, options);
        try {
          await mongo.client.connect();

          console.log('Successfully established a connected to MongoDB');

          const dbName = mongo.client.s.options.dbName;
          mongo.db = mongo.client.db(dbName);

          const result = await mongo.db.command({ connectionStatus: 1 });
          const roles = result.authInfo.authenticatedUserRoles;
          if (roles.length > 0 && roles[0].role == 'readAnyDatabase') {
            console.error('Mongo user is read only');
            cb(new Error('MongoDB connection is in read only mode! Go back to MongoDB configuration and check your database user has read and write access.'), null);
          }

          console.log('Mongo user role seems ok:', roles);

          // If there is a valid callback, then invoke the function to perform the callback
          if (cb && cb.call) {
            cb(null, mongo);
          }
        } catch (err) {
          if (err.message && err.message.includes('AuthenticationFailed')) {
            console.log('Authentication to Mongo failed');
            cb(new Error('MongoDB authentication failed! Double check the URL has the right username and password in MONGODB_URI.'), null);
            return;
          }

          if (err.name && err.name === "MongoServerSelectionError") {
            const timeout = (i > 15) ? 60000 : i * 3000;
            console.log('Error connecting to MongoDB: %j - retrying in ' + timeout / 1000 + ' sec', err);
            setTimeout(connect_with_retry, timeout, i + 1);
            if (i == 1) cb(new Error('MongoDB connection failed! Double check the MONGODB_URI setting in Heroku.'), null);
          } else {
            cb(new Error('MONGODB_URI ' + env.storageURI + ' seems invalid: ' + err.message));
          }
        }
      };

      return connect_with_retry(1);

    }
  }

  mongo.collection = function get_collection(name) {
    return mongo.db.collection(name);
  };

  mongo.ensureIndexes = function ensureIndexes(collection, fields) {
    fields.forEach(function (field) {
      console.info('ensuring index for: ' + field);
      collection.createIndex(field, { 'background': true }, function (err) {
        if (err) {
          console.error('unable to ensureIndex for: ' + field + ' - ' + err);
        }
      });
    });
  };

  return maybe_connect(cb);
}

module.exports = init;
<|endoftext|>


<commit_before>'use strict';

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    // Metadata.
    pkg: grunt.file.readJSON('include.jquery.json'),
    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(", ") %> */\n',
    // Task configuration.
    clean: {
      files: ['dist']
    },
    concat: {
      options: {
        banner: '<%= banner %>',
        stripBanners: true
      },
      dist: {
        src: ['src/jquery.<%= pkg.name %>.js'],
        dest: 'dist/jquery.<%= pkg.name %>.js'
      }
    },
    uglify: {
      options: {
        banner: '<%= banner %>'
      },
      dist: {
        src: '<%= concat.dist.dest %>',
        dest: 'dist/jquery.<%= pkg.name %>.min.js'
      }
    },
    qunit: {
      files: ['test/**/*.html']
    },
    jshint: {
      options: {
        jshintrc: true
      },
      gruntfile: {
        src: 'Gruntfile.js'
      },
      src: {
        src: ['src/**/*.js']
      },
      test: {
        src: ['test/**/*.js']
      }
    },
    watch: {
      gruntfile: {
        files: '<%= jshint.gruntfile.src %>',
        tasks: ['jshint:gruntfile']
      },
      src: {
        files: '<%= jshint.src.src %>',
        tasks: ['jshint:src', 'qunit']
      },
      test: {
        files: '<%= jshint.test.src %>',
        tasks: ['jshint:test', 'qunit']
      }
    }
  });

  // These plugins provide necessary tasks.
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-qunit');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-watch');

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

};
<commit_msg>Fixed test script<commit_after>'use strict';

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    // Metadata.
    pkg: grunt.file.readJSON('include.jquery.json'),
    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(", ") %> */\n',
    // Task configuration.
    clean: {
      files: ['dist']
    },
    concat: {
      options: {
        banner: '<%= banner %>',
        stripBanners: true
      },
      dist: {
        src: ['src/jquery.<%= pkg.name %>.js'],
        dest: 'dist/jquery.<%= pkg.name %>.js'
      }
    },
    uglify: {
      options: {
        banner: '<%= banner %>'
      },
      dist: {
        src: '<%= concat.dist.dest %>',
        dest: 'dist/jquery.<%= pkg.name %>.min.js'
      }
    },
    qunit: {
      files: ['test/*.html']
    },
    jshint: {
      options: {
        jshintrc: true
      },
      gruntfile: {
        src: 'Gruntfile.js'
      },
      src: {
        src: ['src/**/*.js']
      },
      test: {
        src: ['test/**/*.js']
      }
    },
    watch: {
      gruntfile: {
        files: '<%= jshint.gruntfile.src %>',
        tasks: ['jshint:gruntfile']
      },
      src: {
        files: '<%= jshint.src.src %>',
        tasks: ['jshint:src', 'qunit']
      },
      test: {
        files: '<%= jshint.test.src %>',
        tasks: ['jshint:test', 'qunit']
      }
    }
  });

  // These plugins provide necessary tasks.
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-qunit');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-watch');

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

};
<|endoftext|>


<commit_before>'use strict';

module.exports = function (grunt) {

  // Time how long tasks take. Can help when optimizing build times
  require('time-grunt')(grunt);

  // Automatically load required grunt tasks
  // Use jit-grunt instead of load-grunt-tasks here as it dramatically decreases grunt initialization time (27.5s -> 1.5s).
  require('jit-grunt')(grunt, {
      useminPrepare: 'grunt-usemin'
  });

  // Configurable options
  var config = {
    app: './app',
    // dist: './dist',
    minimumCoverage: 90 // percents
  };

  // Define the configuration for all the tasks
  grunt.initConfig({

    // Project settings
    config: config,

    // Watches files for changes and runs tasks based on the changed files
    watch: {
      bower: {
        files: ['bower.json'],
        tasks: ['wiredep']
      },
      sass: {
        files: ['<%= config.app %>/styles/sass/{,*/}*.{scss,sass}'],
        tasks: ['sass']
      },
      templates: {
        files: ['<%= config.app %>/templates/{,*/}*.hbs'],
        tasks: ['handlebars']
      },
    },

    browserSync: {
      options: {
        notify: false,
        background: true,
        watchOptions: {
          ignored: ''
        }
      },
      livereload: {
        options: {
          files: [
            '<%= config.app %>/{,*/}*.html',
            '<%= config.app %>/styles/{,*/}*.css',
            '<%= config.app %>/images/{,*/}*',
            '<%= config.app %>/scripts/{,*/}*.js'
          ],
          port: 9000,
          server: {
            baseDir: ['<%= config.app %>', config.app],
            routes: {
              '/bower_components': './bower_components'
            }
          }
        }
      }
    },

    // Empties folders to start fresh
    clean: {
      options: {
        force: true
      },
      dist: {
        files: [{
          dot: true,
          src: [
            '<%= config.app %>/styles/main.css',
            '<%= config.app %>/styles/main.css.map',
            '<%= config.app %>/scripts/compiled-templates.js'
          ]
        }]
      },
    },

    handlebars: {
      compile: {
        options: {
          namespace: 'Handlebars.Templates',
          processName: function(filePath) { // input:  app/templates/AddressInputQuestion.hbs
            var pieces = filePath.split("/");
            return pieces[pieces.length - 1].replace(/\.hbs$/, ''); // output: AddressInputQuestion
          },
        },
        files: {
          '<%= config.app %>/scripts/compiled-templates.js': [ '<%= config.app %>/templates/*.hbs']
        }
      },
      serve: {
        options: {
          namespace: 'Handlebars.Templates',
          processName: function(filePath) { // input:  app/templates/AddressInputQuestion.hbs
            var pieces = filePath.split("/");
            return pieces[pieces.length - 1].replace(/\.hbs$/, ''); // output: AddressInputQuestion
          }
        },
        files: {
          '<%= config.app %>/scripts/compiled-templates.js': [ '<%= config.app %>/templates/*.hbs']
        }
      }
    },

    // Compiles Sass to CSS and generates necessary files if requested
    sass: {
      options: {
        sourceMap: true,
        sourceMapEmbed: true,
        sourceMapContents: true,
        outputStyle: 'compact',
        includePaths: ['.']
      },
      dist: {
        files: {
          '<%= config.app %>/styles/main.css': '<%= config.app %>/styles/sass/master.scss',
        }
      }
    },

    // Automatically inject Bower components into the HTML file
    wiredep: {
      options: {
        cwd: '.'
      },
      app: {
        src: ['<%= config.app %>/index.html'],
        ignorePath: /^(\.\.\/)*\.\./
      },
      sass: {
        src: ['<%= config.app %>/styles/{,*/}*.{scss,sass}'],
        ignorePath: /^(\.\.\/)+/
      },
      js: {
        src: ['<%= config.app %>/scripts/{,*/}*.js'],
        options: {
          fileTypes: {
            js: {
              block: /(((?:[\t ])*)\/\/\s*bower:(\S*))((?:\r|\n|.)*?)(\/\/\s*endbower)/gi,
              detect: {
                js: /".*\.js"/gi
              },
              replace: {
                js: "'{{filePath}}',"
              }
            }
          }
        }
      }
    },

  //   // Copies remaining files to places other tasks can use
  //   ,copy: {
  //     dist: {
  //       files: [{
  //         expand: true,
  //         dot: true,
  //         cwd: '<%= config.app %>',
  //         dest: '<%= config.dist %>',
  //         src: [
  //           'styles/*.css',
  //           'images/{,*/}*',
  //         ]
  //       },
  //       {
  //         expand: true,
  //         dot: true,
  //         cwd: '<%= config.app %>',
  //         dest: '<%= config.dist %>',
  //         src: [
  //           'scripts/localization/*.js'
  //         ]
  //       }]
  //     }
  //   },

  });

  grunt.registerTask('build', [
    'clean',
    'sass',
    'handlebars',
    'wiredep',
    // 'copy:dist',
  ]);

  grunt.registerTask('default', [
    'build'
  ]);

  grunt.registerTask('serve', 'Prepares files for main serve task', [
    'clean',
    'sass',
    'handlebars',
    'wiredep',
    'browserSync:livereload',
    'watch'
  ]);
};
<commit_msg>removed config for handlebars to serve files<commit_after>'use strict';

module.exports = function (grunt) {

  // Time how long tasks take. Can help when optimizing build times
  require('time-grunt')(grunt);

  // Automatically load required grunt tasks
  // Use jit-grunt instead of load-grunt-tasks here as it dramatically decreases grunt initialization time (27.5s -> 1.5s).
  require('jit-grunt')(grunt, {
      useminPrepare: 'grunt-usemin'
  });

  // Configurable options
  var config = {
    app: './app',
    // dist: './dist',
    minimumCoverage: 90 // percents
  };

  // Define the configuration for all the tasks
  grunt.initConfig({

    // Project settings
    config: config,

    // Watches files for changes and runs tasks based on the changed files
    watch: {
      bower: {
        files: ['bower.json'],
        tasks: ['wiredep']
      },
      sass: {
        files: ['<%= config.app %>/styles/sass/{,*/}*.{scss,sass}'],
        tasks: ['sass']
      },
      templates: {
        files: ['<%= config.app %>/templates/{,*/}*.hbs'],
        tasks: ['handlebars']
      },
    },

    browserSync: {
      options: {
        notify: false,
        background: true,
        watchOptions: {
          ignored: ''
        }
      },
      livereload: {
        options: {
          files: [
            '<%= config.app %>/{,*/}*.html',
            '<%= config.app %>/styles/{,*/}*.css',
            '<%= config.app %>/images/{,*/}*',
            '<%= config.app %>/scripts/{,*/}*.js'
          ],
          port: 9000,
          server: {
            baseDir: ['<%= config.app %>', config.app],
            routes: {
              '/bower_components': './bower_components'
            }
          }
        }
      }
    },

    // Empties folders to start fresh
    clean: {
      options: {
        force: true
      },
      dist: {
        files: [{
          dot: true,
          src: [
            '<%= config.app %>/styles/main.css',
            '<%= config.app %>/styles/main.css.map',
            '<%= config.app %>/scripts/compiled-templates.js'
          ]
        }]
      },
    },

    handlebars: {
      compile: {
        options: {
          namespace: 'Handlebars.Templates',
          processName: function(filePath) { // input:  app/templates/AddressInputQuestion.hbs
            var pieces = filePath.split("/");
            return pieces[pieces.length - 1].replace(/\.hbs$/, ''); // output: AddressInputQuestion
          },
        },
        files: {
          '<%= config.app %>/scripts/compiled-templates.js': [ '<%= config.app %>/templates/*.hbs']
        }
      }
    },

    // Compiles Sass to CSS and generates necessary files if requested
    sass: {
      options: {
        sourceMap: true,
        sourceMapEmbed: true,
        sourceMapContents: true,
        outputStyle: 'compact',
        includePaths: ['.']
      },
      dist: {
        files: {
          '<%= config.app %>/styles/main.css': '<%= config.app %>/styles/sass/master.scss',
        }
      }
    },

    // Automatically inject Bower components into the HTML file
    wiredep: {
      options: {
        cwd: '.'
      },
      app: {
        src: ['<%= config.app %>/index.html'],
        ignorePath: /^(\.\.\/)*\.\./
      },
      sass: {
        src: ['<%= config.app %>/styles/{,*/}*.{scss,sass}'],
        ignorePath: /^(\.\.\/)+/
      },
      js: {
        src: ['<%= config.app %>/scripts/{,*/}*.js'],
        options: {
          fileTypes: {
            js: {
              block: /(((?:[\t ])*)\/\/\s*bower:(\S*))((?:\r|\n|.)*?)(\/\/\s*endbower)/gi,
              detect: {
                js: /".*\.js"/gi
              },
              replace: {
                js: "'{{filePath}}',"
              }
            }
          }
        }
      }
    },

  //   // Copies remaining files to places other tasks can use
  //   ,copy: {
  //     dist: {
  //       files: [{
  //         expand: true,
  //         dot: true,
  //         cwd: '<%= config.app %>',
  //         dest: '<%= config.dist %>',
  //         src: [
  //           'styles/*.css',
  //           'images/{,*/}*',
  //         ]
  //       },
  //       {
  //         expand: true,
  //         dot: true,
  //         cwd: '<%= config.app %>',
  //         dest: '<%= config.dist %>',
  //         src: [
  //           'scripts/localization/*.js'
  //         ]
  //       }]
  //     }
  //   },

  });

  grunt.registerTask('build', [
    'clean',
    'sass',
    'handlebars',
    'wiredep',
    // 'copy:dist',
  ]);

  grunt.registerTask('default', [
    'build'
  ]);

  grunt.registerTask('serve', 'Prepares files for main serve task', [
    'clean',
    'sass',
    'handlebars',
    'wiredep',
    'browserSync:livereload',
    'watch'
  ]);
};
<|endoftext|>