-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathafter_deploy.js
executable file
·61 lines (51 loc) · 1.88 KB
/
after_deploy.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
#!/usr/bin/env node
var models = require('./models'),
fs = require('fs'),
async = require('async');
var User = models.User,
Item = models.Item;
var firstUser = false;
var imports = [];
var users = [
{username: 'Andrew', avatar_url: 'https://github.com/identicons/jasonlong.png'},
{username: 'Sergey', avatar_url: 'https://avatars0.githubusercontent.com/u/4436860?v=3&s=96'},
{username: 'Thomas', avatar_url: 'https://avatars0.githubusercontent.com/u/125464?v=3&s=96'}
];
module.exports = importData = function() {
// create the first user before everything else
console.log('Starting import with User admin');
User.create({username: 'admin', avatar_url: 'https://avatars0.githubusercontent.com/u/4336861?v=3&s=96'}, function(err, createdUser) {
firstUser = createdUser;
for (var i in users) {
imports.push(function(newUser) {
return function(done) {
console.log('Importing User', newUser.username);
User.create(newUser, function(err, createdUser) {
if (!firstUser) {
firstUser = createdUser;
}
done(err);
});
}
}(users[i]));
}
var mediaFiles = fs.readdirSync('./media/');
mediaFiles.forEach(function(fileName){
imports.push(function(done) {
console.log('Importing Item', fileName);
Item.create({user: firstUser._id, image_url: fileName}, function(err, createdItem){
done(err);
});
});
});
async.parallel(imports,
function(err) {
if (err) console.log(err);
console.log('import completed');
process.exit(0);
});
});
};
if(!module.parent){
importData();
}