-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
port validation and configOptions to TS #1309
Changes from 2 commits
b74ae8f
3fb6f47
10c30c4
d625070
fedda8a
574f829
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
// @ts-nocheck | ||
const { logger } = require('@hubspot/local-dev-lib/logger'); | ||
const { | ||
import { logger } from '@hubspot/local-dev-lib/logger'; | ||
import { | ||
updateAllowUsageTracking, | ||
updateDefaultCmsPublishMode, | ||
updateHttpTimeout, | ||
} = require('@hubspot/local-dev-lib/config'); | ||
const { CMS_PUBLISH_MODE } = require('@hubspot/local-dev-lib/constants/files'); | ||
const { commaSeparatedValues } = require('@hubspot/local-dev-lib/text'); | ||
const { trackCommandUsage } = require('./usageTracking'); | ||
const { promptUser } = require('./prompts/promptUtils'); | ||
const { i18n } = require('../lib/lang'); | ||
} from '@hubspot/local-dev-lib/config'; | ||
import { CmsPublishMode } from '@hubspot/local-dev-lib/types/Files'; | ||
import { CMS_PUBLISH_MODE } from '@hubspot/local-dev-lib/constants/files'; | ||
import { commaSeparatedValues } from '@hubspot/local-dev-lib/text'; | ||
import { trackCommandUsage } from './usageTracking'; | ||
import { promptUser } from './prompts/promptUtils'; | ||
import { i18n } from '../lib/lang'; | ||
|
||
const i18nKey = 'commands.config.subcommands.set.options'; | ||
|
||
const enableOrDisableUsageTracking = async () => { | ||
const { isEnabled } = await promptUser([ | ||
async function enableOrDisableUsageTracking(): Promise<boolean> { | ||
const { isEnabled } = await promptUser<{ isEnabled: boolean }>([ | ||
{ | ||
type: 'list', | ||
look: false, | ||
name: 'isEnabled', | ||
pageSize: 20, | ||
message: i18n(`${i18nKey}.allowUsageTracking.promptMessage`), | ||
|
@@ -36,12 +35,18 @@ const enableOrDisableUsageTracking = async () => { | |
]); | ||
|
||
return isEnabled; | ||
}; | ||
} | ||
|
||
const setAllowUsageTracking = async ({ accountId, allowUsageTracking }) => { | ||
trackCommandUsage('config-set-allow-usage-tracking', null, accountId); | ||
export async function setAllowUsageTracking({ | ||
accountId, | ||
allowUsageTracking, | ||
}: { | ||
accountId: number; | ||
allowUsageTracking?: boolean; | ||
}): Promise<void> { | ||
trackCommandUsage('config-set-allow-usage-tracking', undefined, accountId); | ||
|
||
let isEnabled; | ||
let isEnabled: boolean; | ||
|
||
if (typeof allowUsageTracking === 'boolean') { | ||
isEnabled = allowUsageTracking; | ||
|
@@ -51,18 +56,21 @@ const setAllowUsageTracking = async ({ accountId, allowUsageTracking }) => { | |
|
||
updateAllowUsageTracking(isEnabled); | ||
|
||
return logger.log( | ||
i18n(`${i18nKey}.allowUsageTracking.success`, { isEnabled }) | ||
logger.success( | ||
i18n(`${i18nKey}.allowUsageTracking.success`, { | ||
isEnabled: isEnabled.toString(), | ||
}) | ||
); | ||
}; | ||
} | ||
|
||
const ALL_CMS_PUBLISH_MODES = Object.values(CMS_PUBLISH_MODE); | ||
|
||
const selectCmsPublishMode = async () => { | ||
const { cmsPublishMode } = await promptUser([ | ||
async function selectCmsPublishMode(): Promise<CmsPublishMode> { | ||
const { cmsPublishMode } = await promptUser<{ | ||
cmsPublishMode: CmsPublishMode; | ||
}>([ | ||
{ | ||
type: 'list', | ||
look: false, | ||
name: 'cmsPublishMode', | ||
pageSize: 20, | ||
message: i18n(`${i18nKey}.defaultMode.promptMessage`), | ||
|
@@ -72,15 +80,18 @@ const selectCmsPublishMode = async () => { | |
]); | ||
|
||
return cmsPublishMode; | ||
}; | ||
} | ||
|
||
const setDefaultCmsPublishMode = async ({ | ||
export async function setDefaultCmsPublishMode({ | ||
accountId, | ||
defaultCmsPublishMode, | ||
}) => { | ||
trackCommandUsage('config-set-default-mode', null, accountId); | ||
}: { | ||
accountId: number; | ||
defaultCmsPublishMode?: CmsPublishMode; | ||
}): Promise<void> { | ||
trackCommandUsage('config-set-default-mode', undefined, accountId); | ||
|
||
let newDefault; | ||
let newDefault: CmsPublishMode; | ||
|
||
if (!defaultCmsPublishMode) { | ||
newDefault = await selectCmsPublishMode(); | ||
|
@@ -91,25 +102,24 @@ const setDefaultCmsPublishMode = async ({ | |
newDefault = defaultCmsPublishMode; | ||
} else { | ||
logger.error( | ||
i18n(`${i18nKey}.defaultMode.errors`, { | ||
mode: newDefault, | ||
i18n(`${i18nKey}.defaultMode.error`, { | ||
validModes: commaSeparatedValues(ALL_CMS_PUBLISH_MODES), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We were using the wrong lang key, and |
||
}) | ||
); | ||
newDefault = await selectCMsPublishMode(); | ||
newDefault = await selectCmsPublishMode(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We had a casing issue here that TS picked up 🎉 |
||
|
||
updateDefaultCmsPublishMode(newDefault); | ||
|
||
return logger.success( | ||
logger.success( | ||
i18n(`${i18nKey}.defaultMode.success`, { | ||
mode: newDefault, | ||
}) | ||
); | ||
}; | ||
} | ||
|
||
const enterTimeout = async () => { | ||
const { timeout } = await promptUser([ | ||
async function enterTimeout(): Promise<string> { | ||
const { timeout } = await promptUser<{ timeout: string }>([ | ||
{ | ||
name: 'timeout', | ||
message: i18n(`${i18nKey}.httpTimeout.promptMessage`), | ||
|
@@ -119,12 +129,18 @@ const enterTimeout = async () => { | |
]); | ||
|
||
return timeout; | ||
}; | ||
} | ||
|
||
const setHttpTimeout = async ({ accountId, httpTimeout }) => { | ||
trackCommandUsage('config-set-http-timeout', null, accountId); | ||
export async function setHttpTimeout({ | ||
accountId, | ||
httpTimeout, | ||
}: { | ||
accountId: number; | ||
httpTimeout?: string; | ||
}): Promise<void> { | ||
trackCommandUsage('config-set-http-timeout', undefined, accountId); | ||
|
||
let newHttpTimeout; | ||
let newHttpTimeout: string; | ||
|
||
if (!httpTimeout) { | ||
newHttpTimeout = await enterTimeout(); | ||
|
@@ -134,13 +150,7 @@ const setHttpTimeout = async ({ accountId, httpTimeout }) => { | |
|
||
updateHttpTimeout(newHttpTimeout); | ||
|
||
return logger.success( | ||
logger.success( | ||
i18n(`${i18nKey}.httpTimeout.success`, { timeout: newHttpTimeout }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no need for any of these to return |
||
); | ||
}; | ||
|
||
module.exports = { | ||
setAllowUsageTracking, | ||
setDefaultCmsPublishMode, | ||
setHttpTimeout, | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
look
does not exist as a supported field (search in repo)