Skip to content
Snippets Groups Projects
Gruntfile.coffee 19.5 KiB
Newer Older
  • Learn to ignore specific revisions
  • Laura Cappelli's avatar
    Laura Cappelli committed
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
    ###
    Build scripts for Fancytree
    ###
    
    # jshint directives for the generated JS:
    
    ###jshint node: true, unused: false ###
    
    "use strict"
    
    module.exports = (grunt) ->
    
      grunt.initConfig
    
        pkg:
            grunt.file.readJSON("package.json")
    
        # Project metadata, used by the <banner> directive.
        meta:
            # banner: "/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - " +
            banner: "/*! <%= pkg.title || pkg.name %> - @VERSION - @DATE\n" +
                    # "<%= grunt.template.today('yyyy-mm-dd HH:mm') %>\n" +
                    "<%= pkg.homepage ? '  * ' + pkg.homepage + '\\n' : '' %>" +
                    "  * Copyright (c) <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>;" +
                    " Licensed <%= _.map(pkg.licenses, 'type').join(', ') %> */\n"
    
        clean:
            build:
                src: [ "build" ]
            dist:
                src: [ "dist" ]
            extMin:
                src: [ "build/jquery.fancytree.*.min.js" ]
    
        # compress:
        #     dist:
        #         options:
        #             archive: "archive/<%= pkg.name %>-<%= pkg.version %>.zip"
        #         files: [
        #             {expand: true, cwd: "dist/", src: ["**/*"], dest: ""}
        #             ]
    
        concat:
            core:
                options:
                    stripBanners: true
                src: ["<banner:meta.banner>"
                      # "lib/intro.js"
                      "src/<%= pkg.name %>.js"
                      # "lib/outro.js"
                      ]
                dest: "build/<%= pkg.name %>.js"
            all:
                options:
                    stripBanners: true
                src: [
                    "<%= meta.banner %>"
                    # "lib/intro.js"
                    "src/jquery.fancytree.js"
    #                "build/jquery.fancytree.ariagrid.js"
                    "src/jquery.fancytree.childcounter.js"
                    "src/jquery.fancytree.clones.js"
    #                "src/jquery.fancytree.columnview.js"
                    "src/jquery.fancytree.dnd.js"
                    "src/jquery.fancytree.dnd5.js"
                    "src/jquery.fancytree.edit.js"
                    "src/jquery.fancytree.filter.js"
    #                "src/jquery.fancytree.fixed.js"
                    "src/jquery.fancytree.glyph.js"
                    "src/jquery.fancytree.gridnav.js"
    #                "src/jquery.fancytree.menu.js"
                    "src/jquery.fancytree.persist.js"
                    "src/jquery.fancytree.table.js"
                    "src/jquery.fancytree.themeroller.js"
                    "src/jquery.fancytree.wide.js"
                    # "lib/outro.js"
                    ]
                dest: "build/<%= pkg.name %>-all.js"
            custom:
                options:
                    banner: "<%= meta.banner %>"
                    stripBanners: true
                    process: (src, fspec) ->
                      # Remove all comments, including /*! ... */
                      src = src.replace(/\/\*(.|\n)*\*\//g, "")
                      if /fancytree..+.min.js/.test(fspec)
                        # If it is an extension:
                        # Prepend a one-liner instead
                        fspec = fspec.substr(6) # strip 'build/'
                        src = "\n/*! Extension '" + fspec + "' */" + src
                      return src
                src: [
                    "lib/intro.js"
                    "build/jquery.fancytree.min.js"
    #                "build/jquery.fancytree.ariagrid.min.js"
                    "build/jquery.fancytree.childcounter.min.js"
                    "build/jquery.fancytree.clones.min.js"
    #                "build/jquery.fancytree.columnview.min.js"
                    "build/jquery.fancytree.dnd.min.js"
                    "build/jquery.fancytree.dnd5.min.js"
                    "build/jquery.fancytree.edit.min.js"
                    "build/jquery.fancytree.filter.min.js"
    #                "build/jquery.fancytree.fixed.min.js"
                    "build/jquery.fancytree.glyph.min.js"
                    "build/jquery.fancytree.gridnav.min.js"
    #                "build/jquery.fancytree.menu.min.js"
                    "build/jquery.fancytree.persist.min.js"
                    "build/jquery.fancytree.table.min.js"
                    "build/jquery.fancytree.themeroller.min.js"
                    "build/jquery.fancytree.wide.min.js"
                    "lib/outro.js"
                    ]
                dest: "build/<%= pkg.name %>-all.min.js"
    
            "all-deps":
                options:
                    banner: "<%= meta.banner %>"
                    stripBanners: true
                    process: (src, fspec) ->
                      # Remove all comments, including /*! ... */
                      # (but keep disclaimer for jQuery-UI)
                      if not /jquery-ui..+.min.js/.test(fspec)
                          src = src.replace(/\/\*(.|\n)*\*\//g, "")
                      if /jquery.fancytree.min.js/.test(fspec)
                          src = "\n/*! Fancytree Core */" + src
                      if /fancytree..+.min.js/.test(fspec)
                        # If it is an extension:
                        # Prepend a one-liner instead
                        fspec = fspec.substr(6) # strip 'build/'
                        src = "\n/*! Extension '" + fspec + "' */" + src
                      return src
                src: [
                    "lib/intro.js"
                    "src/jquery-ui-dependencies/jquery-ui.min.js"
    #                "build/jquery.fancytree.ariagrid.min.js"
                    "build/jquery.fancytree.min.js"
                    "build/jquery.fancytree.childcounter.min.js"
                    "build/jquery.fancytree.clones.min.js"
    #                "build/jquery.fancytree.dnd.min.js"
                    "build/jquery.fancytree.dnd5.min.js"
                    "build/jquery.fancytree.edit.min.js"
                    "build/jquery.fancytree.filter.min.js"
    #                "build/jquery.fancytree.fixed.min.js"
                    "build/jquery.fancytree.glyph.min.js"
                    "build/jquery.fancytree.gridnav.min.js"
                    "build/jquery.fancytree.persist.min.js"
                    "build/jquery.fancytree.table.min.js"
    #                "build/jquery.fancytree.themeroller.min.js"
                    "build/jquery.fancytree.wide.min.js"
                    "lib/outro.js"
                    ]
                dest: "build/<%= pkg.name %>-all-deps.min.js"
    
        connect:
            forever:
                options:
                    port: 8080
                    base: "./"
                    keepalive: true
            dev: # pass on, so subsequent tasks (like watch) can start
                options:
                    port: 8080
                    base: "./"
                    keepalive: false
            sauce:
                options:
                    hostname: "localhost"
                    port: 9999
                    base: ""
                    keepalive: false
    
        copy:
            build: # copy production files to build folder
                files: [{
                    expand: true # required for cwd
                    cwd: "src/"
                    src: [
                        "skin-**/*.{css,gif,md,png,less}"
                        "skin-common.less"
                        "*.txt"
                        ]
                    dest: "build/"
                }, {
                    expand: true
                    cwd: "src/"
                    src: [
                        "jquery.*.js"
                        ]
                    # src: [
                    #   "skin-**/*.{css,gif,png,less,md}"
                    #   "*.txt"
                    #   "jquery.*.js"
                    #   "skin-common.less"
                    #   ]
                    dest: "build/src/"
                }, {
                    # src: ["*.txt", "*.md"]
                    src: ["LICENSE.txt"]
                    dest: "build/"
                }]
            dist: # copy build folder to dist
                files: [{expand: true, cwd: "build/", src: ["**"], dest: "dist/"}]
    
        cssmin:
            options:
              report: "min"
            build:
                expand: true
                cwd: "build/"
                src: ["**/*.fancytree.css", "!*.min.css"]
                dest: "build/"
                ext: ".fancytree.min.css"
    
        devUpdate:
            main:
                options:
                    reportUpdated: true
                    updateType: 'prompt'  # 'report'
    
        docco:
            docs:
                src: ["src/jquery.fancytree.childcounter.js"]
                options:
                    output: "doc/annotated-src"
    
        eslint:
            # options:
            #   # See https://github.com/sindresorhus/grunt-eslint/issues/119
            #   quiet: true
            # We have to explicitly declare "src" property otherwise "newer"
            # task wouldn't work properly :/
            dist:
                src: "dist/jquery.js"
            dev:
                # src: [ "src/**/*.js", "test/**/*.js", "build/**/*.js" ]
                src: [ "src/jquery.fancytree.ariagrid.js" ]
    
        exec:
            tabfix:
                # Cleanup whitespace according to http://contribute.jquery.org/style-guide/js/
                # (requires https://github.com/mar10/tabfix)
    #              cmd: "tabfix -t --line=UNIX -r -m*.js,*.css,*.html,*.json -inode_modules src demo test"
                cmd: "tabfix -t -r -m*.js,*.css,*.html,*.json -inode_modules src demo test"
            upload:
                # FTP upload the demo files (requires https://github.com/mar10/pyftpsync)
                cmd: "pyftpsync --progress upload . ftp://www.wwwendt.de/tech/fancytree --delete-unmatched --omit build,node_modules,.*,_*"
    #            cmd: "pyftpsync --progress upload . ftp://www.wwwendt.de/tech/fancytree --omit build,node_modules,.*,_*  -x"
            upload_force:
                # FTP upload the demo files (requires https://github.com/mar10/pyftpsync)
                cmd: "pyftpsync --progress upload . ftp://www.wwwendt.de/tech/fancytree --delete-unmatched --omit build,node_modules,.*,_* --resolve=local --force"
    
        # htmllint:
        #     all: ["demo/**/*.html", "doc/**/*.html", "test/**/*.html"]
    
    #     jsdoc:
    #         build:
    #             src: ["src/*.js", "doc/README.md", "doc/jsdoctest.js"]
    #             options:
    #                 destination: "doc/jsdoc_new"
    # #                template: "bin/jsdoc3-moogle",
    # #                template: "node_modules/ink-docstrap/template",
    #                 template: "../docstrap/template",
    #                 configure: "doc/jsdoc.conf.json"
    #                 verbose: true
    
        jshint:
            options:
                # Linting according to http://contribute.jquery.org/style-guide/js/
                jshintrc: ".jshintrc"
            beforeConcat: [
                # "Gruntfile.js"
                "src/*.js"
                "3rd-party/**/jquery.fancytree.*.js"
                "test/unit/*.js"
                "demo/**/*.js"
                ]
            afterConcat: [
                "<%= concat.core.dest %>"
                "<%= concat.all.dest %>"
                ]
    
        less:
            development:
                options:
    #               paths: ["src/"]
    #               report: "min"
                    compress: false
                    yuicompress: false
    #               optimization: 10
                files: [
                    {expand: true, cwd: "src/", src: "**/ui.fancytree.less", dest: "src/", ext: ".fancytree.css"}
                ]
    
        qunit:
            build: [
                "test/unit/test-core-build.html"
            ]
            develop: [
                "test/unit/test-core.html"
                "test/unit/test-ext-filter.html"
                "test/unit/test-ext-table.html"
                "test/unit/test-ext-misc.html"
            ]
    
        replace: # grunt-text-replace
            production:
                src: ["build/**/*.js"]
                overwrite : true
                replacements: [ {
                    from : /@DATE/g
                    # https://github.com/felixge/node-dateformat
                    to : "<%= grunt.template.today('isoUtcDateTime') %>"
                },{
                    from : /buildType:\s*\"[a-zA-Z]+\"/g
                    to : "buildType: \"production\""
                },{
                    from : /debugLevel:\s*[0-9]/g
                    to : "debugLevel: 1"
                } ]
            release:
                src: ["dist/**/*.js"]
                overwrite : true
                replacements: [ {
                    from : /@VERSION/g
                    to : "<%= pkg.version %>"
                } ]
    
        "saucelabs-qunit":
            ui_109:
                options:
                    testname: "Fancytree qunit tests (jQuery 1.9, jQuery UI 1.9)"
                    urls: ["http://localhost:9999/test/unit/test-jQuery19-ui19.html"]
                    build: process.env.TRAVIS_JOB_ID
                    throttled: 5
                    recordVideo: false
                    videoUploadOnPass: false
                    # jQuery 1.9     dropped supports IE 6..?
                    # jQuery UI 1.9  supports IE 6+ and ?
                    browsers: [
                      { browserName: "internet explorer", version: "6", platform: "Windows XP" }
                    ]
            ui_110:
                options:
                    testname: "Fancytree qunit tests (jQuery 1.10, jQuery UI 1.10)"
                    urls: ["http://localhost:9999/test/unit/test-jQuery110-ui110.html"]
                    build: process.env.TRAVIS_JOB_ID
                    throttled: 5
                    recordVideo: false
                    videoUploadOnPass: false
                    # jQuery 1.10    dropped support for IE 6
                    # jQuery UI 1.10 supports IE 7+ and ?
                    browsers: [
                      { browserName: "internet explorer", version: "7", platform: "Windows XP" }
                      { browserName: "internet explorer", version: "8", platform: "Windows 7" }
                    ]
            ui_111:
                options:
                    testname: "Fancytree qunit tests (jQuery 1.11, jQuery UI 1.11)"
                    urls: ["http://localhost:9999/test/unit/test-jQuery111-ui111.html"]
                    build: process.env.TRAVIS_JOB_ID
                    throttled: 5
                    recordVideo: false
                    videoUploadOnPass: false
                    # jQuery 1.11     supports IE + and latest Chrome/Edge/Firefox/Safari (-1)
                    # jQuery UI 1.11  supports IE 7+ and ?
                    browsers: [
                      { browserName: "internet explorer", version: "9", platform: "Windows 7" }
                      { browserName: "internet explorer", version: "10", platform: "Windows 8" }
                      { browserName: "safari", version: "7", platform: "OS X 10.9" }
                      { browserName: "safari", version: "8", platform: "OS X 10.10" }
                    ]
            ui_112:
                options:
                    testname: "Fancytree qunit tests (jQuery 3, jQuery UI 1.12)"
                    urls: ["http://localhost:9999/test/unit/test-core.html"]
                    build: process.env.TRAVIS_JOB_ID
                    throttled: 5
                    recordVideo: false
                    videoUploadOnPass: false
                    # jQuery 3        supports IE 9+ and latest Chrome/Edge/Firefox/Safari (-1)
                    # jQuery UI 1.12  supports IE 11 and latest Chrome/Edge/Firefox/Safari (-1)
                    browsers: [
                      { browserName: "chrome", platform: "Windows 8.1" }
                      { browserName: "firefox", platform: "Windows 8.1" }
                      { browserName: "firefox", platform: "Linux" }
                      { browserName: "internet explorer", version: "11", platform: "Windows 8.1" }
                      { browserName: "microsoftedge", platform: "Windows 10" }
                      { browserName: "safari", version: "9", platform: "OS X 10.11" }
                      { browserName: "safari", version: "10", platform: "OS X 10.12" }
                    ]
    
        uglify:
            # build:
            #     options:
            #         banner: "<%= meta.banner %>"
            #         # preserveComments: "some"
            #         report: "min"
            #         sourceMap:
            #             (path) -> path.replace(/.js/, ".js.map")
            #         sourceMappingURL:
            #             (path) -> path.replace(/^build\//, "") + ".map"
            #         sourceMapPrefix: 1 # strip 'build/' from paths
    
            #     files:
            #         "build/<%= pkg.name %>.min.js": ["<%= concat.core.dest %>"],
            #         "build/<%= pkg.name %>-all.min.js": ["<%= concat.all.dest %>"]
    
            custom:
                options:  # see https://github.com/gruntjs/grunt-contrib-uglify/issues/366
                    report: "min"
                    # preserveComments: "some"
                    preserveComments: /(?:^!|@(?:license|preserve|cc_on))/
                files: [
                  {
                      src: ["**/jquery.fancytree*.js", "!*.min.js"]
                      cwd: "src/"
                      dest: "build/"
                      expand: true
                      rename: (dest, src) ->
                          folder = src.substring(0, src.lastIndexOf("/"))
                          filename = src.substring(src.lastIndexOf("/"), src.length)
                          filename  = filename.substring(0, filename.lastIndexOf("."))
                          return dest + folder + filename + ".min.js"
                  }
                  ]
            # map_all:
            #     options:
            #         compress: false
            #         mangle: false
            #         sourceMap: true
            #         preserveComments: 'all'
            #     files: [
            #       {
            #           src: 'build/jquery.fancytree-all.min.js'
            #           dest: 'build/jquery.fancytree-all.min.js.map'
            #       }
            #       ]
    
        watch:
            less:
                files: "src/**/*.less"
                tasks: ["less:development"]
            jshint:
                options:
                    atBegin: true
                files: ["src/*.js", "test/unit/*.js", "demo/**/*.js"]
                tasks: ["jshint:beforeConcat", "eslint:dev"]
    
        yabs:
            release:
                common: # defaults for all tools
                  manifests: ['package.json', 'bower.json']
                # The following tools are run in order:
                run_test: { tasks: ['test'] }
                check: { branch: ['master'], canPush: true, clean: true, cmpVersion: 'gte' }
                bump: {} # 'bump' also uses the increment mode `yabs:release:MODE`
                run_build: { tasks: ['make_release'] }
                commit: { add: '.' }
                tag: {}
                push: { tags: true, useFollowTags: true },
                githubRelease:
                  repo: 'mar10/fancytree'
                  draft: false
                npmPublish: {}
                bump_develop: { inc: 'prepatch' }
                commit_develop: { message: 'Bump prerelease ({%= version %}) [ci skip]' }
                push_develop: {}
    
      # ----------------------------------------------------------------------------
    
    
      # Load "grunt*" dependencies
    
      for key of grunt.file.readJSON("package.json").devDependencies
          grunt.loadNpmTasks key  if key isnt "grunt" and key.indexOf("grunt") is 0
    
      # Register tasks
    
      grunt.registerTask "server", ["connect:forever"]
      grunt.registerTask "dev", ["connect:dev", "watch"]
      grunt.registerTask "tabfix", ["exec:tabfix"]
      grunt.registerTask "test", [
          "jshint:beforeConcat",
          "eslint:dev",
          # "csslint",
          # "htmllint",
          "qunit:develop"
      ]
    
      grunt.registerTask "sauce", ["connect:sauce", "saucelabs-qunit"]
      if parseInt(process.env.TRAVIS_PULL_REQUEST, 10) > 0
          # saucelab keys do not work on forks
          # http://support.saucelabs.com/entries/25614798
          grunt.registerTask "travis", ["test"]
      else
          grunt.registerTask "travis", ["test", "sauce"]
    
      grunt.registerTask "default", ["test"]
      grunt.registerTask "ci", ["test"]  # Called by 'npm test'
    
      grunt.registerTask "build", [
          "less:development"
          "test"
          # "jsdoc:build"
          "docco:docs"
          "clean:build"
          "copy:build"
          "cssmin:build"
          "concat:core"
          "concat:all"
          "uglify:custom"
          "concat:custom"
          "concat:all-deps"
          "clean:extMin"
          "replace:production"
          "jshint:afterConcat"
          # "uglify:build"
          "qunit:build"
          ]
    
      grunt.registerTask "make_release", [
          "exec:tabfix"
          "build"
          "clean:dist"
          "copy:dist"
          "clean:build"
          "replace:release"
          # "compress:dist"
          ]
    
      grunt.registerTask "upload", [
          "build"
          "exec:upload"
          ]
    
      grunt.registerTask "upload_force", [
          "build"
          "exec:upload_force"
          ]