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

  grunt.loadNpmTasks("grunt-contrib-connect");
  grunt.loadNpmTasks("grunt-contrib-jshint");
  grunt.loadNpmTasks("grunt-contrib-uglify");
  grunt.loadNpmTasks("grunt-este-watch");

  var testFailed = [];
  var hasExclusiveTest = function() {
    var files = grunt.file.expand("src/cc/**/*_test.js");
    return files.some(function(file) {
      var code = grunt.file.read(file);
      return/^\s*(describe|it)\.only\(\"/m.test(code);
    });
  };

  grunt.initConfig({
    pkg: grunt.file.readJSON("package.json"),
    esteWatch: {
      options: {
        dirs: [ "./", "src/**/", "documents/**/" ],
      },
      js: function(filepath) {
        if (/documents\//.test(filepath)) {
          return;
        }
        if (/src\//.test(filepath)) {
          if (/_test\.js$/.test(filepath)) {
            return "test:" + filepath;
          }
          grunt.config(["jshint", "files"], filepath);
          var tasks = [ "typo", "jshint", "test:" + filepath, "dryice", "uglify" ];
          return tasks;
        }
      },
      json: function() {
        return [ "dryice" ];
      },
      as: function() {
        return [ "swf" ];
      }
    },
    connect: {
      server: {
        options: {
          port    : process.env.PORT || 3000,
          hostname: "*"
        }
      }
    },
    jshint: {
      files: "src/cc/**/*.js",
      options: grunt.file.readJSON(".jshintrc")
    },
    uglify: {
      cc: {
        files: {
          "coffee-collider-min.js": [ "coffee-collider.js" ]
        },
        options: {
          sourceMap: "coffee-collider-min.map",
          report: "min"
        }
      }
    }
  });

  grunt.registerTask("typo", function() {
    var check = 0;
    var typo  = 0;
    var constants = grunt.file.readJSON("src/const.json");
    var re1 = /^define\(function\(require, exports, module\) {$/;
    var re2 = /[^a-zA-Z0-9_$]C\.([A-Z0-9_]+)/g;

    var files = grunt.file.expand(grunt.config(["jshint", "files"]));
    files = files.filter(function(file) {
      return !/_test\.js$/.test(file);
    });
    files.forEach(function(file) {
      var code = grunt.file.read(file);
      var head = code.split("\n")[0];
      if (!re1.test(head)) {
        grunt.verbose.or.write("Typong " + file + "...");
        grunt.log.error();
        grunt.log.writeln("  " + head);
        typo += 1;
      }
      var m;
      re2.lastIndex = 0;
      while ((m = re2.exec(code)) !== null) {
        if (!constants.hasOwnProperty(m[1])) {
          grunt.verbose.or.write("Typong " + file + "...");
          grunt.log.error();
          grunt.log.writeln("  C." + m[1]);
          typo += 1;
        }
      }
      check += 1;
    });
    if (typo === 0) {
      grunt.log.ok(check + " files typo free.");
      return true;
    }
    return false;
  });

  grunt.registerTask("dryice", function() {
    if (hasExclusiveTest()) {
      grunt.fail.warn("NOT builded, '.only' attribute is detected in any tests.");
    }
    var copy = require("dryice").copy;
    var srcroot = "src";
    var main = "cc/loader";
    var dest = "coffee-collider";

    var coffeeColliderProject = {
      roots: [srcroot]
    };
    var project = copy.createCommonJsProject(coffeeColliderProject);
    var cc = copy.createDataObject();
    var filter;

    var header = "";
    header += "(function(global) {" + "\n";
    header += '"use strict";' + "\n";

    var footer = "";
    footer += "})(this.self||global);" + "\n";

    copy({
      source: { value:header },
      dest  : cc
    });
    copy({
      source: [ "./src/require.js" ],
      dest  : cc
    });
    filter = [
      copy.filter.moduleDefines,
      function(text) {
        var constants = grunt.file.readJSON("src/const.json");
        Object.keys(constants).forEach(function(key) {
          var re = new RegExp("C\." + key + "(?![A-Z0-9_])", "g");
          text = text.replace(re, constants[key]);
        });
        return text;
      },
      function(text) {
        var re = /(global\.(?:.+?) = "load\((.+?)\)";)/gm;
        var m;
        while ((m = re.exec(text)) !== null) {
          var code = grunt.file.read(m[2]);
          text = text.replace(m[1], code);
        }
        return text;
      },
      function(text) {
        text = text.replace(/^define\((['"].+?['"]), \[(.+?)\], function\(require, exports, module\) {$/gm, "define($1, function(require, exports, module) {");
        text = text.replace(/\s*['"]use strict['"];$/gm, "");
        text = text.replace(/#{VERSION}/g, grunt.config.get("pkg.version"));
        return text + '_require("cc/cc", "' + main + '");\n';
      }
    ];
    copy({
      source: [ { project:project, require:main } ],
      filter: filter,
      dest  : cc
    });
    copy({
      source: { value:footer },
      dest  : cc
    });
    copy({
      source: cc,
      dest  : dest + ".js"
    });
  });

  grunt.registerTask("swf", function() {
    var done = this.async();
    var child = grunt.util.spawn({
      cmd : "mxmlc",
      args: ["-o", "coffee-collider-fallback.swf", "./src/fallback.as"]
    }, function(err, result) {
      if (result.code !== 0) {
        grunt.fail.fatal("Compile failed. See the above error message.");
      }
      done();
    });
    child.stdout.pipe(process.stdout);
    child.stderr.pipe(process.stderr);
  });

  grunt.registerTask("test", function() {
    Object.keys(require.cache).forEach(function(filepath) {
      if (!/\/node_modules\//.test(filepath)) {
        delete require.cache[filepath];
      }
    });
    require("amd-loader");

    var Mocha = require("mocha");
    var mocha = new Mocha();

    global.C = grunt.file.readJSON("src/const.json");

    var reporter = "dot";
    var args  = arguments[0];
    var files = [];
    if (args) {
      if (args === "travis") {
        reporter = "list";
      } else {
        if (grunt.file.exists(args)) {
          files.push(args);
        }
        var related = args.replace(/\.js$/, "_test.js");
        if (grunt.file.exists(related)) {
          files.push(related);
        }
      }
    }

    if (!files.length) {
      files = grunt.file.expand("src/cc/**/*_test.js");
    }
    files = files.concat(testFailed);
    var set = {};
    files = files.filter(function(file) {
      if (!set[file] && /_test\.js$/.test(file)) {
        set[file] = true;
        return true;
      }
      return false;
    });
    files.forEach(function(file) {
      mocha.addFile(file);
    });
    var done = this.async();
    mocha.reporter(reporter).run(function(failures) {
      if (failures) {
        grunt.fail.fatal("test failed.");
        testFailed = files;
      } else {
        testFailed = [];
      }
      if (args === "travis") {
        if (hasExclusiveTest()) {
          grunt.fail.warn("test succeeded, but not completely.");
        }
      }
      done();
    });
  });

  grunt.registerTask("check"  , ["typo", "jshint", "test"]);
  grunt.registerTask("build"  , ["check", "dryice", "uglify"]);
  grunt.registerTask("default", ["build", "connect", "esteWatch"]);
  grunt.registerTask("travis" , ["typo", "jshint", "test:travis"]);

};
<commit_msg>Updated Gruntfile.js<commit_after>module.exports = function(grunt) {
  "use strict";

  grunt.loadNpmTasks("grunt-contrib-connect");
  grunt.loadNpmTasks("grunt-contrib-jshint");
  grunt.loadNpmTasks("grunt-contrib-uglify");
  grunt.loadNpmTasks("grunt-este-watch");

  var testFailed = [];
  var hasExclusiveTest = function() {
    var files = grunt.file.expand("src/cc/**/*_test.js");
    return files.some(function(file) {
      var code = grunt.file.read(file);
      return/^\s*(describe|it)\.only\(\"/m.test(code);
    });
  };

  grunt.initConfig({
    pkg: grunt.file.readJSON("package.json"),
    esteWatch: {
      options: {
        dirs: [ "./", "src/**/", "documents/**/" ],
      },
      js: function(filepath) {
        if (/documents\//.test(filepath)) {
          return;
        }
        if (/src\//.test(filepath)) {
          if (/_test\.js$/.test(filepath)) {
            return "test:" + filepath;
          }
          grunt.config(["jshint", "files"], filepath);
          var tasks = [ "typo", "jshint", "test:" + filepath, "dryice", "uglify" ];
          return tasks;
        }
      },
      json: function() {
        return [ "dryice" ];
      },
      as: function() {
        return [ "swf" ];
      }
    },
    connect: {
      server: {
        options: {
          port    : process.env.PORT || 3000,
          hostname: "*"
        }
      }
    },
    jshint: {
      files: "src/cc/**/*.js",
      options: grunt.file.readJSON(".jshintrc")
    },
    uglify: {
      cc: {
        files: {
          "coffee-collider-min.js": [ "coffee-collider.js" ]
        },
        options: {
          sourceMap: "coffee-collider-min.map",
          report: "min"
        }
      }
    }
  });

  grunt.registerTask("typo", function() {
    var check = 0;
    var typo  = 0;
    var constants = grunt.file.readJSON("src/const.json");
    var re1 = /^define\(function\(require, exports, module\) {$/;
    var re2 = /[^a-zA-Z0-9_$]C\.([A-Z0-9_]+)/g;

    var files = grunt.file.expand(grunt.config(["jshint", "files"]));
    files = files.filter(function(file) {
      return !/_test\.js$/.test(file);
    });
    files.forEach(function(file) {
      var code = grunt.file.read(file);
      var head = code.split("\n")[0];
      if (!re1.test(head)) {
        grunt.verbose.or.write("Typong " + file + "...");
        grunt.log.error();
        grunt.log.writeln("  " + head);
        typo += 1;
      }
      var m;
      re2.lastIndex = 0;
      while ((m = re2.exec(code)) !== null) {
        if (!constants.hasOwnProperty(m[1])) {
          grunt.verbose.or.write("Typong " + file + "...");
          grunt.log.error();
          grunt.log.writeln("  C." + m[1]);
          typo += 1;
        }
      }
      check += 1;
    });
    if (typo === 0) {
      grunt.log.ok(check + " files typo free.");
      return true;
    }
    return false;
  });

  grunt.registerTask("dryice", function() {
    if (hasExclusiveTest()) {
      grunt.fail.warn("NOT builded, '.only' attribute is detected in any tests.");
      return;
    }
    var copy = require("dryice").copy;
    var srcroot = "src";
    var main = "cc/loader";
    var dest = "coffee-collider";

    var coffeeColliderProject = {
      roots: [srcroot]
    };
    var project = copy.createCommonJsProject(coffeeColliderProject);
    var cc = copy.createDataObject();
    var filter;

    var header = "";
    header += "(function(global) {" + "\n";
    header += '"use strict";' + "\n";

    var footer = "";
    footer += "})(this.self||global);" + "\n";

    copy({
      source: { value:header },
      dest  : cc
    });
    copy({
      source: [ "./src/require.js" ],
      dest  : cc
    });
    filter = [
      copy.filter.moduleDefines,
      function(text) {
        var constants = grunt.file.readJSON("src/const.json");
        Object.keys(constants).forEach(function(key) {
          var re = new RegExp("C\." + key + "(?![A-Z0-9_])", "g");
          text = text.replace(re, constants[key]);
        });
        return text;
      },
      function(text) {
        var re = /(global\.(?:.+?) = "load\((.+?)\)";)/gm;
        var m;
        while ((m = re.exec(text)) !== null) {
          var code = grunt.file.read(m[2]);
          text = text.replace(m[1], code);
        }
        return text;
      },
      function(text) {
        text = text.replace(/^define\((['"].+?['"]), \[(.+?)\], function\(require, exports, module\) {$/gm, "define($1, function(require, exports, module) {");
        text = text.replace(/\s*['"]use strict['"];$/gm, "");
        text = text.replace(/#{VERSION}/g, grunt.config.get("pkg.version"));
        return text + '_require("cc/cc", "' + main + '");\n';
      }
    ];
    copy({
      source: [ { project:project, require:main } ],
      filter: filter,
      dest  : cc
    });
    copy({
      source: { value:footer },
      dest  : cc
    });
    copy({
      source: cc,
      dest  : dest + ".js"
    });
  });

  grunt.registerTask("swf", function() {
    var done = this.async();
    var child = grunt.util.spawn({
      cmd : "mxmlc",
      args: ["-o", "coffee-collider-fallback.swf", "./src/fallback.as"]
    }, function(err, result) {
      if (result.code !== 0) {
        grunt.fail.fatal("Compile failed. See the above error message.");
      }
      done();
    });
    child.stdout.pipe(process.stdout);
    child.stderr.pipe(process.stderr);
  });

  grunt.registerTask("test", function() {
    Object.keys(require.cache).forEach(function(filepath) {
      if (!/\/node_modules\//.test(filepath)) {
        delete require.cache[filepath];
      }
    });
    require("amd-loader");

    var Mocha = require("mocha");
    var mocha = new Mocha();

    global.C = grunt.file.readJSON("src/const.json");

    var reporter = "dot";
    var args  = arguments[0];
    var files = [];
    if (args) {
      if (args === "travis") {
        reporter = "list";
      } else {
        if (grunt.file.exists(args)) {
          files.push(args);
        }
        var related = args.replace(/\.js$/, "_test.js");
        if (grunt.file.exists(related)) {
          files.push(related);
        }
      }
    }

    if (!files.length) {
      files = grunt.file.expand("src/cc/**/*_test.js");
    }
    files = files.concat(testFailed);
    var set = {};
    files = files.filter(function(file) {
      if (!set[file] && /_test\.js$/.test(file)) {
        set[file] = true;
        return true;
      }
      return false;
    });
    files.forEach(function(file) {
      mocha.addFile(file);
    });
    var done = this.async();
    mocha.reporter(reporter).run(function(failures) {
      if (failures) {
        grunt.fail.fatal("test failed.");
        testFailed = files;
      } else {
        testFailed = [];
      }
      if (args === "travis") {
        if (hasExclusiveTest()) {
          grunt.fail.warn("test succeeded, but not completely.");
        }
      }
      done();
    });
  });

  grunt.registerTask("check"  , ["typo", "jshint", "test"]);
  grunt.registerTask("build"  , ["check", "dryice", "uglify"]);
  grunt.registerTask("default", ["connect", "esteWatch"]);
  grunt.registerTask("travis" , ["typo", "jshint", "test:travis"]);

};
<|endoftext|>


<commit_before>module.exports = function(grunt) {
  // time
  require('time-grunt')(grunt);

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

    //package the theme and remove folders
    compress: {
      main: {
        options: {
          archive: 'deploy/<%= pkg.name %>.zip'
        },
        expand: true,
        cwd: '.',
        src: ['**/*','!**/node_modules/**','!**/bower_components/**','!**/scss/**','!**/deploy/**','!**/bower.json','!**/Gruntfile.js','!**/package.json','!**/composer.json','!**/composer.lock','!**/codesniffer.rulese.xml'],
        dest: '<%= pkg.name %>'
      },
    },

    sass: {
      options: {
        // If you can't get source maps to work, run the following command in your terminal:
        // $ sass scss/foundation.scss:css/foundation.css --sourcemap
        // (see this link for details: http://thesassway.com/intermediate/using-source-maps-with-sass )
        sourceMap: true
      },

      dist: {
        options: {
          outputStyle: 'compressed'
        },
        files: {
          'css/foundation.css': 'scss/foundation.scss'
        }
      }
    },

    copy: {
      scripts: {
        expand: true,
        cwd: 'bower_components/foundation/js/vendor/',
        src: '**',
        flatten: 'true',
        dest: 'js/vendor/'
      },

      iconfonts: {
        expand: true,
        cwd: 'bower_components/fontawesome/',
        src: ['**', '!**/less/**', '!**/css/**', '!bower.json'],
        dest: 'assets/fontawesome/'
      },

    },

      'string-replace': {

        fontawesome: {
          files: {
            'assets/fontawesome/scss/_variables.scss': 'assets/fontawesome/scss/_variables.scss'
          },
          options: {
            replacements: [
              {
                pattern: '../fonts',
                replacement: '../assets/fontawesome/fonts'
              }
            ]
          }
        },
      },

    concat: {
        options: {
          separator: ';',
        },
        dist: {
          src: [

          // Foundation core
          'bower_components/foundation/js/foundation/foundation.js',

          // Pick the componenets you need in your project
          'bower_components/foundation/js/foundation/foundation.abide.js',
          'bower_components/foundation/js/foundation/foundation.accordion.js',
          'bower_components/foundation/js/foundation/foundation.alert.js',
          'bower_components/foundation/js/foundation/foundation.clearing.js',
          'bower_components/foundation/js/foundation/foundation.dropdown.js',
          'bower_components/foundation/js/foundation/foundation.equalizer.js',
          'bower_components/foundation/js/foundation/foundation.interchange.js',
          'bower_components/foundation/js/foundation/foundation.joyride.js',
          'bower_components/foundation/js/foundation/foundation.magellan.js',
          'bower_components/foundation/js/foundation/foundation.offcanvas.js',
          'bower_components/foundation/js/foundation/foundation.orbit.js',
          'bower_components/foundation/js/foundation/foundation.reveal.js',
          'bower_components/foundation/js/foundation/foundation.slider.js',
          'bower_components/foundation/js/foundation/foundation.tab.js',
          'bower_components/foundation/js/foundation/foundation.tooltip.js',
          'bower_components/foundation/js/foundation/foundation.topbar.js',

          // Include your own custom scripts (located in the custom folder)
          'js/custom/*.js'

          ],
          // Finally, concatinate all the files above into one single file
          dest: 'js/foundation.js',
        },
      },

    uglify: {
      dist: {
        files: {
          // Shrink the file size by removing spaces
          'js/foundation.js': ['js/foundation.js']
        }
      }
    },

    watch: {
      grunt: { files: ['Gruntfile.js'] },

      sass: {
        files: 'scss/**/*.scss',
        tasks: ['sass'],
        options: {
              livereload:true,
            }
      },

      js: {
        files: 'js/custom/**/*.js',
        tasks: ['concat', 'uglify'],
        options: {
          livereload:true,
        }
      },

       all: {
        files: '**/*.php',
        options: {
            livereload:true,
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-sass');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-string-replace');
  grunt.loadNpmTasks('grunt-contrib-compress');

  grunt.registerTask('deploy', ['compress:main']);
  grunt.registerTask('build', ['copy', 'string-replace:fontawesome', 'sass', 'concat', 'uglify']);
  grunt.registerTask('default', ['watch']);
};<commit_msg>renamed deploy command to package<commit_after>module.exports = function(grunt) {
  // time
  require('time-grunt')(grunt);

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

    //package the theme and remove folders
    compress: {
      main: {
        options: {
          archive: 'packaged/<%= pkg.name %>.zip'
        },
        expand: true,
        cwd: '.',
        src: ['**/*','!**/node_modules/**','!**/bower_components/**','!**/scss/**','!**/deploy/**','!**/bower.json','!**/Gruntfile.js','!**/package.json','!**/composer.json','!**/composer.lock','!**/codesniffer.rulese.xml'],
        dest: '<%= pkg.name %>'
      },
    },

    sass: {
      options: {
        // If you can't get source maps to work, run the following command in your terminal:
        // $ sass scss/foundation.scss:css/foundation.css --sourcemap
        // (see this link for details: http://thesassway.com/intermediate/using-source-maps-with-sass )
        sourceMap: true
      },

      dist: {
        options: {
          outputStyle: 'compressed'
        },
        files: {
          'css/foundation.css': 'scss/foundation.scss'
        }
      }
    },

    copy: {
      scripts: {
        expand: true,
        cwd: 'bower_components/foundation/js/vendor/',
        src: '**',
        flatten: 'true',
        dest: 'js/vendor/'
      },

      iconfonts: {
        expand: true,
        cwd: 'bower_components/fontawesome/',
        src: ['**', '!**/less/**', '!**/css/**', '!bower.json'],
        dest: 'assets/fontawesome/'
      },

    },

      'string-replace': {

        fontawesome: {
          files: {
            'assets/fontawesome/scss/_variables.scss': 'assets/fontawesome/scss/_variables.scss'
          },
          options: {
            replacements: [
              {
                pattern: '../fonts',
                replacement: '../assets/fontawesome/fonts'
              }
            ]
          }
        },
      },

    concat: {
        options: {
          separator: ';',
        },
        dist: {
          src: [

          // Foundation core
          'bower_components/foundation/js/foundation/foundation.js',

          // Pick the componenets you need in your project
          'bower_components/foundation/js/foundation/foundation.abide.js',
          'bower_components/foundation/js/foundation/foundation.accordion.js',
          'bower_components/foundation/js/foundation/foundation.alert.js',
          'bower_components/foundation/js/foundation/foundation.clearing.js',
          'bower_components/foundation/js/foundation/foundation.dropdown.js',
          'bower_components/foundation/js/foundation/foundation.equalizer.js',
          'bower_components/foundation/js/foundation/foundation.interchange.js',
          'bower_components/foundation/js/foundation/foundation.joyride.js',
          'bower_components/foundation/js/foundation/foundation.magellan.js',
          'bower_components/foundation/js/foundation/foundation.offcanvas.js',
          'bower_components/foundation/js/foundation/foundation.orbit.js',
          'bower_components/foundation/js/foundation/foundation.reveal.js',
          'bower_components/foundation/js/foundation/foundation.slider.js',
          'bower_components/foundation/js/foundation/foundation.tab.js',
          'bower_components/foundation/js/foundation/foundation.tooltip.js',
          'bower_components/foundation/js/foundation/foundation.topbar.js',

          // Include your own custom scripts (located in the custom folder)
          'js/custom/*.js'

          ],
          // Finally, concatinate all the files above into one single file
          dest: 'js/foundation.js',
        },
      },

    uglify: {
      dist: {
        files: {
          // Shrink the file size by removing spaces
          'js/foundation.js': ['js/foundation.js']
        }
      }
    },

    watch: {
      grunt: { files: ['Gruntfile.js'] },

      sass: {
        files: 'scss/**/*.scss',
        tasks: ['sass'],
        options: {
              livereload:true,
            }
      },

      js: {
        files: 'js/custom/**/*.js',
        tasks: ['concat', 'uglify'],
        options: {
          livereload:true,
        }
      },

       all: {
        files: '**/*.php',
        options: {
            livereload:true,
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-sass');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-string-replace');
  grunt.loadNpmTasks('grunt-contrib-compress');

  grunt.registerTask('package', ['compress:main']);
  grunt.registerTask('build', ['copy', 'string-replace:fontawesome', 'sass', 'concat', 'uglify']);
  grunt.registerTask('default', ['watch']);
};<|endoftext|>


<commit_before>/*global module:false,requirejs:false*/
module.exports = function(grunt) {
    'use strict';

    var allSrcs = ['./Gruntfile.js', './src/**/*.js', './test/**/*.js'];
    // Project configuration.
    grunt.initConfig({

        clean: {
            files: ['dist']
        },

        jshint: {
            options: grunt.file.readJSON('./.jshintrc'),
            lenient: allSrcs,
            strict: {
                files: {
                    src: allSrcs
                },
                options: {
                    unused: true,
                    maxparams: 3
                }
            }
        },

        jasmine: {
            run: {
                src: ['dist/bundle.src.js'],
                options: {
                    outfile: 'specRunner.html',
                    keepRunner: true,
                    specs: ['dist/bundle.test.js'],
                    helpers: ['test/helpers/**/*.js']
                    // template: require('grunt-template-jasmine-istanbul'),
                    // templateOptions: {
                    //     coverage: 'reports/coverage.json',
                    //     report: [
                    //         {
                    //             type: 'html',
                    //             options: {
                    //                 dir: 'reports/coverage'
                    //             }
                    //         },
                    //         {
                    //             type: 'text-summary'
                    //         }
                    //     ]
                    // }
                }
            }
        },
        watch: {
            sass: {
                files: ['styles/sass/**/*.scss'],
                tasks: 'sass:dev'
            },
            js: {
                files: ['src/**/*.js'],
                tasks: 'browserify:dev'
            }
        },
        sass: {
            dist: {
                options: {
                    style: 'compressed'
                },
                files: {
                    './dist/styles/css/main.css': './styles/sass/main.scss'
                }
            },
            dev: {
                options: {
                    style: 'expanded'
                },
                files: {
                    './styles/css/main.css': './styles/sass/main.scss'
                }
            }
        },
        htmlmin: {

            dist: {
                options: {                                 // Target options
                    removeComments: true,
                    collapseWhitespace: true
                },
                files: {
                    './dist/index.html': './index.html'
                }
            }
        },
        uglify: {
            dist: {
                src: './lib/requirejs/require.js',
                dest: './dist/lib/requirejs/require.js'
            }
        },
        browserify: {
            prod: {
                options: {
                    debug: false
                },
                files: {
                    'dist/bundle.min.js': ['./src/main.js']
                }
            },
            dev: {
                options: {
                    debug: true
                },
                files: {
                    'dist/bundle.js': ['./src/main.js']
                }
            },
            src: {
                files: {
                    'dist/bundle.src.js': ['./dist/instrument/src/**/*.js', '!./dist/instrument/src/main.js']
                },
                options: {
                    debug: false,
                    aliasMappings: {
                        cwd: './dist/instrument/src/',      // Src matches are relative to this path.
                        src: ['**/*.js'], // Actual pattern(s) to match.
                        dest: './theapp/',   // Destination path prefix.
                        ext: '.js'   // Dest filepaths will have this extension.
                        // src: ['./dist/instrument/src/**/*.js:theapp/**/*.js']
                    }
                }
            },
            test: {
                options: {
                    debug: false,
                    external: grunt.file.expand('src/**/*').map(function (item) {return item.replace(/\.js$/, '').replace('src/', 'theapp/');})
                },
                files: {
                    'dist/bundle.test.js': ['test/**/*.js']
                }
            }
        },
        instrument: {
            files: ['./src/**/*.js', '!./src/main.js'],
            options: {
                lazy: true,
                basePath: 'dist/instrument/'
            }
        },
        reloadTasks : {
            rootPath : 'dist/instrument/src'
        },
        storeCoverage : {
            options : {
                dir : 'reports'
            }
        },
        makeReport : {
            src : './reports/coverage.json',
            options : {
                type : 'html',
                dir : './reports',
                print : 'detail'
            }
        }
    });

    // These plugins provide necessary tasks.
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-jasmine');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-requirejs');
    grunt.loadNpmTasks('grunt-contrib-htmlmin');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-sass');
    grunt.loadNpmTasks('grunt-contrib-connect');
    grunt.loadNpmTasks('grunt-browserify');
    grunt.loadNpmTasks('grunt-istanbul');

    grunt.registerTask('cover', [ 'instrument', 'browserify:src', 'reloadTasks', 'browserify:test', 'jshint:lenient', 'jasmine:run', 'cleanRunner',
      'storeCoverage', 'makeReport' ]);

    // Default task.
    grunt.registerTask('test', ['browserify:src', 'browserify:test', 'jshint:lenient', 'jasmine:run', 'cleanRunner']);
    grunt.registerTask('lint', ['jshint:strict']);
    grunt.registerTask('build', ['test', 'clean', 'sass:dist', 'requirejs:dist', 'htmlmin:dist', 'uglify:dist', 'miscBuildTasks']);

    grunt.registerTask('cleanRunner', function () {
        var fs = require('fs'),
            done = this.async();
        fs.readFile('specRunner.html', 'utf8', function (err, data) {
            if (err) {
                throw err;
            }
            fs.writeFile('specRunner.html', data.replace('src=".grunt/grunt-contrib-jasmine/dist', 'src="./dist')
                .replace('\'.grunt/grunt-contrib-jasmine/grunt-template-jasmine-istanbul/reporter.js\',\'./.grunt/grunt-contrib-jasmine/reporter.js\'', ''), function (err) {
                if (err) {
                    throw err;
                }
                done();
            });
        });
    });

    grunt.registerTask('miscBuildTasks', function () {
        // copy assets
        grunt.file.recurse('./assets', function (path) {
            if (path.indexOf('DS_Store') === -1) {
                grunt.file.copy(path, './dist/' + path);
            }
        });
    });
    // add to teh build process something that creates a spec file for modules not having one built already and then halts the build

};
<commit_msg>further attempts at integrating istanbul<commit_after>/*global module:false,requirejs:false*/
module.exports = function(grunt) {
    'use strict';

    var allSrcs = ['./Gruntfile.js', './src/**/*.js', './test/**/*.js'];
    // Project configuration.
    grunt.initConfig({

        clean: {
            files: ['dist']
        },

        jshint: {
            options: grunt.file.readJSON('./.jshintrc'),
            lenient: allSrcs,
            strict: {
                files: {
                    src: allSrcs
                },
                options: {
                    unused: true,
                    maxparams: 3
                }
            }
        },

        jasmine: {
            run: {
                src: ['tmp/bundle.src.js'],
                options: {
                    outfile: 'specRunner.html',
                    keepRunner: true,
                    specs: ['dist/bundle.test.js']//,
                    //helpers: ['test/helpers/**/*.js']
                }
            }
        },
        watch: {
            sass: {
                files: ['styles/sass/**/*.scss'],
                tasks: 'sass:dev'
            },
            js: {
                files: ['src/**/*.js'],
                tasks: 'browserify:dev'
            }
        },
        sass: {
            dist: {
                options: {
                    style: 'compressed'
                },
                files: {
                    './dist/styles/css/main.css': './styles/sass/main.scss'
                }
            },
            dev: {
                options: {
                    style: 'expanded'
                },
                files: {
                    './styles/css/main.css': './styles/sass/main.scss'
                }
            }
        },
        htmlmin: {

            dist: {
                options: {                                 // Target options
                    removeComments: true,
                    collapseWhitespace: true
                },
                files: {
                    './dist/index.html': './index.html'
                }
            }
        },
        uglify: {
            dist: {
                src: './lib/requirejs/require.js',
                dest: './dist/lib/requirejs/require.js'
            }
        },
        browserify: {
            prod: {
                options: {
                    debug: false
                },
                files: {
                    'dist/bundle.min.js': ['./src/main.js']
                }
            },
            dev: {
                options: {
                    debug: true
                },
                files: {
                    'dist/bundle.js': ['./src/main.js']
                }
            },
            src: {
                files: {
                    'tmp/bundle.src.js': ['./dist/instrument/src/**/*.js', '!./dist/instrument/src/main.js']
                },
                options: {
                    debug: false,
                    aliasMappings: {
                        cwd: './dist/instrument/src/',      // Src matches are relative to this path.
                        src: ['**/*.js'], // Actual pattern(s) to match.
                        dest: './theapp/',   // Destination path prefix.
                        //ext: '.js'   // Dest filepaths will have this extension.
                        // src: ['./dist/instrument/src/**/*.js:theapp/**/*.js']
                    }
                }
            },
            test: {
                options: {
                    debug: false,
                    external: grunt.file.expand('src/**/*').map(function (item) {return item.replace(/\.js$/, '').replace('src/', 'theapp/');})
                },
                files: {
                    'dist/bundle.test.js': ['test/**/*.js']
                }
            }
        },
        instrument: {
            files: ['./src/**/*.js', '!./src/main.js'],
            options: {
                lazy: false,
                basePath: 'dist/instrument/'
            }
        },
        reloadTasks : {
            rootPath : 'tmp/'
        },
        storeCoverage : {
            options : {
                dir : 'reports/'
            }
        },
        makeReport : {
            src : './reports/coverage.json',
            options : {
                type : 'html',
                dir : './reports',
                print : 'detail'
            }
        }
    });

    // These plugins provide necessary tasks.
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-jasmine');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-requirejs');
    grunt.loadNpmTasks('grunt-contrib-htmlmin');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-sass');
    grunt.loadNpmTasks('grunt-contrib-connect');
    grunt.loadNpmTasks('grunt-browserify');
    grunt.loadNpmTasks('grunt-istanbul');

    grunt.registerTask('cover', [ 'instrument', 'browserify:src', 'browserify:test', 'jshint:lenient', 'coverup']);

    grunt.registerTask('coverup', ['reloadTasks', 'jasmine:run', 'storeCoverage', 'makeReport' ]);

    // Default task.
    grunt.registerTask('test', ['browserify:src', 'browserify:test', 'jshint:lenient', 'jasmine:run', 'cleanRunner']);
    grunt.registerTask('lint', ['jshint:strict']);
    grunt.registerTask('build', ['test', 'clean', 'sass:dist', 'requirejs:dist', 'htmlmin:dist', 'uglify:dist', 'miscBuildTasks']);

    grunt.registerTask('cleanRunner', function () {
        var fs = require('fs'),
            done = this.async();
        fs.readFile('specRunner.html', 'utf8', function (err, data) {
            if (err) {
                throw err;
            }
            fs.writeFile('specRunner.html', data.replace('src=".grunt/grunt-contrib-jasmine/dist', 'src="./dist')
                .replace('\'.grunt/grunt-contrib-jasmine/grunt-template-jasmine-istanbul/reporter.js\',\'./.grunt/grunt-contrib-jasmine/reporter.js\'', ''), function (err) {
                if (err) {
                    throw err;
                }
                done();
            });
        });
    });

    grunt.registerTask('miscBuildTasks', function () {
        // copy assets
        grunt.file.recurse('./assets', function (path) {
            if (path.indexOf('DS_Store') === -1) {
                grunt.file.copy(path, './dist/' + path);
            }
        });
    });
    // add to teh build process something that creates a spec file for modules not having one built already and then halts the build

};
<|endoftext|>


<commit_before>import Class from "./class.js"
import { Pair } from "./pair.js"
import _ from "../deps/underscore-1.10.2-esm.js"

//
// Parser
// copied from jsScheme - should be rewrriten (support #0=, etc)
//
const Parser = Class.create({
  initialize: function(txt){
    this.tokens = this.tokenize(txt);
    this.i = 0;
  },

  inspect: function(){
    return [
      "#<Parser:",
      this.i, "/", this.tokens.length, " ",
      BiwaScheme.inspect(this.tokens),
      ">"
    ].join("");
  },

  tokenize: function(txt) {
    var tokens = new Array(), oldTxt=null;
    var in_srfi_30_comment = 0;

    while( txt != "" && oldTxt != txt ) {
      oldTxt = txt;
      txt = txt.replace( /^\s*(;[^\r\n]*(\r|\n|$)|#;|#\||#\\[^\w]|#?(\(|\[|{)|\)|\]|}|\'|`|,@|,|\+inf\.0|-inf\.0|\+nan\.0|\"(\\(.|$)|[^\"\\])*(\"|$)|[^\s()\[\]{}]+)/,
      function($0,$1) {
        var t = $1;

        if (t == "#|") {
          in_srfi_30_comment++;
          return "";
        }
        else if (in_srfi_30_comment > 0) {
          if ( /(.*\|#)/.test(t) ) {
            in_srfi_30_comment--;
            if (in_srfi_30_comment < 0) {
              throw new BiwaScheme.Error("Found an extra comment terminator: `|#'")
            }
            // Push back the rest substring to input stream.
            return t.substring(RegExp.$1.length, t.length);
          }
          else {
            return "";
          }
        }
        else {
          if( t.charAt(0) != ';' ) tokens[tokens.length]=t;
          return "";
        }
      } );
    }
    return tokens;
  },

  sexpCommentMarker: new Object,
  getObject: function() {
    var r = this.getObject0();

    if (r != this.sexpCommentMarker)
      return r;

    r = this.getObject();
    if (r == BiwaScheme.Parser.EOS)
      throw new BiwaScheme.Error("Readable object not found after S exression comment");

    r = this.getObject();
    return r;
  },

  getList: function( close ) {
    var list = BiwaScheme.nil, prev = list;
    while( this.i < this.tokens.length ) {

      this.eatObjectsInSexpComment("Input stream terminated unexpectedly(in list)");

      if( this.tokens[ this.i ] == ')' || this.tokens[ this.i ] == ']' || this.tokens[ this.i ] == '}' ) {
        this.i++; break;
      }

      if( this.tokens[ this.i ] == '.' ) {
        this.i++;
        var o = this.getObject();
        if( o != BiwaScheme.Parser.EOS && list != BiwaScheme.nil ) {
          prev.cdr = o;
        }
      } else {
          var cur = new BiwaScheme.Pair( this.getObject(), BiwaScheme.nil);
          if( list == BiwaScheme.nil ) list = cur;
          else prev.cdr = cur;
          prev = cur;
      }
    }
    return list;
  },

  getVector: function( close ) {
    var arr = new Array();
    while( this.i < this.tokens.length ) {

      this.eatObjectsInSexpComment("Input stream terminated unexpectedly(in vector)");

      if( this.tokens[ this.i ] == ')' ||
      this.tokens[ this.i ] == ']' ||
      this.tokens[ this.i ] == '}' ) { this.i++; break; }
      arr[ arr.length ] = this.getObject();
    }
    return arr;
  },

  eatObjectsInSexpComment: function(err_msg) {
    while( this.tokens[ this.i ] == '#;' ) {
      this.i++;
      if ((this.getObject() == BiwaScheme.Parser.EOS) || (this.i >= this.tokens.length))
        throw new BiwaScheme.Error(err_msg);
    }
  },

  getObject0: function() {
    if( this.i >= this.tokens.length )
      return BiwaScheme.Parser.EOS;

    var t = this.tokens[ this.i++ ];
    // if( t == ')' ) return null;

    if (t == '#;')
      return this.sexpCommentMarker;

    var s = t == "'"  ? 'quote' :
            t == "`"  ? 'quasiquote' :
            t == ","  ? 'unquote' :
            t == ",@" ? 'unquote-splicing' : false;

    if( s || t == '(' || t == '#(' || t == '[' || t == '#[' || t == '{' || t == '#{' ) {
      return s ? new BiwaScheme.Pair( BiwaScheme.Sym(s), new BiwaScheme.Pair( this.getObject(), BiwaScheme.nil ))
      : (t=='(' || t=='[' || t=='{') ? this.getList(t) : this.getVector(t);
    }
    else {
      switch(t){
        case "+inf.0" : return Infinity;
        case "-inf.0" : return -Infinity;
        case "+nan.0" : return NaN;
      }

      var n;
      if( /^#x[0-9a-z]+$/i.test(t) ) {  // #x... Hex
        n = new Number('0x'+t.substring(2,t.length) );
      }
      else if( /^#d[0-9\.]+$/i.test(t) ) {  // #d... Decimal
        n = new Number( t.substring(2,t.length) );
      }
      else{
        n = new Number(t);  // use constrictor as parser
      }

      if( ! isNaN(n) ) {
        return n.valueOf();
      } else if( t == '#f' || t == '#F' ) {
        return false;
      } else if( t == '#t' || t == '#T' ) {
        return true;
      } else if( t.toLowerCase() == '#\\newline' ) {
        return BiwaScheme.Char.get('\n');
      } else if( t.toLowerCase() == '#\\space' ) {
        return BiwaScheme.Char.get(' ');
      } else if( t.toLowerCase() == '#\\tab' ) {
        return BiwaScheme.Char.get('\t');
      } else if( /^#\\.$/.test(t) ) {
        return BiwaScheme.Char.get( t.charAt(2) );
      } else if( /^#\\x[a-zA-Z0-9]+$/.test(t) ) {
        var scalar = parseInt(t.slice(3), 16);
        // R6RS 11.11 (surrogate codepoints)
        if (scalar >= 0xD800 && scalar <= 0xDFFF) {
          throw new BiwaScheme.Error("Character in Unicode excluded range.");
        }
        // ECMA-262 4.3.16 -- Basically, strings are sequences of 16-bit
        // unsigned integers, so anything greater than 0xFFFF won't fit.
        // NOTE: This violates R6RS which requires the full Unicode range!
        else if (scalar > 0xFFFF) {
          throw new BiwaScheme.Error("Character literal out of range.");
        } else {
          return BiwaScheme.Char.get(String.fromCharCode(scalar));
        }
      } else if( /^\"(\\(.|$)|[^\"\\])*\"?$/.test(t) ) {
        return t.replace(/(\r?\n|\\n)/g, "\n").replace( /^\"|\\(.|$)|\"$/g, function($0,$1) {
          return $1 ? $1 : '';
        } );
      } else return BiwaScheme.Sym(t);  // 2Do: validate !!
    }
  }
});
// indicates end of source file
Parser.EOS = new Object();

export default Parser;
<commit_msg>feat(parser): esmfy<commit_after>import _ from "../deps/underscore-1.10.2-esm.js"
import { nil } from "../header.js"
import { inspect } from "./_writer.js"
import Char from "./char.js"
import Class from "./class.js"
import { BiwaError } from "./error.js"
import { Pair } from "./pair.js"
import { Sym } from "./symbol.js"

//
// Parser
// copied from jsScheme - should be rewrriten (support #0=, etc)
//
const Parser = Class.create({
  initialize: function(txt){
    this.tokens = this.tokenize(txt);
    this.i = 0;
  },

  inspect: function(){
    return [
      "#<Parser:",
      this.i, "/", this.tokens.length, " ",
      inspect(this.tokens),
      ">"
    ].join("");
  },

  tokenize: function(txt) {
    var tokens = new Array(), oldTxt=null;
    var in_srfi_30_comment = 0;

    while( txt != "" && oldTxt != txt ) {
      oldTxt = txt;
      txt = txt.replace( /^\s*(;[^\r\n]*(\r|\n|$)|#;|#\||#\\[^\w]|#?(\(|\[|{)|\)|\]|}|\'|`|,@|,|\+inf\.0|-inf\.0|\+nan\.0|\"(\\(.|$)|[^\"\\])*(\"|$)|[^\s()\[\]{}]+)/,
      function($0,$1) {
        var t = $1;

        if (t == "#|") {
          in_srfi_30_comment++;
          return "";
        }
        else if (in_srfi_30_comment > 0) {
          if ( /(.*\|#)/.test(t) ) {
            in_srfi_30_comment--;
            if (in_srfi_30_comment < 0) {
              throw new BiwaError("Found an extra comment terminator: `|#'")
            }
            // Push back the rest substring to input stream.
            return t.substring(RegExp.$1.length, t.length);
          }
          else {
            return "";
          }
        }
        else {
          if( t.charAt(0) != ';' ) tokens[tokens.length]=t;
          return "";
        }
      } );
    }
    return tokens;
  },

  sexpCommentMarker: new Object,
  getObject: function() {
    var r = this.getObject0();

    if (r != this.sexpCommentMarker)
      return r;

    r = this.getObject();
    if (r == Parser.EOS)
      throw new BiwaError("Readable object not found after S exression comment");

    r = this.getObject();
    return r;
  },

  getList: function( close ) {
    var list = nil, prev = list;
    while( this.i < this.tokens.length ) {

      this.eatObjectsInSexpComment("Input stream terminated unexpectedly(in list)");

      if( this.tokens[ this.i ] == ')' || this.tokens[ this.i ] == ']' || this.tokens[ this.i ] == '}' ) {
        this.i++; break;
      }

      if( this.tokens[ this.i ] == '.' ) {
        this.i++;
        var o = this.getObject();
        if( o != Parser.EOS && list != nil ) {
          prev.cdr = o;
        }
      } else {
          var cur = new Pair( this.getObject(), nil);
          if( list == nil ) list = cur;
          else prev.cdr = cur;
          prev = cur;
      }
    }
    return list;
  },

  getVector: function( close ) {
    var arr = new Array();
    while( this.i < this.tokens.length ) {

      this.eatObjectsInSexpComment("Input stream terminated unexpectedly(in vector)");

      if( this.tokens[ this.i ] == ')' ||
      this.tokens[ this.i ] == ']' ||
      this.tokens[ this.i ] == '}' ) { this.i++; break; }
      arr[ arr.length ] = this.getObject();
    }
    return arr;
  },

  eatObjectsInSexpComment: function(err_msg) {
    while( this.tokens[ this.i ] == '#;' ) {
      this.i++;
      if ((this.getObject() == Parser.EOS) || (this.i >= this.tokens.length))
        throw new BiwaError(err_msg);
    }
  },

  getObject0: function() {
    if( this.i >= this.tokens.length )
      return Parser.EOS;

    var t = this.tokens[ this.i++ ];
    // if( t == ')' ) return null;

    if (t == '#;')
      return this.sexpCommentMarker;

    var s = t == "'"  ? 'quote' :
            t == "`"  ? 'quasiquote' :
            t == ","  ? 'unquote' :
            t == ",@" ? 'unquote-splicing' : false;

    if( s || t == '(' || t == '#(' || t == '[' || t == '#[' || t == '{' || t == '#{' ) {
      return s ? new Pair(Sym(s), new Pair( this.getObject(), nil ))
      : (t=='(' || t=='[' || t=='{') ? this.getList(t) : this.getVector(t);
    }
    else {
      switch(t){
        case "+inf.0" : return Infinity;
        case "-inf.0" : return -Infinity;
        case "+nan.0" : return NaN;
      }

      var n;
      if( /^#x[0-9a-z]+$/i.test(t) ) {  // #x... Hex
        n = new Number('0x'+t.substring(2,t.length) );
      }
      else if( /^#d[0-9\.]+$/i.test(t) ) {  // #d... Decimal
        n = new Number( t.substring(2,t.length) );
      }
      else{
        n = new Number(t);  // use constrictor as parser
      }

      if( ! isNaN(n) ) {
        return n.valueOf();
      } else if( t == '#f' || t == '#F' ) {
        return false;
      } else if( t == '#t' || t == '#T' ) {
        return true;
      } else if( t.toLowerCase() == '#\\newline' ) {
        return Char.get('\n');
      } else if( t.toLowerCase() == '#\\space' ) {
        return Char.get(' ');
      } else if( t.toLowerCase() == '#\\tab' ) {
        return Char.get('\t');
      } else if( /^#\\.$/.test(t) ) {
        return Char.get( t.charAt(2) );
      } else if( /^#\\x[a-zA-Z0-9]+$/.test(t) ) {
        var scalar = parseInt(t.slice(3), 16);
        // R6RS 11.11 (surrogate codepoints)
        if (scalar >= 0xD800 && scalar <= 0xDFFF) {
          throw new BiwaError("Character in Unicode excluded range.");
        }
        // ECMA-262 4.3.16 -- Basically, strings are sequences of 16-bit
        // unsigned integers, so anything greater than 0xFFFF won't fit.
        // NOTE: This violates R6RS which requires the full Unicode range!
        else if (scalar > 0xFFFF) {
          throw new BiwaError("Character literal out of range.");
        } else {
          return Char.get(String.fromCharCode(scalar));
        }
      } else if( /^\"(\\(.|$)|[^\"\\])*\"?$/.test(t) ) {
        return t.replace(/(\r?\n|\\n)/g, "\n").replace( /^\"|\\(.|$)|\"$/g, function($0,$1) {
          return $1 ? $1 : '';
        } );
      } else return Sym(t);  // 2Do: validate !!
    }
  }
});
// indicates end of source file
Parser.EOS = new Object();

export default Parser;
<|endoftext|>


<commit_before>'use strict';
var LIVERELOAD_PORT = 35729;
var lrSnippet = require('connect-livereload')({ port: LIVERELOAD_PORT });

var mountFolder = function (connect, dir) {
  return connect.static(require('path').resolve(dir));
};

module.exports = function (grunt) {
  // load all grunt tasks
  require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
  grunt.loadNpmTasks('assemble');

  // configurable paths
  var config = {
    app: 'app',
    dist: 'public',
    tests: 'tests'
  };

  grunt.initConfig({
    config: config,
    watch: {
      grunt: {
        files: ['Gruntfile.js'],
        options: { reload: true }
      },
      assemble: {
        files: [ '<%= config.app %>/templates/{,*/}*.{hbs,html}' ],
        tasks: [ 'assemble:server' ]
      },
      sass: {
        files: [ '<%= config.app %>/styles/{,*/}*.{scss,sass}' ],
        tasks: [ 'sass:server' ]
      },
      livereload: {
        options: {
          livereload: LIVERELOAD_PORT
        },
        files: [
          '{.tmp,<%= config.app %>/views}/{,*/}*.html',
          '{.tmp,<%= config.app %>}/styles/{,*/}*.css',
          '{.tmp,<%= config.app %>}/scripts/{,*/}*.js',
          '<%= config.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
        ]
      }
    },
    connect: {
      options: {
        port: 9000,
        // Change this to '0.0.0.0' to access the server from outside.
        hostname: '0.0.0.0'
      },
      livereload: {
        options: {
          middleware: function (connect) {
            return [
              lrSnippet,
              mountFolder(connect, '.tmp'),
              mountFolder(connect, config.app),
              mountFolder(connect, config.tests)
            ];
          }
        }
      },
// 			test: {
// 				options: {
// 					middleware: function (connect) {
// 						return [
// 							mountFolder(connect, '.tmp'),
// 							mountFolder(connect, 'test')
// 						];
// 					}
// 				}
// 			},
      dist: {
        options: {
          middleware: function (connect) {
            return [
              mountFolder(connect, config.dist)
            ];
          }
        }
      }
    },
    clean: {
      dist: {
        files: [{
          expand: true,
          dot: true,
          cwd: '<%= config.dist %>',
          src: [
            '*'
          ]
        }]
      },
      server: '.tmp',
      test: [
        '<%= config.tests %>/media/themes',
        '<%= config.tests %>/media/themes-diff'
      ]
    },
    jshint: {
      options: {
        jshintrc: '.jshintrc'
      },
      all: [
        'Gruntfile.js',
        '<%= config.app %>/scripts/{,*/}*.js'
      ]
    },
    assemble: {
      options: {
        layoutdir: '<%= config.app %>/templates/layouts',
        partials: [
          '<%= config.app %>/templates/partials/**/*.html'
        ]
      },
      server: {
        options: {
          collections: [{
            name: 'posted',
            inflection: 'post',
            sortby: 'posted',
            sortorder: 'descending'
          }]
        },
        files: [{
          expand: true,
          cwd: '<%= config.app %>/templates',
          src: '**/*.hbs',
          dest: '.tmp'
        }]
      },
      dist: {
        options: {
          collections: [{
            name: 'posted',
            inflection: 'post',
            sortby: 'posted',
            sortorder: 'descending'
          }]
        },
        files: [{
          expand: true,
          cwd: '<%= config.app %>/templates',
          src: '**/*.hbs',
          dest: '<%= config.dist %>'
        }]
      }
    },
    sass: {
      dist: {
        files: {
          '.tmp/styles/main.css': '<%= config.app %>/styles/main.scss'
        }
      },
      server: {
        files: {
          '.tmp/styles/main.css': '<%= config.app %>/styles/main.scss'
        }
      }
    },
    rev: {
      dist: {
        files: {
          src: [
            '<%= config.dist %>/scripts/{,*/}*.js',
            '<%= config.dist %>/styles/{,*/}*.css',
            '<%= config.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
            '<%= config.dist %>/styles/fonts/*'
          ]
        }
      }
    },
    useminPrepare: {
      html: [
        //'<%= config.dist %>/{,*/}*.{html,hbs}'
        '<%= config.dist %>/{,*/}index.html'
      ],
      options: {
        dest: '<%= config.dist %>'
      }
    },
    usemin: {
      html: ['<%= config.dist %>/{,*/}*.html'],
      css: ['<%= config.dist %>/styles/{,*/}*.css'],
      js: ['<%= config.dist %>/scripts/*.js'],
      options: {
        assetsDirs: [
          '<%= config.dist %>',
          '<%= config.dist %>/images'
        ],
        patterns: {
          js: [
            [/(images\/.*?\.(?:gif|jpeg|jpg|png|webp|svg))/gm]
          ]
        }
      }
    },
    htmlmin: {
      dist: {
        files: [{
          expand: true,
          cwd: '<%= config.dist %>',
          src: ['*.html', 'views/*.html'],
          dest: '<%= config.dist %>'
        }]
      }
    },
    copy: {
      dev: {
        files: [{
          expand: true,
          dot: true,
          cwd: '<%= config.app %>/dev',
          dest: '<%= config.dist %>',
          src: [
            'CNAME',
            '*.*'
          ]
        }]
      },
      dist: {
        files: [{
          expand: true,
          dot: true,
          cwd: '<%= config.app %>',
          dest: '<%= config.dist %>',
          src: [
            'CNAME',
            '*.*',
            //'bower_components/**/*',
            'bower_components/font-awesome/**/*',
            'images/{,*/}*.*',
            'styles/fonts/*'
          ]
        }, {
          expand: true,
          cwd: '.tmp/images',
          dest: '<%= config.dist %>/images',
          src: [
            'generated/*'
          ]
        }]
      }
    },
    karma: {
      unit: {
        configFile: 'tests/karma.conf.js',
        singleRun: true
      }
    },
    ngtemplates: {
      dist: {
        options: {
          usemin: '<%= config.dist %>/scripts/app.js',
          module: 'businessCardMaker'
        },
        cwd: '<%= config.app %>',
        src: 'views/{,*/}*.html',
        dest: '.tmp/scripts/templates.js'
      }
    },
    ngAnnotate: {
      dist: {
        files: [{
          expand: true,
          cwd: '.tmp/concat/scripts',
          src: '*.js',
          dest: '.tmp/concat/scripts'
        }]
      }
    },
    uglify: {
      options: {
        compress: {
          drop_console: true
        }
      }
    },
    protractor: {
      options: {
        keepAlive: false,
        configFile: 'tests/protractor.conf.js'
      },
      themes: {
        options: {
          args: {
            specs: [
              'tests/e2e/themes.spec.js'
            ]
          }
        }
      }
    },
    execute: {
      themes: {
        src: [ 'tests/themes/themes-diff.js' ]
      }
    },
    'ftp-deploy': {
      development: {
        auth: {
          host: 'server134.web-hosting.com',
          authPath: 'deploy.json',
          authKey: 'namecheap'
        },
        src: '<%= config.dist %>',
        dest: './releases/development/'
      },
      staging: {
        auth: {
          host: 'server134.web-hosting.com',
          authPath: 'deploy.json',
          authKey: 'namecheap'
        },
        src: '<%= config.dist %>',
        dest: './releases/staging/'
      },
      www: {
        auth: {
          host: 'server134.web-hosting.com',
          authPath: 'deploy.json',
          authKey: 'namecheap'
        },
        src: '<%= config.dist %>',
        dest: './releases/www/'
      }
    }
  });

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

    grunt.task.run([
      'clean:server',
      'sass:server',
      'assemble:server',
      'connect:livereload',
      'watch'
    ]);

  });

// 	grunt.registerTask('test', [
// 		'clean:server',
// 		'concurrent:test',
// 		'connect:test',
// 		'karma'
// 	]);

  grunt.registerTask('build', [
    'clean:dist',
    'sass:dist',
    'assemble:dist',
    'htmlmin',
    'useminPrepare',
    'ngtemplates',
    'copy:dist',
    'concat',
    'ngAnnotate',
    'cssmin',
    'uglify',
    'rev',
    'usemin'
  ]);

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

  grunt.registerTask('test', function(target) {

    grunt.task.run([
      'default',
      'connect:dist',
      'clean:test',
      'protractor:themes',
      'execute:themes'
    ]);

  });

  var deployConfig = grunt.file.readJSON('deploy.json');

  var purgeCloudflareCache = function() {

    var done = this.async();

    var https = require('https');
    var querystring = require('querystring');

    // Build the post string from an object
    var postData = querystring.stringify({
      tkn: deployConfig.cloudflare.key,
      email: deployConfig.cloudflare.email,
      a: 'fpurge_ts',
      v: 1,
      z: 'bizcardmaker.com'
    });

    // An object of options to indicate where to post to
    var post_options = {
        host: 'www.cloudflare.com',
        path: '/api_json.html',
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Content-Length': postData.length
        }
    };

    // Set up the request
    var postReq = https.request(post_options, function(res) {

      res.setEncoding('utf8');
      res.on('data', function (chunk) {
        console.log(chunk);
        done();
      });

    });

    // post the data
    postReq.write(postData);
    postReq.end();

  };

  grunt.registerTask('cloudflare', purgeCloudflareCache);

  grunt.registerTask('deploy', function (target) {

    if (target === 'live') {
      return grunt.task.run([
        'test',
        'ftp-deploy:www',
        'cloudflare'
      ]);
    }

    grunt.task.run([
      'test',
      'copy:dev',
      'ftp-deploy:development',
      'ftp-deploy:staging',
      'cloudflare'
    ]);

  });

};
<commit_msg>Temporarily disable the theme testing, because protractor is acting up.<commit_after>'use strict';
var LIVERELOAD_PORT = 35729;
var lrSnippet = require('connect-livereload')({ port: LIVERELOAD_PORT });

var mountFolder = function (connect, dir) {
  return connect.static(require('path').resolve(dir));
};

module.exports = function (grunt) {
  // load all grunt tasks
  require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
  grunt.loadNpmTasks('assemble');

  // configurable paths
  var config = {
    app: 'app',
    dist: 'public',
    tests: 'tests'
  };

  grunt.initConfig({
    config: config,
    watch: {
      grunt: {
        files: ['Gruntfile.js'],
        options: { reload: true }
      },
      assemble: {
        files: [ '<%= config.app %>/templates/{,*/}*.{hbs,html}' ],
        tasks: [ 'assemble:server' ]
      },
      sass: {
        files: [ '<%= config.app %>/styles/{,*/}*.{scss,sass}' ],
        tasks: [ 'sass:server' ]
      },
      livereload: {
        options: {
          livereload: LIVERELOAD_PORT
        },
        files: [
          '{.tmp,<%= config.app %>/views}/{,*/}*.html',
          '{.tmp,<%= config.app %>}/styles/{,*/}*.css',
          '{.tmp,<%= config.app %>}/scripts/{,*/}*.js',
          '<%= config.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
        ]
      }
    },
    connect: {
      options: {
        port: 9000,
        // Change this to '0.0.0.0' to access the server from outside.
        hostname: '0.0.0.0'
      },
      livereload: {
        options: {
          middleware: function (connect) {
            return [
              lrSnippet,
              mountFolder(connect, '.tmp'),
              mountFolder(connect, config.app),
              mountFolder(connect, config.tests)
            ];
          }
        }
      },
// 			test: {
// 				options: {
// 					middleware: function (connect) {
// 						return [
// 							mountFolder(connect, '.tmp'),
// 							mountFolder(connect, 'test')
// 						];
// 					}
// 				}
// 			},
      dist: {
        options: {
          middleware: function (connect) {
            return [
              mountFolder(connect, config.dist)
            ];
          }
        }
      }
    },
    clean: {
      dist: {
        files: [{
          expand: true,
          dot: true,
          cwd: '<%= config.dist %>',
          src: [
            '*'
          ]
        }]
      },
      server: '.tmp',
      test: [
        '<%= config.tests %>/media/themes',
        '<%= config.tests %>/media/themes-diff'
      ]
    },
    jshint: {
      options: {
        jshintrc: '.jshintrc'
      },
      all: [
        'Gruntfile.js',
        '<%= config.app %>/scripts/{,*/}*.js'
      ]
    },
    assemble: {
      options: {
        layoutdir: '<%= config.app %>/templates/layouts',
        partials: [
          '<%= config.app %>/templates/partials/**/*.html'
        ]
      },
      server: {
        options: {
          collections: [{
            name: 'posted',
            inflection: 'post',
            sortby: 'posted',
            sortorder: 'descending'
          }]
        },
        files: [{
          expand: true,
          cwd: '<%= config.app %>/templates',
          src: '**/*.hbs',
          dest: '.tmp'
        }]
      },
      dist: {
        options: {
          collections: [{
            name: 'posted',
            inflection: 'post',
            sortby: 'posted',
            sortorder: 'descending'
          }]
        },
        files: [{
          expand: true,
          cwd: '<%= config.app %>/templates',
          src: '**/*.hbs',
          dest: '<%= config.dist %>'
        }]
      }
    },
    sass: {
      dist: {
        files: {
          '.tmp/styles/main.css': '<%= config.app %>/styles/main.scss'
        }
      },
      server: {
        files: {
          '.tmp/styles/main.css': '<%= config.app %>/styles/main.scss'
        }
      }
    },
    rev: {
      dist: {
        files: {
          src: [
            '<%= config.dist %>/scripts/{,*/}*.js',
            '<%= config.dist %>/styles/{,*/}*.css',
            '<%= config.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
            '<%= config.dist %>/styles/fonts/*'
          ]
        }
      }
    },
    useminPrepare: {
      html: [
        //'<%= config.dist %>/{,*/}*.{html,hbs}'
        '<%= config.dist %>/{,*/}index.html'
      ],
      options: {
        dest: '<%= config.dist %>'
      }
    },
    usemin: {
      html: ['<%= config.dist %>/{,*/}*.html'],
      css: ['<%= config.dist %>/styles/{,*/}*.css'],
      js: ['<%= config.dist %>/scripts/*.js'],
      options: {
        assetsDirs: [
          '<%= config.dist %>',
          '<%= config.dist %>/images'
        ],
        patterns: {
          js: [
            [/(images\/.*?\.(?:gif|jpeg|jpg|png|webp|svg))/gm]
          ]
        }
      }
    },
    htmlmin: {
      dist: {
        files: [{
          expand: true,
          cwd: '<%= config.dist %>',
          src: ['*.html', 'views/*.html'],
          dest: '<%= config.dist %>'
        }]
      }
    },
    copy: {
      dev: {
        files: [{
          expand: true,
          dot: true,
          cwd: '<%= config.app %>/dev',
          dest: '<%= config.dist %>',
          src: [
            'CNAME',
            '*.*'
          ]
        }]
      },
      dist: {
        files: [{
          expand: true,
          dot: true,
          cwd: '<%= config.app %>',
          dest: '<%= config.dist %>',
          src: [
            'CNAME',
            '*.*',
            //'bower_components/**/*',
            'bower_components/font-awesome/**/*',
            'images/{,*/}*.*',
            'styles/fonts/*'
          ]
        }, {
          expand: true,
          cwd: '.tmp/images',
          dest: '<%= config.dist %>/images',
          src: [
            'generated/*'
          ]
        }]
      }
    },
    karma: {
      unit: {
        configFile: 'tests/karma.conf.js',
        singleRun: true
      }
    },
    ngtemplates: {
      dist: {
        options: {
          usemin: '<%= config.dist %>/scripts/app.js',
          module: 'businessCardMaker'
        },
        cwd: '<%= config.app %>',
        src: 'views/{,*/}*.html',
        dest: '.tmp/scripts/templates.js'
      }
    },
    ngAnnotate: {
      dist: {
        files: [{
          expand: true,
          cwd: '.tmp/concat/scripts',
          src: '*.js',
          dest: '.tmp/concat/scripts'
        }]
      }
    },
    uglify: {
      options: {
        compress: {
          drop_console: true
        }
      }
    },
    protractor: {
      options: {
        keepAlive: false,
        configFile: 'tests/protractor.conf.js'
      },
      themes: {
        options: {
          args: {
            specs: [
              'tests/e2e/themes.spec.js'
            ]
          }
        }
      }
    },
    execute: {
      themes: {
        src: [ 'tests/themes/themes-diff.js' ]
      }
    },
    'ftp-deploy': {
      development: {
        auth: {
          host: 'server134.web-hosting.com',
          authPath: 'deploy.json',
          authKey: 'namecheap'
        },
        src: '<%= config.dist %>',
        dest: './releases/development/'
      },
      staging: {
        auth: {
          host: 'server134.web-hosting.com',
          authPath: 'deploy.json',
          authKey: 'namecheap'
        },
        src: '<%= config.dist %>',
        dest: './releases/staging/'
      },
      www: {
        auth: {
          host: 'server134.web-hosting.com',
          authPath: 'deploy.json',
          authKey: 'namecheap'
        },
        src: '<%= config.dist %>',
        dest: './releases/www/'
      }
    }
  });

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

    grunt.task.run([
      'clean:server',
      'sass:server',
      'assemble:server',
      'connect:livereload',
      'watch'
    ]);

  });

// 	grunt.registerTask('test', [
// 		'clean:server',
// 		'concurrent:test',
// 		'connect:test',
// 		'karma'
// 	]);

  grunt.registerTask('build', [
    'clean:dist',
    'sass:dist',
    'assemble:dist',
    'htmlmin',
    'useminPrepare',
    'ngtemplates',
    'copy:dist',
    'concat',
    'ngAnnotate',
    'cssmin',
    'uglify',
    'rev',
    'usemin'
  ]);

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

  grunt.registerTask('test', function(target) {

    grunt.task.run([
      'default',
      'connect:dist',
      'clean:test',
      'protractor:themes',
      'execute:themes'
    ]);

  });

  var deployConfig = grunt.file.readJSON('deploy.json');

  var purgeCloudflareCache = function() {

    var done = this.async();

    var https = require('https');
    var querystring = require('querystring');

    // Build the post string from an object
    var postData = querystring.stringify({
      tkn: deployConfig.cloudflare.key,
      email: deployConfig.cloudflare.email,
      a: 'fpurge_ts',
      v: 1,
      z: 'bizcardmaker.com'
    });

    // An object of options to indicate where to post to
    var post_options = {
        host: 'www.cloudflare.com',
        path: '/api_json.html',
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Content-Length': postData.length
        }
    };

    // Set up the request
    var postReq = https.request(post_options, function(res) {

      res.setEncoding('utf8');
      res.on('data', function (chunk) {
        console.log(chunk);
        done();
      });

    });

    // post the data
    postReq.write(postData);
    postReq.end();

  };

  grunt.registerTask('cloudflare', purgeCloudflareCache);

  grunt.registerTask('deploy', function (target) {

    if (target === 'live') {
      return grunt.task.run([
        //'test',
        'default',

        'ftp-deploy:www',
        'cloudflare'
      ]);
    }

    grunt.task.run([
      //'test',
      'default',

      'copy:dev',
      'ftp-deploy:development',
      'ftp-deploy:staging',
      'cloudflare'
    ]);

  });

};
<|endoftext|>