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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
// This is the main application configuration file. It is a Grunt
// configuration file, which you can learn more about here:
// https://github.com/cowboy/grunt/blob/master/docs/configuring.md
module.exports = function(grunt) {
var helper = require('./tasks/helper').init(grunt),
path = require('path');
var couch_config = function () {
var default_couch_config = {
fauxton: {
db: 'http://localhost:5984/fauxton',
app: './couchapp.js',
options: {
okay_if_missing: true
}
}
};
var settings_couch_config = helper.readSettingsFile().couch_config;
return settings_couch_config || default_couch_config;
}();
var cleanable = function(){
// Whitelist files and directories to be cleaned
// You'll always want to clean these two directories
var theListToClean = ["dist/", "app/load_addons.js"];
// Now find the external addons you have and add them for cleaning up
helper.processAddons(function(addon){
// Only clean addons that are included from a local dir
if (addon.path){
theListToClean.push("app/addons/" + addon.name);
}
});
return theListToClean;
}();
var assets = function(){
// Base assets
var theAssets = {
less:{
paths: ["assets/less"],
files: {
"dist/debug/css/fauxton.css": "assets/less/fauxton.less"
}
},
img: ["assets/img/**"]
};
helper.processAddons(function(addon){
// Less files from addons
var root = addon.path || "app/addons/" + addon.name;
var lessPath = root + "/assets/less";
if(path.existsSync(lessPath)){
// .less files exist for this addon
theAssets.less.paths.push(lessPath);
theAssets.less.files["dist/debug/css/" + addon.name + ".css"] =
lessPath + "/" + addon.name + ".less";
}
// Images
root = addon.path || "app/addons/" + addon.name;
var imgPath = root + "/assets/img";
if(path.existsSync(imgPath)){
theAssets.img.push(imgPath + "/**");
}
});
grunt.log.write(theAssets.img[0]);
return theAssets;
}();
var templateSettings = function(){
var defaultSettings = {
"src": "assets/index.underscore",
"dest": "dist/debug/index.html",
"variables": {
"assets_root": "./",
"requirejs": "require.js",
"base": null
}
};
var settings = helper.readSettingsFile();
return {template: settings.template || defaultSettings};
}();
grunt.initConfig({
// The clean task ensures all files are removed from the dist/ directory so
// that no files linger from previous builds.
clean: cleanable,
// The lint task will run the build configuration and the application
// JavaScript through JSHint and report any errors. You can change the
// options for this task, by reading this:
// https://github.com/cowboy/grunt/blob/master/docs/task_lint.md
lint: {
files: [
"build/config.js", "app/**/*.js"
]
},
less: {
compile: {
options: {
paths: assets.less.paths
},
files: assets.less.files
}
},
// The jshint option for scripturl is set to lax, because the anchor
// override inside main.js needs to test for them so as to not accidentally
// route.
jshint: {
all: ['app/**/*.js', 'Gruntfile.js'],
options: {
scripturl: true,
evil: true
}
},
// The jst task compiles all application templates into JavaScript
// functions with the underscore.js template function from 1.2.4. You can
// change the namespace and the template options, by reading this:
// https://github.com/gruntjs/grunt-contrib/blob/master/docs/jst.md
//
// The concat task depends on this file to exist, so if you decide to
// remove this, ensure concat is updated accordingly.
jst: {
"dist/debug/templates.js": [
"app/templates/**/*.html",
"app/addons/**/templates/**/*.html"
]
},
template: templateSettings,
// The concatenate task is used here to merge the almond require/define
// shim and the templates into the application code. It's named
// dist/debug/require.js, because we want to only load one script file in
// index.html.
concat: {
requirejs: {
src: ["assets/js/libs/almond.js", "dist/debug/templates.js", "dist/debug/require.js"],
dest: "dist/debug/js/require.js"
},
index_css: {
src: ["dist/debug/css/*.css", 'assets/css/*.css'],
dest: 'dist/debug/css/index.css'
}
},
cssmin: {
compress: {
files: {
"dist/release/css/index.css": [
"dist/debug/css/index.css", 'assets/css/*.css',
"app/addons/**/assets/css/*.css"
]
},
options: {
report: 'min'
}
}
},
uglify: {
release: {
files: {
"dist/release/js/require.js": [
"dist/debug/js/require.js"
]
}
}
},
// Runs a proxy server for easier development, no need to keep deploying to couchdb
couchserver: {
dist: './dist/debug/',
port: 8000,
proxy: {
host: 'localhost',
port: 5984,
https: false
}
},
watch: {
files: './app/**/*',
tasks: ['debug', 'template']
},
requirejs: {
compile: {
options: {
baseUrl: 'app',
// Include the main configuration file.
mainConfigFile: "app/config.js",
// Output file.
out: "dist/debug/require.js",
// Root application module.
name: "config",
// Do not wrap everything in an IIFE.
wrap: false,
optimize: "none"
}
}
},
// The headless QUnit testing environment is provided for "free" by Grunt.
// Simply point the configuration to your test directory.
qunit: {
all: ["test/qunit/*.html"]
},
// The headless Jasmine testing is provided by grunt-jasmine-task. Simply
// point the configuration to your test directory.
jasmine: {
all: ["test/jasmine/*.html"]
},
// Copy build artifacts and library code into the distribution
// see - http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically
copy: {
couchdb: {
files: [
// this gets built in the template task
{src: "dist/release/index.html", dest: "../../share/www/fauxton/index.html"},
{src: ["**"], dest: "../../share/www/fauxton/js/", cwd:'dist/release/js/', expand: true},
{src: ["**"], dest: "../../share/www/fauxton/img/", cwd:'dist/release/img/', expand: true},
{src: ["**"], dest: "../../share/www/fauxton/css/", cwd:"dist/release/css/", expand: true}
]
},
couchdebug: {
files: [
// this gets built in the template task
{src: "dist/debug/index.html", dest: "../../share/www/fauxton/index.html"},
{src: ["**"], dest: "../../share/www/fauxton/js/", cwd:'dist/debug/js/', expand: true},
{src: ["**"], dest: "../../share/www/fauxton/img/", cwd:'dist/debug/img/', expand: true},
{src: ["**"], dest: "../../share/www/fauxton/css/", cwd:"dist/debug/css/", expand: true}
]
},
dist:{
files:[
{src: "dist/debug/index.html", dest: "dist/release/index.html"},
{src: assets.img, dest: "dist/release/img/", flatten: true, expand: true}
]
},
debug:{
files:[
{src: assets.img, dest: "dist/debug/img/", flatten: true, expand: true}
]
}
},
get_deps: {
"default": {
src: "settings.json"
}
},
gen_load_addons: {
"default": {
src: "settings.json"
}
},
mkcouchdb: couch_config,
rmcouchdb: couch_config,
couchapp: couch_config
});
/*
* Load Grunt plugins
*/
// Load fauxton specific tasks
grunt.loadTasks('tasks');
// Load the couchapp task
grunt.loadNpmTasks('grunt-couchapp');
// Load the copy task
grunt.loadNpmTasks('grunt-contrib');
// Load the exec task
grunt.loadNpmTasks('grunt-exec');
// Load Require.js task
grunt.loadNpmTasks('grunt-requirejs');
// Load UglifyJS task
grunt.loadNpmTasks('grunt-contrib-uglify');
// Load CSSMin task
grunt.loadNpmTasks('grunt-contrib-cssmin');
/*
* Default task
*/
// defult task - install minified app to local CouchDB
grunt.registerTask('default', 'couchdb');
/*
* Transformation tasks
*/
// clean out previous build artefacts, lint and unit test
grunt.registerTask('test', ['clean', 'jshint']); //qunit
// Fetch dependencies (from git or local dir), lint them and make load_addons
grunt.registerTask('dependencies', ['get_deps', 'jshint', 'gen_load_addons:default']);
// build templates, js and css
grunt.registerTask('build', ['jst', 'requirejs', 'concat:requirejs', 'less', 'concat:index_css', 'template']);
// minify code and css, ready for release.
grunt.registerTask('minify', ['uglify', 'cssmin:compress']);
/*
* Build the app in either dev, debug, or release mode
*/
// dev server
grunt.registerTask('dev', ['debug', 'couchserver']);
// build a debug release
grunt.registerTask('debug', ['test', 'dependencies', 'build', 'copy:debug']);
// build a release
grunt.registerTask('release', ['test' ,'dependencies', 'build', 'minify', 'copy:dist']);
/*
* Install into CouchDB in either debug, release, or couchapp mode
*/
// make a development install that is server by mochiweb under _utils
grunt.registerTask('couchdebug', ['debug', 'copy:couchdebug']);
// make a minimized install that is server by mochiweb under _utils
grunt.registerTask('couchdb', ['release', 'copy:couchdb']);
// make an install that can be deployed as a couchapp
grunt.registerTask('couchapp_setup', ['build', 'minify', 'copy:dist']);
// install fauxton as couchapp
grunt.registerTask('couchapp_install', ['rmcouchdb:fauxton', 'mkcouchdb:fauxton', 'couchapp:fauxton']);
// setup and install fauxton as couchapp
grunt.registerTask('couchapp_deploy', ['couchapp_setup', 'couchapp_install']);
};
|