-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimport.js
47 lines (45 loc) · 2.48 KB
/
import.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
const shopifyImportCtrl = require("./importScripts/shopify"),
woocommerceImportCtrl = require("./importScripts/woocommerce"),
magentoImportCtrl = require("./importScripts/magento"),
prestashopImportCtrl = require("./importScripts/prestashop"),
fs = require("fs"),
Papa = require('papaparse'),
config = require("./config.json"),
importFileName = process.argv.slice(-1)[0],
importType = process.argv.slice(-2)[0];
(() => {
if (importType && importFileName && process.argv.length == 4) {
if (fs.existsSync(importFileName)) {
const importCSV = fs.createReadStream(`${importFileName}`);
Papa.parse(importCSV, {
complete: async (results) => {
if (importType == "shopify") {
rows = results.data;
formattedImportResults = await shopifyImportCtrl.importShopifyProductListings(rows);
} else if (importType == "woocommerce") {
rows = results.data;
formattedImportResults = await woocommerceImportCtrl.importWoocommerceProductListings(rows);
} else if (importType == "magento") {
rows = results.data;
formattedImportResults = await magentoImportCtrl.importMagentoProductListings(rows);
} else if (importType == "prestashop") {
rows = results.data;
formattedImportResults = await prestashopImportCtrl.importPrestashopProductListings(rows);
} else {
console.log(`\nCSV type is not supported yet. \n\nCSV import options available are: "shopify" or "woocommerce". \n\nAn example valid command would be: "node import shopify products_export.csv"`);
return;
}
console.log("\nYour import has finished, the results are below:")
console.log("\nSuccessfully Imported Listings:\n", formattedImportResults.listingSuccessArray.length);
console.log("\nFailed Listing Imports:\n", formattedImportResults.listingErrorsArray.length);
}
})
} else {
console.log(`\nError: CSV is empty or nonexistent`);
return;
};
} else {
console.log(`\nError: Incorrect command format. \n\nAn example valid command would be: "node import shopify products_export.csv"`);
return;
}
})();