Gruntfile.js - 找不到任务“默认”

时间:2015-03-19 15:03:39

标签: javascript node.js gruntjs

我正在尝试扩展此处构建的D3 Calendar Viz库:https://github.com/kamisama/cal-heatmap

我已经克隆了回购。代码使用Grunt作为构建过程,因此我已经安装了Grunt-Cli并在目录中运行npm install,这有效。正在运行grunt我收到错误:

Warning: Task "default" not found. Use --force to continue.

我已将grunt.js文件放入http://esprima.org/demo/validate.html并且它已返回且没有错误。我无法弄清楚为什么咕噜不在这里工作。

这是grunt.js文件:

module.exports = function(grunt) {

    "use strict";

    var headerComment = "/*! <%= pkg.name %> v<%= pkg.version %> (<%= grunt.template.today() %>)\n" +
                " *  ---------------------------------------------\n" +
                " *  <%= pkg.description %>\n" +
                " *  <%= pkg.homepage %>\n" +

                " *  Licensed under the <%= pkg.license %> license\n" +
                " *  Copyright 2014 <%= pkg.author.name %>\n" +
                " */\n";

    // Project configuration.
    grunt.initConfig({
        pkg: grunt.file.readJSON("package.json"),
        jshint: {
            options: {
                jshintrc: ".jshintrc"
            },
            lib: {
                src: ["src/<%= pkg.name %>.js"]
            },
            test: {
                options: {
                    jshintrc: "test/.jshintrc"
                },
                src: ["test/test.js", "test/test-amd.js"]
            }
        },
        csslint: {
            base: {
                src: "<%= pkg.name %>.css",
                rules: {
                    "known-properties": false,
                    "box-sizing": false
                }
            }
        },
        uglify: {
            options: {
                banner: headerComment
            },
            base: {
                files: {
                    "<%= pkg.name %>.min.js" : ["<%= pkg.name %>.js"]
                }
            }
        },
        qunit: {
            options: {
                "--web-security": "no",
                coverage: {
                    src: ["src/*.js"],
                    instrumentedFiles: "temp/",
                    htmlReport: "report/coverage",
                    coberturaReport: "report/"
                }
            },
            all: ["test/*.html"]
        },
        concat: {
            options: {
                banner: headerComment + "\n"
            },
            js: {
                src: ["src/<%= pkg.name %>.js"],
                dest: "<%= pkg.name %>.js"
            },
            test: {
                src: ["test/src/function.js", "test/src/**/*.js"],
                dest: "test/test.js"
            }
        },
        coveralls: {
            options: {
                coverage_dir: "coverage/"
            }
        },
        watch: {
            scripts: {
                files: "test/src/**/*.js",
                tasks: ["concat:test"],
                options: {
                    interrupt: true,
                }
            },
            lint: {
                files: "src/*.js",
                tasks: ["jshint:lib"],
                options: {
                    interrupt: true,
                }
            }
        }
    });

    grunt.loadNpmTasks("grunt-contrib-jshint");
    grunt.loadNpmTasks("grunt-contrib-uglify");
    grunt.loadNpmTasks("grunt-css");
    grunt.loadNpmTasks("grunt-contrib-qunit");
    grunt.loadNpmTasks("grunt-contrib-concat");
    grunt.loadNpmTasks("grunt-karma-coveralls");
    grunt.loadNpmTasks("grunt-contrib-watch");

    // TO RUN BEFORE COMMIT
    // ====================
    grunt.registerTask("quick-build", ["csslint", "jshint"]);

    // Full build without version bump
    grunt.registerTask("build", ["concat", "qunit", "csslint", "jshint", "uglify"]);

    // FOR TRAVIS
    // ==========
    grunt.registerTask("travis", ["jshint", "csslint"]);
};

这是package.json文件:

{
  "name": "cal-heatmap",
  "version": "3.5.2",
  "description": "Cal-Heatmap is a javascript module to create calendar heatmap to visualize time series data",
  "keywords": [
    "calendar",
    "graph",
    "d3js",
    "heat map"
  ],
  "main": "cal-heatmap.min.js",
  "directories": {
    "test": "test"
  },
  "dependencies": {
    "d3": ">= v3.0.6"
  },
  "devDependencies": {
    "grunt": "~0.4.5",
    "grunt-contrib-uglify": "~0.7.0",
    "grunt-contrib-copy": "~0.7.0",
    "grunt-contrib-jshint": "~0.11.0",
    "grunt-contrib-concat": "~0.5.0",
    "grunt-contrib-watch": "~0.6.1",
    "grunt-contrib-qunit": "~0.5.2",

    "grunt-css": "~0.5.4",
    "grunt-replace": "~0.8.0",

    "phantomjs": "~1.9.15",
    "karma": "~0.12.31",
    "karma-coverage": "~0.2.7",
    "karma-qunit": "~0.1.4",
    "karma-phantomjs-launcher": "~0.1.4",
    "grunt-karma-coveralls": "~2.5.3",

    "qunitjs": "~1.17.0",
    "jquery": "~1.9.1"
  },
  "scripts": {
    "test": "grunt travis --verbose; ./node_modules/karma/bin/karma start --single-run --browsers PhantomJS"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/kamisama/cal-heatmap.git"
  },
  "homepage": "https://github.com/kamisama/cal-heatmap",
  "author": {
    "name": "Wan Qi Chen",
    "url": "http://www.kamisama.me"
  },
  "license": "MIT",
  "gitHead": "e7bf798c210e0c25df9f6857bdb268001ef67fd1",
  "volo": {
    "dependencies": {
      "d3": "d3"
    }
  },
  "jam": {
    "dependencies": {
      "d3": ">=3.0.6"
    }
  },
  "bugs": "https://github.com/kamisama/cal-heatmap/issues",
  "github": "https://github.com/kamisama/cal-heatmap",
  "categories": [
    "Data",
    "Visualization"
  ]
}

1 个答案:

答案 0 :(得分:1)

您需要定义默认任务,例如下面的内容。

grunt.registerTask("default", [ "lint", "test", "coverage" ]);