Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions commands/function.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
// @ts-nocheck
const { addGlobalOptions } = require('../lib/commonOpts');
const list = require('./function/list');
import { Argv } from 'yargs';
import list from './function/list';
const deploy = require('./function/deploy');
const server = require('./function/server');
const { i18n } = require('../lib/lang');
import { i18n } from '../lib/lang';
import { makeYargsBuilder } from '../lib/yargsUtils';
import { YargsCommandModuleBucket } from '../types/Yargs';

exports.command = ['function', 'functions'];
exports.describe = i18n(`commands.function.describe`);
export const command = ['function', 'functions'];
export const describe = i18n(`commands.function.describe`);

exports.builder = yargs => {
addGlobalOptions(yargs);
function functionBuilder(yargs: Argv): Argv {
yargs.command(list).command(deploy).command(server).demandCommand(1, '');

return yargs;
}

const builder = makeYargsBuilder(functionBuilder, command, describe, {
useGlobalOptions: true,
});

const functionCommand: YargsCommandModuleBucket = {
command,
describe,
builder,
handler: () => {},
};

export default functionCommand;

// TODO Remove this legacy export once we've migrated all commands to TS
module.exports = functionCommand;
88 changes: 58 additions & 30 deletions commands/function/list.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
// @ts-nocheck
const moment = require('moment');
const { getRoutes } = require('@hubspot/local-dev-lib/api/functions');
const { logger } = require('@hubspot/local-dev-lib/logger');
const { logError, ApiErrorContext } = require('../../lib/errorHandlers/index');
const { getTableContents, getTableHeader } = require('../../lib/ui/table');
const {
addConfigOptions,
addAccountOptions,
addUseEnvironmentOptions,
} = require('../../lib/commonOpts');
const { trackCommandUsage } = require('../../lib/usageTracking');
const { i18n } = require('../../lib/lang');

const { EXIT_CODES } = require('../../lib/enums/exitCodes');

exports.command = ['list', 'ls'];
exports.describe = i18n('commands.function.subcommands.list.describe');

exports.handler = async options => {
const { derivedAccountId } = options;

trackCommandUsage('functions-list', null, derivedAccountId);
import { Argv, ArgumentsCamelCase } from 'yargs';
import moment from 'moment';
import { getRoutes } from '@hubspot/local-dev-lib/api/functions';
import { logger } from '@hubspot/local-dev-lib/logger';

import { logError, ApiErrorContext } from '../../lib/errorHandlers/index';
import { getTableContents, getTableHeader } from '../../lib/ui/table';
import { trackCommandUsage } from '../../lib/usageTracking';
import { i18n } from '../../lib/lang';
import { EXIT_CODES } from '../../lib/enums/exitCodes';
import {
CommonArgs,
ConfigArgs,
AccountArgs,
EnvironmentArgs,
YargsCommandModule,
} from '../../types/Yargs';
import { makeYargsBuilder } from '../../lib/yargsUtils';

const command = ['list', 'ls'];
const describe = i18n('commands.function.subcommands.list.describe');

type FunctionListArgs = CommonArgs &
ConfigArgs &
AccountArgs &
EnvironmentArgs & { json?: boolean };

async function handler(
args: ArgumentsCamelCase<FunctionListArgs>
): Promise<void> {
const { derivedAccountId } = args;

trackCommandUsage('function-list', undefined, derivedAccountId);

logger.debug(
i18n('commands.function.subcommands.list.debug.gettingFunctions')
Expand All @@ -39,7 +49,7 @@ exports.handler = async options => {
);
}

if (options.json) {
if (args.json) {
return logger.log(routesResp.objects);
}

Expand All @@ -58,13 +68,9 @@ exports.handler = async options => {
getTableHeader(['Route', 'Method', 'Secrets', 'Created', 'Updated'])
);
return logger.log(getTableContents(functionsAsArrays));
};

exports.builder = yargs => {
addConfigOptions(yargs);
addAccountOptions(yargs);
addUseEnvironmentOptions(yargs);
}

function functionListBuilder(yargs: Argv): Argv<FunctionListArgs> {
yargs.options({
json: {
describe: i18n(
Expand All @@ -73,4 +79,26 @@ exports.builder = yargs => {
type: 'boolean',
},
});

return yargs as Argv<FunctionListArgs>;
}

const builder = makeYargsBuilder<FunctionListArgs>(
functionListBuilder,
command,
describe,
{
useConfigOptions: true,
useAccountOptions: true,
useEnvironmentOptions: true,
}
);

const functionListCommand: YargsCommandModule<unknown, FunctionListArgs> = {
command,
describe,
handler,
builder,
};

export default functionListCommand;