Repository navigation
Expand file tree
/
Copy pathGruntfile.js
More file actions
125 lines (115 loc) · 3.72 KB
/
Copy pathGruntfile.js
File metadata and controls
125 lines (115 loc) · 3.72 KB
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
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
banner: '/* ritsu.js v<%= pkg.version %> \n' +
' * Created <%= grunt.template.today("yyyy-mm-dd") %>\n' +
' * Licensed under the <%= pkg.license %> license\n' +
' * Source code can be found here: <%= pkg.repository.url %> \n' +
' */\n',
jqueryCheck: 'if (typeof jQuery === \'undefined\' && typeof $ === \'undefined\') {\n' +
' throw new Error(\'ritsu.js requires jQuery or a jQuery-compatible API\');\n' +
'}\n',
ritsuHeader: 'var ritsu = (function() {',
ritsuFooter: '\nvar r = rules(); return core(r, validation(r));\n' +
'})();',
/* grunt stamp ************************************************************/
stamp: {
js: {
options: {
banner: '<%= banner %>\n<%= ritsuHeader %>',
footer: '<%= ritsuFooter %>'
},
files: {
src: ['dist/**/ritsu.js']
}
},
css: {
options: {
banner: '<%= banner %>'
},
files: {
src: ['dist/**/*.css']
}
}
},
/* css minify Task ********************************************************/
cssmin: {
options: {
shorthandCompacting: false,
roundingPrecision: -1,
sourceMap: true
},
base: {
files: {
'dist/ritsu.min.css': ['dist/ritsu.css']
}
}
},
/* Uglify Task *************************************************************/
uglify: {
options: {
preserveComments: false,
sourceMap: {
includeSources: true
},
banner: '<%= banner %>\n<%= ritsuHeader %>',
footer: '<%= ritsuFooter %>'
},
base: {
files: {
'dist/ritsu.min.js': ['dist/ritsu.js']
}
}
},
/* Concat Task **************************************************************/
concat: {
options: {
// Custom function to remove all module.exports
process: function (src) {
return src.replace(/^(module\.exports).*/gm, '')
.replace(/^(.*mocha_).*/gm, '')
.replace(/\$\{version\}*/, grunt.file.readJSON('package.json').version)
.replace('//For mocha tests temporarily', '');
}
},
dist: {
src: ['src/rules.js', 'src/validation.js', 'src/core.js'],
dest: 'dist/ritsu.js'
}
},
/* Copy Task **************************************************************/
copy: {
main: {
files: [{
src: 'src/validation-styles.css',
dest: 'dist/ritsu.css'
}]
},
},
/* Watch Task **************************************************************/
watch: {
configFiles: {
files: ['Gruntfile.js'],
tasks: ['concat', 'uglify', 'copy', 'cssmin', 'stamp']
},
css: {
files: ['src/*.css'],
tasks: ['cssmin', 'copy', 'stamp']
},
scripts: {
files: ['src/*.js'],
tasks: ['concat', 'uglify', 'copy', 'stamp']
}
}
});
// Load dem plugins
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-stamp');
//Register dem tasks
grunt.registerTask('default', ['watch']);
grunt.registerTask('build', ['copy', 'concat:dist', 'cssmin', 'uglify', 'stamp:css', 'stamp:js']);
};