This repository was archived by the owner on May 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathitemsapi-items.js
More file actions
84 lines (69 loc) · 2.15 KB
/
itemsapi-items.js
File metadata and controls
84 lines (69 loc) · 2.15 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
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env node
var program = require('commander');
var service = require('./src/items')
var colors = require('colors');
program
.usage('test')
.option('-a, --api [api]', 'ItemsAPI URL i.e. http://localhost:4000/api/v1')
.option('-c, --collection [collection]', 'Collection name')
program
.command('import')
.description('Import JSON data into collection')
.option('-l, --limit [limit]', 'Amount of items you want to load')
.option('-f, --filename [filename]', 'JSON file')
.action(function(options){
if (!program.api) {
console.log(`The --api parameter is required`.red);
process.exit()
}
if (!program.collection) {
console.log(`The --collection parameter is required`.red);
process.exit()
}
if (!options.filename) {
console.log(`The --filename parameter is required`.red);
process.exit()
}
console.log('Trying to import data.. Please wait..');
options.api = program.api
options.collection = program.collection
service.import(options)
.then(function(val) {
console.log('Data has been imported successfully..'.green)
var url = program.api + '/items/' + program.collection;
console.log('Open %s in web browser to test it out', url);
})
.catch(function(err) {
console.log(err)
console.log('Unexpected error..'.red)
})
})
program
.command('export')
.description('Export items')
//.option('-l, --limit [limit]', 'Amount of items you want to load')
//.option('-f, --filename [filename]', 'JSON file')
.action(function(options){
if (!program.api) {
console.log(`The --api parameter is required`.red);
process.exit()
}
if (!program.collection) {
console.log(`The --collection parameter is required`.red);
process.exit()
}
options.api = program.api
options.collection = program.collection
service.export(options)
.then(function(val) {
console.log(JSON.stringify(val, null, 2));
})
.catch(function(err) {
console.log(err)
console.log('Unexpected error..'.red)
})
})
if (process.argv.length < 3) {
program.outputHelp()
}
program.parse(process.argv);