103 lines
4.1 KiB
JavaScript
103 lines
4.1 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 write_1 = require("@plastichub/fs/write");
|
|
const osr_cli_commons_1 = require("@plastichub/osr-cli-commons");
|
|
const _cli_1 = require("../_cli");
|
|
const options_1 = require("../options");
|
|
const __1 = require("..");
|
|
const lib_1 = require("../lib");
|
|
const category_1 = require("../lib/cscart/category");
|
|
const defaultOptions = (yargs) => {
|
|
return yargs.option('debug', {
|
|
default: false,
|
|
describe: 'debug messages',
|
|
type: 'boolean'
|
|
}).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('category <verb>', 'Category 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 _categories = yield (0, lib_1.categories)(config.cscart);
|
|
if (opts.dst) {
|
|
(0, category_1.writeCategories)(_categories, opts);
|
|
}
|
|
else {
|
|
__1.logger.debug('Categories', _categories);
|
|
}
|
|
}
|
|
if (opts.verb == 'get') {
|
|
let cat = yield (0, category_1.get_category)(opts.id, config.cscart);
|
|
opts.debug && __1.logger.debug(`Get category ${opts.id} `, cat);
|
|
if (cat && opts.dst) {
|
|
let _path = path.resolve(opts.dst);
|
|
(0, write_1.sync)(_path, cat);
|
|
opts.debug && __1.logger.debug(`Writing category to ${_path}`);
|
|
}
|
|
}
|
|
if (opts.verb == 'delete') {
|
|
return yield (0, category_1.delete_category)(opts.id, config.cscart);
|
|
}
|
|
if (opts.verb == 'create') {
|
|
const args = {
|
|
category: 'cat',
|
|
company_id: 1,
|
|
status: 'H',
|
|
parent_id: 6
|
|
};
|
|
let _item = yield (0, category_1.create_category)(args, config.cscart);
|
|
__1.logger.debug(`Created category ! ID:`, _item);
|
|
}
|
|
if (opts.verb == 'update') {
|
|
const args = {
|
|
category: 'renamed'
|
|
};
|
|
let _item = yield (0, category_1.update_category)(opts.id, args, config.cscart);
|
|
__1.logger.debug(`Updated category ! ID:${opts.id}`, _item);
|
|
}
|
|
return;
|
|
}));
|
|
};
|
|
exports.register = register;
|
|
//# sourceMappingURL=category.js.map
|