This repository was archived by the owner on Jul 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgruntfile.js
201 lines (180 loc) · 5.31 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/**
* Configures Grunt, a task runner.
*/
// Declare variables for Grunt configuration and regex'ing.
var files = {};
/**
* Set files to watch or edit, grouping related files together.
*/
// List project directories.
files.dir = { build: "build/", src: "src/", tests: "tests/" };
// List development files.
files.dev = [ "*.sh", "*.json", "*.py", "*.yml", "README.md", ".gitignore",
".jshintrc", "gruntfile.js" ];
// List project's HTML.
files.html = [ "*.html", files.dir.tests + "**/*.html" ];
// List project's scripts.
files.scripts = [ "*.js", "src/**/*", "tests/unit/*.js",
"tests/functional/*.js" ];
// List project's stylesheets and other design resources.
files.styles = [ "src/styles/*", "src/media/*" ];
// List all project files.
files.all = (function() {
return [].concat( files.dev, files.html, files.scripts );
}());
/**
* Initialize configuration.
*/
module.exports = function( grunt ) {
"use strict";
/*
* Loads plugins.
*
* @note Replaces need to load each task using grunt.loadNpmTasks.
*/
require( "load-grunt-tasks" )( grunt, { pattern: [ "grunt-*",
"!grunt-lib-phantomjs", "intern" ] } );
/*
* Displays execution time of Grunt tasks.
*/
require( "time-grunt" )( grunt );
/**
* Initialize configuration object.
*/
grunt.initConfig({
// Set project settings.
pkg: grunt.file.readJSON( "package.json" ),
config: grunt.file.readJSON( "config.json" ),
/**
* Removes files.
*/
clean: {
mocks: {
"src": [ "build/{**/}*.js" ]
}
},
/**
* Uses Node to serve the file system on a web server.
*/
connect: {
server: {
options: {
base: {
options: { maxAge: 1000 * 60 * 5 },
path: "."
},
hostname: "localhost",
keepalive: true,
open: true,
port: 8080,
useAvailablePort: true,
onCreateServer: function() {
grunt.log.writeln( "Created server." );
}
}
}
},
/**
* Runs tests using Intern.
*/
intern: {
options: {
config: "tests/intern",
sauceUsername: "<%= config.sauceUsername %>",
sauceAccessKey: "<%= config.sauceAccessKey %>"
},
runner: {
options: {
runType: "runner",
reporters: [ "Console" ]
}
},
client: {
options: {
runType: "client",
reporters: [ "Console" ],
suites: [ "tests/unit/index" ]
}
}
},
/**
* Lints JavaScript using JSLint.
*
* @link http://www.jshint.com/docs/options/
*/
jshint: {
options: {
jshintrc: true
},
all: {
src: [ "*.js", files.scripts, "!**/*.map" ]
}
},
/**
* Increments version number in package.json and commits it.
*/
bump: {
options: {
files: [ "package.json" ],
updateConfigs: [ "pkg" ],
commit: true,
commitMessage: "Increments version to %VERSION%.",
commitFiles: [ "package.json" ],
createTag: true,
tagName: "v%VERSION%",
tagMessage: "Increments version to %VERSION%.",
push: false,
pushTo: "hub",
gitDescribeOptions: "--tags --always --abbrev=1 --dirty=-d",
globalReplace: false
}
},
/**
* Enables executing Shell commands using Grunt.
*/
shell: {
options: {
stdout: true
},
babel: {
command: [
"mkdir -p build",
"babel ./src/index.js -o ./build/index.js"
].join( "&&" )
},
update: {
command: "sudo npm update"
}
},
/**
* Executes tasks when files change.
*/
watch: {
options: {
atBegin: true,
interrupt: true
},
all: {
files: files.all,
tasks: [ "lint", "test" ]
},
test: {
files: files.all,
tasks: [ "test" ]
}
}
});
/**
* Register tasks.
*/
// Make a build.
grunt.registerTask( "make", [ "shell:babel" ] );
// Assert the build meets the acceptance criteria.
grunt.registerTask( "test", [ "qunit:unit" ] );
// Assert the build meets the acceptance criteria.
grunt.registerTask( "lint", [ "jshint" ] );
// Make a build & deploy it to a web server.
grunt.registerTask( "deploy", [ "make", "connect" ] );
// Set default task to watch file changes.
grunt.registerTask( "default", [ "deploy", "watch:all" ] );
};