forked from iotaweb/angular-hapi-couch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
211 lines (184 loc) · 6.55 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
202
203
204
205
206
207
208
209
210
211
var path = require('path');
var nano = require('nano')('http://localhost:5984');
var dbName = 'angular-hapi-couch';
module.exports = function(grunt) {
grunt.initConfig({
jade: {
compile: {
options: {
doctype: '5', // needed for angular.js directives
pretty: true
},
files: [{
expand: true,
src: '**/*.jade',
dest: 'app/public/lib/cores/templates',
cwd: 'app/views/templates',
ext: '.html'
}]
}
},
stylus: {
compile: {
options: {
pretty: true
},
files: {
'app/public/css/styles.css': 'app/views/styles/styles.styl'
}
}
},
ngtemplates: {
cores: {
src: 'app/public/lib/cores/templates/*.html',
dest: 'app/public/lib/cores/templates/templates.js',
options: {
base: 'app/public/lib/cores/templates',
prepend: 'cr-',
module: 'cores.templates'
}
}
},
concat: {
components: {
src: [
'app/public/components/jquery/jquery.js',
'app/public/components/angular/angular.js',
'app/public/components/angular-route/angular-route.js',
'app/public/components/bootstrap/dist/js/bootstrap.js',
'app/public/components/markdown/lib/markdown.js',
'app/public/components/jquery-autosize/jquery-autosize.js'
],
dest: 'app/public/components/components.js'
},
cores: {
src: [ // order matters!
'app/public/lib/cores/index.js',
'app/public/lib/cores/templates/templates.js',
'app/public/lib/cores/filters/*.js',
'app/public/lib/cores/controllers/*.js',
'app/public/lib/cores/services/*.js',
'app/public/lib/cores/directives/*.js'
],
dest: 'app/public/lib/cores.js'
},
app: {
src: [
'app/public/js/app.js',
'app/public/js/controllers.js',
'app/public/js/directives.js',
'app/public/js/filters.js',
'app/public/js/services.js'
],
dest: 'app/public/js/main.js',
options: {
// Replace all 'use strict' statements with a single one at the top
banner: "'use strict';\n\n",
process: function(src, filepath) {
return '/* ---------- Source: ' + filepath + ' ----------- */\n\n' +
src.replace(/(^|\n)[ \t]*('use strict'|"use strict");?\s*/g, '$1') + '\n';
}
}
}
},
ngmin: {
cores: {
src: 'app/public/lib/cores.js',
dest: 'app/public/lib/cores.js'
},
app: {
src: 'app/public/js/main.js',
dest: 'app/public/js/main.js'
}
},
uglify: {
components: {
files: {
'app/public/components/components.min.js': ['app/public/components/components.js']
}
},
cores: {
files: {
'app/public/lib/cores.min.js': ['app/public/lib/cores.js']
}
},
main: {
files: {
'app/public/js/main.min.js': ['app/public/js/main.js']
}
}
},
watch: {
styles: {
files: 'app/views/styles/*.styl',
tasks: 'stylus'
},
cores: {
files: 'app/public/lib/cores/**/*.js',
tasks: 'concat'
},
templates: {
files: 'app/views/templates/*.jade',
tasks: ['jade', 'ngtemplates', 'concat']
}
}
});
// npm tasks
grunt.loadNpmTasks('grunt-angular-templates');
grunt.loadNpmTasks('grunt-ngmin');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-jade');
grunt.loadNpmTasks('grunt-contrib-stylus');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
// single tasks
grunt.registerTask('db', 'db:create');
grunt.registerTask('server', 'server:run');
// multi tasks
grunt.registerTask('default', ['jade', 'stylus', 'ngtemplates', 'concat']);
//grunt.registerTask('min', ['jade', 'stylus', 'ngtemplates', 'concat', 'ngmin', 'uglify']);
grunt.registerTask('users', ['db', 'db:fixtures']);
// db tasks
grunt.registerTask('db:create', 'create DB', function() {
var done = this.async();
// create db for testing
nano.db.get(dbName, function(error, body) {
if (!error) {
// db exists, recreate
nano.db.destroy(dbName, function(error) {
if (error) {
done(error);
}
nano.db.create(dbName, done);
});
} else if (error.reason === 'no_db_file') {
// create the db
nano.db.create(dbName, done);
} else {
done(error);
}
});
});
grunt.registerTask('db:fixtures', 'populate DB', function() {
var done = this.async();
var db = nano.use(dbName);
var users = require('./test/fixtures/users.json');
// add test users
db.bulk(users, function (error, body) {
if(error) {
done(error);
}
});
});
// server tasks
grunt.registerTask('server:run', 'start server', function() {
var done = this.async();
var startServer = require('./app/server.js');
startServer(function(error) {
if (error) {
console.log(error);
}
});
// never call done to run endlessly
});
};