-
Notifications
You must be signed in to change notification settings - Fork 9
/
Gruntfile.js
162 lines (140 loc) · 3.36 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
"use strict";
module.exports = function (grunt) {
var filesList = [
"*.js",
"*.json",
"!package-lock.json",
"i18n/*.js",
"tests/*.js"
];
// Project configuration.
grunt.initConfig({
jshint: {
all: filesList,
options: {
jshintrc: ".jshintrc"
}
},
lineending: {
all: {
options: {
eol: "crlf",
overwrite: true
},
files: {
"": filesList
}
}
},
jsbeautifier: {
files: filesList,
options: {
config: ".jshintrc",
js: {
jslintHappy: true,
indentWithTabs: true
}
}
},
// Run Intern from grunt while still using the intern.json file.
// There are many ways to do this, so I just picked one.
// Note though that the grunt intern task does not automatically load intern.json.
run: {
"intern-local": {
cmd: "npx",
args: ["intern"],
options: {
failOnError: true
}
},
"intern-remote": {
cmd: "npx",
args: ["intern", "config=@sauce"],
options: {
failOnError: true
}
}
},
clean: {
// Delete files created by the "testBuild" target.
testBuild: [
"tests/functional/cssApp/{bower_components,node_modules,build,tmp}"
]
}
});
// These plugins provide necessary tasks.
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-jsbeautifier");
grunt.loadNpmTasks("grunt-lineending");
grunt.loadNpmTasks("grunt-run");
// By default, lint and run all tests.
grunt.registerTask("default", ["jshint", "test:remote"]);
// Just lint
grunt.registerTask("lint", ["jshint"]);
// Travis build
grunt.registerTask("travis", ["jshint", "test:remote"]);
grunt.registerTask("testBuild", "Run the build used by the functional test", function (test) {
var done = this.async();
var appRootDir = "tests/functional/" + test + "App";
function npmInstall(error, bowerResults) {
if (error !== null) {
grunt.log.writeln(bowerResults.stdout);
done(error);
return;
}
grunt.util.spawn({
cmd: "npm",
args: ["install"],
opts: {
cwd: appRootDir
}
}, startBuild);
}
function startBuild(error, npmResults) {
if (error !== null) {
grunt.log.writeln(npmResults.stdout);
done(error);
return;
}
grunt.util.spawn({
cmd: "grunt",
args: ["build"],
opts: {
cwd: appRootDir
}
}, finish);
}
function finish(error, buildResults) {
if (error !== null) {
grunt.log.writeln(buildResults.stdout);
done(error);
return;
}
done(true);
}
grunt.util.spawn({
cmd: "bower",
args: ["install"],
opts: {
cwd: appRootDir
}
}, npmInstall);
});
// Testing.
// Always specify the target e.g. grunt test:remote, grunt test:remote.
// For more control, run testBuild:css manually, then
// directly call "npx intern".
var testTaskDescription = "Run this task instead of the intern task directly! \n" +
"Always specify the test target e.g. \n" +
"grunt test:local\n" +
"grunt test:remote";
grunt.registerTask("test", testTaskDescription, function (target) {
// First create the test builds. These are referenced from the intern tests.
grunt.task.run("testBuild:css");
// Then run the intern tests.
grunt.task.run("run:intern-" + target);
// Finally, delete the test builds so that they don't show up in "git status" as "untracked files".
grunt.task.run("clean:testBuild");
});
};