浏览代码

added gulp load plugins, removed grunt file

Emanuele Marchi 11 年之前
父节点
当前提交
e715dc6b37
共有 3 个文件被更改,包括 27 次插入165 次删除
  1. 0 131
      Gruntfile.coffee
  2. 25 33
      gulpfile.js
  3. 2 1
      package.json

+ 0 - 131
Gruntfile.coffee

@@ -1,131 +0,0 @@
-"use strict"
-
-module.exports = (grunt) ->
-
-  # load all grunt tasks
-  require("matchdep").filterDev("grunt-*").forEach grunt.loadNpmTasks
-
-  grunt.initConfig
-
-    # load package.json
-    pkg: grunt.file.readJSON "package.json"
-
-    coffeelint:
-      options:
-        arrow_spacing:
-          level: "error"
-        no_empty_param_list:
-          level: "error"
-        no_unnecessary_fat_arrows:
-          level: "error"
-        space_operators:
-          level: "error"
-        indentation:
-          value: 2
-          level: "error"
-        max_line_length:
-          level: "ignore"
-      build: ["Gruntfile.coffee", "src/**/*.coffee"]
-
-    coffee:
-      default:
-        expand: true
-        cwd: "src/coffee"
-        src: "**/*.coffee"
-        dest: "build/js"
-        ext: ".js"
-      test:
-        expand: true
-        cwd: "src/test"
-        src: "**/*.coffee"
-        dest: "test/"
-        ext: ".js"
-
-    uglify:
-      build:
-        expand: true
-        src: "build/js/bootstrap-switch.js"
-        ext: ".min.js"
-
-    less:
-      build:
-        files:
-          "build/css/bootstrap2/bootstrap-switch.css": "src/less/bootstrap2/build.less"
-          "build/css/bootstrap3/bootstrap-switch.css": "src/less/bootstrap3/build.less"
-
-    cssmin:
-      build:
-        expand: true
-        src: ["build/css/bootstrap2/bootstrap-switch.css", "build/css/bootstrap3/bootstrap-switch.css"]
-        ext: ".min.css"
-
-    usebanner:
-      options:
-        banner: "/* ========================================================================\n" +
-        " * <%= pkg.name %> - v<%= pkg.version %>\n" +
-        " * <%= pkg.homepage %>\n" +
-        " * ========================================================================\n" +
-        " * Copyright 2012-2013 <%= pkg.author.name %>\n" +
-        " *\n" +
-        " * ========================================================================\n" +
-        " * Licensed under the Apache License, Version 2.0 (the \"License\");\n" +
-        " * you may not use this file except in compliance with the License.\n" +
-        " * You may obtain a copy of the License at\n" +
-        " *\n" +
-        " *     http://www.apache.org/licenses/LICENSE-2.0\n" +
-        " *\n" +
-        " * Unless required by applicable law or agreed to in writing, software\n" +
-        " * distributed under the License is distributed on an \"AS IS\" BASIS,\n" +
-        " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" +
-        " * See the License for the specific language governing permissions and\n" +
-        " * limitations under the License.\n" +
-        " * ========================================================================\n" +
-        " */\n"
-      css:
-        files:
-          src: ["build/**/*.css"]
-      js:
-        files:
-          src: ["build/**/*.js"]
-
-    jshint:
-      all: ["*.json"]
-
-    clean:
-      css: "build/css"
-      js: "build/js"
-      test: "test"
-
-    connect:
-      go:
-        options:
-          port: 3000
-
-    open:
-      go:
-        path: "http://localhost:<%= connect.go.options.port %>"
-
-    bump:
-      options:
-        files: ["package.json", "bower.json"]
-        commitFiles: ["-a"]
-        push: false
-
-    jasmine:
-      options:
-        keepRunner: true
-        specs: "test/**/*.js"
-        vendor: ["docs/vendor/jquery.min.js", "docs/vendor/bootstrap.min.js"]
-      src: "build/js/bootstrap-switch.js"
-
-    watch:
-      coffee:
-        files: ["src/**/*.coffee"]
-        tasks: ["clean:js", "coffeelint", "coffee", "uglify", "usebanner:js"]
-      less:
-        files: ["src/**/*.less"],
-        tasks: ["clean:css", "less", "cssmin", "usebanner:css"]
-
-  grunt.registerTask "go", ["build", "connect", "open", "watch"]
-  grunt.registerTask "build", ["clean", "coffeelint", "coffee", "uglify", "less", "cssmin", "usebanner"]
-  grunt.registerTask "test", ["build", "jasmine"]

+ 25 - 33
gulpfile.js

