Skip to content

Commit

Permalink
Add prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-yeager committed Nov 22, 2024
1 parent f134846 commit e18e900
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
25 changes: 17 additions & 8 deletions commands/customObject/schema/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-nocheck
import { inputPrompt } from '../../../lib/prompts/promptUtils';
import { inputPrompt, listPrompt } from '../../../lib/prompts/promptUtils';
import { fetchObjectSchemas } from '@hubspot/local-dev-lib/api/customObjects';

const path = require('path');
const { isConfigFlagEnabled } = require('@hubspot/local-dev-lib/config');
Expand Down Expand Up @@ -28,15 +29,23 @@ exports.handler = async options => {
await loadAndValidateOptions(options);

trackCommandUsage('custom-object-schema-fetch', null, derivedAccountId);

// TODO: Fetch the schemas and show a list. Allow the user to select one.
const name =
providedName || (await inputPrompt(i18n(`${i18nKey}.selectSchema`)));
const dest =
providedDest || (await inputPrompt(i18n(`${i18nKey}.inputDest`)));
console.log(name);
let name;

try {
const {
data: { results },
} = await fetchObjectSchemas(derivedAccountId);
const schemaNames = results?.map(({ name: schemaName }) => schemaName);

name =
providedName ||
(await listPrompt(i18n(`${i18nKey}.selectSchema`), {
choices: schemaNames,
}));

const dest =
providedDest || (await inputPrompt(i18n(`${i18nKey}.inputDest`)));

if (isConfigFlagEnabled(CONFIG_FLAGS.USE_CUSTOM_OBJECT_HUBFILE)) {
const fullpath = path.resolve(getCwd(), dest);
await fetchSchema(derivedAccountId, name, fullpath);
Expand Down
18 changes: 16 additions & 2 deletions commands/customObject/schema/update.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @ts-nocheck
import { fetchObjectSchemas } from '@hubspot/local-dev-lib/api/customObjects';
import { listPrompt } from '../../../lib/prompts/promptUtils';

const { logger } = require('@hubspot/local-dev-lib/logger');
const { logError } = require('../../../lib/errorHandlers/index');
const { getAbsoluteFilePath } = require('@hubspot/local-dev-lib/path');
Expand Down Expand Up @@ -28,11 +31,11 @@ const { i18n } = require('../../../lib/lang');
const i18nKey = 'commands.customObject.subcommands.schema.subcommands.update';
const { EXIT_CODES } = require('../../../lib/enums/exitCodes');

exports.command = 'update <name>';
exports.command = 'update [name]';
exports.describe = i18n(`${i18nKey}.describe`);

exports.handler = async options => {
const { path, name, derivedAccountId } = options;
const { path, name: providedName, derivedAccountId } = options;

await loadAndValidateOptions(options);

Expand All @@ -44,7 +47,18 @@ exports.handler = async options => {
process.exit(EXIT_CODES.ERROR);
}

let name = providedName;
try {
const {
data: { results },
} = await fetchObjectSchemas(derivedAccountId);
const schemaNames = results?.map(({ name: schemaName }) => schemaName);

name =
providedName ||
(await listPrompt(i18n(`${i18nKey}.selectSchema`), {
choices: schemaNames,
}));
if (isConfigFlagEnabled(CONFIG_FLAGS.USE_CUSTOM_OBJECT_HUBFILE)) {
await updateSchemaFromHubFile(derivedAccountId, filePath);
logger.success(
Expand Down
1 change: 1 addition & 0 deletions lang/en.lyaml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ en:
success:
update: "Your schema has been updated in account \"{{ accountId }}\""
viewAtUrl: "Schema can be viewed at {{ url }}"
selectSchema: "Which schema would you like to update?"
doctor:
describe: "Retrieve diagnostic information about your local HubSpot configurations."
options:
Expand Down
Empty file removed lib/prompts/customObjectPrompts.ts
Empty file.

0 comments on commit e18e900

Please sign in to comment.