@hubspot/cli 4.1.8-beta.1 → 4.1.8-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/README.md +2 -2
  2. package/bin/cli.js +1 -1
  3. package/commands/accounts/info.js +1 -1
  4. package/commands/accounts/list.js +1 -1
  5. package/commands/accounts/remove.js +1 -1
  6. package/commands/accounts/rename.js +1 -1
  7. package/commands/accounts/use.js +1 -1
  8. package/commands/accounts.js +1 -1
  9. package/commands/auth.js +1 -1
  10. package/commands/cms/convertFields.js +1 -1
  11. package/commands/cms/lighthouseScore.js +1 -1
  12. package/commands/cms.js +1 -1
  13. package/commands/config/set/allowUsageTracking.js +1 -1
  14. package/commands/config/set/defaultMode.js +1 -1
  15. package/commands/config/set/httpTimeout.js +1 -1
  16. package/commands/config/set.js +1 -1
  17. package/commands/config.js +1 -1
  18. package/commands/create/api-sample.js +2 -2
  19. package/commands/create/module.js +1 -1
  20. package/commands/create/template.js +1 -1
  21. package/commands/create.js +1 -1
  22. package/commands/customObject/create.js +1 -1
  23. package/commands/customObject/schema/create.js +1 -1
  24. package/commands/customObject/schema/delete.js +1 -1
  25. package/commands/customObject/schema/fetch-all.js +1 -1
  26. package/commands/customObject/schema/fetch.js +1 -1
  27. package/commands/customObject/schema/list.js +1 -1
  28. package/commands/customObject/schema/update.js +1 -1
  29. package/commands/customObject/schema.js +1 -1
  30. package/commands/customObject.js +1 -1
  31. package/commands/feedback.js +1 -1
  32. package/commands/fetch.js +1 -1
  33. package/commands/filemanager/fetch.js +1 -1
  34. package/commands/filemanager/upload.js +1 -1
  35. package/commands/filemanager.js +1 -1
  36. package/commands/functions/deploy.js +1 -1
  37. package/commands/functions/list.js +1 -1
  38. package/commands/functions/server.js +1 -1
  39. package/commands/functions.js +1 -1
  40. package/commands/hubdb/clear.js +1 -1
  41. package/commands/hubdb/create.js +1 -1
  42. package/commands/hubdb/delete.js +1 -1
  43. package/commands/hubdb/fetch.js +1 -1
  44. package/commands/hubdb.js +1 -1
  45. package/commands/init.js +1 -1
  46. package/commands/lint.js +1 -1
  47. package/commands/list.js +1 -1
  48. package/commands/logs.js +1 -1
  49. package/commands/module/marketplace-validate.js +1 -1
  50. package/commands/module.js +1 -1
  51. package/commands/mv.js +1 -1
  52. package/commands/open.js +1 -1
  53. package/commands/project/add.js +56 -0
  54. package/commands/project/create.js +7 -4
  55. package/commands/project/deploy.js +33 -19
  56. package/commands/project/dev.js +300 -0
  57. package/commands/project/download.js +28 -17
  58. package/commands/project/logs.js +1 -1
  59. package/commands/project/open.js +1 -1
  60. package/commands/project/upload.js +28 -76
  61. package/commands/project/watch.js +1 -1
  62. package/commands/project.js +4 -0
  63. package/commands/remove.js +1 -1
  64. package/commands/sandbox/create.js +159 -10
  65. package/commands/sandbox/delete.js +6 -7
  66. package/commands/sandbox/sync.js +15 -1
  67. package/commands/secrets/addSecret.js +1 -1
  68. package/commands/secrets/deleteSecret.js +1 -1
  69. package/commands/secrets/listSecrets.js +1 -1
  70. package/commands/secrets/updateSecret.js +1 -1
  71. package/commands/secrets.js +1 -1
  72. package/commands/theme/marketplace-validate.js +1 -1
  73. package/commands/theme.js +1 -1
  74. package/commands/upload.js +1 -1
  75. package/commands/watch.js +1 -1
  76. package/lang/en.lyaml +1202 -0
  77. package/lib/LocalDevManager.js +533 -0
  78. package/lib/SpinniesManager.js +96 -0
  79. package/lib/commonOpts.js +1 -1
  80. package/lib/interpolation.js +137 -0
  81. package/lib/interpolationHelpers.js +23 -0
  82. package/lib/lang.js +95 -0
  83. package/lib/marketplace-validate.js +1 -1
  84. package/lib/projects.js +315 -127
  85. package/lib/prompts/accountsPrompt.js +3 -7
  86. package/lib/prompts/buildIdPrompt.js +35 -0
  87. package/lib/prompts/cmsFieldPrompt.js +1 -1
  88. package/lib/prompts/createApiSamplePrompt.js +1 -1
  89. package/lib/prompts/createFunctionPrompt.js +1 -1
  90. package/lib/prompts/createModulePrompt.js +1 -1
  91. package/lib/prompts/createProjectPrompt.js +44 -7
  92. package/lib/prompts/createTemplatePrompt.js +1 -1
  93. package/lib/prompts/downloadProjectPrompt.js +44 -0
  94. package/lib/prompts/enterAccountNamePrompt.js +1 -1
  95. package/lib/prompts/feedbackPrompt.js +1 -1
  96. package/lib/prompts/folderOverwritePrompt.js +1 -1
  97. package/lib/prompts/personalAccessKeyPrompt.js +1 -1
  98. package/lib/prompts/projectAddPrompt.js +57 -0
  99. package/lib/prompts/projectDevTargetAccountPrompt.js +105 -0
  100. package/lib/prompts/projectNamePrompt.js +1 -1
  101. package/lib/prompts/projectsLogsPrompt.js +1 -1
  102. package/lib/prompts/promptUtils.js +13 -0
  103. package/lib/prompts/sandboxesPrompt.js +13 -5
  104. package/lib/prompts/secretPrompt.js +1 -1
  105. package/lib/prompts/setAsDefaultAccountPrompt.js +1 -1
  106. package/lib/prompts/uploadPrompt.js +1 -1
  107. package/lib/sandbox-create.js +22 -160
  108. package/lib/sandbox-sync.js +89 -64
  109. package/lib/sandboxes.js +162 -15
  110. package/lib/ui.js +20 -8
  111. package/package.json +7 -4
