This repository has been archived by the owner on Oct 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathGruntfile.js
173 lines (152 loc) · 5.66 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
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
/*global module:false*/
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
/**
* Watching
* ========
*
* Automatically tests and builds your code
* whenever you edit the source files or tests.
*/
watch: {
scripts: {
files: ['src/**/!(templates).js', 'src/**/*.html', 'test/**/*.js'],
tasks: ['build'],
options: {
interrupt: true
}
}
},
/**
* Linting
* =======
*
* Catch errors quickly with JS Hint
*/
jshint: {
all: ['Gruntfile.js', 'src/**/!(templates).js', 'test/!(libs)/*.js'],
options: {
curly: true, // Always use curlys {}
eqeqeq: true, // No more == for you, === only
immed: true, // prohibits the use of immediate function invocations without wrapping them in parentheses
latedef: true, // no setting variables before they are defined
newcap: true, // Always call constructors with a Cap
noarg: true, // prohibits arguments.caller and arguments.callee
sub: true, // This option suppresses warnings about using [] notation when it can be expressed in dot notation: person['name'] vs. person.name.
undef: true, // prohibits the use of explicitly undeclared variables
boss: true, // Allows assignments in ifs - if (a = 10) {}
eqnull: true, // Allows == null check for null or undefined
browser: true, // Sets up globals for browser like window and document
maxdepth: 3, // Max nesting of methods 3 layers deep
unused: true, // Warns on unused variables
expr: true, // Allowed for chais expect(false).to.be.false; assertion style.
devel: true, // Allows console.log's etc
trailing: true, // Prohibits trailing whitespace
globals: {
require: true,
define: true,
requirejs: true,
suite: true,
expect: true,
test: true,
setup: true,
teardown: true,
sinon: true,
mocha: true
}
}
},
/**
* Testing
* =======
*
* Run your unit tests in headless phantomJS
*/
mocha: {
index: ['test/test-runner.html']
},
/**
* Templating
* ==========
*
* Pre-compile your handlebars templates
*/
handlebars: {
compile: {
options: {
amd: true,
wrapped: true,
processName: function(filename) {
return filename.replace("src/templates/", "");
}
},
files: {
"src/templates.js": "src/**/*.html"
}
}
},
/**
* Building
* ========
*
* Build your amd modules into a single minified JS file
*/
requirejs: {
compile: {
options: {
name: "../components/almond/almond", // Path to almond requirejs production runner for built js
baseUrl: "src",
mainConfigFile: "./require.config.js",
include: ['main'], // Include the main module defined
insertRequire: ['main'], // Add a require step in at the end for the main module.
wrap: true, // Wrap everything up in a closure
generateSourceMaps: true, // Experimental
preserveLicenseComments: false, // Needs turned off for generateSourceMaps
optimize: "uglify2", // Supports generateSourceMaps
out: "assets/javascripts/build.js"
}
}
},
/**
* Stylesheets
* ===========
*
* Compile, concat & lint css and less files into a single output file
*/
less: {
dist: {
options: {
paths: ["src/styles"],
yuicompress: true
},
files: {
'assets/stylesheets/styles.css': 'src/styles/main.less'
}
}
}
});
// Version assets
grunt.registerTask('version-assets', 'version the static assets just created', function() {
var Version = require("node-version-assets");
var versionInstance = new Version({
assets: ['assets/stylesheets/styles.css', 'assets/javascripts/build.js'],
grepFiles: ['index.html']
});
var cb = this.async(); // grunt async callback
versionInstance.run(cb);
});
// Load Tasks
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-handlebars');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-mocha');
grunt.loadNpmTasks('grunt-contrib-less');
// Define tasks
grunt.registerTask('test', ['jshint', 'handlebars', 'mocha']);
grunt.registerTask('styles', ['less']);
grunt.registerTask('build', ['test', 'requirejs', 'styles', 'version-assets']);
grunt.registerTask('default', 'build');
};