<commit_before>/* File: GruntFile.js
 *
 * Copyright (c) 2014
 * Centre National d’Enseignement à Distance (Cned), Boulevard Nicephore Niepce, 86360 CHASSENEUIL-DU-POITOU, France
 * (direction-innovation@cned.fr)
 *
 * GNU Affero General Public License (AGPL) version 3.0 or later version
 *
 * This file is part of a program which is free software: you can
 * redistribute it and/or modify it under the terms of the
 * GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this program.
 * If not, see <http://www.gnu.org/licenses/>.
 *
 */

'use strict';

var path = require('path');

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

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

    try {
        yeomanConfig.app = require('./bower.json').appPath || yeomanConfig.app;
    } catch (e) {}

    grunt.initConfig({
        yeoman: yeomanConfig,
        watch: {
            main: {
                files: ['app/**/*.{html,css,png,jpeg,GIF,jpg,eot,svg,ttf,woff}'],
            },
            options: {
                livereload: true/*,
                port: 3000,
                key: grunt.file.read('../sslcert/key.pem'),
                cert: grunt.file.read('../sslcert/cert.pem')*/
            }
        },
        express: {
            options: {
                hostname: '0.0.0.0'
            },
            livereload: {
                options: {
                    server: path.resolve('./app.js'),
                    livereload: false,
                    serverreload: false,
                    bases: [path.resolve('./.tmp'), path.resolve(__dirname, yeomanConfig.app)],
                    spawn: false
                }
            },
            test: {
                options: {
                    server: path.resolve('./app.js'),
                    bases: [path.resolve('./.tmp'), path.resolve(__dirname, 'test')]
                }
            },
            dist: {
                options: {
                    server: path.resolve('./app.js'),
                    bases: path.resolve(__dirname, yeomanConfig.dist)
                }
            },
            server: {
                options: {
                    port: 80
                }
            }
        },
        open: {
            server: {
                url: 'http://localhost:<%= express.options.port %>'
            }
        },
        clean: {
            dist: {
                files: [{
                    dot: true,
                    src: [
                        '.tmp',
                        '<%= yeoman.dist %>/*',
                        '<%= yeoman.generated %>/*',
                        '!<%= yeoman.dist %>/.git*']
                }]
            },
            server: '.tmp'
        },
        jshint: {
            options: {
                jshintrc: '.jshintrc',
                reporter: 'checkstyle',
                reporterOutput: 'generated/jshint/resultJSHint.xml'
            },
            all: {
                src: ['Gruntfile.js', 'app/scripts/**/*.js', 'api/**/*.js', 'test/spec/**/*.js']
            }
        },
        rev: {
            dist: {
                files: {
                    src: [
                        '<%= yeoman.dist %>/scripts/{,*/}*.js',
                        '<%= yeoman.dist %>/styles/{,*/}*.css',
                        '<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
                        '<%= yeoman.dist %>/styles/fonts/*']
                }
            }
        },
        useminPrepare: {
            html: '<%= yeoman.app %>/index.html',
            options: {
                dest: '<%= yeoman.dist %>'
            }
        },
        usemin: {
            html: ['<%= yeoman.dist %>/{,*/}*.html'],
            css: ['<%= yeoman.dist %>/styles/{,*/}*.css'],
            options: {
                dirs: ['<%= yeoman.dist %>']
            }
        },
        imagemin: {
            dist: {
                files: [{
                    expand: true,
                    cwd: '<%= yeoman.app %>/images',
                    src: '{,*/}*.{png,jpg,jpeg}',
                    dest: '<%= yeoman.dist %>/images'
                }]
            }
        },
        svgmin: {
            dist: {
                files: [{
                    expand: true,
                    cwd: '<%= yeoman.app %>/images',
                    src: '{,*/}*.svg',
                    dest: '<%= yeoman.dist %>/images'
                }]
            }
        },
        cssmin: {
            // By default, your `index.html` <!-- Usemin Block --> will take care of
            // minification. This option is pre-configured if you do not wish to use
            // Usemin blocks.
            // 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', 'views/*.html'],
                    dest: '<%= yeoman.dist %>'
                }]
            }
        },
        copy: {
            dist: {
                files: [{
                    expand: true,
                    dot: true,
                    cwd: '<%= yeoman.app %>',
                    dest: '<%= yeoman.dist %>',
                    src: [
                        'app/**/*.{html,css,png,jpeg,GIF,jpg,eot,svg,ttf,woff}',
                        'app/bower_components/**/*.js',
                        'api/**/*',
                        'models/**/*',
                        'routes/**/*',
                        'custom_node_modules/**',
                        'app.js',
                        'Gruntfile.js',
                        'package.json',
                        'files/**/**/**',
                        'po/**']
                }, {
                    expand: true,
                    cwd: '<%= yeoman.app %>',
                    dest: '<%= yeoman.dist %>',
                    src: ['env/config.<%= [NODE_ENV] %>.json'],
                    rename: function(dest, src) {
                        return dest + '/env/config.json';
                    }
                }, {
                    expand: true,
                    cwd: '.tmp/images',
                    dest: '<%= yeoman.dist %>/images',
                    src: [
                        'generated/*']
                }]
            }
        },
        concurrent: {
            dist: [
                'imagemin',
                'svgmin']
        },
        ngmin: {
            controllers: {
                expand: true,
                cwd: 'app',
                src: ['scripts/**/*.js'],
                dest: 'generated/'
            }
        },
        uglify: {
            build: {
                src: ' <%= yeoman.generated %>/scripts/**/*.js',
                dest: '<%= yeoman.dist %>/app/scripts/front.js'
            }
        },
        karma: {
            unit: {
                configFile: 'karma.conf.js',
                singleRun: true
            }
        },
        cdnify: {
            dist: {
                html: ['<%= yeoman.dist %>/*.html']
            }
        },
        nggettext_extract: {
            pot: {
                files: {
                    'po/template.pot': ['app/views/**/*.html']
                }
            }
        },
        nggettext_compile: {
            all: {
                files: {
                    'app/scripts/translations.js': ['po/*.po']
                }
            }
        },
        /**
         * Specification de chaque configuration d'un ENV comme task
         */
        env: {
            dev: {
                src: 'env/config.json'
            },
            test: {
                src: 'env/config.test.json'
            },
            integ: {
                src: 'env/config.integ.json'
            },
            recette: {
                src: 'env/config.recette.json'
            },
            prod: {
                src: 'env/config.prod.json'
            }
        },
        /**
         *  Generation des fichiers avec
         *  des liens absoluts selon l'environnement
         */
        template: {
            'generate-from-tpl': {
                options: {
                    data: {
                        'URL_REQUEST': '<%= [URL_REQUEST] %>'
                    }
                },
                files: {
                    './app/index.html': ['./app/index.html.tpl'],
                    './app/scripts/app.js': ['./app/scripts/app.js.tpl'],
                    './app/scripts/services/config.js': ['./app/scripts/services/config.js.tpl']
                }
            },
            'replace-custom-node-modules': {
                files: {
                    './node_modules/passport-local/lib/passport-local/strategy.js': ['./custom_node_modules/passport-local/lib/passport-local/strategy.js']
                }
            }
        }

    });

    grunt.registerTask('build', [
        'clean:dist',
        'copy:dist',
        'useminPrepare',
        'ngmin',
        'uglify',
        'usemin']);

    grunt.registerTask('setEnv', function() {
        grunt.config('NODE_ENV', process.env.NODE_ENV);
        grunt.config('URL_REQUEST', process.env.URL_REQUEST);
        console.log('ENV = ' + process.env.NODE_ENV);
    });

    grunt.registerTask('build-dev', [
        'env:dev',
        'setEnv',
        'template:generate-from-tpl',
        'build']);

    grunt.registerTask('build-integ', [
        'env:integ',
        'setEnv',
        'template:generate-from-tpl',
        'build']);

    grunt.registerTask('build-recette', [
        'env:recette',
        'setEnv',
        'template:generate-from-tpl',
        'build']);

    grunt.registerTask('build-prod', [
        'env:prod',
        'setEnv',
        'template:generate-from-tpl',
        'build']);

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

        var env = grunt.file.readJSON('./env/config.json').NODE_ENV;
        if (env === 'dev') {
            grunt.task.run([
                'env:dev',
                'setEnv',
                'template:generate-from-tpl',
                'template:replace-custom-node-modules',
                'clean:server',
                'express:livereload',
                'watch:main']);
            //'concurrent:server',
        } else {
            grunt.task.run([
                'template:replace-custom-node-modules',
                'clean:server',
            //'concurrent:server',
            'express:livereload',
                'watch:main']);
        }
    });

    grunt.registerTask('test', [
        'env:test',
        'clean:server',
        'express:test',
        'jshint:all',
        'karma']);
};<commit_msg>Génération des fichier de l'environnement dans le task "TEST"<commit_after>/* File: GruntFile.js
 *
 * Copyright (c) 2014
 * Centre National d’Enseignement à Distance (Cned), Boulevard Nicephore Niepce, 86360 CHASSENEUIL-DU-POITOU, France
 * (direction-innovation@cned.fr)
 *
 * GNU Affero General Public License (AGPL) version 3.0 or later version
 *
 * This file is part of a program which is free software: you can
 * redistribute it and/or modify it under the terms of the
 * GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this program.
 * If not, see <http://www.gnu.org/licenses/>.
 *
 */

'use strict';

