@hubspot/cli 5.0.1 → 5.0.2-beta.0

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.
@@ -40,7 +40,8 @@ module.exports = {
40
40
  downloadSpinner.start();
41
41
  const samplesConfig = await fetchJsonFromRepository(
42
42
  'HubSpot/sample-apps-list',
43
- 'main/samples.json'
43
+ 'samples.json',
44
+ 'main'
44
45
  );
45
46
  downloadSpinner.stop();
46
47
  if (!samplesConfig) {
@@ -63,7 +64,7 @@ module.exports = {
63
64
  const created = await cloneGitHubRepo(
64
65
  filePath,
65
66
  assetType,
66
- sampleType,
67
+ `HubSpot/${sampleType}`,
67
68
  sampleLanguage,
68
69
  {
69
70
  ...options,
@@ -4,5 +4,11 @@ module.exports = {
4
4
  hidden: true,
5
5
  dest: ({ name, assetType }) => name || assetType,
6
6
  execute: async ({ options, dest, assetType }) =>
7
- cloneGitHubRepo(dest, assetType, 'crm-card-weather-app', '', options),
7
+ cloneGitHubRepo(
8
+ dest,
9
+ assetType,
10
+ 'HubSpot/crm-card-weather-app',
11
+ '',
12
+ options
13
+ ),
8
14
  };
@@ -3,5 +3,11 @@ const { cloneGitHubRepo } = require('@hubspot/cli-lib/github');
3
3
  module.exports = {
4
4
  dest: ({ name, assetType }) => name || assetType,
5
5
  execute: async ({ options, dest, assetType }) =>
6
- cloneGitHubRepo(dest, assetType, 'cms-react-boilerplate', '', options),
6
+ cloneGitHubRepo(
7
+ dest,
8
+ assetType,
9
+ 'HubSpot/cms-react-boilerplate',
10
+ '',
11
+ options
12
+ ),
7
13
  };
@@ -3,5 +3,11 @@ const { cloneGitHubRepo } = require('@hubspot/cli-lib/github');
3
3
  module.exports = {
4
4
  dest: ({ name, assetType }) => name || assetType,
5
5
  execute: async ({ options, dest, assetType }) =>
6
- cloneGitHubRepo(dest, assetType, 'cms-vue-boilerplate', '', options),
6
+ cloneGitHubRepo(
7
+ dest,
8
+ assetType,
9
+ 'HubSpot/cms-vue-boilerplate',
10
+ '',
11
+ options
12
+ ),
7
13
  };
@@ -6,7 +6,7 @@ module.exports = {
6
6
  cloneGitHubRepo(
7
7
  dest,
8
8
  assetType,
9
- 'cms-webpack-serverless-boilerplate',
9
+ 'HubSpot/cms-webpack-serverless-boilerplate',
10
10
  '',
11
11
  options
12
12
  ),
@@ -14,6 +14,12 @@ module.exports = {
14
14
  // releaseType has to be 'REPOSITORY' to download a specific branch
15
15
  options.releaseType = GITHUB_RELEASE_TYPES.REPOSITORY;
16
16
  }
17
- cloneGitHubRepo(dest, assetType, 'cms-theme-boilerplate', 'src', options);
17
+ cloneGitHubRepo(
18
+ dest,
19
+ assetType,
20
+ 'HubSpot/cms-theme-boilerplate',
21
+ 'src',
22
+ options
23
+ );
18
24
  },
19
25
  };
@@ -1,6 +1,7 @@
1
1
  const { logger } = require('@hubspot/cli-lib/logger');
2
2
  const { getAccountId } = require('@hubspot/cli-lib/lib/config');
3
3
  const { logErrorInstance } = require('@hubspot/cli-lib/errorHandlers');
4
+ const { fetchReleaseData } = require('@hubspot/cli-lib/github');
4
5
 
5
6
  const { trackCommandUsage } = require('../../lib/usageTracking');
6
7
  const { i18n } = require('../../lib/lang');
@@ -8,6 +9,9 @@ const { projectAddPrompt } = require('../../lib/prompts/projectAddPrompt');
8
9
  const { createProjectComponent } = require('../../lib/projects');
9
10
  const { loadAndValidateOptions } = require('../../lib/validation');
10
11
  const { uiBetaTag } = require('../../lib/ui');
12
+ const {
13
+ HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH,
14
+ } = require('../../lib/constants');
11
15
 
12
16
  const i18nKey = 'cli.commands.project.subcommands.add';
13
17
 
@@ -22,12 +26,25 @@ exports.handler = async options => {
22
26
  logger.log('');
23
27
  logger.log(i18n(`${i18nKey}.creatingComponent.message`));
24
28
  logger.log('');
25
- const { type, name } = await projectAddPrompt(options);
29
+
30
+ const releaseData = await fetchReleaseData(
31
+ HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH
32
+ );
33
+ const projectComponentsVersion = releaseData.tag_name;
34
+
35
+ const { type, name } = await projectAddPrompt(
36
+ projectComponentsVersion,
37
+ options
38
+ );
26
39
 
27
40
  trackCommandUsage('project-add', null, accountId);
28
41
 
29
42
  try {
30
- await createProjectComponent(options.type || type, options.name || name);
43
+ await createProjectComponent(
44
+ options.type || type,
45
+ options.name || name,
46
+ projectComponentsVersion
47
+ );
31
48
  logger.log('');
32
49
  logger.log(
33
50
  i18n(`${i18nKey}.success.message`, {
@@ -15,7 +15,11 @@ const {
15
15
  const { createProjectConfig } = require('../../lib/projects');
16
16
  const { i18n } = require('../../lib/lang');
17
17
  const { uiBetaTag, uiFeatureHighlight } = require('../../lib/ui');
18
+ const {
19
+ HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH,
20
+ } = require('../../lib/constants');
18
21
  const { logger } = require('@hubspot/cli-lib/logger');
22
+ const { fetchReleaseData } = require('@hubspot/cli-lib/github');
19
23
 
20
24
  const i18nKey = 'cli.commands.project.subcommands.create';
21
25
 
@@ -27,7 +31,21 @@ exports.handler = async options => {
27
31
 
28
32
  const accountId = getAccountId(options);
29
33
 
30
- const { name, template, location } = await createProjectPrompt(options);
34
+ const hasCustomTemplateSource = Boolean(options.templateSource);
35
+
36
+ let githubRef = '';
37
+
38
+ if (!hasCustomTemplateSource) {
39
+ const releaseData = await fetchReleaseData(
40
+ HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH
41
+ );
42
+ githubRef = releaseData.tag_name;
43
+ }
44
+
45
+ const { name, template, location } = await createProjectPrompt(
46
+ githubRef,
47
+ options
48
+ );
31
49
 
32
50
  trackCommandUsage(
33
51
  'project-create',
@@ -39,7 +57,8 @@ exports.handler = async options => {
39
57
  path.resolve(getCwd(), options.location || location),
40
58
  options.name || name,
41
59
  template || { path: options.template },
42
- options.templateSource
60
+ options.templateSource,
61
+ githubRef
43
62
  );
44
63
 
45
64
  logger.log('');
@@ -0,0 +1,8 @@
1
+ const HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH =
2
+ 'HubSpot/hubspot-project-components';
3
+ const DEFAULT_PROJECT_TEMPLATE_BRANCH = 'main';
4
+
5
+ module.exports = {
6
+ HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH,
7
+ DEFAULT_PROJECT_TEMPLATE_BRANCH,
8
+ };
@@ -19,8 +19,11 @@ const isHelperIdentifier = identifier => {
19
19
 
20
20
  const generateReplaceFn = (matchedText, startIndex, replacementString) => {
21
21
  return currentStringValue =>
22
- `${currentStringValue.slice(0, startIndex)}${replacementString ||
23
- ''}${currentStringValue.slice(startIndex + matchedText.length)}`;
22
+ `${currentStringValue.slice(0, startIndex)}${
23
+ replacementString !== null && replacementString !== undefined
24
+ ? replacementString
25
+ : ''
26
+ }${currentStringValue.slice(startIndex + matchedText.length)}`;
24
27
  };
25
28
 
26
29
  /**
package/lib/projects.js CHANGED
@@ -45,6 +45,7 @@ const {
45
45
  isSpecifiedError,
46
46
  isSpecifiedHubSpotAuthError,
47
47
  } = require('@hubspot/cli-lib/errorHandlers/apiErrors');
48
+ const { HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH } = require('./constants');
48
49
 
49
50
  const i18nKey = 'cli.lib.projects';
50
51
 
@@ -96,7 +97,8 @@ const createProjectConfig = async (
96
97
  projectPath,
97
98
  projectName,
98
99
  template,
99
- templateSource
100
+ templateSource,
101
+ githubRef
100
102
  ) => {
101
103
  const { projectConfig, projectDir } = await getProjectConfig(projectPath);
102
104
 
@@ -133,7 +135,14 @@ const createProjectConfig = async (
133
135
  }`
134
136
  );
135
137
 
136
- await downloadGitHubRepoContents(templateSource, template.path, projectPath);
138
+ const hasCustomTemplateSource = Boolean(templateSource);
139
+
140
+ await downloadGitHubRepoContents(
141
+ templateSource || HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH,
142
+ template.path,
143
+ projectPath,
144
+ hasCustomTemplateSource ? {} : { ref: githubRef }
145
+ );
137
146
  const _config = JSON.parse(fs.readFileSync(projectConfigPath));
138
147
  writeProjectConfig(projectConfigPath, {
139
148
  ..._config,
@@ -796,7 +805,11 @@ const logFeedbackMessage = buildId => {
796
805
  }
797
806
  };
798
807
 
799
- const createProjectComponent = async (component, name) => {
808
+ const createProjectComponent = async (
809
+ component,
810
+ name,
811
+ projectComponentsVersion
812
+ ) => {
800
813
  const i18nKey = 'cli.commands.project.subcommands.add';
801
814
  let componentName = name;
802
815
 
@@ -815,9 +828,12 @@ const createProjectComponent = async (component, name) => {
815
828
  );
816
829
 
817
830
  await downloadGitHubRepoContents(
818
- 'HubSpot/hubspot-project-components',
831
+ HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH,
819
832
  component.path,
820
- componentPath
833
+ componentPath,
834
+ {
835
+ ref: projectComponentsVersion,
836
+ }
821
837
  );
822
838
  };
823
839
 
@@ -9,6 +9,10 @@ const { fetchJsonFromRepository } = require('@hubspot/cli-lib/github');
9
9
  const { i18n } = require('../lang');
10
10
  const { logger } = require('@hubspot/cli-lib/logger');
11
11
  const { EXIT_CODES } = require('../../lib/enums/exitCodes');
12
+ const {
13
+ HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH,
14
+ DEFAULT_PROJECT_TEMPLATE_BRANCH,
15
+ } = require('../constants');
12
16
 
13
17
  const i18nKey = 'cli.lib.prompts.createProjectPrompt';
14
18
 
@@ -20,12 +24,17 @@ const hasAllProperties = projectList => {
20
24
  );
21
25
  };
22
26
 
23
- const createTemplateOptions = async templateSource => {
24
- const isTemplateSource = !!templateSource;
27
+ const createTemplateOptions = async (templateSource, githubRef) => {
28
+ const hasCustomTemplateSource = Boolean(templateSource);
29
+ let branch = hasCustomTemplateSource
30
+ ? DEFAULT_PROJECT_TEMPLATE_BRANCH
31
+ : githubRef;
32
+
25
33
  const config = await fetchJsonFromRepository(
26
- templateSource,
27
- 'main/config.json',
28
- isTemplateSource
34
+ templateSource || HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH,
35
+ 'config.json',
36
+ branch,
37
+ hasCustomTemplateSource
29
38
  );
30
39
 
31
40
  if (!config || !config[PROJECT_COMPONENT_TYPES.PROJECTS]) {
@@ -41,9 +50,10 @@ const createTemplateOptions = async templateSource => {
41
50
  return config[PROJECT_COMPONENT_TYPES.PROJECTS];
42
51
  };
43
52
 
44
- const createProjectPrompt = async (promptOptions = {}) => {
53
+ const createProjectPrompt = async (githubRef, promptOptions = {}) => {
45
54
  const projectTemplates = await createTemplateOptions(
46
- promptOptions.templateSource
55
+ promptOptions.templateSource,
56
+ githubRef
47
57
  );
48
58
 
49
59
  return promptUser([
@@ -1,21 +1,26 @@
1
1
  const { promptUser } = require('./promptUtils');
2
2
  const { fetchJsonFromRepository } = require('@hubspot/cli-lib/github');
3
3
  const { i18n } = require('../lang');
4
+ const { HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH } = require('../constants');
4
5
  const { PROJECT_COMPONENT_TYPES } = require('@hubspot/cli-lib/lib/constants');
5
6
 
6
7
  const i18nKey = 'cli.lib.prompts.projectAddPrompt';
7
8
 
8
- const createTypeOptions = async () => {
9
+ const createTypeOptions = async projectComponentsVersion => {
9
10
  const config = await fetchJsonFromRepository(
10
- 'HubSpot/hubspot-project-components',
11
- 'main/config.json'
11
+ HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH,
12
+ 'config.json',
13
+ projectComponentsVersion
12
14
  );
13
15
 
14
16
  return config[PROJECT_COMPONENT_TYPES.COMPONENTS];
15
17
  };
16
18
 
17
- const projectAddPrompt = async (promptOptions = {}) => {
18
- const components = await createTypeOptions();
19
+ const projectAddPrompt = async (
20
+ projectComponentsVersion,
21
+ promptOptions = {}
22
+ ) => {
23
+ const components = await createTypeOptions(projectComponentsVersion);
19
24
  return promptUser([
20
25
  {
21
26
  name: 'type',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cli",
3
- "version": "5.0.1",
3
+ "version": "5.0.2-beta.0",
4
4
  "description": "CLI for working with HubSpot",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -8,7 +8,7 @@
8
8
  "url": "https://github.com/HubSpot/hubspot-cms-tools"
9
9
  },
10
10
  "dependencies": {
11
- "@hubspot/cli-lib": "^4.2.2",
11
+ "@hubspot/cli-lib": "^5.0.1",
12
12
  "@hubspot/serverless-dev-runtime": "4.2.1-beta.3",
13
13
  "@hubspot/ui-extensions-dev-server": "^0.7.2",
14
14
  "archiver": "^5.3.0",
@@ -42,5 +42,5 @@
42
42
  "publishConfig": {
43
43
  "access": "public"
44
44
  },
45
- "gitHead": "0f88273233124d513c4338fed7bd01fa4678251d"
45
+ "gitHead": "539e279526f9554f840b857bf4873a3b856684a3"
46
46
  }