-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
52 lines (40 loc) · 1.28 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
var flatten = require('lodash.flatten');
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
function importTestData() {
// Get all the collections we're importing in to
var folders = grunt.file.expand({ filter: 'isDirectory' }, 'test/data/*');
// Start building the operations for mongoimport to work with
var collections = folders.map(function (folder) {
// This provides the name of the collection
var collName = folder.split('test/data/')[1];
// Match all JSON files for that collection
var files = grunt.file.expand(folder + '/**/*.json');
console.log(collName);
console.log(files);
// Build the individual operations for mongoimport
var ops = files.map(function (file) {
var obj = {};
obj.name = collName;
obj.type = 'json';
obj.jsonArray = true;
obj.file = file;
return obj;
});
// We want the first op to drop the collection
ops[0].drop = true;
return ops;
});
return flatten(collections);
}
grunt.initConfig({
mongoimport: {
options: {
db: 'expressPermit',
stopOnError: 'true',
collections: importTestData(),
},
},
});
grunt.registerTask('default', ['mongoimport']);
};