var path = require('path');

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

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

    try {
        yeomanConfig.app = require('./bower.json').appPath || yeomanConfig.app;
    } catch (e) {}

    grunt.initConfig({
        yeoman: yeomanConfig,
        watch: {
            main: {
                files: ['app/**/*.{html,css,png,jpeg,GIF,jpg,eot,svg,ttf,woff}'],
            },
            options: {
                livereload: true
                /*,
                port: 3000,
                key: grunt.file.read('../sslcert/key.pem'),
                cert: grunt.file.read('../sslcert/cert.pem')*/
            }
        },
        express: {
            options: {
                hostname: '0.0.0.0'
            },
            livereload: {
                options: {
                    server: path.resolve('./app.js'),
                    livereload: false,
                    serverreload: false,
                    bases: [path.resolve('./.tmp'), path.resolve(__dirname, yeomanConfig.app)],
                    spawn: false
                }
            },
            test: {
                options: {
                    server: path.resolve('./app.js'),
                    bases: [path.resolve('./.tmp'), path.resolve(__dirname, 'test')]
                }
            },
            dist: {
                options: {
                    server: path.resolve('./app.js'),
                    bases: path.resolve(__dirname, yeomanConfig.dist)
                }
            },
            server: {
                options: {
                    port: 80
                }
            }
        },
        open: {
            server: {
                url: 'http://localhost:<%= express.options.port %>'
            }
        },
        clean: {
            dist: {
                files: [{
                    dot: true,
                    src: [
                        '.tmp',
                        '<%= yeoman.dist %>/*',
                        '<%= yeoman.generated %>/*',
                        '!<%= yeoman.dist %>/.git*']
                }]
            },
            server: '.tmp'
        },
        jshint: {
            options: {
                jshintrc: '.jshintrc',
                reporter: 'checkstyle',
                reporterOutput: 'generated/jshint/resultJSHint.xml'
            },
            all: {
                src: ['Gruntfile.js', 'app/scripts/**/*.js', 'api/**/*.js', 'test/spec/**/*.js']
            }
        },
        rev: {
            dist: {
                files: {
                    src: [
                        '<%= yeoman.dist %>/scripts/{,*/}*.js',
                        '<%= yeoman.dist %>/styles/{,*/}*.css',
                        '<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
                        '<%= yeoman.dist %>/styles/fonts/*']
                }
            }
        },
        useminPrepare: {
            html: '<%= yeoman.app %>/index.html',
            options: {
                dest: '<%= yeoman.dist %>'
            }
        },
        usemin: {
            html: ['<%= yeoman.dist %>/{,*/}*.html'],
            css: ['<%= yeoman.dist %>/styles/{,*/}*.css'],
            options: {
                dirs: ['<%= yeoman.dist %>']
            }
        },
        imagemin: {
            dist: {
                files: [{
                    expand: true,
                    cwd: '<%= yeoman.app %>/images',
                    src: '{,*/}*.{png,jpg,jpeg}',
                    dest: '<%= yeoman.dist %>/images'
                }]
            }
        },
        svgmin: {
            dist: {
                files: [{
                    expand: true,
                    cwd: '<%= yeoman.app %>/images',
                    src: '{,*/}*.svg',
                    dest: '<%= yeoman.dist %>/images'
                }]
            }
        },
        cssmin: {
            // By default, your `index.html` <!-- Usemin Block --> will take care of
            // minification. This option is pre-configured if you do not wish to use
            // Usemin blocks.
            // 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', 'views/*.html'],
                    dest: '<%= yeoman.dist %>'
                }]
            }
        },
        copy: {
            dist: {
                files: [{
                    expand: true,
                    dot: true,
                    cwd: '<%= yeoman.app %>',
                    dest: '<%= yeoman.dist %>',
                    src: [
                        'app/**/*.{html,css,png,jpeg,GIF,jpg,eot,svg,ttf,woff}',
                        'app/bower_components/**/*.js',
                        'api/**/*',
                        'models/**/*',
                        'routes/**/*',
                        'custom_node_modules/**',
                        'app.js',
                        'Gruntfile.js',
                        'package.json',
                        'files/**/**/**',
                        'po/**']
                }, {
                    expand: true,
                    cwd: '<%= yeoman.app %>',
                    dest: '<%= yeoman.dist %>',
                    src: ['env/config.<%= [NODE_ENV] %>.json'],
                    rename: function(dest, src) {
                        return dest + '/env/config.json';
                    }
                }, {
                    expand: true,
                    cwd: '.tmp/images',
                    dest: '<%= yeoman.dist %>/images',
                    src: [
                        'generated/*']
                }]
            }
        },
        concurrent: {
            dist: [
                'imagemin',
                'svgmin']
        },
        ngmin: {
            controllers: {
                expand: true,
                cwd: 'app',
                src: ['scripts/**/*.js'],
                dest: 'generated/'
            }
        },
        uglify: {
            build: {
                src: ' <%= yeoman.generated %>/scripts/**/*.js',
                dest: '<%= yeoman.dist %>/app/scripts/front.js'
            }
        },
        karma: {
            unit: {
                configFile: 'karma.conf.js',
                singleRun: true
            }
        },
        cdnify: {
            dist: {
                html: ['<%= yeoman.dist %>/*.html']
            }
        },
        nggettext_extract: {
            pot: {
                files: {
                    'po/template.pot': ['app/views/**/*.html']
                }
            }
        },
        nggettext_compile: {
            all: {
                files: {
                    'app/scripts/translations.js': ['po/*.po']
                }
            }
        },
        /**
         * Specification de chaque configuration d'un ENV comme task
         */
        env: {
            dev: {
                src: 'env/config.json'
            },
            test: {
                src: 'env/config.test.json'
            },
            integ: {
                src: 'env/config.integ.json'
            },
            recette: {
                src: 'env/config.recette.json'
            },
            prod: {
                src: 'env/config.prod.json'
            }
        },
        /**
         *  Generation des fichiers avec
         *  des liens absoluts selon l'environnement
         */
        template: {
            'generate-from-tpl': {
                options: {
                    data: {
                        'URL_REQUEST': '<%= [URL_REQUEST] %>'
                    }
                },
                files: {
                    './app/index.html': ['./app/index.html.tpl'],
                    './app/scripts/app.js': ['./app/scripts/app.js.tpl'],
                    './app/scripts/services/config.js': ['./app/scripts/services/config.js.tpl']
                }
            },
            'replace-custom-node-modules': {
                files: {
                    './node_modules/passport-local/lib/passport-local/strategy.js': ['./custom_node_modules/passport-local/lib/passport-local/strategy.js']
                }
            }
        }

    });

    grunt.registerTask('build', [
        'clean:dist',
        'copy:dist',
        'useminPrepare',
        'ngmin',
        'uglify',
        'usemin']);

    grunt.registerTask('setEnv', function() {
        grunt.config('NODE_ENV', process.env.NODE_ENV);
        grunt.config('URL_REQUEST', process.env.URL_REQUEST);
        console.log('ENV = ' + process.env.NODE_ENV);
    });

    grunt.registerTask('build-dev', [
        'env:dev',
        'setEnv',
        'template:generate-from-tpl',
        'build']);

    grunt.registerTask('build-integ', [
        'env:integ',
        'setEnv',
        'template:generate-from-tpl',
        'build']);

    grunt.registerTask('build-recette', [
        'env:recette',
        'setEnv',
        'template:generate-from-tpl',
        'build']);

    grunt.registerTask('build-prod', [
        'env:prod',
        'setEnv',
        'template:generate-from-tpl',
        'build']);

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

        var env = grunt.file.readJSON('./env/config.json').NODE_ENV;
        if (env === 'dev') {
            grunt.task.run([
                'env:dev',
                'setEnv',
                'template:generate-from-tpl',
                'template:replace-custom-node-modules',
                'clean:server',
                'express:livereload',
                'watch:main']);
            //'concurrent:server',
        } else {
            grunt.task.run([
                'template:replace-custom-node-modules',
                'clean:server',
            //'concurrent:server',
            'express:livereload',
                'watch:main']);
        }
    });

    grunt.registerTask('test', [
        'env:dev',
        'setEnv',
        'template:generate-from-tpl',
        'env:test',
        'clean:server',
        'express:test',
        'jshint:all',
        'karma']);
};<|endoftext|>


