1 | const program = require("commander");
|
2 | const jsonfile = require("jsonfile");
|
3 |
|
4 | const helpers = require("../dist");
|
5 | const apis = require("../dist");
|
6 |
|
7 | program.parse(process.argv);
|
8 |
|
9 | const stdout = console.log.bind(console);
|
10 | const stderr = console.error.bind(console);
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | async function importing(file) {
|
17 | await helpers.checkApiKey();
|
18 |
|
19 | if (typeof file === "undefined") {
|
20 | stderr("collection file not given!");
|
21 | process.exit(1);
|
22 | }
|
23 |
|
24 | const collection = jsonfile.readFileSync(file);
|
25 | const collections = await apis.listCollections();
|
26 | const { info = {} } = collection;
|
27 | const found = collections.find(c => c.name === info.name);
|
28 |
|
29 | if (found) {
|
30 | await apis.updateCollection(found.id, collection);
|
31 | stdout("updated collection", info.name);
|
32 | } else {
|
33 | await apis.createCollection(collection);
|
34 | stdout("created collection", info.name);
|
35 | }
|
36 | }
|
37 |
|
38 | importing(program.file).catch(err => {
|
39 | stderr(err);
|
40 | process.exit(1);
|
41 | });
|