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 { amazonAppendImagesCommand } from "./amazon-append-images";
|
||||||
import { amazonCrawleeProductsCommand } from "./amazon-crawlee-products";
|
import { amazonCrawleeProductsCommand } from "./amazon-crawlee-products";
|
||||||
import { amazonProcureASINsCommand } from "./amazon-procure-asins";
|
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';
|
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';
|
export const COMMAND_NAME = 'logs';
|
||||||
|
|
||||||
const log = console.log;
|
export const amazonGetItemsLogsCommand = (commandName: string, amazonGetItemsCommand: Command) => {
|
||||||
|
const log = console.log;
|
||||||
export const amazonGetItemsLogsCommand = (amazonGetItemsCommand: Command) => {
|
const command = amazonGetItemsCommand.command(commandName).alias('log')
|
||||||
const command = amazonGetItemsCommand.command(COMMAND_NAME).alias('log')
|
|
||||||
.description('Prints the get-items JSON response')
|
.description('Prints the get-items JSON response')
|
||||||
.argument('<log-ids...>')
|
.argument('<log-ids...>')
|
||||||
.action(async (logIds: string[]) => {
|
.action(async (logIds: string[]) => {
|
||||||
|
|
|
@ -9,15 +9,16 @@ import { DateTime } from "luxon";
|
||||||
|
|
||||||
export const COMMAND_NAME = 'ls';
|
export const COMMAND_NAME = 'ls';
|
||||||
|
|
||||||
const log = logForCommand(COMMAND_NAME);
|
export const amazonGetItemsLsCommand = (commandName: string, amazonGetItemsCommand: Command) => {
|
||||||
|
const log = logForCommand(commandName);
|
||||||
export const amazonGetItemsLsCommand = (amazonGetItemsCommand: Command) => {
|
const command = amazonGetItemsCommand.command(commandName).alias('list')
|
||||||
const command = amazonGetItemsCommand.command(COMMAND_NAME).alias('list')
|
.description('Fetch Amazon Items by inputting one or more ASINs separated by spaces.')
|
||||||
.description('List all the get-items logs')
|
.argument('<ASINs...>', 'Amazon Standard Identification Numbers')
|
||||||
.action(async (args: string[]) => {
|
.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);
|
let logsDto = await core.getContentsUsingJsonQuery<AmazonGetItem>(SCHEMAS.AMAZON_GET_ITEMS);
|
||||||
logsDto.items.forEach((logDto, index) => {
|
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)}`)
|
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.`)
|
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 { config } from "../../config.js";
|
||||||
import { SquidexClient } from "@squidex/squidex";
|
import { Squidex, SquidexClient } from "@squidex/squidex";
|
||||||
import type { ContentsDto } from "../internals/ContentsDtoT.js";
|
import type { ContentsDto } from "../internals/ContentsDtoT.js";
|
||||||
import type { SupportedLocales } from "../internals/LocalizedT.js";
|
import type { SupportedLocales } from "../internals/LocalizedT.js";
|
||||||
import type { SCHEMAS } from "../models/schemas.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({
|
export const client = new SquidexClient({
|
||||||
appName: config.squidexAppName!,
|
appName: config.squidexAppName!,
|
||||||
|
|
|
@ -2,6 +2,9 @@ import type { PageSeo } from "../components/PageSeo";
|
||||||
import type { Localized } from "../../internals/LocalizedT";
|
import type { Localized } from "../../internals/LocalizedT";
|
||||||
import type { NonLocalized } from "../../internals/NonLocalizedT";
|
import type { NonLocalized } from "../../internals/NonLocalizedT";
|
||||||
import type { Component } from "../../internals/Component";
|
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 {
|
export interface Page {
|
||||||
title: Localized<string>,
|
title: Localized<string>,
|
||||||
|
@ -9,4 +12,10 @@ export interface Page {
|
||||||
content: Localized<Component[]>,
|
content: Localized<Component[]>,
|
||||||
seo: Localized<PageSeo>,
|
seo: Localized<PageSeo>,
|
||||||
parentPage: NonLocalized<string[]>,
|
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