<commit_before>var child_process = require('child_process');
var util = require('util');

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

  var bower = grunt.file.readJSON('bower.json');
  var components = [];
  for (var i in bower.concat.app) {
    components.push('components/' + bower.concat.app[i] + '/**/*.js');
  }

  var libtextsecurecomponents = [];
  for (i in bower.concat.libtextsecure) {
    libtextsecurecomponents.push('components/' + bower.concat.libtextsecure[i] + '/**/*.js');
  }

  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    concat: {
      components: {
        src: components,
        dest: 'js/components.js',
      },
      libtextsecurecomponents: {
        src: libtextsecurecomponents,
        dest: 'libtextsecure/components.js',
      },
      test: {
        src: [
          'components/mocha/mocha.js',
          'components/chai/chai.js',
          'test/_test.js'
        ],
        dest: 'test/test.js',
      },
      //TODO: Move errors back down?
      libtextsecure: {
        options: {
          banner: ";(function() {\n",
          footer: "})();\n",
        },
        src: [
          'libtextsecure/errors.js',
          'libtextsecure/libaxolotl.js',
          'libtextsecure/axolotl_wrapper.js',

          'libtextsecure/crypto.js',
          'libtextsecure/storage.js',
          'libtextsecure/storage/user.js',
          'libtextsecure/storage/devices.js',
          'libtextsecure/storage/groups.js',
          'libtextsecure/protobufs.js',
          'libtextsecure/websocket.js',
          'libtextsecure/websocket-resources.js',
          'libtextsecure/helpers.js',
          'libtextsecure/stringview.js',
          'libtextsecure/api.js',
          'libtextsecure/account_manager.js',
          'libtextsecure/message_receiver.js',
          'libtextsecure/sendmessage.js',
          'libtextsecure/contacts_parser.js',
        ],
        dest: 'js/libtextsecure.js',
      },
      libtextsecuretest: {
        src: [
          'components/mock-socket/dist/mock-socket.js',
          'components/mocha/mocha.js',
          'components/chai/chai.js',
          'libtextsecure/test/_test.js'
        ],
        dest: 'libtextsecure/test/test.js',
      }
    },
    sass: {
        stylesheets: {
            files: {
                'stylesheets/manifest.css': 'stylesheets/manifest.scss',
                'stylesheets/options.css': 'stylesheets/options.scss'
            }
        }
    },
    jshint: {
      files: [
        'Gruntfile.js',
        'js/background.js',
        'js/chromium.js',
        'js/bimap.js',
        'js/conversation_panel.js',
        'js/database.js',
        'js/inbox_controller.js',
        'js/index.js',
        'js/libphonenumber-util.js',
        'js/options.js',
        'js/panel_controller.js',
        'js/models/*.js',
        'js/views/*.js',
      ],
      options: { jshintrc: '.jshintrc' },
    },
    dist: {
      src: [
        'manifest.json',
        'background.html',
        'index.html',
        'conversation.html',
        'options.html',
        'protos/*',
        'js/**',
        'stylesheets/*.css',
        '!js/register.js'
      ],
      res: [
        'images/**',
        'fonts/*',
      ]
    },
    copy: {
      res: {
        files: [{ expand: true, dest: 'dist/', src: ['<%= dist.res %>'] }],
      },
      src: {
        files: [{ expand: true, dest: 'dist/', src: ['<%= dist.src %>'] }],
        options: {
          process: function(content, srcpath) {
            if (srcpath.match('libtextsecure') || srcpath.match('background.js')) {
              return content.replace(
                /textsecure-service-staging.whispersystems.org/g,
                'textsecure-service-ca.whispersystems.org:4433').replace(
                /whispersystems-textsecure-attachments-staging.s3.amazonaws.com/g,
                'whispersystems-textsecure-attachments.s3.amazonaws.com');
            } else {
              return content;
            }
          }
        }
      }
    },
    jscs: {
      all: {
        src: ['js/**/*.js', '!js/libtextsecure.js', '!js/libaxolotl-worker.js', '!js/components.js', 'test/**/*.js']
      }
    },
    watch: {
      scripts: {
        files: ['<%= jshint.files %>', './js/**/*.js'],
        tasks: ['jshint']
      },
      sass: {
        files: ['./stylesheets/*.scss'],
        tasks: ['sass']
      },
      libtextsecure: {
        files: ['./libtextsecure/*.js', './libtextsecure/storage/*.js'],
        tasks: ['concat:libtextsecure']
      },
      dist: {
        files: ['<%= dist.src %>', '<%= dist.res %>'],
        tasks: ['copy']
      },
    },
    connect: {
      server: {
        options: {
          base: '.',
          port: 9999
        }
      }
    },
    'saucelabs-mocha': {
      all: {
        options: {
          urls: [
            'http://127.0.0.1:9999/test/index.html',
            'http://127.0.0.1:9999/libtextsecure/test/index.html',
          ],
          build: process.env.TRAVIS_JOB_ID,
          browsers: [
            { browserName: 'chrome', version: '40' },
            { platform: 'linux', browserName: 'firefox', version: '34' }
          ],
          testname: 'TextSecure-Browser Tests',
          'max-duration': 300,
          statusCheckAttempts: 200
        }
      }
    },
  });

  Object.keys(grunt.config.get('pkg').devDependencies).forEach(function(key) {
    if (/^grunt(?!(-cli)?$)/.test(key)) {  // ignore grunt and grunt-cli
      grunt.loadNpmTasks(key);
    }
  });

  grunt.registerTask('dev', ['default', 'connect', 'watch']);
  grunt.registerTask('test', ['jshint', 'jscs', 'connect', 'saucelabs-mocha']);
  grunt.registerTask('default', ['concat', 'sass', 'copy']);

};
<commit_msg>Remove deleted file from concatentation list<commit_after>var child_process = require('child_process');
var util = require('util');

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

  var bower = grunt.file.readJSON('bower.json');
  var components = [];
  for (var i in bower.concat.app) {
    components.push('components/' + bower.concat.app[i] + '/**/*.js');
  }

  var libtextsecurecomponents = [];
  for (i in bower.concat.libtextsecure) {
    libtextsecurecomponents.push('components/' + bower.concat.libtextsecure[i] + '/**/*.js');
  }

  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    concat: {
      components: {
        src: components,
        dest: 'js/components.js',
      },
      libtextsecurecomponents: {
        src: libtextsecurecomponents,
        dest: 'libtextsecure/components.js',
      },
      test: {
        src: [
          'components/mocha/mocha.js',
          'components/chai/chai.js',
          'test/_test.js'
        ],
        dest: 'test/test.js',
      },
      //TODO: Move errors back down?
      libtextsecure: {
        options: {
          banner: ";(function() {\n",
          footer: "})();\n",
        },
        src: [
          'libtextsecure/errors.js',
          'libtextsecure/libaxolotl.js',
          'libtextsecure/axolotl_wrapper.js',

          'libtextsecure/crypto.js',
          'libtextsecure/storage.js',
          'libtextsecure/storage/user.js',
          'libtextsecure/storage/devices.js',
          'libtextsecure/storage/groups.js',
          'libtextsecure/protobufs.js',
          'libtextsecure/websocket-resources.js',
          'libtextsecure/helpers.js',
          'libtextsecure/stringview.js',
          'libtextsecure/api.js',
          'libtextsecure/account_manager.js',
          'libtextsecure/message_receiver.js',
          'libtextsecure/sendmessage.js',
          'libtextsecure/contacts_parser.js',
        ],
        dest: 'js/libtextsecure.js',
      },
      libtextsecuretest: {
        src: [
          'components/mock-socket/dist/mock-socket.js',
          'components/mocha/mocha.js',
          'components/chai/chai.js',
          'libtextsecure/test/_test.js'
        ],
        dest: 'libtextsecure/test/test.js',
      }
    },
    sass: {
        stylesheets: {
            files: {
                'stylesheets/manifest.css': 'stylesheets/manifest.scss',
                'stylesheets/options.css': 'stylesheets/options.scss'
            }
        }
    },
    jshint: {
      files: [
        'Gruntfile.js',
        'js/background.js',
        'js/chromium.js',
        'js/bimap.js',
        'js/conversation_panel.js',
        'js/database.js',
        'js/inbox_controller.js',
        'js/index.js',
        'js/libphonenumber-util.js',
        'js/options.js',
        'js/panel_controller.js',
        'js/models/*.js',
        'js/views/*.js',
      ],
      options: { jshintrc: '.jshintrc' },
    },
    dist: {
      src: [
        'manifest.json',
        'background.html',
        'index.html',
        'conversation.html',
        'options.html',
        'protos/*',
        'js/**',
        'stylesheets/*.css',
        '!js/register.js'
      ],
      res: [
        'images/**',
        'fonts/*',
      ]
    },
    copy: {
      res: {
        files: [{ expand: true, dest: 'dist/', src: ['<%= dist.res %>'] }],
      },
      src: {
        files: [{ expand: true, dest: 'dist/', src: ['<%= dist.src %>'] }],
        options: {
          process: function(content, srcpath) {
            if (srcpath.match('libtextsecure') || srcpath.match('background.js')) {
              return content.replace(
                /textsecure-service-staging.whispersystems.org/g,
                'textsecure-service-ca.whispersystems.org:4433').replace(
                /whispersystems-textsecure-attachments-staging.s3.amazonaws.com/g,
                'whispersystems-textsecure-attachments.s3.amazonaws.com');
            } else {
              return content;
            }
          }
        }
      }
    },
    jscs: {
      all: {
        src: ['js/**/*.js', '!js/libtextsecure.js', '!js/libaxolotl-worker.js', '!js/components.js', 'test/**/*.js']
      }
    },
    watch: {
      scripts: {
        files: ['<%= jshint.files %>', './js/**/*.js'],
        tasks: ['jshint']
      },
      sass: {
        files: ['./stylesheets/*.scss'],
        tasks: ['sass']
      },
      libtextsecure: {
        files: ['./libtextsecure/*.js', './libtextsecure/storage/*.js'],
        tasks: ['concat:libtextsecure']
      },
      dist: {
        files: ['<%= dist.src %>', '<%= dist.res %>'],
        tasks: ['copy']
      },
    },
    connect: {
      server: {
        options: {
          base: '.',
          port: 9999
        }
      }
    },
    'saucelabs-mocha': {
      all: {
        options: {
          urls: [
            'http://127.0.0.1:9999/test/index.html',
            'http://127.0.0.1:9999/libtextsecure/test/index.html',
          ],
          build: process.env.TRAVIS_JOB_ID,
          browsers: [
            { browserName: 'chrome', version: '40' },
            { platform: 'linux', browserName: 'firefox', version: '34' }
          ],
          testname: 'TextSecure-Browser Tests',
          'max-duration': 300,
          statusCheckAttempts: 200
        }
      }
    },
  });

  Object.keys(grunt.config.get('pkg').devDependencies).forEach(function(key) {
    if (/^grunt(?!(-cli)?$)/.test(key)) {  // ignore grunt and grunt-cli
      grunt.loadNpmTasks(key);
    }
  });

  grunt.registerTask('dev', ['default', 'connect', 'watch']);
  grunt.registerTask('test', ['jshint', 'jscs', 'connect', 'saucelabs-mocha']);
  grunt.registerTask('default', ['concat', 'sass', 'copy']);

};
<|endoftext|>


<commit_before>var semver   = require('semver'),
    f        = require('util').format,
    jsFiles  = [
        '<%= srcDir %>/js/notify-me.js'
    ];

module.exports = function(grunt) {
    grunt.initConfig({
        version: grunt.file.readJSON('package.json').version,

        srcDir: 'src',
        buildDir: 'dist',

        banner: [
            '/*!',
            ' * notify.me <%= version %>',
            ' * https://github.com/oltodo/notify.me',
            ' * Copyright 2013 Oltodo, Inc. and other contributors; Licensed MIT',
            ' */\n\n'
        ].join('\n'),

        clean: ['<%= buildDir %>/*'],

        uglify: {
            options: {
                banner: '<%= banner %>',
                enclose: { 'window.jQuery': '$' }
            },
            js: {
                options: {
                    mangle: false,
                    beautify: true,
                    compress: false
                },
                src: jsFiles,
                dest: '<%= buildDir %>/js/notify-me.js'
            },
            jsmin: {
                options: {
                    mangle: true,
                    compress: true
                },
                src: jsFiles,
                dest: '<%= buildDir %>/js/notify-me.min.js'
            }
        },

        less: {
            all: {
                files: {
                    '<%= buildDir %>/css/notify-me.css': '<%= srcDir %>/less/main.less'
                }
            }
        },

        cssmin: {
            combine: {
                files: {
                    '<%= buildDir %>/css/notify-me.min.css': '<%= buildDir %>/css/notify-me.css'
                }
            }
        },

        imagemin: {
            'static': {
                options: {
                    optimizationLevel: 3
                },
                files: {
                    '<%= buildDir %>/img/icons.png': '<%= srcDir %>/img/icons.png'
                }
            }
        },

        sed: {
            version: {
                pattern: '%VERSION%',
                replacement: '<%= version %>',
                path: ['<%= uglify.js.dest %>', '<%= uglify.jsmin.dest %>']
            }
        },

        jshint: {
            options: {
                jshintrc: '.jshintrc'
            },
            src: jsFiles,
            tests: ['test/*.js'],
            gruntfile: ['Gruntfile.js']
        },

        watch: {
            js: {
                files: jsFiles,
                tasks: 'build:js'
            }
        },

        jasmine: {
            js: {
                src: jsFiles,
                options: {
                    specs: 'test/*_spec.js',
                    helpers: 'test/helpers/*',
                    vendor: 'test/vendor/*'
                }
            }
        },

        exec: {
            open_spec_runner: {
                cmd: 'open _SpecRunner.html'
            },
            git_is_clean: {
                cmd: 'test -z "$(git status --porcelain src)"'
            },
            git_on_master: {
                cmd: 'test $(git symbolic-ref --short -q HEAD) = master'
            },
            git_add: {
                cmd: 'git add .'
            },
            git_commit: {
                cmd: function(m) { return f('git commit -m "%s"', m); }
            },
            git_tag: {
                cmd: function(v) { return f('git tag v%s -am "%s"', v, v); }
            },
            git_push: {
                cmd: 'git push && git push --tags'
            },
            publish_assets: {
                cmd: [
                    'cp -r <%= buildDir %> notify-me.js',
                    'zip -r notify-me.js/notify-me.js.zip notify-me.js',
                    'git checkout gh-pages',
                    'rm -rf releases/latest',
                    'cp -r notify-me.js releases/<%= version %>',
                    'cp -r notify-me.js releases/latest',
                    'git add releases/<%= version %> releases/latest',
                    'sed -E -i "" \'s/v[0-9]+\\.[0-9]+\\.[0-9]+/v<%= version %>/\' index.html',
                    'git add index.html',
                    'git commit -m "Add assets for <%= version %>."',
                    'git push',
                    'git checkout -',
                    'rm -rf notify-me.js'
                ].join(' && ')
            }
        },

        connect: {
            server: {
                options: {
                    port: 8888, keepalive: true
                }
            }
        },

        parallel: {
            dev: [
                { grunt: true, args: ['server'] },
                { grunt: true, args: ['watch'] }
            ]
        }
    });

    grunt.registerTask('sprite', 'Build the sprite', function() {
    });

    grunt.registerTask('release', 'Ship it.', function(version) {
        var curVersion = grunt.config.get('version');

        version = semver.inc(curVersion, version) || version;

        if (!semver.valid(version) || semver.lte(version, curVersion)) {
            grunt.fatal('invalid version dummy');
        }

        grunt.config.set('version', version);

        grunt.task.run([
            'exec:git_on_master',
            'exec:git_is_clean',
            'lint',
            'test',
            'manifests:' + version,
            'build',
            'exec:git_add',
            'exec:git_commit:' + version,
            'exec:git_tag:' + version,
            'exec:git_push'/*,
            'exec:publish_assets'*/
        ]);
    });

    grunt.registerTask('manifests', 'Update manifests.', function(version) {
        var _ = grunt.util._,
            pkg = grunt.file.readJSON('package.json'),
            bower = grunt.file.readJSON('bower.json')/*,
            jqueryPlugin = grunt.file.readJSON('notify-me.js.jquery.json')*/;

        bower = JSON.stringify(_.extend(bower, {
            name: pkg.name,
            version: version
        }), null, 2);

        // jqueryPlugin = JSON.stringify(_.extend(jqueryPlugin, {
        //     name: pkg.name,
        //     title: pkg.name,
        //     version: version,
        //     author: pkg.author,
        //     description: pkg.description,
        //     keywords: pkg.keywords,
        //     homepage: pkg.homepage,
        //     bugs: pkg.bugs,
        //     maintainers: pkg.contributors
        // }), null, 2);

        pkg = JSON.stringify(_.extend(pkg, {
            version: version
        }), null, 2);

        grunt.file.write('package.json', pkg);
        grunt.file.write('bower.json', bower);
        // grunt.file.write('notify-me.js.jquery.json', jqueryPlugin);
    });

    // aliases
    // -------

    grunt.registerTask('default', 'build');
    grunt.registerTask('build', ['clean', 'uglify', 'sed:version', 'less', 'cssmin', 'imagemin']);
    grunt.registerTask('server', 'connect:server');
    grunt.registerTask('lint', 'jshint');
    grunt.registerTask('test', 'jasmine:js');
    grunt.registerTask('test:browser', ['jasmine:js:build', 'exec:open_spec_runner']);
    grunt.registerTask('dev', 'parallel:dev');

    // load tasks
    // ----------

    grunt.loadNpmTasks('grunt-sed');
    grunt.loadNpmTasks('grunt-exec');
    grunt.loadNpmTasks('grunt-parallel');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-connect');
    grunt.loadNpmTasks('grunt-contrib-jasmine');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-imagemin');
    grunt.loadNpmTasks('grunt-contrib-less');
};<commit_msg>Fixed grunt<commit_after>var semver   = require('semver'),
    f        = require('util').format,
    jsFiles  = [
        '<%= srcDir %>/js/notify-me.js'
    ];

