Skip to content

Commit a35aa53

Browse files
committed
Add Gruntfile.js for grunt 0.4
1 parent 26e2b5c commit a35aa53

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

Gruntfile.js

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*global module:false*/
2+
module.exports = function(grunt) {
3+
4+
// Project configuration.
5+
grunt.initConfig({
6+
pkg: grunt.file.readJSON('smooth-scroll.jquery.json'),
7+
component: './component.json',
8+
meta: {
9+
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
10+
'<%= grunt.template.today("yyyy-mm-dd") + "\\n" %>' +
11+
'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
12+
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
13+
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */' +
14+
'<%= "\\n\\n" %>',
15+
version: '\\n \\nvar version = <%= pkg.version %>;\\n'
16+
},
17+
concat: {
18+
all: {
19+
src: ['src/jquery.<%= pkg.name %>.js'],
20+
dest: 'jquery.<%= pkg.name %>.js'
21+
},
22+
options: {
23+
stripBanners: true,
24+
banner: '<%= meta.banner %>'
25+
}
26+
},
27+
uglify: {
28+
all: {
29+
files: {
30+
'jquery.<%= pkg.name %>.min.js': ['<%= concat.all.dest %>']
31+
},
32+
options: {
33+
preserveComments: false,
34+
banner: '<%= meta.banner %>'
35+
}
36+
}
37+
},
38+
watch: {
39+
files: '<config:lint.files>',
40+
tasks: 'lint'
41+
},
42+
jshint: {
43+
files: ['grunt.js', 'src/**/*.js'],
44+
options: {
45+
curly: true,
46+
// eqeqeq: true,
47+
// immed: true,
48+
latedef: true,
49+
newcap: true,
50+
noarg: true,
51+
sub: true,
52+
undef: true,
53+
boss: true,
54+
eqnull: true,
55+
browser: true,
56+
globals: {
57+
jQuery: true
58+
}
59+
}
60+
}
61+
});
62+
63+
// Default task.
64+
grunt.registerTask('build', ['jshint', 'concat', 'version', 'component', 'uglify']);
65+
66+
grunt.registerTask( 'component', 'update component.json', function() {
67+
var comp = grunt.config('component'),
68+
pkg = grunt.config("pkg"),
69+
json = {};
70+
71+
['name', 'version', 'dependencies'].forEach(function(el) {
72+
json[el] = pkg[el];
73+
});
74+
75+
json.main = grunt.config('concat.all.dest');
76+
json.ignore = [
77+
'demo/',
78+
'lib/',
79+
'src/',
80+
'*.json'
81+
];
82+
83+
grunt.file.write( comp, JSON.stringify(json, null, 2) );
84+
85+
grunt.log.writeln( "File '" + comp + "' updated." );
86+
});
87+
88+
grunt.registerTask( 'version', 'insert version', function() {
89+
// Concat specified files.
90+
var name = grunt.config('concat.all.dest'),
91+
pkg = grunt.config("pkg"),
92+
compiled = grunt.file.read(name),
93+
version = "version = '" + pkg.version + "'";
94+
95+
// compiled = '/* concatenated files:\n' + this.file.src.join(', ') + '\n*/\n\n' + compiled;
96+
97+
// Embed Version
98+
compiled = compiled.replace( /version = '[^']+'/, version );
99+
// Write concatenated source to file
100+
grunt.file.write( name, compiled );
101+
102+
// Fail task if errors were logged.
103+
if ( this.errorCount ) {
104+
return false;
105+
}
106+
107+
// Otherwise, print a success message.
108+
grunt.log.writeln( "File '" + name + "' created." );
109+
110+
});
111+
112+
grunt.loadNpmTasks('grunt-contrib-jshint');
113+
grunt.loadNpmTasks('grunt-contrib-uglify');
114+
grunt.loadNpmTasks('grunt-contrib-concat');
115+
116+
};

0 commit comments

Comments
 (0)