Grunt之添加文件监视:Grunt-watch (已备份)

今天又完善了一下Grunt的Task,增加了JSHint和Watch功能,再修改了每个NodeJs代码之后,会运行JSHint对代码进行检查。修改了LESS文件之后,会重现编译LESS为CSS代码:


"use restrict";

var _ = require('underscore')
  , path = require('path')
  , fs = require('fs');


var scriptFiles = _.chain({
    self: ['*.js'],
    test: ['../Test/*.js', '../Test/test/*.js', '../Test/FakedWebService/*.js', '../Test/FakedWebService/*/*.js'],
    webSite: ['../WebSite/*.js', '../WebSite/*/*.js'],
    webService: ['../WebService/*.js', '../WebService/*/*.js']
}).values().flatten().value();

var lessFilePairs = [
    { "../WebSite/public/css/site.css": "../WebSite/public/less/site.less" },
    { "../WebSite/public/css/page_send_report.css": "../WebSite/public/less/page_send_report.less" },
    { "../WebSite/public/css/page_data_mining.css": "../WebSite/public/less/page_data_mining.less" },
    { "../WebSite/public/css/page_bucket_table.css": "../WebSite/public/less/page_bucket_table.less" }
];


module.exports = function (grunt) {
    grunt.initConfig({
        ftpscript: {
            uploadFixRateData: {
                options: {
                    host: 'cadcptdgaop5',
                    port: 21,
                    passive: false
                },
                files: [
                    { expand: true, cwd: './tmp', src: ['fixed_report_count.txt'], dest: '/data/' }
                ]
            }
        },

        shell: {
            exportFixRateData: {
                command: '../WebService/DbAdmin.exe -e tmp/fixed_report_count.txt',
                options: {
                    async: false,
                    stdout: true
                }
            }
        },

        less: {
            dev: {
                options: {
                    paths: ["../WebSite/public/less"]
                },
                files: lessFilePairs
            },
            prod: {
                options: {
                    paths: ["../WebSite/public/less"],
                    yuicompress: true
                },
                files: lessFilePairs
            }
        },

        mochacli: {
            options: {
                //require: ['should'],
                files: '../Test/test/*.js'
            },
            spec: {
                options: {
                    reporter: 'spec'
                }
            },
            "default": {
            }
        },

        jshint: {

            options: {
                laxcomma: true,   // Allow comma-first coding style
                expr: true,       // Be compatible with the "cute" shouldJs
                globals: {
                    node: true,
                    mootools: true
                }
            },

            "default": scriptFiles
        },

        watch: {
            scripts: {
                files: scriptFiles,
                tasks: ['jshint'],
                options: {
                    debounceDelay: 250
                }
            }, 

            less: {
                files: "../WebSite/public/less/*.less",
                tasks: ['less:dev'],
                options: {
                    debounceDelay: 250
                }
            }
        }
    });

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

    // Help
    //
    grunt.registerTask(
        "default", "Help",
        function () {
            console.log(fs.readFileSync('ReadMe.txt').toString());
        }
    );

    // Backup and Restore
    //
    grunt.registerTask(
        "backup_fix_rate_data",
        "upload exported fix rate data to backup server",
        ["shell:exportFixRateData", "ftpscript:uploadFixRateData"]);

    // Build & Compile
    //
    grunt.registerTask(
        "dev",
        "Compile and make",
        ["less:dev"], ["watch"]);

    grunt.registerTask(
        "prod",
        "Compile and release",
        ["less:prod"]);

    grunt.registerTask(
        "ut",
        "Run Mocha Unit Test",
        ['mochacli:default']);

    grunt.registerTask(
        "spec",
        "Run Mocha Unit Test",
        ['mochacli:spec']);

};

在研究JSHint的时候,发现,原来还有个JSLint,JSHint是基于JSLint的并做了改进。

另外,使用Should库的时候,JSHint会报错,他认为should库使用表达式作为语句运行时不规范的,例如 something.should.be.ok;我也看到了TJ大神与某个人的辩论,TJ认为,shouldJs库是可爱的,而且Unit Test框架应该可爱些,TJ是不会妥协的:https://github.com/visionmedia/should.js/issues/9,解决方法很简单,修改JSHint的参数就可以了。没啥大不了的。




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值