forked from okfn/timemapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
94 lines (89 loc) · 2.34 KB
/
cli.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
var step = require('step');
var dao = require('./dao.js');
var loader = require('./loader.js');
// removes 'node' and this script
args = process.ARGV.splice(2);
// Create some fixtures (e.g. for demoing)
if (args && args[0] == 'fixtures') {
var username = 'tester';
var noteIds = [];
step(
function makeAccount() {
var acc = dao.Account.create({
id: 'tester'
, email: 'tester@okfn.org'
, fullname: 'The Tester'
});
acc.setPassword('tester');
acc.save(this);
}
, function makeNotes(account) {
var group = this.group();
groupCallbacks = [];
var count = 0;
for (x=1;x<4;x++) {
groupCallbacks.push(group());
dao.Note.upsert({
owner: username
, title: 'Note ' + x
}
, function(data) {
var err = null;
groupCallbacks[count](err, data.id);
count += 1;
}
);
}
}
, function makeThread(err, noteIds) {
if (err) throw err;
var self = this;
dao.Thread.upsert({
id:'testerdefault',
name:'default',
title:'Default Thread',
description:'Default thread - where notes go by default.',
owner:username,
notes:noteIds
}, function(data) {
self(null, data);
});
}
, function report(err, thread) {
if (err) throw err;
console.log('Fixtures created (tester@okfn.org / pass)');
}
);
} else if (args && args[0] == 'rebuild_db') {
var mappings = {
mappings: {
note: {
properties: {
start: { type: 'string' }
, end: { type: 'string' }
}
}
}
};
dao.esclient.deleteIndex(dao.config.databaseName)
.on('done', function() {
dao.esclient.createIndex(dao.config.databaseName, mappings)
.on('done', function() {
console.log('DB rebuilt');
})
.exec()
})
.exec();
} else if (args && args[0] == 'load') {
if (args.length < 3) {
console.log('Usage: load {filepath} {owner-user-id}');
return;
}
var filepath = args[1];
var owner = args[2];
loader.load(filepath, owner, function(thread) {
console.log('Successfully loaded thread: ' + thread.id + ' (' + thread.title + ')');
});
} else {
console.log('Commands are: fixtures | rebuild_db | load ');
}