module.exports = function(grunt) {
    grunt.initConfig({
        version: grunt.file.readJSON('package.json').version,

        srcDir: 'src',
        buildDir: 'dist',

        banner: [
            '/*!',
            ' * notify.me <%= version %>',
            ' * https://github.com/oltodo/notify.me',
            ' * Copyright 2013 Oltodo, Inc. and other contributors; Licensed MIT',
            ' */\n\n'
        ].join('\n'),

        clean: ['<%= buildDir %>/*'],

        uglify: {
            options: {
                banner: '<%= banner %>',
                enclose: { 'window.jQuery': '$' }
            },
            js: {
                options: {
                    mangle: false,
                    beautify: true,
                    compress: false
                },
                src: jsFiles,
                dest: '<%= buildDir %>/js/notify-me.js'
            },
            jsmin: {
                options: {
                    mangle: true,
                    compress: true
                },
                src: jsFiles,
                dest: '<%= buildDir %>/js/notify-me.min.js'
            }
        },

        less: {
            all: {
                files: {
                    '<%= buildDir %>/css/notify-me.css': '<%= srcDir %>/less/main.less'
                }
            }
        },

        cssmin: {
            combine: {
                files: {
                    '<%= buildDir %>/css/notify-me.min.css': '<%= buildDir %>/css/notify-me.css'
                }
            }
        },

        imagemin: {
            'static': {
                options: {
                    optimizationLevel: 3
                },
                files: {
                    '<%= buildDir %>/img/icons.png': '<%= srcDir %>/img/icons.png'
                }
            }
        },

        sed: {
            version: {
                pattern: '%VERSION%',
                replacement: '<%= version %>',
                path: ['<%= uglify.js.dest %>', '<%= uglify.jsmin.dest %>']
            }
        },

        jshint: {
            options: {
                jshintrc: '.jshintrc'
            },
            src: jsFiles,
            tests: ['test/*.js'],
            gruntfile: ['Gruntfile.js']
        },

        watch: {
            js: {
                files: jsFiles,
                tasks: 'build:js'
            }
        },

        jasmine: {
            js: {
                src: jsFiles,
                options: {
                    specs: 'test/*_spec.js',
                    helpers: 'test/helpers/*',
                    vendor: 'test/vendor/*'
                }
            }
        },

        exec: {
            open_spec_runner: {
                cmd: 'open _SpecRunner.html'
            },
            git_is_clean: {
                cmd: 'test -z "$(git status --porcelain src)"'
            },
            git_on_master: {
                cmd: 'test $(git symbolic-ref --short -q HEAD) = master'
            },
            git_add: {
                cmd: 'git add dist bower.json package.json'
            },
            git_commit: {
                cmd: function(m) { return f('git commit -m "%s"', m); }
            },
            git_tag: {
                cmd: function(v) { return f('git tag v%s -am "%s"', v, v); }
            },
            git_push: {
                cmd: 'git push && git push --tags'
            },
            publish_assets: {
                cmd: [
                    'cp -r <%= buildDir %> notify-me.js',
                    'zip -r notify-me.js/notify-me.js.zip notify-me.js',
                    'git checkout gh-pages',
                    'rm -rf releases/latest',
                    'cp -r notify-me.js releases/<%= version %>',
                    'cp -r notify-me.js releases/latest',
                    'git add releases/<%= version %> releases/latest',
                    'sed -E -i "" \'s/v[0-9]+\\.[0-9]+\\.[0-9]+/v<%= version %>/\' index.html',
                    'git add index.html',
                    'git commit -m "Add assets for <%= version %>."',
                    'git push',
                    'git checkout -',
                    'rm -rf notify-me.js'
                ].join(' && ')
            }
        },

        connect: {
            server: {
                options: {
                    port: 8888, keepalive: true
                }
            }
        },

        parallel: {
            dev: [
                { grunt: true, args: ['server'] },
                { grunt: true, args: ['watch'] }
            ]
        }
    });

    grunt.registerTask('sprite', 'Build the sprite', function() {
    });

    grunt.registerTask('release', 'Ship it.', function(version) {
        var curVersion = grunt.config.get('version');

        version = semver.inc(curVersion, version) || version;

        if (!semver.valid(version) || semver.lte(version, curVersion)) {
            grunt.fatal('invalid version dummy');
        }

        grunt.config.set('version', version);

        grunt.task.run([
            'exec:git_on_master',
            'exec:git_is_clean',
            'lint',
            'test',
            'manifests:' + version,
            'build',
            'exec:git_add',
            'exec:git_commit:' + version,
            'exec:git_tag:' + version,
            'exec:git_push'/*,
            'exec:publish_assets'*/
        ]);
    });

    grunt.registerTask('manifests', 'Update manifests.', function(version) {
        var _ = grunt.util._,
            pkg = grunt.file.readJSON('package.json'),
            bower = grunt.file.readJSON('bower.json')/*,
            jqueryPlugin = grunt.file.readJSON('notify-me.js.jquery.json')*/;

        bower = JSON.stringify(_.extend(bower, {
            name: pkg.name,
            version: version
        }), null, 2);

        // jqueryPlugin = JSON.stringify(_.extend(jqueryPlugin, {
        //     name: pkg.name,
        //     title: pkg.name,
        //     version: version,
        //     author: pkg.author,
        //     description: pkg.description,
        //     keywords: pkg.keywords,
        //     homepage: pkg.homepage,
        //     bugs: pkg.bugs,
        //     maintainers: pkg.contributors
        // }), null, 2);

        pkg = JSON.stringify(_.extend(pkg, {
            version: version
        }), null, 2);

        grunt.file.write('package.json', pkg);
        grunt.file.write('bower.json', bower);
        // grunt.file.write('notify-me.js.jquery.json', jqueryPlugin);
    });

    // aliases
    // -------

    grunt.registerTask('default', 'build');
    grunt.registerTask('build', ['clean', 'uglify', 'sed:version', 'less', 'cssmin', 'imagemin']);
    grunt.registerTask('server', 'connect:server');
    grunt.registerTask('lint', 'jshint');
    grunt.registerTask('test', 'jasmine:js');
    grunt.registerTask('test:browser', ['jasmine:js:build', 'exec:open_spec_runner']);
    grunt.registerTask('dev', 'parallel:dev');

    // load tasks
    // ----------

    grunt.loadNpmTasks('grunt-sed');
    grunt.loadNpmTasks('grunt-exec');
    grunt.loadNpmTasks('grunt-parallel');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-connect');
    grunt.loadNpmTasks('grunt-contrib-jasmine');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-imagemin');
    grunt.loadNpmTasks('grunt-contrib-less');
};<|endoftext|>


<commit_before>'use strict';

module.exports = function(grunt) {
  grunt.initConfig({
    exec: {
      test: 'npm test',

      jshint: 'node_modules/jshint/bin/jshint .',
      jslint: 'find . -type d -name node_modules -prune -o -type d -name bower_components -prune -o -type f -name "*[-.]min.js" -prune -o -type f -name "*.js" -exec node_modules/jslint/bin/jslint.js {} \\;',
      eslint: 'node_modules/eslint/bin/eslint.js .',
      lili: 'bundle exec lili .',
      editorconfig: 'find . -type f -name Thumbs.db -prune -o -type f -name .DS_Store -prune -o -type d -name .git -prune -o -type d -name .svn -prune -o -type d -name tmp -prune -o -type d -name bin -prune -o -type d -name target -prune -o -name "*.app*" -prune -o -type d -name node_modules -prune -o -type d -name bower_components -prune -o -type f -name "*[-.]min.js" -prune -o -type d -name "*.dSYM" -prune -o -type f -name "*.scpt" -prune -o -type d -name "*.xcodeproj" -prune -o -type d -name .vagrant -prune -o -type f -name .exe -prune -o -type f -name "*.o" -prune -o -type f -name "*.pyc" -prune -o -type f -name "*.hi" -prune -o -type f -name "*.beam" -prune -o -type f -name "*.png" -prune -o -type f -name "*.gif" -prune -o -type f -name "*.jp*g" -prune -o -type f -name "*.ico" -prune -o -type f -name "*.ttf" -prune -o -type f -name "*.zip" -prune -o -type f -name "*.jar" -prune -o -type f -name "*.dot" -prune -o -type f -name "*.pdf" -prune -o -type f -name "*.wav" -prune -o -type f -name "*.mp[34]" -prune -o -type f -name "*.svg" -prune -o -type f -name "*.flip" -prune -o -type f -name "*.class" -prune -o -type f -name "*.jad" -prune -o -type d -name .idea -prune -o -type f -name "*.iml" -prune -o -type f -name "*.log" -prune -o -type f -name "*" -exec node_modules/editorconfig-tools/bin/index.js check {} \\;'
    }
  });

  grunt.loadNpmTasks('grunt-exec');

  grunt.registerTask('default', ['exec:test']);

  grunt.registerTask('test', ['exec:test']);

  grunt.registerTask('lint', [
    'exec:jshint',
    // Go to bed, Crockford
    // 'exec:jslint',
    'exec:eslint',
    'exec:lili',
    'exec:editorconfig'
  ]);

  grunt.registerTask('jshint', ['exec:jshint']);
  grunt.registerTask('jslint', ['exec:jslint']);
  grunt.registerTask('eslint', ['exec:eslint']);
  grunt.registerTask('lili', ['exec:lili']);
  grunt.registerTask('editorconfig', ['exec:editorconfig']);
};
<commit_msg>jslint bin/ scripts, if any<commit_after>'use strict';

