-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathseed.js
More file actions
72 lines (55 loc) · 1.53 KB
/
seed.js
File metadata and controls
72 lines (55 loc) · 1.53 KB
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
var chalk = require('chalk');
var db = require('./server/db');
var User = db.model('user');
var Word = db.model('word');
var fs = require('fs');
var Promise = require('sequelize').Promise;
var seedUsers = function () {
var users = [
{
username: 'Tester',
email: 'testing@fsa.com',
password: 'password'
},
{
username: 'Jon',
email: 'jon@jon.com',
password: 'jon'
},
{
username: 'Jan',
email: 'jan@jan.com',
password: 'jan'
}
];
var creatingUsers = users.map(function (userObj) {
return User.create(userObj);
});
return Promise.all(creatingUsers);
};
var seedWords = function () {
var words = fs.readFileSync('./dictionary/twl.txt').toString().split('\n');
var dictionaryJs = `var app = angular.module('dictionary', []);
app.factory("DictionaryFactory", function() {
var DictionaryFactory = {};
DictionaryFactory.dictionary = ${JSON.stringify(words)};
return DictionaryFactory;
});`
fs.writeFile('./dictionary/dictionary.js', dictionaryJs, 'utf8', function(err) {
if (err) throw err;
console.log('dictionary seeded')
})
};
seedWords();
db.sync({ force: true })
.then(function () {
return seedUsers();
})
.then(function () {
console.log(chalk.green('Seed successful!'));
process.kill(0);
})
.catch(function (err) {
console.error(err);
process.kill(1);
});