forked from craftyjs/Crafty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
143 lines (119 loc) · 3.85 KB
/
Gruntfile.js
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
require("coffee-script");
var fs = require('fs');
module.exports = function (grunt) {
var pkg = grunt.file.readJSON('package.json');
var fileList = pkg.files, version = pkg.version;
var banner = '/**\n' +
' * <%= pkg.name %> <%= pkg.version %>\n' +
' * <%= pkg.author.url %>\n *\n' +
' * Copyright <%= grunt.template.today("yyyy") %>, <%= pkg.author.name %>\n' +
' * Dual licensed under the MIT or GPL licenses.\n' +
' */\n\n';
var getFiles = function (){
return fileList;
};
var docGen = function(){
done = this.async();
buildDir = "build/api/";
grunt.file.mkdir(buildDir);
var callback = function(){
console.log("Documentation created in " + buildDir);
done();
};
var md = require("./build/api-gen");
md.document(getFiles(), buildDir, "build/template.html", version, callback);
};
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
usebanner: {
dist: {
options: {
position: 'top',
banner: banner
},
files: {
src: ['crafty.js']
}
}
},
browserify: {
dist: {
files: {
'crafty.js': ['src/*.js']
}
},
debug: {
files: {
'crafty.js': ['src/*.js']
},
options: {
debug: true
}
}
},
watch: {
files: ['src/*.js'],
tasks: ['build:dev']
},
uglify: {
options: {
banner: banner
},
build: {
src: 'crafty.js',
dest: 'crafty-min.js'
}
},
jshint: {
files: ['Gruntfile.js', 'src/**/*.js', 'tests/**/*.js'],
options: {
trailing: true,
ignores: ['tests/lib/*.js'],
globals: {
}
}
},
qunit: {
all: [
'tests/index.html'
]
},
jsvalidate: {
files: ['crafty.js', 'tests/**/*.js']
},
connect: {
server: {
options: {
keepalive: true
}
}
}
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-jsvalidate');
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-banner');
grunt.registerTask('version', 'Takes the version into src/version.js', function() {
fs.writeFileSync('src/version.js', 'module.exports = "' + version + '";');
});
// Build development
grunt.registerTask('build:dev', ['browserify:debug', 'usebanner']);
// Build release
grunt.registerTask('build:release', ['browserify:dist', 'usebanner']);
// Building the documentation
grunt.registerTask('api', "Generate api documentation", docGen);
// Default task.
grunt.registerTask('default', ['build:dev', 'jsvalidate']);
// Run the test suite
grunt.registerTask('check', ['build:dev', 'jsvalidate', 'qunit', 'jshint']);
// Make crafty.js ready for release - minified version
grunt.registerTask('release', ['version', 'build:release', 'uglify', 'api']);
// Run only tests
grunt.registerTask('validate', ['qunit']);
};