Debian Codegraph @

Gruntfile.js

raw symbols SCIP
1 /*global module:false, require:false*/
2 var md = require('matchdep');
3
4 module.exports = function(grunt) {
5
6 'use strict';
7
8 var gruntfile = 'Gruntfile.js';
9 var sources = ['src/<%= pkg.name %>.js'];
10
11 md.filter('grunt-*').forEach(grunt.loadNpmTasks);
12
13 // Project configuration.
14 grunt.initConfig({
15 pkg: grunt.file.readJSON('package.json'),
16 meta: {
17 banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
18 '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
19 '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
20 '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author[0].name %> (<%= pkg.author[0].url %>);\n' +
21 '* Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> http://deuxhuithuit.mit-license.org */\n'
22 },
23 concat: {
24 options: {
25 process: true,
26 banner: '<%= meta.banner %>'
27 },
28 dist: {
29 src: sources,
30 dest: 'dist/<%= pkg.name %>.js'
31 }
32 },
33
34 watch: {
35 files: sources.concat(gruntfile),
36 tasks: ['dev']
37 },
38
39 jshint: {
40 files: sources.concat(gruntfile),
41 options: {
42 curly: true,
43 eqeqeq: false, // allow ==
44 immed: false, //
45 latedef: false, // late definition
46 newcap: false, // capitalize ctos
47 nonew: true, // no new ..()
48 noarg: true,
49 sub: true,
50 undef: true,
51 //boss: true,
52 eqnull: true, // relax
53 browser: true,
54 regexp: true,
55 strict: true,
56 trailing: false,
57 smarttabs: true,
58 lastsemic: true,
59 globals: {
60 console: true,
61 jQuery: true,
62 pd: true,
63 _: true,
64 Popcorn: true,
65 DEBUG: true,
66 CSS3: true,
67 JSON: true
68 }
69 }
70 },
71 uglify: {
72 prod: {
73 files: {
74 'dist/<%= pkg.name %>.min.js': '<%= concat.dist.dest %>'
75 }
76 },
77 options: {
78 banner: '<%= meta.banner %>',
79 report: 'gzip',
80 sourceMap: 'dist/<%= pkg.name %>.min.js.map',
81 sourceMappingURL: '<%= pkg.name %>.min.js.map',
82 sourceMapRoot: '../',
83 mangle: true,
84 compress: {
85 global_defs: {
86 DEBUG: false
87 },
88 dead_code: true,
89 unused: true,
90 warnings: true
91 }
92 }
93 },
94
95 complexity: {
96 generic: {
97 src: sources,
98 options: {
99 //jsLintXML: 'report.xml', // create XML JSLint-like report
100 errorsOnly: false, // show only maintainability errors
101 cyclomatic: 10, // 3
102 halstead: 20, // 8
103 maintainability: 95 //100
104 }
105 }
106 }
107 });
108
109 // fix source map url
110 grunt.registerTask('fix-source-map', 'Fix the wrong file path in the source map', function() {
111 var sourceMapPath = grunt.template.process('<%= uglify.options.sourceMap %>');
112 var sourceMapUrl = grunt.template.process('<%= uglify.options.sourceMappingURL %>');
113 var diff = sourceMapPath.replace(sourceMapUrl, '');
114 var sourceMap = grunt.file.readJSON(sourceMapPath);
115 sourceMap.file = sourceMap.file.replace(diff, '');
116 var newSources = [];
117 sourceMap.sources.forEach(function (elem) {
118 newSources.push(elem.replace(diff, ''));
119 });
120 sourceMap.sources = newSources;
121 grunt.log.write(sourceMap.sources);
122 grunt.file.write(sourceMapPath, JSON.stringify(sourceMap));
123 });
124
125 // Default tasks.
126 grunt.registerTask('dev', ['jshint','complexity']);
127 grunt.registerTask('build', ['concat','uglify','fix-source-map']);
128 grunt.registerTask('default', ['dev','build']);
129 };