module.exports = function(grunt) {
  grunt.initConfig({
    exec: {
      test: 'npm test',

      jshint: 'node_modules/jshint/bin/jshint .',
      jslint: 'find . -type d -name node_modules -prune -o -type d -name bower_components -prune -o -type f -name "*[-.]min.js" -prune -o -type f -name "*.bat" -prune -o -type f \\( -wholename "*/bin/*" -or -name "*.js" \\) -exec node_modules/jslint/bin/jslint.js {} \\;',
      eslint: 'node_modules/eslint/bin/eslint.js .',
      lili: 'bundle exec lili .',
      editorconfig: 'find . -type f -name Thumbs.db -prune -o -type f -name .DS_Store -prune -o -type d -name .git -prune -o -type d -name .svn -prune -o -type d -name tmp -prune -o -type d -name bin -prune -o -type d -name target -prune -o -name "*.app*" -prune -o -type d -name node_modules -prune -o -type d -name bower_components -prune -o -type f -name "*[-.]min.js" -prune -o -type d -name "*.dSYM" -prune -o -type f -name "*.scpt" -prune -o -type d -name "*.xcodeproj" -prune -o -type d -name .vagrant -prune -o -type f -name .exe -prune -o -type f -name "*.o" -prune -o -type f -name "*.pyc" -prune -o -type f -name "*.hi" -prune -o -type f -name "*.beam" -prune -o -type f -name "*.png" -prune -o -type f -name "*.gif" -prune -o -type f -name "*.jp*g" -prune -o -type f -name "*.ico" -prune -o -type f -name "*.ttf" -prune -o -type f -name "*.zip" -prune -o -type f -name "*.jar" -prune -o -type f -name "*.dot" -prune -o -type f -name "*.pdf" -prune -o -type f -name "*.wav" -prune -o -type f -name "*.mp[34]" -prune -o -type f -name "*.svg" -prune -o -type f -name "*.flip" -prune -o -type f -name "*.class" -prune -o -type f -name "*.jad" -prune -o -type d -name .idea -prune -o -type f -name "*.iml" -prune -o -type f -name "*.log" -prune -o -type f -name "*" -exec node_modules/editorconfig-tools/bin/index.js check {} \\;'
    }
  });

  grunt.loadNpmTasks('grunt-exec');

  grunt.registerTask('default', ['exec:test']);

  grunt.registerTask('test', ['exec:test']);

  grunt.registerTask('lint', [
    'exec:jshint',
    // Go to bed, Crockford
    // 'exec:jslint',
    'exec:eslint',
    'exec:lili',
    'exec:editorconfig'
  ]);

  grunt.registerTask('jshint', ['exec:jshint']);
  grunt.registerTask('jslint', ['exec:jslint']);
  grunt.registerTask('eslint', ['exec:eslint']);
  grunt.registerTask('lili', ['exec:lili']);
  grunt.registerTask('editorconfig', ['exec:editorconfig']);
};
<|endoftext|>


<commit_before>'use strict';

var SERVER_PORT = 9000;

// # Globbing

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',
    originalScriptTag: '<script src="scripts/main.js"></script>',
    tmpScriptTag: '<script src="scripts/.build.js"></script>'
  };

  grunt.initConfig({
    yeoman: yeomanConfig,
    pkg: grunt.file.readJSON('bower.json'),
    banner: '/* <%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %> */\n',

    clean: {
      dev: ['.sass-cache', '.tmp', '<%= yeoman.app %>/.css'],
      dist: ['.sass-cache', '.tmp', '<%= yeoman.app %>/.css',
             '<%= yeoman.dist %>/scripts', '<%= yeoman.dist %>/styles', '<%= yeoman.dist %>/vendor'],
      tmpBuild: ['<%= yeoman.app %>/scripts/.build.js']
    },

    compass: {
      compile: {
        options: {
          cssDir: '<%= yeoman.app %>/.css',
          sassDir: '<%= yeoman.app %>/styles',
          javascriptsDir: '<%= yeoman.app %>/scripts',
          imagesDir: '<%= yeoman.app %>/images',
          noLineComments: true,
          relativeAssets: true,
          raw: 'preferred_syntax = :scss\n'
        }
      }
    },

    handlebars: {
      compile: {
        options: {
          namespace: 'JST',
          amd: true
        },
        files: {
          '.tmp/scripts/templates.js': ['<%= yeoman.app %>/scripts/templates/*.hbs']
        }
      }
    },

    bower: {
      all: {
        rjsConfig: '<%= yeoman.app %>/scripts/main.js',
        options: {
          exclude: ['jquery', 'modernizr', 'requirejs']
        }
      }
    },

    requirejs: {
      dist: {
        options: {
          baseUrl: '<%= yeoman.app %>/scripts',
          mainConfigFile: "<%= yeoman.app %>/scripts/main.js",
          name: 'main',
          optimize: 'none',
          out: "<%= yeoman.app %>/scripts/.build.js",

          paths: {
            'templates': '.tmp/scripts/templates'
          },

          almond: false,
          preserveLicenseComments: false
        }
      }
    },

    watch: {
      options: {
        spawn: false
      },
      css: {
        files: ['<%= yeoman.app %>/styles/{,*/}*.scss'],
        tasks: ['compass']
      },
      handlebars: {
        files: [
          '<%= yeoman.app %>/scripts/templates/*.hbs'
        ],
        tasks: ['handlebars']
      }
    },

    useminPrepare: {
      html: '<%= yeoman.app %>/index.html',
      options: {
        dest: '<%= yeoman.dist %>'
      }
    },

    cssmin: {
      options: {
        banner: '<%= banner %>'
      }
    },

    uglify: {
      options: {
        banner: '<%= banner %>'
      }
    },

    imagemin: {
      dist: {
        files: [{
          expand: true,
          cwd: '<%= yeoman.app %>/images',
          src: '{,*/}*.{png,jpg,jpeg,svg}',
          dest: '<%= yeoman.dist %>/images'
        }]
      }
    },

    htmlmin: {
      dist: {
        files: [{
          expand: true,
          cwd: '<%= yeoman.app %>',
          src: '*.html',
          dest: '<%= yeoman.dist %>'
        }]
      }
    },

    rev: {
      dist: {
        files: {
          src: [
            '<%= yeoman.dist %>/scripts/{,*/}*.js',
            '<%= yeoman.dist %>/styles/{,*/}*.css',
            '<%= yeoman.dist %>/vendor/{,*/}*.js',
          ]
        }
      }
    },

    usemin: {
      html: ['<%= yeoman.dist %>/{,*/}*.html'],
      options: {
        dirs: ['<%= yeoman.dist %>']
      }
    },

    copy: {
      dist: {
        files: [{
          expand: true,
          cwd: '<%= yeoman.app %>',
          src: [
            '*.{ico,png}',
            'audio/{,*/}*.*'
          ],
          dest: '<%= yeoman.dist %>'
        }]
      }
    },

    connect: {
      options: {
        protocol: 'https',
        port: grunt.option('port') || SERVER_PORT,
        open: true,
        // change this to '0.0.0.0' to access the server from outside
        hostname: '192.168.1.106'
      },
      dev: {
        options: {
          base: [
            '.tmp',
            '<%= yeoman.app %>'
          ]
        }
      },
      dist: {
        options: {
          protocol: 'https',
          base: '<%= yeoman.dist %>'
        }
      }
    },

    jshint: {
      options: {
        jshintrc: '.jshintrc',
        reporter: require('jshint-stylish')
      },
      all: [
        'Gruntfile.js',
        '<%= yeoman.app %>/scripts/{,*/}*.js',
        '!<%= yeoman.app %>/vendor/*'
      ]
    }
  });

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

  grunt.registerTask('createTmpScriptTag', function (rollBack) {
    var path = yeomanConfig.app + '/index.html';
    var indexFile = grunt.file.read(path);
    if (typeof rollBack === 'undefined') {
      grunt.file.write(path, indexFile.replace(yeomanConfig.originalScriptTag, yeomanConfig.tmpScriptTag));
    } else {
      grunt.file.write(path, indexFile.replace(yeomanConfig.tmpScriptTag, yeomanConfig.originalScriptTag));
      grunt.task.run(['clean:tmpBuild']);
    }
  });

  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', 'connect:dist:keepalive']);
    }

    grunt.task.run([
      'clean:dev',
      'compass',
      'createDefaultTemplate',
      'handlebars',
      'connect:dev',
      'watch'
    ]);
  });

  grunt.registerTask('build', [
    'jshint',
    'clean:dist',
    'compass',
    'createDefaultTemplate',
    'handlebars',
    'requirejs',
    'createTmpScriptTag',
    'useminPrepare',
    'concat',
    'cssmin',
    'uglify',
    'newer:imagemin',
    'htmlmin',
    'rev',
    'usemin',
    'newer:copy',
    'createTmpScriptTag:rollBack'
  ]);

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

};<commit_msg>hostname: localhost<commit_after>'use strict';

var SERVER_PORT = 9000;

