Skip to content
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

chore!: Rename Mode to CmsPublishMode #1269

Open
wants to merge 5 commits into
base: next
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions acceptance-tests/tests/commands/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ describe('hs config', () => {
});

describe('hs config set', () => {
it('should set the default mode to draft', async () => {
it('should set the default CMS publish mode to draft', async () => {
await testState.cli.executeWithTestConfig(
['config', 'set'],
[ENTER, DOWN, ENTER]
);

const parsedConfig = testState.getParsedConfig();

expect(parsedConfig.defaultMode).toEqual('draft');
expect(parsedConfig.defaultCmsPublishMode).toEqual('draft');
});
});
});
8 changes: 5 additions & 3 deletions commands/__tests__/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
addAccountOptions,
addConfigOptions,
addOverwriteOptions,
addModeOptions,
addCmsPublishModeOptions,
addUseEnvironmentOptions,
} from '../../lib/commonOpts';

Expand Down Expand Up @@ -66,8 +66,10 @@ describe('commands/fetch', () => {
expect(addOverwriteOptions).toHaveBeenCalledTimes(1);
expect(addOverwriteOptions).toHaveBeenCalledWith(yargs);

expect(addModeOptions).toHaveBeenCalledTimes(1);
expect(addModeOptions).toHaveBeenCalledWith(yargs, { read: true });
expect(addCmsPublishModeOptions).toHaveBeenCalledTimes(1);
expect(addCmsPublishModeOptions).toHaveBeenCalledWith(yargs, {
read: true,
});

expect(addUseEnvironmentOptions).toHaveBeenCalledTimes(1);
expect(addUseEnvironmentOptions).toHaveBeenCalledWith(yargs);
Expand Down
25 changes: 14 additions & 11 deletions commands/config/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { trackCommandUsage } = require('../../lib/usageTracking');
const { promptUser } = require('../../lib/prompts/promptUtils');
const { EXIT_CODES } = require('../../lib/enums/exitCodes');
const {
setDefaultMode,
setDefaultCmsPublishMode,
setHttpTimeout,
setAllowUsageTracking,
} = require('../../lib/configOptions');
Expand All @@ -16,29 +16,32 @@ exports.command = 'set';
exports.describe = i18n(`${i18nKey}.describe`);

const selectOptions = async () => {
const { mode } = await promptUser([
const { cmsPublishMode } = await promptUser([
{
type: 'list',
look: false,
name: 'mode',
name: 'cmsPublishMode',
pageSize: 20,
message: i18n(`${i18nKey}.promptMessage`),
choices: [
{ name: 'Default mode', value: { defaultMode: '' } },
{
name: 'Default CMS publish mode',
value: { defaultCmsPublishMode: '' },
},
{ name: 'Allow usage tracking', value: { allowUsageTracking: '' } },
{ name: 'HTTP timeout', value: { httpTimeout: '' } },
],
},
]);

return mode;
return cmsPublishMode;
};

const handleConfigUpdate = async (accountId, options) => {
const { allowUsageTracking, defaultMode, httpTimeout } = options;
const { allowUsageTracking, defaultCmsPublishMode, httpTimeout } = options;

if (typeof defaultMode !== 'undefined') {
await setDefaultMode({ defaultMode, accountId });
if (typeof defaultCmsPublishMode !== 'undefined') {
await setDefaultCmsPublishMode({ defaultCmsPublishMode, accountId });
return true;
} else if (typeof httpTimeout !== 'undefined') {
await setHttpTimeout({ httpTimeout, accountId });
Expand Down Expand Up @@ -72,7 +75,7 @@ exports.handler = async options => {
exports.builder = yargs => {
yargs
.options({
'default-mode': {
'default-cms-publish-mode': {
describe: i18n(`${i18nKey}.options.defaultMode.describe`),
type: 'string',
},
Expand All @@ -85,8 +88,8 @@ exports.builder = yargs => {
type: 'string',
},
})
.conflicts('defaultMode', 'allowUsageTracking')
.conflicts('defaultMode', 'httpTimeout')
.conflicts('defaultCmsPublishMode', 'allowUsageTracking')
.conflicts('defaultCmsPublishMode', 'httpTimeout')
.conflicts('allowUsageTracking', 'httpTimeout')
.example([['$0 config set', i18n(`${i18nKey}.examples.default`)]]);

Expand Down
19 changes: 11 additions & 8 deletions commands/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ const {
addConfigOptions,
addAccountOptions,
addOverwriteOptions,
addModeOptions,
addCmsPublishModeOptions,
addUseEnvironmentOptions,
getCmsPublishMode,
addGlobalOptions,
getMode,
} = require('../lib/commonOpts');
const { resolveLocalPath } = require('../lib/filesystem');
const { validateMode, loadAndValidateOptions } = require('../lib/validation');
const {
validateCmsPublishMode,
loadAndValidateOptions,
} = require('../lib/validation');
const { trackCommandUsage } = require('../lib/usageTracking');
const { i18n } = require('../lib/lang');

Expand All @@ -27,7 +30,7 @@ exports.handler = async options => {

await loadAndValidateOptions(options);

if (!validateMode(options)) {
if (!validateCmsPublishMode(options)) {
process.exit(EXIT_CODES.ERROR);
}

Expand All @@ -37,17 +40,17 @@ exports.handler = async options => {
}

const { derivedAccountId } = options;
const mode = getMode(options);
const cmsPublishMode = getCmsPublishMode(options);

trackCommandUsage('fetch', { mode }, derivedAccountId);
trackCommandUsage('fetch', { mode: cmsPublishMode }, accountId);

try {
// Fetch and write file/folder.
await downloadFileOrFolder(
derivedAccountId,
src,
resolveLocalPath(dest),
mode,
cmsPublishMode,
options
);
} catch (err) {
Expand Down Expand Up @@ -86,7 +89,7 @@ exports.builder = yargs => {
addConfigOptions(yargs);
addAccountOptions(yargs);
addOverwriteOptions(yargs);
addModeOptions(yargs, { read: true });
addCmsPublishModeOptions(yargs, { read: true });
addUseEnvironmentOptions(yargs);
addGlobalOptions(yargs);

Expand Down
21 changes: 12 additions & 9 deletions commands/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ const {
const {
addConfigOptions,
addAccountOptions,
addModeOptions,
addCmsPublishModeOptions,
addUseEnvironmentOptions,
addGlobalOptions,
getMode,
getCmsPublishMode,
} = require('../lib/commonOpts');
const { uploadPrompt } = require('../lib/prompts/uploadPrompt');
const { cleanUploadPrompt } = require('../lib/prompts/cleanUploadPrompt');
const { validateMode, loadAndValidateOptions } = require('../lib/validation');
const {
validateCmsPublishMode,
loadAndValidateOptions,
} = require('../lib/validation');
const { trackCommandUsage } = require('../lib/usageTracking');
const { getUploadableFileList } = require('../lib/upload');

Expand Down Expand Up @@ -66,12 +69,12 @@ const logThemePreview = (filePath, accountId) => {
exports.handler = async options => {
await loadAndValidateOptions(options);

if (!validateMode(options)) {
if (!validateCmsPublishMode(options)) {
process.exit(EXIT_CODES.WARNING);
}

const { derivedAccountId } = options;
const mode = getMode(options);
const cmsPublishMode = getCmsPublishMode(options);

const uploadPromptAnswers = await uploadPrompt(options);
const src = options.src || uploadPromptAnswers.src;
Expand Down Expand Up @@ -126,7 +129,7 @@ exports.handler = async options => {
const normalizedDest = convertToUnixPath(dest);
trackCommandUsage(
'upload',
{ mode, type: stats.isFile() ? 'file' : 'folder' },
{ mode: cmsPublishMode, type: stats.isFile() ? 'file' : 'folder' },
derivedAccountId
);
const srcDestIssues = await validateSrcAndDestPaths(
Expand Down Expand Up @@ -160,7 +163,7 @@ exports.handler = async options => {
derivedAccountId,
absoluteSrcPath,
normalizedDest,
getFileMapperQueryValues(mode, options)
getFileMapperQueryValues(cmsPublishMode, options)
)
.then(() => {
logger.success(
Expand Down Expand Up @@ -241,7 +244,7 @@ exports.handler = async options => {
absoluteSrcPath,
dest,
{
mode,
cmsPublishMode,
},
options,
filePaths
Expand Down Expand Up @@ -316,7 +319,7 @@ exports.builder = yargs => {

addConfigOptions(yargs);
addAccountOptions(yargs);
addModeOptions(yargs, { write: true });
addCmsPublishModeOptions(yargs, { write: true });
addUseEnvironmentOptions(yargs);
addGlobalOptions(yargs);

Expand Down
19 changes: 11 additions & 8 deletions commands/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ const { logger } = require('@hubspot/local-dev-lib/logger');
const {
addConfigOptions,
addAccountOptions,
addModeOptions,
addCmsPublishModeOptions,
addUseEnvironmentOptions,
addGlobalOptions,
getMode,
getCmsPublishMode,
} = require('../lib/commonOpts');
const { uploadPrompt } = require('../lib/prompts/uploadPrompt');
const { validateMode, loadAndValidateOptions } = require('../lib/validation');
const {
validateCmsPublishMode,
loadAndValidateOptions,
} = require('../lib/validation');
const { trackCommandUsage } = require('../lib/usageTracking');
const { i18n } = require('../lib/lang');
const { getUploadableFileList } = require('../lib/upload');
Expand All @@ -38,11 +41,11 @@ exports.handler = async options => {

await loadAndValidateOptions(options);

if (!validateMode(options)) {
if (!validateCmsPublishMode(options)) {
process.exit(EXIT_CODES.ERROR);
}

const mode = getMode(options);
const cmsPublishMode = getCmsPublishMode(options);

const uploadPromptAnswers = await uploadPrompt(options);

Expand Down Expand Up @@ -90,7 +93,7 @@ exports.handler = async options => {
);
}

trackCommandUsage('watch', { mode }, derivedAccountId);
trackCommandUsage('watch', { mode: cmsPublishMode }, derivedAccountId);

const postInitialUploadCallback = null;
const onUploadFolderError = error => {
Expand Down Expand Up @@ -128,7 +131,7 @@ exports.handler = async options => {
absoluteSrcPath,
dest,
{
mode,
cmsPublishMode,
remove,
disableInitial: initialUpload ? false : true,
notify,
Expand Down Expand Up @@ -191,7 +194,7 @@ exports.builder = yargs => {

addConfigOptions(yargs);
addAccountOptions(yargs);
addModeOptions(yargs, { write: true });
addCmsPublishModeOptions(yargs, { write: true });
addUseEnvironmentOptions(yargs);
addGlobalOptions(yargs);

Expand Down
2 changes: 1 addition & 1 deletion docs/HubspotConfigFile.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ description: Specifies the default portal(account) to use with the `hs` commands

default: Whatever the first accountId added to the config is

### defaultMode
### defaultCmsPublishMode

type: `draft` or `publish` or _Undefined_

Expand Down
Loading