This repository has been archived by the owner on Feb 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
cli.js
47 lines (38 loc) · 1.7 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
'use strict'
const config = require('./config')
const program = require('commander')
const logger = require('./src/common/logger')
const productImporter = require('./src/importer/products')
const categoryImporter = require('./src/importer/categories')
const attributeImporter = require('./src/importer/attributes')
const WooCommerceAPI = require('woocommerce-api');
const elasticsearch = require('elasticsearch')
const client = new elasticsearch.Client({
host: `${config.db.host}:${config.db.port}`,
log: 'warning'
})
const connector = () => {
let {protocol, host} = config.woo.api
return WooCommerceAPI({
url: `${protocol}://${host}`,
consumerKey: config.woo.api.auth.consumer_key,
consumerSecret: config.woo.api.auth.consumer_secret,
wpAPI: true,
version: 'wc/v1'
})
}
program.command('attributes').option('-p, --page', 'current page').option('-P, --pages', 'pages')
.action(cmd => { attributeImporter.importer({ config: config, elasticClient: client, apiConnector: connector, logger }).importAttributes() })
program.command('products')
.option('--perPage <n>', 'per page', parseInt)
.option('--page <n>', 'current page', parseInt)
.action((cmd) => { productImporter.importer({ config: config, elasticClient: client, apiConnector: connector, logger: logger, page: cmd.page, perPage: cmd.perPage}).importProducts() })
program.command('categories')
.action(cmd => { categoryImporter.importer({ config: config, elasticClient: client, apiConnector: connector, logger }).importCategories() })
program
.on('command:*', () => {
logger.warn('Invalid command: %s\nSee --help for a list of available commands.', program.args.join(' '));
process.exit(1);
});
program
.parse(process.argv)