@@ -0,0 +1,137 @@
1
+ const helpers = require('./interpolationHelpers');
2
+ const delimiters = {
3
+ interpolation: {
4
+ start: '{{',
5
+ end: '}}',
6
+ },
7
+ helpers: {
8
+ start: '#',
9
+ end: '/',
10
+ },
11
+ };
12
+
13
+ const isHelperIdentifier = identifier => {
14
+ return (
15
+ identifier.startsWith(delimiters.helpers.start) ||
16
+ identifier.startsWith(delimiters.helpers.end)
17
+ );
18
+ };
19
+
20
+ const generateReplaceFn = (matchedText, startIndex, replacementString) => {
21
+ return currentStringValue =>
22
+ `${currentStringValue.slice(0, startIndex)}${replacementString ||
23
+ ''}${currentStringValue.slice(startIndex + matchedText.length)}`;
24
+ };
25
+
26
+ /**
27
+ * Interpolate a string with data
28
+ * @param {string} stringValue - The string to interpolate
29
+ * @param {object} interpolationData - The data to interpolate with
30
+ * @returns {string} - The interpolated string
31
+ * @example
32
+ * interpolation('Hello {{name}}', { name: 'World' })
33
+ * // 'Hello World'
34
+ */
35
+ const interpolation = (stringValue, interpolationData) => {
36
+ const interpolationIdentifierRegEx = new RegExp(
37
+ `${delimiters.interpolation.start}(.*?)${delimiters.interpolation.end}`,
38
+ 'g'
39
+ );
40
+ const replaceQueue = [];
41
+ let match;
42
+
43
+ // while & reduce necessary because RegExp.exec is stateful and only runs
44
+ // from beginning to end of string
45
+ while ((match = interpolationIdentifierRegEx.exec(stringValue)) != null) {
46
+ const { 0: matchedText, 1: rawIdentifier, index } = match;
47
+ const identifier = rawIdentifier.trim();
48
+
49
+ if (identifier && !isHelperIdentifier(identifier)) {
50
+ replaceQueue.unshift(
51
+ generateReplaceFn(matchedText, index, interpolationData[identifier])
52
+ );
53
+ }
54
+ }
55
+
56
+ const compiledString = replaceQueue.reduce(
57
+ (currentValue, replaceFn) => replaceFn(currentValue),
58
+ stringValue
59
+ );
60
+
61
+ return compiledString;
62
+ };
63
+
64
+ /**
65
+ * Compile a string using a specified helper function
66
+ * @param {string} stringValue - The string to modify
67
+ * @param {object} helperIdentifier - Helper name
68
+ * @param {function} helperFn - Helper function to call on string
69
+ * @returns {string} - The modified string
70
+ * @example
71
+ * compileHelper('White {{#yellow}}yellow{{/yellow}}', 'yellow', (string) => { chalk.reset.yellow(string) }))))
72
+ * // 'White yellow' (with 'yellow' colored yellow)
73
+ */
74
+ const compileHelper = (stringValue, helperIdentifier, helperFn) => {
75
+ const helperIdentifierRegEx = new RegExp(
76
+ `${delimiters.interpolation.start}(${delimiters.helpers.start}${helperIdentifier})${delimiters.interpolation.end}(.*?)${delimiters.interpolation.start}(${delimiters.helpers.end}${helperIdentifier})${delimiters.interpolation.end}`,
77
+ 'g'
78
+ );
79
+ const replaceQueue = [];
80
+ let match;
81
+
82
+ // while & reduce necessary because RegExp.exec is stateful and only runs
83
+ // from beginning to end of string
84
+ while ((match = helperIdentifierRegEx.exec(stringValue)) != null) {
85
+ const {
86
+ 0: matchedText,
87
+ 1: rawHelperIdentifierStart,
88
+ 2: innerText,
89
+ index,
90
+ } = match;
91
+ const identifier = rawHelperIdentifierStart
92
+ .replace(delimiters.helpers.start, '')
93
+ .trim();
94
+
95
+ if (identifier && helperFn) {
96
+ replaceQueue.unshift(
97
+ generateReplaceFn(matchedText, index, helperFn(innerText))
98
+ );
99
+ }
100
+ }
101
+
102
+ const compiledString = replaceQueue.reduce(
103
+ (currentValue, replaceFn) => replaceFn(currentValue),
104
+ stringValue
105
+ );
106
+
107
+ return compiledString;
108
+ };
109
+
110
+ const compileHelpers = stringValue => {
111
+ return Object.keys(helpers).reduce((currentStringValue, helperIdentifier) => {
112
+ return compileHelper(
113
+ currentStringValue,
114
+ helperIdentifier,
115
+ helpers[helperIdentifier]
116
+ );
117
+ }, stringValue);
118
+ };
119
+
120
+ /**
121
+ * Interpolate a string with data and compile helpers on the string
122
+ * @param {string} stringValue - The string to interpolate
123
+ * @param {object} interpolationData - The data to interpolate with
124
+ * @returns {string} - The interpolated and helper-compiled string
125
+ * @example
126
+ * interpolateAndCompile('Some {{#bold}}{{text}}{{/bold}} text', { text: 'awesomely bold' })
127
+ * // 'Some awsomely bold text' (with the words 'awesomely bold' in bold)
128
+ */
129
+ const interpolate = (stringValue, interpolationData) => {
130
+ const interpolatedString = interpolation(stringValue, interpolationData);
131
+ const helperCompiledString = compileHelpers(interpolatedString);
132
+ return helperCompiledString;
133
+ };
134
+
135
+ module.exports = {
136
+ interpolate,
137
+ };
@@ -0,0 +1,23 @@
1
+ const chalk = require('chalk');
2
+
3
+ /**
4
+ * These helper methods are used to modify text output within the CLI. They
5
+ * should all take in a string value and output a modified string value.
6
+ */
7
+ module.exports = {
8
+ bold: function(stringValue) {
9
+ return chalk.bold(stringValue);
10
+ },
11
+ yellow: function(stringValue) {
12
+ return chalk.reset.yellow(stringValue);
13
+ },
14
+ green: function(stringValue) {
15
+ return chalk.reset.green(stringValue);
16
+ },
17
+ red: function(stringValue) {
18
+ return chalk.reset.red(stringValue);
19
+ },
20
+ cyan: function(stringValue) {
21
+ return chalk.cyan(stringValue);
22
+ },
23
+ };
package/lib/lang.js ADDED
@@ -0,0 +1,95 @@
1
+ const util = require('util');
2
+ const path = require('path');
3
+ const fs = require('fs-extra');
4
+ const yaml = require('js-yaml');
5
+ const { logger } = require('@hubspot/cli-lib/logger');
6
+ const { interpolate } = require('./interpolation');
7
+
8
+ const MISSING_LANGUAGE_DATA_PREFIX = '[Missing language data]';
9
+
10
+ let locale;
11
+ let languageObj;
12
+
13
+ const loadLanguageFromYaml = () => {
14
+ if (languageObj) return;
15
+
16
+ try {
17
+ const nodeLocale = Intl.DateTimeFormat()
18
+ .resolvedOptions()
19
+ .locale.split('-')[0];
20
+ const languageFilePath = path.join(
21
+ __dirname,
22
+ `../lang/${nodeLocale}.lyaml`
23
+ );
24
+ const languageFileExists = fs.existsSync(languageFilePath);
25
+
26
+ // Fall back to using the default language file
27
+ locale = languageFileExists ? nodeLocale : 'en';
28
+ languageObj = yaml.load(
29
+ fs.readFileSync(path.join(__dirname, `../lang/${locale}.lyaml`), 'utf8')
30
+ );
31
+
32
+ logger.debug(
33
+ 'Loaded language data: ',
34
+ util.inspect(languageObj, true, 999, true)
35
+ );
36
+ } catch (e) {
37
+ logger.error('Error loading language data: ', e);
38
+ }
39
+ };
40
+
41
+ const getTextValue = lookupDotNotation => {
42
+ const lookupProps = [locale, ...lookupDotNotation.split('.')];
43
+ const missingTextData = `${MISSING_LANGUAGE_DATA_PREFIX}: ${lookupProps.join(
44
+ '.'
45
+ )}`;
46
+ let textValue = languageObj;
47
+ let previouslyCheckedProp = lookupProps[0];
48
+
49
+ try {
50
+ lookupProps.forEach(prop => {
51
+ textValue = textValue[prop];
52
+ previouslyCheckedProp = prop;
53
+ });
54
+ } catch (e) {
55
+ logger.error(
56
+ `Unable to access language property: ${lookupProps.join(
57
+ '.'
58
+ )}. Failed to access prop "${previouslyCheckedProp}".`
59
+ );
60
+ return missingTextData;
61
+ }
62
+
63
+ if (!textValue) {
64
+ return missingTextData;
65
+ }
66
+
67
+ return textValue;
68
+ };
69
+
70
+ const i18n = (lookupDotNotation, options = {}) => {
71
+ if (!languageObj) {
72
+ loadLanguageFromYaml();
73
+ }
74
+
75
+ if (typeof lookupDotNotation !== 'string') {
76
+ throw new Error(
77
+ `i18n must be passed a string value for lookupDotNotation, received ${typeof lookupDotNotation}`
78
+ );
79
+ }
80
+
81
+ const textValue = getTextValue(lookupDotNotation);
82
+ const shouldInterpolate = !textValue.startsWith(MISSING_LANGUAGE_DATA_PREFIX);
83
+
84
+ return shouldInterpolate ? interpolate(textValue, options) : textValue;
85
+ };
86
+
87
+ const setLangData = (newLocale, newLangObj) => {
88
+ locale = newLocale;
89
+ languageObj = newLangObj;
90
+ };
91
+
92
+ module.exports = {
93
+ i18n,
94
+ setLangData,
95
+ };
@@ -6,7 +6,7 @@ const {
6
6
  getValidationStatus,
7
7
  getValidationResults,
8
8
  } = require('@hubspot/cli-lib/api/marketplaceValidation');
9
- const { i18n } = require('@hubspot/cli-lib/lib/lang');
9
+ const { i18n } = require('./lang');
10
10
  const { EXIT_CODES } = require('./enums/exitCodes');
11
11
 
12
12
  const SLEEP_TIME = 2000;