// # Globbing

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',
    originalScriptTag: '<script src="scripts/main.js"></script>',
    tmpScriptTag: '<script src="scripts/.build.js"></script>'
  };

  grunt.initConfig({
    yeoman: yeomanConfig,
    pkg: grunt.file.readJSON('bower.json'),
    banner: '/* <%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %> */\n',

    clean: {
      dev: ['.sass-cache', '.tmp', '<%= yeoman.app %>/.css'],
      dist: ['.sass-cache', '.tmp', '<%= yeoman.app %>/.css',
             '<%= yeoman.dist %>/scripts', '<%= yeoman.dist %>/styles', '<%= yeoman.dist %>/vendor'],
      tmpBuild: ['<%= yeoman.app %>/scripts/.build.js']
    },

    compass: {
      compile: {
        options: {
          cssDir: '<%= yeoman.app %>/.css',
          sassDir: '<%= yeoman.app %>/styles',
          javascriptsDir: '<%= yeoman.app %>/scripts',
          imagesDir: '<%= yeoman.app %>/images',
          noLineComments: true,
          relativeAssets: true,
          raw: 'preferred_syntax = :scss\n'
        }
      }
    },

    handlebars: {
      compile: {
        options: {
          namespace: 'JST',
          amd: true
        },
        files: {
          '.tmp/scripts/templates.js': ['<%= yeoman.app %>/scripts/templates/*.hbs']
        }
      }
    },

    bower: {
      all: {
        rjsConfig: '<%= yeoman.app %>/scripts/main.js',
        options: {
          exclude: ['jquery', 'modernizr', 'requirejs']
        }
      }
    },

    requirejs: {
      dist: {
        options: {
          baseUrl: '<%= yeoman.app %>/scripts',
          mainConfigFile: "<%= yeoman.app %>/scripts/main.js",
          name: 'main',
          optimize: 'none',
          out: "<%= yeoman.app %>/scripts/.build.js",

          paths: {
            'templates': '.tmp/scripts/templates'
          },

          almond: false,
          preserveLicenseComments: false
        }
      }
    },

    watch: {
      options: {
        spawn: false
      },
      css: {
        files: ['<%= yeoman.app %>/styles/{,*/}*.scss'],
        tasks: ['compass']
      },
      handlebars: {
        files: [
          '<%= yeoman.app %>/scripts/templates/*.hbs'
        ],
        tasks: ['handlebars']
      }
    },

    useminPrepare: {
      html: '<%= yeoman.app %>/index.html',
      options: {
        dest: '<%= yeoman.dist %>'
      }
    },

    cssmin: {
      options: {
        banner: '<%= banner %>'
      }
    },

    uglify: {
      options: {
        banner: '<%= banner %>'
      }
    },

    imagemin: {
      dist: {
        files: [{
          expand: true,
          cwd: '<%= yeoman.app %>/images',
          src: '{,*/}*.{png,jpg,jpeg,svg}',
          dest: '<%= yeoman.dist %>/images'
        }]
      }
    },

    htmlmin: {
      dist: {
        files: [{
          expand: true,
          cwd: '<%= yeoman.app %>',
          src: '*.html',
          dest: '<%= yeoman.dist %>'
        }]
      }
    },

    rev: {
      dist: {
        files: {
          src: [
            '<%= yeoman.dist %>/scripts/{,*/}*.js',
            '<%= yeoman.dist %>/styles/{,*/}*.css',
            '<%= yeoman.dist %>/vendor/{,*/}*.js',
          ]
        }
      }
    },

    usemin: {
      html: ['<%= yeoman.dist %>/{,*/}*.html'],
      options: {
        dirs: ['<%= yeoman.dist %>']
      }
    },

    copy: {
      dist: {
        files: [{
          expand: true,
          cwd: '<%= yeoman.app %>',
          src: [
            '*.{ico,png}',
            'audio/{,*/}*.*'
          ],
          dest: '<%= yeoman.dist %>'
        }]
      }
    },

    connect: {
      options: {
        protocol: 'https',
        port: grunt.option('port') || SERVER_PORT,
        open: true,
        // change this to '0.0.0.0' to access the server from outside
        hostname: 'localhost'
      },
      dev: {
        options: {
          base: [
            '.tmp',
            '<%= yeoman.app %>'
          ]
        }
      },
      dist: {
        options: {
          protocol: 'https',
          base: '<%= yeoman.dist %>'
        }
      }
    },

    jshint: {
      options: {
        jshintrc: '.jshintrc',
        reporter: require('jshint-stylish')
      },
      all: [
        'Gruntfile.js',
        '<%= yeoman.app %>/scripts/{,*/}*.js',
        '!<%= yeoman.app %>/vendor/*'
      ]
    }
  });

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

  grunt.registerTask('createTmpScriptTag', function (rollBack) {
    var path = yeomanConfig.app + '/index.html';
    var indexFile = grunt.file.read(path);
    if (typeof rollBack === 'undefined') {
      grunt.file.write(path, indexFile.replace(yeomanConfig.originalScriptTag, yeomanConfig.tmpScriptTag));
    } else {
      grunt.file.write(path, indexFile.replace(yeomanConfig.tmpScriptTag, yeomanConfig.originalScriptTag));
      grunt.task.run(['clean:tmpBuild']);
    }
  });

  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', 'connect:dist:keepalive']);
    }

    grunt.task.run([
      'clean:dev',
      'compass',
      'createDefaultTemplate',
      'handlebars',
      'connect:dev',
      'watch'
    ]);
  });

  grunt.registerTask('build', [
    'jshint',
    'clean:dist',
    'compass',
    'createDefaultTemplate',
    'handlebars',
    'requirejs',
    'createTmpScriptTag',
    'useminPrepare',
    'concat',
    'cssmin',
    'uglify',
    'newer:imagemin',
    'htmlmin',
    'rev',
    'usemin',
    'newer:copy',
    'createTmpScriptTag:rollBack'
  ]);

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

};<|endoftext|>


<commit_before>"use strict";

module.exports = function(grunt) {
  grunt.initConfig({
    eslint: { target: ["Gruntfile.js", "lib", "examples"] },
    }
  });

  grunt.loadNpmTasks("grunt-eslint");

  grunt.registerTask("default", ["eslint"]);
  grunt.registerTask("lint", ["eslint"]);
};

<commit_msg>Fix syntax error<commit_after>"use strict";

module.exports = function(grunt) {
  grunt.initConfig({
    eslint: { target: ["Gruntfile.js", "lib", "examples"] },
    }
  );

  grunt.loadNpmTasks("grunt-eslint");

  grunt.registerTask("default", ["eslint"]);
  grunt.registerTask("lint", ["eslint"]);
};
<|endoftext|>


<commit_before>import * as Kefir from "kefir"
import * as R     from "ramda"
import React      from "karet"
import ReactDOM   from "react-dom/server"

import K, * as U from "../dist/karet.util.cjs"

function show(x) {
  switch (typeof x) {
    case "string":
    case "object":
      return JSON.stringify(x)
    default:
      return `${x}`
  }
}

const testEq = (exprIn, expect) => {
  const expr = exprIn.replace(/[ \n]+/g, " ")
  return it(`${expr} => ${show(expect)}`, done => {
    const actual =
      eval(`(K, Kefir, R, U, C) => ${expr}`)(K, Kefir, R, U, Kefir.constant)
    const check = actual => {
      if (!R.equals(actual, expect))
        throw new Error(`Expected: ${show(expect)}, actual: ${show(actual)}`)
      done()
    }
    if (actual instanceof Kefir.Observable)
      actual.take(1).onValue(check)
    else
      check(actual)
  })
}

const testRender = (vdom, expect) => it(`${expect}`, () => {
  const actual = ReactDOM.renderToStaticMarkup(vdom)

  if (actual !== expect)
    throw new Error(`Expected: ${show(expect)}, actual: ${show(actual)}`)
})

describe("actions", () => {
  testEq(`{let i = "";
           U.actions(false,
                     C(x => i += "1" + x),
                     undefined,
                     x => i += "2" + x)
            .onValue(f => f("z"));
           return i}`,
         "1z2z")
})

describe("bind", () => {
  testEq(`{const a = U.atom(1);
           const e = {a: 2};
           const x = U.bind({a});
           x.onChange({target: e});
           return a}`,
         2)
})

describe("view", () => {
  testEq(`U.view("x", Kefir.constant({x: 101}))`, 101)
  testEq(`U.view(Kefir.constant("x"), Kefir.constant({x: 101}))`, 101)
  testEq(`U.view("x", {x: 101})`, 101)
  testEq(`U.view("x", U.atom({x: 101}))`, 101)
  testEq(`U.view(Kefir.constant("x"), U.atom({x: 101}))`, 101)
})

describe("bindProps", () => {
  testEq(`{const a = U.atom(1);
           const e = {a: 2};
           const x = U.bindProps({ref: "onChange", a});
           x.ref(e);
           a.set(3);
           return e.a}`,
         3)

  testEq(`{const a = U.atom(1);
           const e = {a: 2};
           const x = U.bindProps({ref: "onChange", a});
           x.ref(e);
           e.a = 3;
           x.onChange({target: e});
           return a}`,
         3)
})

describe("classes", () => {
  testEq('U.classes()', {className: ""})

  testEq('U.classes("a")', {className: "a"})

  testEq('U.classes("a", undefined, 0, false, "", "b")',
         {className: "a b"})

  testEq('K(U.classes("a", C("b")), R.identity)',
         {className: "a b"})
})

describe("cns", () => {
  testEq(`U.cns()`, "")
  testEq(`U.cns(null, ["a", false], undefined, C("b"), 0, "")`, "a b")
})

describe("mapCached", () => {
  testEq(`U.seq(Kefir.concat([C([2, 1, 1]), C([1, 3, 2])]),
                U.toProperty,
                U.mapCached(i => "item " + i))`,
         ["item 1", "item 3", "item 2"])
})

describe("mapElems", () => {
  testEq(`{let uniq = 0;
           const xs = U.atom([2, 1, 1]);
           const ys =
             U.seq(xs,
                   U.mapElems((x, i) => [x, i, ++uniq]),
                   U.flatMapLatest(U.template),
                   U.toProperty);
          ys.onValue(() => {});
          xs.set([1, 3, 2]);
          return ys}`,
         [[1, 0, 1], [3, 1, 2], [2, 2, 3]])
})

describe("mapElemsWithIds", () => {
  testEq(`{let uniq = 0;
           const xs = U.atom([{id: "2"}, {id: "1"}, {id: "3"}]);
           const ys =
             U.seq(xs,
                   U.mapElemsWithIds(s => s.id, (x, i) => [x, i, ++uniq]),
                   U.flatMapLatest(U.template),
                   U.toProperty);
           ys.onValue(() => {});
           xs.set([{id: "1"}, {id: "2"}, {id: "3"}]);
           return ys}`,
         [[{id: "1"}, "1", 2],
          [{id: "2"}, "2", 1],
          [{id: "3"}, "3", 3]])
})

describe("sink", () => {
  testEq('U.sink(C("lol"))', undefined)
})

describe("string", () => {
  testEq('U.string`Hello!`', "Hello!")
  testEq('U.string`Hello, ${"constant"}!`', "Hello, constant!")
  testEq('U.string`Hello, ${C("World")}!`', "Hello, World!")
  testEq('U.string`Hello, ${"constant"} ${C("property")}!`',
         "Hello, constant property!")
})