@@ -1,13 +1,5 @@
 var gulp = require('gulp');
-var gutil = require('gulp-util');
-var coffeelint = require('gulp-coffeelint');
-var coffee = require('gulp-coffee');
-var rename = require('gulp-rename');
-var uglify = require('gulp-uglify');
-var less = require('gulp-less');
-var header = require('gulp-header');
-var clean = require('gulp-clean');
-var open = require('gulp-open');
+var plugins = require("gulp-load-plugins")();
 var pkg = require('./package.json');
 var name = pkg.name;
 var banner = [
@@ -36,60 +28,58 @@ var banner = [
 
 gulp.task('coffee', function() {
   gulp.src('src/coffee/' + name + '.coffee')
-    .pipe(coffeelint({
+    .pipe(plugins.coffeelint({
       indentation: 2,
       no_trailing_semicolons: true,
       no_trailing_whitespace: true
     }))
-    .pipe(coffee()).on('error', gutil.log)
-    .pipe(header(banner, { pkg: pkg }))
+    .pipe(plugins.coffee()).on('error', plugins.util.log)
+    .pipe(plugins.header(banner, { pkg: pkg }))
     .pipe(gulp.dest('build/js'))
-    .pipe(uglify())
-    .pipe(header(banner, { pkg: pkg }))
-    .pipe(rename({ suffix: '.min' }))
+    .pipe(plugins.uglify())
+    .pipe(plugins.header(banner, { pkg: pkg }))
+    .pipe(plugins.rename({ suffix: '.min' }))
     .pipe(gulp.dest('build/js'));
 });
 
 gulp.task('less-bootstrap2', function() {
   gulp.src('src/less/bootstrap2/build.less')
-    .pipe(less())
-    .pipe(header(banner, { pkg: pkg }))
-    .pipe(rename({ basename: name }))
+    .pipe(plugins.less())
+    .pipe(plugins.header(banner, { pkg: pkg }))
+    .pipe(plugins.rename({ basename: name }))
     .pipe(gulp.dest('build/css/bootstrap2'))
-    .pipe(less({
+    .pipe(plugins.less({
       compress: true,
       cleancss: true
     }))
-    .pipe(header(banner, { pkg: pkg }))
-    .pipe(rename({ suffix: '.min' }))
+    .pipe(plugins.header(banner, { pkg: pkg }))
+    .pipe(plugins.rename({ suffix: '.min' }))
     .pipe(gulp.dest('build/css/bootstrap2'));
 });
 
 gulp.task('less-bootstrap3', function() {
-  gulp.src([
-      'src/less/bootstrap3/build.less',
-    ])
-    .pipe(less())
-    .pipe(header(banner, { pkg: pkg }))
-    .pipe(rename({ basename: name }))
+  gulp.src('src/less/bootstrap3/build.less')
+    .pipe(plugins.less())
+    .pipe(plugins.header(banner, { pkg: pkg }))
+    .pipe(plugins.rename({ basename: name }))
     .pipe(gulp.dest('build/css/bootstrap3'))
-    .pipe(less({
+    .pipe(plugins.less({
       compress: true,
       cleancss: true
     }))
-    .pipe(header(banner, { pkg: pkg }))
-    .pipe(rename({ suffix: '.min' }))
+    .pipe(plugins.header(banner, { pkg: pkg }))
+    .pipe(plugins.rename({ suffix: '.min' }))
     .pipe(gulp.dest('build/css/bootstrap3'));
 });
 
 gulp.task('clean', function() {
   gulp.src(['build/css', 'build/js'], { read: false })
-    .pipe(clean());
+    .pipe(plugins.clean());
 });
 
 gulp.task('open', function(){
   gulp.src('index.html')
-    .pipe(open());
+    .pipe(plugins.open());
 });
 
 gulp.task('watch', function () {
@@ -98,4 +88,6 @@ gulp.task('watch', function () {
   gulp.watch('src/less/bootstrap3/*.less', ['less-bootstrap3']);
 });
 
-gulp.task('default', ['clean', 'coffee', 'less-bootstrap2', 'less-bootstrap3', 'open', 'watch']);
+gulp.task('default', ['clean'], function() {
+  gulp.start('coffee', 'less-bootstrap2', 'less-bootstrap3', 'open', 'watch')
+});

+ 2 - 1
package.json

@@ -46,6 +46,7 @@
     "gulp": "~3.5.2",
     "gulp-less": "~1.2.1",
     "gulp-rename": "~1.0.0",
-    "gulp-open": "~0.2.8"
+    "gulp-open": "~0.2.8",
+    "gulp-load-plugins": "~0.3.0"
   }
 }