Working on making CLI app subcommands reusable.
This commit is contained in:
parent
9e4d912320
commit
c989bbaa9c
|
@ -2,7 +2,7 @@ import type { Command } from "commander";
|
|||
import { amazonAppendImagesCommand } from "./amazon-append-images";
|
||||
import { amazonCrawleeProductsCommand } from "./amazon-crawlee-products";
|
||||
import { amazonProcureASINsCommand } from "./amazon-procure-asins";
|
||||
import { amazonGetItemsCommand } from "./get-items/get-items";
|
||||
import { amazonGetItemsCommand } from "./get-items/amazon-get-items";
|
||||
|
||||
const COMMAND_NAME = 'amazon';
|
||||
|
||||
|
|
26
src/apps/catalog/amazon/get-items/amazon-get-items-fetch.ts
Normal file
26
src/apps/catalog/amazon/get-items/amazon-get-items-fetch.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import type { Command } from "commander";
|
||||
import * as core from '../../../../data/core/client'
|
||||
import { getProductsUsingJsonQuery } from "../../../../data/api-client";
|
||||
import type { AmazonMarketplaceConnection } from "../../../../data/models/components/AmazonMarketplaceConnection";
|
||||
import { logForCommand } from "../../common/console";
|
||||
import { SCHEMAS } from "../../../../data/models/schemas";
|
||||
import type { AmazonGetItem } from "../../../../data/models/multis/AmazonGetItem";
|
||||
import { DateTime } from "luxon";
|
||||
|
||||
export const COMMAND_NAME = 'fetch';
|
||||
|
||||
export const amazonGetItemsFetchCommand = (commandName: string, amazonGetItemsCommand: Command) => {
|
||||
const log = logForCommand(commandName);
|
||||
const command = amazonGetItemsCommand.command(commandName).alias('get')
|
||||
.description('List all the get-items logs')
|
||||
.action(async (args: string[]) => {
|
||||
let logsDto = await core.getContentsUsingJsonQuery<AmazonGetItem>(SCHEMAS.AMAZON_GET_ITEMS);
|
||||
logsDto.items.forEach((logDto, index) => {
|
||||
const logEach = logForCommand(`${commandName}:${index+1}`);
|
||||
logEach(`ID: ${logDto.id} Request Date: ${DateTime.fromISO(logDto.data?.requestDate.iv!).toLocaleString(DateTime.DATETIME_SHORT_WITH_SECONDS)}`)
|
||||
});
|
||||
log(`Returned ${logsDto.items.length} get-items logs.`)
|
||||
});
|
||||
command.configureHelp();
|
||||
return command;
|
||||
}
|
|
@ -9,10 +9,9 @@ import { DateTime } from "luxon";
|
|||
|
||||
export const COMMAND_NAME = 'logs';
|
||||
|
||||
const log = console.log;
|
||||
|
||||
export const amazonGetItemsLogsCommand = (amazonGetItemsCommand: Command) => {
|
||||
const command = amazonGetItemsCommand.command(COMMAND_NAME).alias('log')
|
||||
export const amazonGetItemsLogsCommand = (commandName: string, amazonGetItemsCommand: Command) => {
|
||||
const log = console.log;
|
||||
const command = amazonGetItemsCommand.command(commandName).alias('log')
|
||||
.description('Prints the get-items JSON response')
|
||||
.argument('<log-ids...>')
|
||||
.action(async (logIds: string[]) => {
|
||||
|
|
|
@ -9,15 +9,16 @@ import { DateTime } from "luxon";
|
|||
|
||||
export const COMMAND_NAME = 'ls';
|
||||
|
||||
const log = logForCommand(COMMAND_NAME);
|
||||
|
||||
export const amazonGetItemsLsCommand = (amazonGetItemsCommand: Command) => {
|
||||
const command = amazonGetItemsCommand.command(COMMAND_NAME).alias('list')
|
||||
.description('List all the get-items logs')
|
||||
export const amazonGetItemsLsCommand = (commandName: string, amazonGetItemsCommand: Command) => {
|
||||
const log = logForCommand(commandName);
|
||||
const command = amazonGetItemsCommand.command(commandName).alias('list')
|
||||
.description('Fetch Amazon Items by inputting one or more ASINs separated by spaces.')
|
||||
.argument('<ASINs...>', 'Amazon Standard Identification Numbers')
|
||||
.description('Begin automated product procurement from Amazon by inputting one or more ASINs separated by spaces.')
|
||||
.action(async (args: string[]) => {
|
||||
let logsDto = await core.getContentsUsingJsonQuery<AmazonGetItem>(SCHEMAS.AMAZON_GET_ITEMS);
|
||||
logsDto.items.forEach((logDto, index) => {
|
||||
const logEach = logForCommand(`${COMMAND_NAME}:${index+1}`);
|
||||
const logEach = logForCommand(`${commandName}:${index+1}`);
|
||||
logEach(`ID: ${logDto.id} Request Date: ${DateTime.fromISO(logDto.data?.requestDate.iv!).toLocaleString(DateTime.DATETIME_SHORT_WITH_SECONDS)}`)
|
||||
});
|
||||
log(`Returned ${logsDto.items.length} get-items logs.`)
|
||||
|
|
14
src/apps/catalog/amazon/get-items/amazon-get-items.ts
Normal file
14
src/apps/catalog/amazon/get-items/amazon-get-items.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import type { Command } from "commander";
|
||||
import * as fetch from "./amazon-get-items-fetch";
|
||||
import * as ls from "./amazon-get-items-ls";
|
||||
import * as logs from "./amazon-get-items-logs";
|
||||
|
||||
const COMMAND_NAME = 'get-items';
|
||||
|
||||
export const amazonGetItemsCommand = (program: Command) => {
|
||||
const amazonGetItemsCommand = program.command(COMMAND_NAME).alias('get-item').description('Amazon Get Items commands');
|
||||
fetch.amazonGetItemsFetchCommand(fetch.COMMAND_NAME, amazonGetItemsCommand);
|
||||
ls.amazonGetItemsLsCommand(ls.COMMAND_NAME, amazonGetItemsCommand);
|
||||
logs.amazonGetItemsLogsCommand(logs.COMMAND_NAME, amazonGetItemsCommand);
|
||||
return amazonGetItemsCommand;
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
import type { Command } from "commander";
|
||||
import { amazonGetItemsLsCommand } from "./amazon-get-items-ls";
|
||||
import { amazonGetItemsLogsCommand } from "./amazon-get-items-logs";
|
||||
|
||||
const COMMAND_NAME = 'get-items';
|
||||
|
||||
export const amazonGetItemsCommand = (program: Command) => {
|
||||
const amazonGetItemsCommand = program.command(COMMAND_NAME).alias('get-item').description('Amazon Get Items commands');
|
||||
amazonGetItemsLsCommand(amazonGetItemsCommand);
|
||||
amazonGetItemsLogsCommand(amazonGetItemsCommand);
|
||||
return amazonGetItemsCommand;
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
import { config } from "../../config.js";
|
||||
import { SquidexClient } from "@squidex/squidex";
|
||||
import { Squidex, SquidexClient } from "@squidex/squidex";
|
||||
import type { ContentsDto } from "../internals/ContentsDtoT.js";
|
||||
import type { SupportedLocales } from "../internals/LocalizedT.js";
|
||||
import type { SCHEMAS } from "../models/schemas.js";
|
||||
import type { Contents } from "@squidex/squidex/api/resources/contents/client/Client.js";
|
||||
|
||||
export const client = new SquidexClient({
|
||||
appName: config.squidexAppName!,
|
||||
|
|
|
@ -2,6 +2,9 @@ import type { PageSeo } from "../components/PageSeo";
|
|||
import type { Localized } from "../../internals/LocalizedT";
|
||||
import type { NonLocalized } from "../../internals/NonLocalizedT";
|
||||
import type { Component } from "../../internals/Component";
|
||||
import type { ContentDto } from "../../internals/ContentDtoT";
|
||||
import type { ContentsDto } from "../../internals/ContentsDtoT";
|
||||
import type { SCHEMAS } from "../schemas";
|
||||
|
||||
export interface Page {
|
||||
title: Localized<string>,
|
||||
|
@ -10,3 +13,9 @@ export interface Page {
|
|||
seo: Localized<PageSeo>,
|
||||
parentPage: NonLocalized<string[]>,
|
||||
}
|
||||
|
||||
export interface PageDto extends ContentDto<Page> {
|
||||
schemaName: SCHEMAS.PAGES,
|
||||
}
|
||||
|
||||
export type PagesDto = ContentsDto<Page>;
|
Loading…
Reference in New Issue
Block a user