@hubspot/cli 3.0.10 → 3.0.12-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.
package/bin/hubspot ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ require('./cli');
@@ -1,9 +1,4 @@
1
1
  const chalk = require('chalk');
2
- const fs = require('fs');
3
- const path = require('path');
4
- const archiver = require('archiver');
5
- const tmp = require('tmp');
6
- const Spinnies = require('spinnies');
7
2
  const {
8
3
  addAccountOptions,
9
4
  addConfigOptions,
@@ -11,84 +6,25 @@ const {
11
6
  addUseEnvironmentOptions,
12
7
  } = require('../../lib/commonOpts');
13
8
  const { trackCommandUsage } = require('../../lib/usageTracking');
14
- const {
15
- logApiErrorInstance,
16
- ApiErrorContext,
17
- } = require('@hubspot/cli-lib/errorHandlers');
18
9
  const { uiLine, uiAccountDescription } = require('../../lib/ui');
19
10
  const { logger } = require('@hubspot/cli-lib/logger');
20
- const { uploadProject } = require('@hubspot/cli-lib/api/dfs');
21
- const { shouldIgnoreFile } = require('@hubspot/cli-lib/ignoreRules');
22
11
  const { loadAndValidateOptions } = require('../../lib/validation');
23
12
  const {
13
+ ensureProjectExists,
24
14
  getProjectConfig,
25
- validateProjectConfig,
15
+ handleProjectUpload,
26
16
  pollBuildStatus,
27
- ensureProjectExists,
28
17
  pollDeployStatus,
18
+ validateProjectConfig,
29
19
  } = require('../../lib/projects');
30
20
  const { i18n } = require('@hubspot/cli-lib/lib/lang');
21
+ const { EXIT_CODES } = require('../../lib/enums/exitCodes');
31
22
 
32
23
  const i18nKey = 'cli.commands.project.subcommands.upload';
33
- const { EXIT_CODES } = require('../../lib/enums/exitCodes');
34
24
 
35
25
  exports.command = 'upload [path]';
36
26
  exports.describe = i18n(`${i18nKey}.describe`);
37
27
 
38
- const uploadProjectFiles = async (accountId, projectName, filePath) => {
39
- const spinnies = new Spinnies({
40
- succeedColor: 'white',
41
- });
42
- const accountIdentifier = uiAccountDescription(accountId);
43
-
44
- spinnies.add('upload', {
45
- text: i18n(`${i18nKey}.loading.upload.add`, {
46
- accountIdentifier,
47
- projectName,
48
- }),
49
- });
50
-
51
- let buildId;
52
-
53
- try {
54
- const upload = await uploadProject(accountId, projectName, filePath);
55
-
56
- buildId = upload.buildId;
57
-
58
- spinnies.succeed('upload', {
59
- text: i18n(`${i18nKey}.loading.upload.succeed`, {
60
- accountIdentifier,
61
- projectName,
62
- }),
63
- });
64
-
65
- logger.debug(
66
- i18n(`${i18nKey}.debug.buildCreated`, {
67
- buildId,
68
- projectName,
69
- })
70
- );
71
- } catch (err) {
72
- spinnies.fail('upload', {
73
- text: i18n(`${i18nKey}.loading.upload.fail`, {
74
- accountIdentifier,
75
- projectName,
76
- }),
77
- });
78
-
79
- logApiErrorInstance(
80
- err,
81
- new ApiErrorContext({
82
- accountId,
83
- projectName,
84
- })
85
- );
86
- process.exit(EXIT_CODES.ERROR);
87
- }
88
-
89
- return { buildId };
90
- };
91
-
92
28
  exports.handler = async options => {
93
29
  await loadAndValidateOptions(options);
94
30
 
@@ -103,30 +39,8 @@ exports.handler = async options => {
103
39
 
104
40
  await ensureProjectExists(accountId, projectConfig.name, forceCreate);
105
41
 
106
- const tempFile = tmp.fileSync({ postfix: '.zip' });
107
-
108
- logger.debug(
109
- i18n(`${i18nKey}.debug.compressing`, {
110
- path: tempFile.name,
111
- })
112
- );
113
-
114
- const output = fs.createWriteStream(tempFile.name);
115
- const archive = archiver('zip');
116
-
117
- output.on('close', async function() {
42
+ const startPolling = async (tempFile, buildId) => {
118
43
  let exitCode = EXIT_CODES.SUCCESS;
119
- logger.debug(
120
- i18n(`${i18nKey}.debug.compressed`, {
121
- byteCount: archive.pointer(),
122
- })
123
- );
124
-
125
- const { buildId } = await uploadProjectFiles(
126
- accountId,
127
- projectConfig.name,
128
- tempFile.name
129
- );
130
44
 
131
45
  const {
132
46
  isAutoDeployEnabled,
@@ -183,21 +97,9 @@ exports.handler = async options => {
183
97
  }
184
98
 
185
99
  process.exit(exitCode);
186
- });
187
-
188
- archive.on('error', function(err) {
189
- throw err;
190
- });
191
-
192
- archive.pipe(output);
193
-
194
- archive.directory(
195
- path.resolve(projectDir, projectConfig.srcDir),
196
- false,
197
- file => (shouldIgnoreFile(file.name) ? false : file)
198
- );
100
+ };
199
101
 
200
- archive.finalize();
102
+ await handleProjectUpload(accountId, projectConfig, projectDir, startPolling);
201
103
  };
202
104
 
203
105
  exports.builder = yargs => {
@@ -1,6 +1,5 @@
1
1
  const { i18n } = require('@hubspot/cli-lib/lib/lang');
2
2
  const { createWatcher } = require('@hubspot/cli-lib/projectsWatch');
3
- const { cancelStagedBuild } = require('@hubspot/cli-lib/api/dfs');
4
3
  const {
5
4
  logApiErrorInstance,
6
5
  ApiErrorContext,
@@ -14,11 +13,17 @@ const {
14
13
  } = require('../../lib/commonOpts');
15
14
  const { trackCommandUsage } = require('../../lib/usageTracking');
16
15
  const {
16
+ ensureProjectExists,
17
17
  getProjectConfig,
18
- validateProjectConfig,
18
+ handleProjectUpload,
19
19
  pollBuildStatus,
20
20
  pollDeployStatus,
21
+ validateProjectConfig,
21
22
  } = require('../../lib/projects');
23
+ const {
24
+ cancelStagedBuild,
25
+ fetchProjectBuilds,
26
+ } = require('@hubspot/cli-lib/api/dfs');
22
27
  const { loadAndValidateOptions } = require('../../lib/validation');
23
28
  const { EXIT_CODES } = require('../../lib/enums/exitCodes');
24
29
 
@@ -76,13 +81,35 @@ exports.handler = async options => {
76
81
 
77
82
  validateProjectConfig(projectConfig, projectDir);
78
83
 
79
- await createWatcher(
84
+ await ensureProjectExists(accountId, projectConfig.name);
85
+
86
+ const { results } = await fetchProjectBuilds(
80
87
  accountId,
81
- projectConfig,
82
- projectDir,
83
- handleBuildStatus,
84
- handleSigInt
88
+ projectConfig.name,
89
+ options
85
90
  );
91
+
92
+ const startWatching = async () => {
93
+ await createWatcher(
94
+ accountId,
95
+ projectConfig,
96
+ projectDir,
97
+ handleBuildStatus,
98
+ handleSigInt
99
+ );
100
+ };
101
+
102
+ // Upload all files if no build exists for this project yet
103
+ if (!results || !results.length) {
104
+ await handleProjectUpload(
105
+ accountId,
106
+ projectConfig,
107
+ projectDir,
108
+ startWatching
109
+ );
110
+ } else {
111
+ await startWatching();
112
+ }
86
113
  };
87
114
 
88
115
  exports.builder = yargs => {
package/lib/projects.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const fs = require('fs-extra');
2
2
  const path = require('path');
3
-
3
+ const archiver = require('archiver');
4
+ const tmp = require('tmp');
4
5
  const chalk = require('chalk');
5
6
  const findup = require('findup-sync');
6
7
  const Spinnies = require('spinnies');
@@ -22,15 +23,18 @@ const {
22
23
  getBuildStatus,
23
24
  getDeployStatus,
24
25
  fetchProject,
26
+ uploadProject,
25
27
  } = require('@hubspot/cli-lib/api/dfs');
26
28
  const {
27
29
  logApiErrorInstance,
28
30
  ApiErrorContext,
29
31
  } = require('@hubspot/cli-lib/errorHandlers');
32
+ const { shouldIgnoreFile } = require('@hubspot/cli-lib/ignoreRules');
30
33
  const { getCwd } = require('@hubspot/cli-lib/path');
31
34
  const { promptUser } = require('./prompts/promptUtils');
32
35
  const { EXIT_CODES } = require('./enums/exitCodes');
33
36
  const { uiLine, uiAccountDescription } = require('../lib/ui');
37
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
34
38
 
35
39
  const PROJECT_STRINGS = {
36
40
  BUILD: {
@@ -232,6 +236,108 @@ const getProjectDetailUrl = (projectName, accountId) => {
232
236
  return `${baseUrl}/developer-projects/${accountId}/project/${projectName}`;
233
237
  };
234
238
 
239
+ const uploadProjectFiles = async (accountId, projectName, filePath) => {
240
+ const i18nKey = 'cli.commands.project.subcommands.upload';
241
+ const spinnies = new Spinnies({
242
+ succeedColor: 'white',
243
+ });
244
+ const accountIdentifier = uiAccountDescription(accountId);
245
+
246
+ spinnies.add('upload', {
247
+ text: i18n(`${i18nKey}.loading.upload.add`, {
248
+ accountIdentifier,
249
+ projectName,
250
+ }),
251
+ });
252
+
253
+ let buildId;
254
+
255
+ try {
256
+ const upload = await uploadProject(accountId, projectName, filePath);
257
+
258
+ buildId = upload.buildId;
259
+
260
+ spinnies.succeed('upload', {
261
+ text: i18n(`${i18nKey}.loading.upload.succeed`, {
262
+ accountIdentifier,
263
+ projectName,
264
+ }),
265
+ });
266
+
267
+ logger.debug(
268
+ i18n(`${i18nKey}.debug.buildCreated`, {
269
+ buildId,
270
+ projectName,
271
+ })
272
+ );
273
+ } catch (err) {
274
+ spinnies.fail('upload', {
275
+ text: i18n(`${i18nKey}.loading.upload.fail`, {
276
+ accountIdentifier,
277
+ projectName,
278
+ }),
279
+ });
280
+
281
+ logApiErrorInstance(
282
+ err,
283
+ new ApiErrorContext({
284
+ accountId,
285
+ projectName,
286
+ })
287
+ );
288
+ process.exit(EXIT_CODES.ERROR);
289
+ }
290
+
291
+ return { buildId };
292
+ };
293
+
294
+ const handleProjectUpload = async (
295
+ accountId,
296
+ projectConfig,
297
+ projectDir,
298
+ callbackFunc
299
+ ) => {
300
+ const i18nKey = 'cli.commands.project.subcommands.upload';
301
+ const tempFile = tmp.fileSync({ postfix: '.zip' });
302
+
303
+ logger.debug(
304
+ i18n(`${i18nKey}.debug.compressing`, {
305
+ path: tempFile.name,
306
+ })
307
+ );
308
+
309
+ const output = fs.createWriteStream(tempFile.name);
310
+ const archive = archiver('zip');
311
+
312
+ output.on('close', async function() {
313
+ logger.debug(
314
+ i18n(`${i18nKey}.debug.compressed`, {
315
+ byteCount: archive.pointer(),
316
+ })
317
+ );
318
+
319
+ const { buildId } = await uploadProjectFiles(
320
+ accountId,
321
+ projectConfig.name,
322
+ tempFile.name
323
+ );
324
+
325
+ if (callbackFunc) {
326
+ callbackFunc(tempFile, buildId);
327
+ }
328
+ });
329
+
330
+ archive.pipe(output);
331
+
332
+ archive.directory(
333
+ path.resolve(projectDir, projectConfig.srcDir),
334
+ false,
335
+ file => (shouldIgnoreFile(file.name) ? false : file)
336
+ );
337
+
338
+ archive.finalize();
339
+ };
340
+
235
341
  const showWelcomeMessage = () => {
236
342
  logger.log('');
237
343
  logger.log(chalk.bold('Welcome to HubSpot Developer Projects!'));
@@ -392,6 +498,7 @@ module.exports = {
392
498
  writeProjectConfig,
393
499
  getProjectConfig,
394
500
  getIsInProject,
501
+ handleProjectUpload,
395
502
  createProjectConfig,
396
503
  validateProjectConfig,
397
504
  showWelcomeMessage,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cli",
3
- "version": "3.0.10",
3
+ "version": "3.0.12-beta.0",
4
4
  "description": "CLI for working with HubSpot",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -8,8 +8,8 @@
8
8
  "url": "https://github.com/HubSpot/hubspot-cms-tools"
9
9
  },
10
10
  "dependencies": {
11
- "@hubspot/cli-lib": "^3.0.10",
12
- "@hubspot/serverless-dev-runtime": "^3.0.10",
11
+ "@hubspot/cli-lib": "^3.0.12-beta.0",
12
+ "@hubspot/serverless-dev-runtime": "^3.0.12-beta.0",
13
13
  "archiver": "^5.3.0",
14
14
  "chalk": "^4.1.2",
15
15
  "express": "^4.17.1",
@@ -39,5 +39,5 @@
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  },
42
- "gitHead": "cad6c92bb51a24a7958c3c77c3e5ffc4e6418580"
42
+ "gitHead": "cb056da116cf2f64b7e2f7df69f44e5a19d03527"
43
43
  }