-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
50 lines (45 loc) · 1.38 KB
/
app.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
"use strict";
process.on("unhandledRejection", reason => console.error(reason));
const Moltin = require("./moltin");
const uploader = require("./data/uploader");
const objects = require("./data/moltinobjects");
const customobjects = require("./data/customobjects");
const argv = require("./argv");
require("dotenv").load();
const imports = {
// order matters, do products last
images: require("./imports/images"),
collections: require("./imports/collections"),
brands: require("./imports/brands"),
categories: require("./imports/categories"),
products: require("./imports/products")
};
(async function() {
//Delete only what is passed to delete
for (let entity of [
"Products",
"Brands",
"Categories",
"Files",
"Currency",
"Collections"
]) {
console.log(argv.clean(entity.toLowerCase()));
if (argv.clean(entity.toLowerCase())) {
console.log("Catalog cleanup: removing %s", entity);
await Moltin[entity].RemoveAll();
}
}
//set up the object and transform
const catalog = await uploader(argv.path);
//set up flows
await objects(argv.path, catalog);
//Add data objects, unless flagged with skip
for (let entity of Object.keys(imports)) {
if (!argv.skip(entity)) {
console.log("Importing %s", entity);
await imports[entity](argv.path, catalog);
}
}
console.log("New moltin catalog is ready to go");
})();