示例#1
0
module.exports = function(grunt)
{

  grunt.loadNpmTasks('grunt-closure-tools');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-connect');
  grunt.loadNpmTasks('grunt-contrib-nodeunit');
  grunt.loadNpmTasks('grunt-contrib-livereload');
  grunt.loadNpmTasks('grunt-contrib-qunit');
  grunt.loadNpmTasks('grunt-regarde');

  var lrSnippet = require('grunt-contrib-livereload/lib/utils').livereloadSnippet;

  var folderMount = function folderMount(connect, point) {
    return connect.static(path.resolve(point));
  };

  //grunt.loadTasks('closure-tools/tasks');
  // Project configuration.
  grunt.initConfig({
    // closureBuilder not used on purpose.
    closureCompiler: {
      options: {
        compilerFile: compiler.getPathSS()
      },
      server2js: {
        options: {
          compilerOpts: {
            compilation_level: 'ADVANCED_OPTIMIZATIONS',
            warning_level: 'verbose',
            summary_detail_level: 3,
            define: ["'goog.DEBUG=false'", "'ss.STANDALONE=true'"],
            output_wrapper: '"!function(){%output%}.call(this);"',
            externs: 'build/json.extern.js'
          }
        },
        src: [
          'closure-library/closure/goog/base.js',
          'src/server2js.export.js',
          'src/server2.js'
          ],
        dest: 'dist/server2.min.js'
      },
      testHelpers: {
        options: {
          compilerOpts: {
            compilation_level: 'SIMPLE_OPTIMIZATIONS',
            externs: 'test/libs/externs.goog.string.js'
          }
        },
        src: [
          'closure-library/closure/goog/base.js',
          'closure-library/closure/goog/string/string.js',
          'test/libs/build.goog.string.js'
        ],
        dest: 'test/libs/goog.stack.js'
      }
    },
    closureDepsWriter: {
      options: {
        closureLibraryPath: 'closure-library'
      },
       // any name that describes your operation
      targetName: {
        src: ['server2.js', 'build/server2js.export.js'],
        dest: 'build/deps.js'
      }
    },

    /**
     * Live Reload
     *
     */
   regarde: {
      all: {
        files: ['test/**/*.js', 'src/**/*.js', 'lib/**/*.js', './*.js'],
        tasks: ['livereload', 'test:node']
      }
    },

    //
    // watch is not yet compatible with livereload
    //
    watch: {
      test: {
        options: {
          nospawn: true
        },
        files: ['test/**/*.js', 'src/**/*.js', 'lib/**/*.js', './*.js'],
        tasks: ['test']
      }
    },

    /**
     * TESTING
     *
     */
    connect: {
      livereload: {
        options: {
          port: 9001,
          middleware: function(connect, options) {
            return [lrSnippet, folderMount(connect, '.')];
          }
        }
      },
      test: {
        options: {
          port: 8888,
          base: './',
          keepalive: false
        }
      }
    },
    qunit: {
      source: {
        options: {
          urls: ['http://localhost:8888/test/']
        }
      },
      compiled: {
        options:{
          urls: ['http://localhost:8888/test/index.html?compiled=true']
        }
      }
    },

    nodeunit: {
      all: ['test/node/**/*.js']
    }
  });

  grunt.registerTask('test', 'Test all or specific targets', function(target) {
    var nodeTest = [
      'nodeunit:all'
    ];

    var webTest = [
      'connect:test',
      'qunit:source',
      'qunit:compiled'
    ];

    // clear temp folder v0.4 way
    grunt.file.expand( ['temp/*'] )
      .forEach( grunt.file.delete );

    //return;
    switch( target ) {
      case 'node':
        grunt.task.run(nodeTest);
      break;
      case 'web':
        grunt.task.run(webTest);
      break;
      default:
        grunt.task.run(nodeTest);
        grunt.task.run(webTest);
      break;
    }

  });

  // Default task.
  grunt.registerTask('default', 'test');
  grunt.registerTask('build', 'closureCompiler:server2js');
  grunt.registerTask('live', ['livereload-start', 'connect:livereload', 'regarde']);
};
示例#2
0
module.exports = function(grunt) {

  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-nodeunit');

  // initialize the tasks manually.
  closureTools(grunt);

  // Project configuration.
  grunt.initConfig({

    closureDepsWriter: {
      options: {
        depswriter: cTools.getPath( 'build/depswriter.py' ),
        root: 'test/case/'
      },
      testCase: {
        dest: 'temp/deps.js'
      }
    },
   closureBuilder:  {
      options: {
        builder: cTools.getPath('build/closurebuilder.py'),
        // This is required if you set the option "compile" to true.
        compilerFile: ssCompiler.getPathSS(),
        inputs: 'test/case/js/app.js'

      },

      // any name that describes your operation
      testCaseBundle: {
        options: {
          output_mode: 'script',
          compile: false // boolean
        },
        src: ['test/case/js/', 'test/case/closureMock'],
        dest: 'temp/build.bundled.js'
      },
      testCaseCompile: {
        options: {
          output_mode: 'compile',
          compile: true,
          compilerOpts: {
            compilation_level: 'ADVANCED_OPTIMIZATIONS',
            warning_level: 'verbose',
            externs: 'test/case/externs.js',
            summary_detail_level: 3,
            output_wrapper: '(function(){%output%}).call(this);'
          }
        },
        src: ['test/case/js/', 'test/case/closureMock'],
        dest: 'temp/build.compiled.js'
      }
    },
    closureCompiler: {
      options: {
        compilerFile: ssCompiler.getPathSS(),
        compilerOpts: {
          compilation_level: 'ADVANCED_OPTIMIZATIONS',
          warning_level: 'verbose',
          externs: 'test/case/externs.js',
          summary_detail_level: 3,
          output_wrapper: '"(function(){%output%}).call(this);"'
        }
      },
      testCase: {
        src: 'temp/build.bundled.js',
        dest: 'temp/compiler.compiled.js'
      },
      testCaseNoSrc: {
        dest: 'temp/compiler.compiled.js'
      }

    },

    watch: {
      test: {
        files: [
          'test/{builder,compiler,depsWriter}/**/*.js',
          'tasks/**/*.js'
        ],
        tasks: ['test']
      },
      builder: {
        files: ['tasks/*.js'],
        tasks: ['closureBuilder:readyjs']
      },
      depsWriter: {
        files: ['tasks/*.js'],
        tasks: ['closureDepsWriter:todoApp']
      }
    },
    nodeunit: {
      all: [
        // all lib tests
        'test/{builder,compiler,depsWriter}/**/*.js',
        // grunt task tests
        'test/*.js'
      ]
    }
  });

  // "npm test" runs these tasks,
  // run all the build tasks first.
  grunt.registerTask( 'test', [
    'closureDepsWriter:testCase',
    'closureBuilder:testCaseBundle',
    'closureBuilder:testCaseCompile',
    'closureCompiler:testCase',
    // not ready yet
    //'closureCompiler:testCaseNoSrc',
    'nodeunit']);

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

};
module.exports = function (grunt) {

  //
  //
  // Config basic parameters
  //
  //
  //
  var CONF = {
    // the base file of your project. The full path will result by concatenating
    // appPath + bootstrapFile
    bootstrapFile: 'main.js',

    // The folder that contains all the externs files.
    externsPath: 'build/externs/',

    // The path to the closure library
    closureLibrary: 'closure-library',

    // the compiled file
    destCompiled: 'dist/app.js',

    // define the path to the app
    appPath: 'lib/',

    // The location of the source map
    sourceMap: 'dist/sourcemap.js.map',

    // This sting will wrap your code marked as %output%
    // Take care to edit the sourcemap path
    outputWrapper: '(function(){%output%}).call(this);' +
      '//@sourceMappingURL=dist/sourcemap.js.map'
  };

  // the file globbing pattern for vendor file uglification.
  CONF.vendorFiles = [
      // all files JS in vendor folder
      CONF.appPath + '/vendor/*.js',

      // and do not include jQuery, we'll use a CDN for it.
      '!' + CONF.appPath + '/vendor/jQuery*'
    ];



  //
  //
  // Start Gruntconfig
  //
  //
  // load all grunt tasks
  require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

  grunt.initConfig({
    watch: {
      livereload: {
        files: [
          CONF.appPath + '/**/*.js'
        ],
        tasks: ['livereload']
      },
      test: {
        files: [
          CONF.appPath + '/**/*.js',
          'test/**/*.js'
        ],
        tasks: ['livereload']
      }
    },
    connect: {
      options: {
        port: 9000,
        // change this to '0.0.0.0' to access the server from outside
        hostname: 'localhost',
        keepalive: false
      },
      livereload: {
        options: {
          middleware: function (connect) {
            return [ lrSnippet, mountFolder(connect, 'lib/')];
          }
        }
      },
      test: {
        options: {
          port: 4242,
          base: './',
          keepalive: false
        }
      }
    },
    open: {
      server: {
        path: 'http://localhost:<%= connect.options.port %>'
      },
      test: {
        path: 'http://localhost:<%= connect.test.options.port %>/test/'
      }
    },

    mocha: {
      all: {
        options: {
          run: true,
          ignoreLeaks: false,
          urls: [
            'http://localhost:<%= connect.test.options.port %>/test/index.html',
            'http://localhost:<%= connect.test.options.port %>/test/index.html?compiled=true',
            'http://localhost:<%= connect.test.options.port %>/test/index.html?unit=true'
          ]
        }
      }
    },


    //
    //
    //
    // Closure Tools Tasks
    //
    // Dependency & Compiling
    //
    //
    //
    closureDepsWriter: {
      options: {
        closureLibraryPath: CONF.closureLibrary
      },
      app: {
        options: {
          root_with_prefix: ['"' + CONF.appPath + ' ../../../lib"']
        },
        dest: '' + CONF.appPath + '/deps.js'
      },
      bddTest: {
        options: {
          root_with_prefix: ['"test ../../../../../test"']
        },
        dest: 'test/bdd/deps-test-bdd.js'
      },
      unitTest: {
        options: {
          root_with_prefix: ['"test ../../../../../test"']
        },
        dest: 'test/unit/deps-test-tdd.js'
      }
    },
    closureBuilder: {
      options: {
        closureLibraryPath: CONF.closureLibrary,
        inputs: [CONF.appPath + CONF.bootstrapFile],
        compile: true,
        compilerFile: compiler.getPathSS(),
        compilerOpts: {
          compilation_level: 'ADVANCED_OPTIMIZATIONS',
          externs: [CONF.externsPath + '*.js'],
          define: [
            '\'goog.DEBUG=false\''
            ],
          warning_level: 'verbose',
          jscomp_off: ['checkTypes', 'fileoverviewTags'],
          summary_detail_level: 3,
          only_closure_dependencies: null,
          closure_entry_point: CONF.entryPoint,
          create_source_map: CONF.sourceMap,
          source_map_format: 'V3',
          output_wrapper: CONF.outputWrapper

        }
      },
      app: {
        src: [CONF.appPath, CONF.closureLibrary],
        dest: 'temp/compiled.js'
      },
      debug: {
        options: {
          compilerFile: compiler.getPath()
        },
        src: [CONF.appPath, CONF.closureLibrary],
        dest: 'temp/compiled.debug.js'
      }
    },

    // clean, uglify and concat aid in building
    clean: {
      dist: ['temp'],
      server: 'temp'
    },
    uglify: {
      vendor: {
        files: {
          'temp/vendor.js': CONF.vendorFiles
        }
      }
    },
    concat: {
        production: {
          src: ['temp/vendor.js', 'temp/compiled.js'],
          dest: CONF.destCompiled
        }
    },


    //
    //
    //
    // Optional boilerplate tasks
    //
    //
    imagemin: {
      dist: {
        files: [{
          expand: true,
          cwd: 'app/images',
          src: '{,*/}*.{png,jpg,jpeg}',
          dest: 'app/images'
        }]
      }
    },
    cssmin: {
      dist: {
        files: {
          'app/styles/main.css': [
            'temp/styles/{,*/}*.css',
            'app/styles/{,*/}*.css'
          ]
        }
      }
    }
  }); // end grunt.initConfig();



  //
  //
  // initConfig END
  //
  // Register tasks
  //
  //
  grunt.renameTask('regarde', 'watch');

  grunt.registerTask('server', function (target) {
    if (target === 'test') {
      return grunt.task.run([
        'clean:server',
        'livereload-start',
        'connect:test',
        'open:test',
        'watch:test'
      ]);
    }

    grunt.task.run([
      'clean:server',
      'livereload-start',
      'connect:livereload',
      'open:server',
      'watch:livereload'
    ]);
  });

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

  grunt.registerTask('build', [
    'clean:dist',
    'uglify:vendor',
    'closureBuilder:app',
    'concat:production'
  ]);

  grunt.registerTask('deps', [
    'closureDepsWriter:app',
    'closureDepsWriter:bddTest',
    'closureDepsWriter:unitTest'
  ]);

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

};
示例#4
0
module.exports = function(grunt) {

  // load all grunt tasks
  require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

  var lrSnippet = require('grunt-contrib-livereload/lib/utils').livereloadSnippet;

  var folderMount = function folderMount(connect, point) {
    return connect.static(path.resolve(point));
  };


  var externsPath = 'build/externs/';
  // don't put the extension here
  var debugFile = 'src/helpers/debug';

  // Project configuration.
  grunt.initConfig({
    closureDepsWriter: {
      options: {
        closureLibraryPath: 'closure-library/'

      },
      ss: {
        options: {
          root_with_prefix: ['"src ../../../src"']
        },
        dest: 'src/deps-superstartup.js'
      },
      bddTest: {
        options: {
          root_with_prefix: ['"test ../../../../../test"']
        },
        dest: 'test/bdd/deps-test-bdd.js'
      },
      tddTest: {
        options: {
          root_with_prefix: ['"test ../../../../../test"']
        },
        dest: 'test/unit/deps-test-tdd.js'
      }
    },
    closureBuilder: {
      options: {
        closureLibraryPath: 'closure-library',
        inputs: ['src/main.js'],
        compile: true,
        compilerFile: compiler.getPathSS()

      },

      superstartup: {
        options: {
          compilerOpts: {
            compilation_level: 'ADVANCED_OPTIMIZATIONS',
            externs: [externsPath + '*.js', externsPath + 'when.externs.js'],
            define: [
              '\'goog.DEBUG=false\'',
              '\'ss.STANDALONE=false\''
            ],
            warning_level: 'verbose',
            jscomp_off: ['checkTypes', 'fileoverviewTags'],
            summary_detail_level: 3,
            only_closure_dependencies: null,
            closure_entry_point: 'ssd',
            // output_wrapper: '(function(){%output%}).call(this);',
            formatting: 'PRETTY_PRINT',
            debug: null
          }
        },
        src: ['src', 'closure-library'],
        dest: 'dist/superstartup.min.js'


      }
    },



    /**
     * Live Reload
     *
     */
    regarde: {
      compiled: {
        files: ['src/**/*.js'],
        tasks: ['build','livereload']
      },
      dev: {
        files: ['src/**/*.js', 'test/bdd/**/*.js'],
        tasks:['livereload']
      }
    },
    connect: {
      livereload: {
        options: {
          port: 9001,
          middleware: function(connect) {
            return [lrSnippet, folderMount(connect, '.')];
          }
        }
      },
      test: {
        options: {
          port: 4242,
          base: './',
          keepalive: false
        }
      }
    },
    //
    // watch is not yet compatible with livereload
    //
    watch: {
      test: {
        options: {
          nospawn: true
        },
        files: ['src/**/*.js'],
        tasks: ['build']
      }
    },
    open: {
      server: {
        path: 'http://localhost:<%= connect.livereload.options.port %>/test/bdd'
      }
    },




    /**
     *
     * TESTING
     *
     */

    mochaPhantom: 'node_modules/mocha-phantomjs/bin/mocha-phantomjs ' +
      'http://localhost:<%= connect.test.options.port %>/test/',

    mocha: {
      options: {
        run: true
      },
      bdd: {
        options: {
          urls: ['http://localhost:<%= connect.test.options.port %>/test/bdd/']
        }
      },
      bddCompiled: {
        urls: ['http://localhost:<%= connect.test.options.port %>/test/bdd/' +
          'index.html?compiled=true']
      },
      unit: {
        options: {
          urls: ['http://localhost:<%= connect.test.options.port %>/test/unit/']
        }
      }
    }
  });

  grunt.registerTask('test', [
    'connect:test',
    'mocha:bdd'
    // 'shell:mochaPhantomUnit',
    // 'shell:mochaPhantom',
    // 'shell:mochaPhantomCompiled'
  ]);

  grunt.registerTask('deps', 'closureDepsWriter');
  grunt.registerTask('build', 'closureBuilder:superstartup');
  grunt.registerTask('server', [
    'livereload-start',
    'connect:livereload',
    'open:server',
    'regarde:dev'
  ]);

  grunt.registerTask('server:compiled', [
    'livereload-start',
    'connect:livereload',
    'open:server',
    'regarde:compiled'
  ]);

  // Default task.
  grunt.registerTask('default', 'test');

  grunt.registerTask('compile', 'debugOff closureBuilder:superstartup debugOn');

  // "Turn off" the debug file. Remove requirements to
  // goog debug libraries
  grunt.registerTask('debugOff', 'Replace debug file with an empty one', function(){
    var content = 'goog.provide("ss.debug");';

    // execute the task
    grunt.file.write(debugFile + '.js', content);
  });

  // restore the debug file
  grunt.registerTask('debugOn', 'Restore debug file', function(){
    grunt.file.copy(debugFile + '.bak', debugFile + '.js');
  });

};