describe("Context", () => {
  const Who = U.withContext((_, {who}) =>
Hello, {who}!
)

  testRender(
               <Who/>
             ,
             '
Hello, World!
')
})

describe("bus", () => {
  testEq(`{const b = U.bus();
           let result;
           U.seq(b,
                 U.flatMapParallel(R.negate),
                 U.on({value: x => result = x}));
           b.push(-101);
           return result}`,
         101)
  testEq(`{const b = U.bus();
           let result;
           U.seq(b,
                 U.flatMapErrors(R.negate),
                 U.on({value: x => result = x}));
           b.error(-69);
           return result}`,
         69)
  testEq(`{const b = U.bus();
           b.end();
           return U.parallel([b, C(42)])}`,
         42)
})

describe("ifte", () => {
  testEq('U.ifte(C(true), C(1), C(2))', 1)
  testEq('U.ifte(C(false), 1, 2)', 2)
})

describe("ift", () => {
  testEq('U.ift(C(true), C("x"))', "x")
  testEq('U.ift(C(false), "x")', undefined)
})

describe("iftes", () => {
  testEq(`U.iftes()`, undefined)
  testEq(`U.iftes(C(false), 1, 2)`, 2)
  testEq(`U.iftes(C(false), 1,
                  C(false), 2,
                  3)`,
         3)
  testEq(`U.iftes(C(false), 1,
                  C(false), 2,
                  C(false), 3)`,
         undefined)
})

describe("toPartial", () => {
  testEq(`U.toPartial(R.add)(C(1), undefined)`, undefined)
  testEq(`U.toPartial(R.add)(C(undefined), 2)`, undefined)
  testEq(`U.toPartial(R.add)(1, C(2))`, 3)
})

describe("mapIndexed", () => {
  testEq(`U.mapIndexed((x, i) => [x,i], C([3,1,4]))`, [[3,0], [1,1], [4,2]])
})

describe("scope", () => {
  testEq(`U.scope(() => 101)`, 101)
})

describe("refTo", () => {
  testEq(`{const x = U.variable(); U.refTo(x)(null); return x.get()}`,
         undefined)
  testEq(`{const x = U.variable(); U.refTo(x)("y"); return x.get()}`, "y")
})

describe("molecule", () => {
  testEq(`U.molecule({x: U.atom(1), y: U.atom(2)})`, {x: 1, y: 2})
})

describe("template", () => {
  testEq(`U.template({x: C(1), y: C(2)})`, {x: 1, y: 2})
})

describe("set", () => {
  testEq(`U.set(U.atom(0), 1)`, undefined)
  testEq(`U.set(U.atom(0), C(1))`, undefined)
})

describe("show", () => {
  testEq(`U.show("any")`, "any")
})

describe("staged", () => {
  testEq(`U.staged(x => y => x + y)(1)(2)`, 3)
  testEq(`U.staged(x => y => x + y)(1, 2)`, 3)
})

describe("Ramda", () => {
  testEq(`U.add(C(1), C(2))`, 3)
  testEq(`U.addIndex(R.map)((x, i) => [x, i], C([3, 1, 4]))`,
         [[3,0], [1,1], [4,2]])
  testEq(`U.adjust(R.inc, C(1), C([1,2,3]))`, [1,3,3])
  testEq(`U.all(R.equals(1), C([1,2,3]))`, false)
  testEq(`U.allPass([x => x > 1, x => x < 3])(C(2))`, true)
  testEq(`U.filter(U.allPass([C(x => x > 1), C(x => x < 3)]), C([1,2,3]))`, [2])
  testEq(`U.and(C("a"), C("b"))`, "b")
  testEq(`U.any(R.equals(1), C([1,2,3]))`, true)
  testEq(`U.anyPass([x => x > 1, x => x < 3])(C(1))`, true)
  testEq(`U.filter(U.anyPass([C(x => x > 1), C(x => x < 3)]), C([1,2,3]))`,
         [1,2,3])
  testEq(`U.ap([U.multiply(2), C(U.add(3))], C([1,2,3]))`, [2, 4, 6, 4, 5, 6])
  testEq('U.ifElse(U.equals("x"), () => "was x!", x => "was " + x)(C("y"))',
         "was y")
  testEq('U.pipe(U.add(1), U.add(2))(C(3))', 6)
  testEq(`U.always(C(42))(0)`, 42)
  testEq(`U.cond([[R.equals(1), R.always("one")],
                  [R.equals(2), R.always("two")]])(2)`,
         "two")
  testEq(`U.cond([[R.equals(1), R.always("one")],
                  [R.equals(2), R.always("two")]])(C(2))`,
         "two")
  testEq(`U.identity(C(42))`, 42)
  testEq(`U.filter(U.where({id: U.has(U.__, C({x: 1, y: 1}))}),
                   [{id: "y"}, {id: "z"}, {id: "x"}])`,
         [{id: "y"}, {id: "x"}])
})

describe("Kefir", () => {
  testEq('U.mapValue((v) => v * 2, C(2))', 4)
})
<commit_msg>Karet no longer provides default export<commit_after>import * as Kefir from "kefir"
import * as R     from "ramda"
import * as React from "karet"
import ReactDOM   from "react-dom/server"

import K, * as U from "../dist/karet.util.cjs"

function show(x) {
  switch (typeof x) {
    case "string":
    case "object":
      return JSON.stringify(x)
    default:
      return `${x}`
  }
}

const testEq = (exprIn, expect) => {
  const expr = exprIn.replace(/[ \n]+/g, " ")
  return it(`${expr} => ${show(expect)}`, done => {
    const actual =
      eval(`(K, Kefir, R, U, C) => ${expr}`)(K, Kefir, R, U, Kefir.constant)
    const check = actual => {
      if (!R.equals(actual, expect))
        throw new Error(`Expected: ${show(expect)}, actual: ${show(actual)}`)
      done()
    }
    if (actual instanceof Kefir.Observable)
      actual.take(1).onValue(check)
    else
      check(actual)
  })
}

const testRender = (vdom, expect) => it(`${expect}`, () => {
  const actual = ReactDOM.renderToStaticMarkup(vdom)

  if (actual !== expect)
    throw new Error(`Expected: ${show(expect)}, actual: ${show(actual)}`)
})

describe("actions", () => {
  testEq(`{let i = "";
           U.actions(false,
                     C(x => i += "1" + x),
                     undefined,
                     x => i += "2" + x)
            .onValue(f => f("z"));
           return i}`,
         "1z2z")
})

describe("bind", () => {
  testEq(`{const a = U.atom(1);
           const e = {a: 2};
           const x = U.bind({a});
           x.onChange({target: e});
           return a}`,
         2)
})

describe("view", () => {
  testEq(`U.view("x", Kefir.constant({x: 101}))`, 101)
  testEq(`U.view(Kefir.constant("x"), Kefir.constant({x: 101}))`, 101)
  testEq(`U.view("x", {x: 101})`, 101)
  testEq(`U.view("x", U.atom({x: 101}))`, 101)
  testEq(`U.view(Kefir.constant("x"), U.atom({x: 101}))`, 101)
})

describe("bindProps", () => {
  testEq(`{const a = U.atom(1);
           const e = {a: 2};
           const x = U.bindProps({ref: "onChange", a});
           x.ref(e);
           a.set(3);
           return e.a}`,
         3)

  testEq(`{const a = U.atom(1);
           const e = {a: 2};
           const x = U.bindProps({ref: "onChange", a});
           x.ref(e);
           e.a = 3;
           x.onChange({target: e});
           return a}`,
         3)
})

describe("classes", () => {
  testEq('U.classes()', {className: ""})

  testEq('U.classes("a")', {className: "a"})

  testEq('U.classes("a", undefined, 0, false, "", "b")',
         {className: "a b"})

  testEq('K(U.classes("a", C("b")), R.identity)',
         {className: "a b"})
})

describe("cns", () => {
  testEq(`U.cns()`, "")
  testEq(`U.cns(null, ["a", false], undefined, C("b"), 0, "")`, "a b")
})

describe("mapCached", () => {
  testEq(`U.seq(Kefir.concat([C([2, 1, 1]), C([1, 3, 2])]),
                U.toProperty,
                U.mapCached(i => "item " + i))`,
         ["item 1", "item 3", "item 2"])
})

describe("mapElems", () => {
  testEq(`{let uniq = 0;
           const xs = U.atom([2, 1, 1]);
           const ys =
             U.seq(xs,
                   U.mapElems((x, i) => [x, i, ++uniq]),
                   U.flatMapLatest(U.template),
                   U.toProperty);
          ys.onValue(() => {});
          xs.set([1, 3, 2]);
          return ys}`,
         [[1, 0, 1], [3, 1, 2], [2, 2, 3]])
})

describe("mapElemsWithIds", () => {
  testEq(`{let uniq = 0;
           const xs = U.atom([{id: "2"}, {id: "1"}, {id: "3"}]);
           const ys =
             U.seq(xs,
                   U.mapElemsWithIds(s => s.id, (x, i) => [x, i, ++uniq]),
                   U.flatMapLatest(U.template),
                   U.toProperty);
           ys.onValue(() => {});
           xs.set([{id: "1"}, {id: "2"}, {id: "3"}]);
           return ys}`,
         [[{id: "1"}, "1", 2],
          [{id: "2"}, "2", 1],
          [{id: "3"}, "3", 3]])
})

describe("sink", () => {
  testEq('U.sink(C("lol"))', undefined)
})

describe("string", () => {
  testEq('U.string`Hello!`', "Hello!")
  testEq('U.string`Hello, ${"constant"}!`', "Hello, constant!")
  testEq('U.string`Hello, ${C("World")}!`', "Hello, World!")
  testEq('U.string`Hello, ${"constant"} ${C("property")}!`',
         "Hello, constant property!")
})

describe("Context", () => {
  const Who = U.withContext((_, {who}) =>
Hello, {who}!
)

  testRender(
               <Who/>
             ,
             '
Hello, World!
')
})

describe("bus", () => {
  testEq(`{const b = U.bus();
           let result;
           U.seq(b,
                 U.flatMapParallel(R.negate),
                 U.on({value: x => result = x}));
           b.push(-101);
           return result}`,
         101)
  testEq(`{const b = U.bus();
           let result;
           U.seq(b,
                 U.flatMapErrors(R.negate),
                 U.on({value: x => result = x}));
           b.error(-69);
           return result}`,
         69)
  testEq(`{const b = U.bus();
           b.end();
           return U.parallel([b, C(42)])}`,
         42)
})

describe("ifte", () => {
  testEq('U.ifte(C(true), C(1), C(2))', 1)
  testEq('U.ifte(C(false), 1, 2)', 2)
})

describe("ift", () => {
  testEq('U.ift(C(true), C("x"))', "x")
  testEq('U.ift(C(false), "x")', undefined)
})

describe("iftes", () => {
  testEq(`U.iftes()`, undefined)
  testEq(`U.iftes(C(false), 1, 2)`, 2)
  testEq(`U.iftes(C(false), 1,
                  C(false), 2,
                  3)`,
         3)
  testEq(`U.iftes(C(false), 1,
                  C(false), 2,
                  C(false), 3)`,
         undefined)
})

describe("toPartial", () => {
  testEq(`U.toPartial(R.add)(C(1), undefined)`, undefined)
  testEq(`U.toPartial(R.add)(C(undefined), 2)`, undefined)
  testEq(`U.toPartial(R.add)(1, C(2))`, 3)
})

describe("mapIndexed", () => {
  testEq(`U.mapIndexed((x, i) => [x,i], C([3,1,4]))`, [[3,0], [1,1], [4,2]])
})

describe("scope", () => {
  testEq(`U.scope(() => 101)`, 101)
})

describe("refTo", () => {
  testEq(`{const x = U.variable(); U.refTo(x)(null); return x.get()}`,
         undefined)
  testEq(`{const x = U.variable(); U.refTo(x)("y"); return x.get()}`, "y")
})

describe("molecule", () => {
  testEq(`U.molecule({x: U.atom(1), y: U.atom(2)})`, {x: 1, y: 2})
})

describe("template", () => {
  testEq(`U.template({x: C(1), y: C(2)})`, {x: 1, y: 2})
})

describe("set", () => {
  testEq(`U.set(U.atom(0), 1)`, undefined)
  testEq(`U.set(U.atom(0), C(1))`, undefined)
})

describe("show", () => {
  testEq(`U.show("any")`, "any")
})

describe("staged", () => {
  testEq(`U.staged(x => y => x + y)(1)(2)`, 3)
  testEq(`U.staged(x => y => x + y)(1, 2)`, 3)
})

describe("Ramda", () => {
  testEq(`U.add(C(1), C(2))`, 3)
  testEq(`U.addIndex(R.map)((x, i) => [x, i], C([3, 1, 4]))`,
         [[3,0], [1,1], [4,2]])
  testEq(`U.adjust(R.inc, C(1), C([1,2,3]))`, [1,3,3])
  testEq(`U.all(R.equals(1), C([1,2,3]))`, false)
  testEq(`U.allPass([x => x > 1, x => x < 3])(C(2))`, true)
  testEq(`U.filter(U.allPass([C(x => x > 1), C(x => x < 3)]), C([1,2,3]))`, [2])
  testEq(`U.and(C("a"), C("b"))`, "b")
  testEq(`U.any(R.equals(1), C([1,2,3]))`, true)
  testEq(`U.anyPass([x => x > 1, x => x < 3])(C(1))`, true)
  testEq(`U.filter(U.anyPass([C(x => x > 1), C(x => x < 3)]), C([1,2,3]))`,
         [1,2,3])
  testEq(`U.ap([U.multiply(2), C(U.add(3))], C([1,2,3]))`, [2, 4, 6, 4, 5, 6])
  testEq('U.ifElse(U.equals("x"), () => "was x!", x => "was " + x)(C("y"))',
         "was y")
  testEq('U.pipe(U.add(1), U.add(2))(C(3))', 6)
  testEq(`U.always(C(42))(0)`, 42)
  testEq(`U.cond([[R.equals(1), R.always("one")],
                  [R.equals(2), R.always("two")]])(2)`,
         "two")
  testEq(`U.cond([[R.equals(1), R.always("one")],
                  [R.equals(2), R.always("two")]])(C(2))`,
         "two")
  testEq(`U.identity(C(42))`, 42)
  testEq(`U.filter(U.where({id: U.has(U.__, C({x: 1, y: 1}))}),
                   [{id: "y"}, {id: "z"}, {id: "x"}])`,
         [{id: "y"}, {id: "x"}])
})

describe("Kefir", () => {
  testEq('U.mapValue((v) => v * 2, C(2))', 4)
})
<|endoftext|>


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

    require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

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

        changelog: {},

        bump: {
            options: {
                files: ['package.json'],
                updateConfigs: [],
                commit: true,
                commitMessage: 'Release v%VERSION%',
                commitFiles: ['package.json'],
                createTag: true,
                tagName: 'v%VERSION%',
                tagMessage: 'Version %VERSION%',
                push: true,
                pushTo: 'origin',
                gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d'
            }
        },

        jshint: {
            options: {
                node: true,
                browser: true,
                esnext: true,
                bitwise: true,
                curly: true,
                eqeqeq: true,
                immed: true,
                indent: 4,
                latedef: true,
                newcap: true,
                noarg: true,
                regexp: true,
                undef: true,
                unused: true,
                trailing: true,
                smarttabs: true,
                globals: {
                    L: false,

                    // Mocha

                    describe: false,
                    it: false,
                    before: false,
                    after: false,
                    beforeEach: false,
                    afterEach: false,
                    chai: false,
                    expect: false,
                    sinon: false
                }
            },
            source: {
                src: [ 'src/*.js', 'Gruntfile.js', 'package.json' ]
            },
            test: {
                src: [ 'test/SpecHelper.js', 'test/src/**' ],
            },
            grunt: {
                src: [ 'Gruntfile.js' ]
            }
        },

        less: {
            source: {
                files: {
                    'dist/Leaflet.Toolbar.css': 'src/Toolbar.less'
                }
            }
        },

        karma: {
            travis: {
                configFile: 'test/karma.conf.js',
                background: false,
                singleRun: true,
                browsers: [ 'PhantomJS' ]
            },
            development: {
                configFile: 'test/karma.conf.js',
                background: true
            },
            unit: {
                configFile: 'test/karma.conf.js',
                background: false,
                singleRun: true
            }
        },

        watch: {
            options : {
                livereload: true
            },
            source: {
                files: [
                    'src/*.js',
                    'test/**',
                    'Gruntfile.js'
                ],
                tasks: [ 'build:js' ]
            },
            css: {
                files: [ 'src/*.less' ],
                tasks: [ 'build:css' ]
            }

        },

        concat: {
            dist: {
                options: {
                    banner: '(function(window, document, undefined) {\n\n"use strict";\n\n',
                    footer: '\n\n}(window, document));'
                },
                src: [
                    'src/ToolbarAction.js',
                    'src/Toolbar.js',
                    'src/ToolbarGroup.js',
                    'src/Toolbar.*.js'
                ],
                dest: 'dist/Leaflet.Toolbar.js',
            }
        }
    });

    /* Run tests once. */
    grunt.registerTask('test', [ 'jshint', 'karma:test', 'coverage' ]);

    /* Default (development): Watch files and lint, test, and build on change. */
    grunt.registerTask('default', ['karma:development:start', 'watch']);

    grunt.registerTask('build:js', [
        'jshint',
        'karma:development:run',
        'coverage',
        'concat:dist'
    ]);

    grunt.registerTask('build:css', [ 'less' ]);

    grunt.registerTask('coverage', 'Custom commmand-line reporter for karma-coverage', function() {
        var coverageReports = grunt.file.expand('coverage/*/coverage.txt'),
            reports = {},
            report, i, len;

        for (i = 0, len = coverageReports.length; i < len; i++) {
            report = grunt.file.read(coverageReports[i]);
            if (!reports[report]) {
                reports[report] = [coverageReports[i]];
            } else {
                reports[report].push(coverageReports[i]);
            }
        }

        for (report in reports) {
            if (reports.hasOwnProperty(report)) {
                for (i = 0, len = reports[report].length; i < len; i++) {
                    grunt.log.writeln(reports[report][i]);
                }
                grunt.log.writeln(report);
            }
        }
    });
};
<commit_msg>Add travis-ci task to Gruntfile.<commit_after>module.exports = function(grunt) {

    require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

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

        changelog: {},

        bump: {
            options: {
                files: ['package.json'],
                updateConfigs: [],
                commit: true,
                commitMessage: 'Release v%VERSION%',
                commitFiles: ['package.json'],
                createTag: true,
                tagName: 'v%VERSION%',
                tagMessage: 'Version %VERSION%',
                push: true,
                pushTo: 'origin',
                gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d'
            }
        },

        jshint: {
            options: {
                node: true,
                browser: true,
                esnext: true,
                bitwise: true,
                curly: true,
                eqeqeq: true,
                immed: true,
                indent: 4,
                latedef: true,
                newcap: true,
                noarg: true,
                regexp: true,
                undef: true,
                unused: true,
                trailing: true,
                smarttabs: true,
                globals: {
                    L: false,

                    // Mocha

                    describe: false,
                    it: false,
                    before: false,
                    after: false,
                    beforeEach: false,
                    afterEach: false,
                    chai: false,
                    expect: false,
                    sinon: false
                }
            },
            source: {
                src: [ 'src/*.js', 'Gruntfile.js', 'package.json' ]
            },
            test: {
                src: [ 'test/SpecHelper.js', 'test/src/**' ],
            },
            grunt: {
                src: [ 'Gruntfile.js' ]
            }
        },

        less: {
            source: {
                files: {
                    'dist/Leaflet.Toolbar.css': 'src/Toolbar.less'
                }
            }
        },

        karma: {
            travis: {
                configFile: 'test/karma.conf.js',
                background: false,
                singleRun: true,
                browsers: [ 'PhantomJS' ]
            },
            development: {
                configFile: 'test/karma.conf.js',
                background: true
            },
            unit: {
                configFile: 'test/karma.conf.js',
                background: false,
                singleRun: true
            }
        },

        watch: {
            options : {
                livereload: true
            },
            source: {
                files: [
                    'src/*.js',
                    'test/**',
                    'Gruntfile.js'
                ],
                tasks: [ 'build:js' ]
            },
            css: {
                files: [ 'src/*.less' ],
                tasks: [ 'build:css' ]
            }

        },

        concat: {
            dist: {
                options: {
                    banner: '(function(window, document, undefined) {\n\n"use strict";\n\n',
                    footer: '\n\n}(window, document));'
                },
                src: [
                    'src/ToolbarAction.js',
                    'src/Toolbar.js',
                    'src/ToolbarGroup.js',
                    'src/Toolbar.*.js'
                ],
                dest: 'dist/Leaflet.Toolbar.js',
            }
        }
    });

    /* Run tests once. */
    grunt.registerTask('test', [ 'jshint', 'karma:test', 'coverage' ]);

    /* Default (development): Watch files and lint, test, and build on change. */
    grunt.registerTask('default', ['karma:development:start', 'watch']);

    grunt.registerTask('travis', [ 'jshint', 'karma:travis' ]);

    grunt.registerTask('build:js', [
        'jshint',
        'karma:development:run',
        'coverage',
        'concat:dist'
    ]);

    grunt.registerTask('build:css', [ 'less' ]);

    grunt.registerTask('coverage', 'Custom commmand-line reporter for karma-coverage', function() {
        var coverageReports = grunt.file.expand('coverage/*/coverage.txt'),
            reports = {},
            report, i, len;

        for (i = 0, len = coverageReports.length; i < len; i++) {
            report = grunt.file.read(coverageReports[i]);
            if (!reports[report]) {
                reports[report] = [coverageReports[i]];
            } else {
                reports[report].push(coverageReports[i]);
            }
        }

        for (report in reports) {
            if (reports.hasOwnProperty(report)) {
                for (i = 0, len = reports[report].length; i < len; i++) {
                    grunt.log.writeln(reports[report][i]);
                }
                grunt.log.writeln(report);
            }
        }
    });
};
<|endoftext|>


