forked from thm-projects/arsnova-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
185 lines (167 loc) · 3.87 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
/* jshint browser: false, node: true */
"use strict";
module.exports = function (grunt) {
require("time-grunt")(grunt);
var appPath = "src/main/webapp";
var buildPath = appPath + "/build";
var warPath = "target";
/* Files matching the following patterns will be checked by JSHint and JSCS */
var lintJs = [
"Gruntfile.js",
appPath + "/app/**/*.js",
"!" + appPath + "/app/utils/Ext.*.js"
];
grunt.initConfig({
clean: {
build: buildPath
},
connect: {
server: {
options: {
base: buildPath + "/<%= senchaEnv %>/ARSnova",
hostname: "<%= hostname %>",
port: 8081,
useAvailablePort: true,
open: true,
middleware: function (connect, options) {
var proxy = require("grunt-connect-proxy/lib/utils").proxyRequest;
return [
["/", function (req, res, next) {
if ("/" === req.url) {
res.writeHead(301, {Location: "/mobile"});
res.end();
} else {
/* Let the proxy middleware handle this request */
next();
}
}],
/* Serve static files */
["/mobile", connect.static(options.base[0])],
/* Proxy for backend API */
proxy
];
}
},
proxies: [
{
context: ["/", "/api", "/arsnova-config"],
host: "localhost",
port: 8080,
xforward: true
}
]
}
},
jscs: {
all: {
src: lintJs
},
options: {
config: ".jscs.json"
}
},
jshint: {
all: {
src: lintJs
},
options: {
jshintrc: ".jshintrc"
}
},
shell: {
build: {
command: "sencha app build <%= senchaEnv %>",
options: {
execOptions: {
cwd: appPath
}
}
},
refresh: {
command: "sencha app refresh",
options: {
execOptions: {
cwd: appPath
}
}
},
watch: {
command: "sencha app watch -e <%= senchaEnv %>",
options: {
execOptions: {
cwd: appPath
}
}
}
},
war: {
dist: {
/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
options: {
war_dist_folder: warPath,
war_name: "arsnova-mobile",
webxml_display_name: "ARSnova Mobile"
},
/* jscs:enable requireCamelCaseOrUpperCaseIdentifiers */
expand: true,
cwd: buildPath + "/<%= senchaEnv %>/ARSnova",
src: "**",
dest: ""
}
},
watch: {
js: {
files: [lintJs, ".jscs.json", ".jshintrc"],
tasks: ["newer:jscs", "newer:jshint"]
}
}
});
function setSenchaEnv(env) {
/* shortcuts */
if ("prod" === env) {
env = "production";
} else if ("dev" === env) {
env = "testing";
}
grunt.config("senchaEnv", env);
}
grunt.registerTask("build", function (env) {
/* use prod env by default for build task */
setSenchaEnv(env ? env : "prod");
grunt.task.run("shell:build");
});
grunt.registerTask("run", function (env, host) {
/* use dev env by default for run task */
setSenchaEnv(env ? env : "dev");
grunt.config("hostname", host || "localhost");
grunt.util.spawn({
cmd: "sencha",
args: ["app", "watch", "-e", grunt.config("senchaEnv")],
opts: {
cwd: appPath
}
});
/* we want Grunt for this task to continue even if QA checks fail */
grunt.option("force", true);
grunt.task.run([
"newer:jscs",
"newer:jshint",
"configureProxies:server",
"connect"
]);
grunt.task.run("watch");
});
grunt.loadNpmTasks("grunt-connect-proxy");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-connect");
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-jscs");
grunt.loadNpmTasks("grunt-newer");
grunt.loadNpmTasks("grunt-shell");
grunt.loadNpmTasks("grunt-war");
grunt.registerTask("lint", ["jscs", "jshint"]);
grunt.registerTask("refresh", "shell:refresh");
grunt.registerTask("package", ["refresh", "build", "war"]);
grunt.registerTask("default", ["lint", "refresh", "build"]);
};