110 lines
4.4 KiB
JavaScript
110 lines
4.4 KiB
JavaScript
"use strict";
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.register = void 0;
|
|
const path = require("path");
|
|
const osr_cli_commons_1 = require("@plastichub/osr-cli-commons");
|
|
const write_1 = require("@plastichub/fs/write");
|
|
const _cli_1 = require("../_cli");
|
|
const options_1 = require("../options");
|
|
const __1 = require("..");
|
|
const product_1 = require("../lib/cscart/product");
|
|
const defaultOptions = (yargs) => {
|
|
return yargs.option('debug', {
|
|
default: false,
|
|
describe: 'debug messages',
|
|
type: 'boolean'
|
|
}).option('id', {
|
|
describe: 'Entity ID',
|
|
type: 'number'
|
|
}).option('short', {
|
|
default: 'true',
|
|
describe: 'Emit short info only',
|
|
type: 'boolean'
|
|
}).option('disabled', {
|
|
default: 'false',
|
|
describe: 'Enumerate disabled products',
|
|
type: 'boolean'
|
|
}).option('dry', {
|
|
default: 'false',
|
|
describe: 'Process files for debug purposes only.'
|
|
}).option('env_key', {
|
|
default: 'OSR-CONFIG',
|
|
describe: 'Environment key to the config path.'
|
|
});
|
|
};
|
|
let options = (yargs) => defaultOptions(yargs);
|
|
const register = (cli) => {
|
|
return cli.command('product <verb>', 'Product namespace', options, (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
(0, _cli_1.defaults)();
|
|
if (argv.help) {
|
|
return;
|
|
}
|
|
const args = argv;
|
|
const config = (0, osr_cli_commons_1.CONFIG_DEFAULT)(args.env_key);
|
|
let options = (0, _cli_1.sanitize)(argv);
|
|
if (!options) {
|
|
return;
|
|
}
|
|
options.debug && __1.logger.debug(`CLI Args In`, argv);
|
|
let opts = (0, options_1.parse)(options, args);
|
|
if (!opts.verb) {
|
|
__1.logger.error('No verb specified');
|
|
return;
|
|
}
|
|
if (opts.verb == 'list') {
|
|
let _products = yield (0, product_1.products)(config.cscart);
|
|
if (opts.dst) {
|
|
(0, product_1.writeProducts)(_products, opts);
|
|
}
|
|
}
|
|
if (opts.verb == 'delete') {
|
|
return yield (0, product_1.delete_product)(opts.id, config.cscart);
|
|
}
|
|
if (opts.verb == 'get') {
|
|
let _product = yield (0, product_1.get_product)(opts.id, config.cscart);
|
|
opts.debug && __1.logger.debug(`Get product ${opts.id} `, _product);
|
|
if (_product && opts.dst) {
|
|
let _path = path.resolve(opts.dst);
|
|
(0, write_1.sync)(_path, _product);
|
|
opts.debug && __1.logger.debug(`Writing product to ${_path}`);
|
|
}
|
|
}
|
|
if (opts.verb == 'create') {
|
|
const args = {
|
|
product: 'xxxx2',
|
|
price: 1234,
|
|
main_category: 22,
|
|
category_ids: [22],
|
|
status: 'A',
|
|
company_id: 1
|
|
};
|
|
let _product = yield (0, product_1.create_product)(args, config.cscart);
|
|
__1.logger.debug(`Created product ! ID:`, _product);
|
|
}
|
|
if (opts.verb == 'update') {
|
|
const args = {
|
|
price: 12342,
|
|
product: "cscart-api-test",
|
|
status: 'H',
|
|
full_description: "test - es>",
|
|
meta_keywords: "pp,hdpe",
|
|
category_ids: [22, 15],
|
|
lang_code: 'es'
|
|
};
|
|
let _product = yield (0, product_1.update_product)(opts.id, args, config.cscart);
|
|
__1.logger.debug(`Updated product ! ID:${opts.id}`, _product);
|
|
}
|
|
return;
|
|
}));
|
|
};
|
|
exports.register = register;
|
|
//# sourceMappingURL=product.js.map
|