<commit_before>describe('math editor', () => {
    before(waitUntil(() => $('.toolbar').length > 0 &&  $('.toolbar').is(':hidden')))

    describe('initial state', () => {
        it('answer field is contenteditable', () => {
            const $answer = $('.answer')
            expect($answer).to.have.attr('contenteditable', 'true')
            expect($answer).to.have.attr('data-js-handle', 'answer')
        })
    })

    describe('focus state', () => {
        before(() => {
            $('.answer1').focus()
            $('.answer1').focus() // TODO why two calls is necessary?
        })
        before(waitUntil(() => $('.toolbar').is(':visible')))

        it('shows tools', () => {
            expect($('.toolbar')).to.be.visible
            expect($('.answer1').prev()).to.have.class('toolbar')
        })
    })

    describe('start math', () => {
        before(() => {
        })

        it('shows tools', () => {

        })
    })
})

function waitUntil(condition) {
    return done => _waitUntil(condition, done)
}

function _waitUntil(condition, done) {
    if (condition()) done()
    else setTimeout(() => _waitUntil(condition, done), 200)
}
<commit_msg>Add test for clicking equation<commit_after>describe('math editor', () => {

    before(waitUntil(() => $('.toolbar').length > 0 &&  $('.toolbar').is(':hidden')))

    describe('initial state', () => {
        it('answer field is contenteditable', () => {
            const $answer = $('.answer')
            expect($answer).to.have.attr('contenteditable', 'true')
            expect($answer).to.have.attr('data-js-handle', 'answer')
        })
    })

    describe('focus state', () => {
        before(() => {
            $('.answer1').focus()
            $('.answer1').focus() // TODO why two calls is necessary?
        })
        before(waitUntil(() => $('.toolbar').is(':visible')))

        it('shows tools', () => {
            expect($('.toolbar')).to.be.visible
            expect($('.answer1').prev()).to.have.class('toolbar')
        })
    })

    describe('start math', () => {
        before(() => {
            $('.newEquation').mousedown()
        })

        it('shows tools', () => {
            expect($('.math')).to.be.visible
        })
    })
})

function waitUntil(condition) {
    return done => _waitUntil(condition, done)
}

function _waitUntil(condition, done) {
    if (condition()) done()
    else setTimeout(() => _waitUntil(condition, done), 200)
}
<|endoftext|>