@bigcommerce/stencil-cli 4.0.0 → 5.0.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.
@@ -87,6 +87,7 @@ utils.uploadBundle = async (options) => {
87
87
  config: { accessToken },
88
88
  bundleZipPath,
89
89
  storeHash,
90
+ uploadBundleAgain,
90
91
  } = options;
91
92
 
92
93
  const apiHost = options.apiHost || options.config.apiHost;
@@ -97,6 +98,7 @@ utils.uploadBundle = async (options) => {
97
98
  apiHost,
98
99
  bundleZipPath,
99
100
  storeHash,
101
+ uploadBundleAgain,
100
102
  });
101
103
  return {
102
104
  ...options,
@@ -188,12 +190,54 @@ utils.deleteThemesIfNecessary = async (options) => {
188
190
  return options;
189
191
  };
190
192
 
193
+ utils.checkIfDeletionIsComplete = () => {
194
+ return async.retryable(
195
+ {
196
+ interval: 1000,
197
+ errorFilter: (err) => {
198
+ if (err.message === 'ThemeStillExists') {
199
+ console.log(`${'warning'.yellow} -- Theme still exists;Retrying ...`);
200
+ return true;
201
+ }
202
+ return false;
203
+ },
204
+ times: 5,
205
+ },
206
+ utils.checkIfThemeIsDeleted(),
207
+ );
208
+ };
209
+
210
+ utils.checkIfThemeIsDeleted = () => async (options) => {
211
+ const {
212
+ themeLimitReached,
213
+ config: { accessToken },
214
+ storeHash,
215
+ themeIdsToDelete,
216
+ } = options;
217
+
218
+ if (!themeLimitReached) {
219
+ return options;
220
+ }
221
+
222
+ const apiHost = options.apiHost || options.config.apiHost;
223
+
224
+ const result = await themeApiClient.getThemes({ accessToken, apiHost, storeHash });
225
+
226
+ const themeStillExists = result.some((theme) => themeIdsToDelete.includes(theme.uuid));
227
+
228
+ if (themeStillExists) {
229
+ throw new Error('ThemeStillExists');
230
+ }
231
+
232
+ return options;
233
+ };
234
+
191
235
  utils.uploadBundleAgainIfNecessary = async (options) => {
192
236
  if (!options.themeLimitReached) {
193
237
  return options;
194
238
  }
195
239
 
196
- return utils.uploadBundle(options);
240
+ return utils.uploadBundle({ ...options, uploadThemeAgain: true });
197
241
  };
198
242
 
199
243
  utils.notifyUserOfThemeUploadCompletion = async (options) => {
@@ -278,9 +278,10 @@ async function getVariationsByThemeId({ accessToken, apiHost, storeHash, themeId
278
278
  * @param {string} options.accessToken
279
279
  * @param {string} options.apiHost
280
280
  * @param {string} options.storeHash
281
+ * @param {boolean} options.uploadBundleAgain
281
282
  * @returns {Promise<object>}
282
283
  */
283
- async function postTheme({ bundleZipPath, accessToken, apiHost, storeHash }) {
284
+ async function postTheme({ bundleZipPath, accessToken, apiHost, storeHash, uploadBundleAgain }) {
284
285
  const formData = new FormData();
285
286
  formData.append('file', fs.createReadStream(bundleZipPath), {
286
287
  filename: path.basename(bundleZipPath),
@@ -303,7 +304,12 @@ async function postTheme({ bundleZipPath, accessToken, apiHost, storeHash }) {
303
304
  // This status code is overloaded, so we need to check the message to determine
304
305
  // if we want to trigger the theme deletion flow.
305
306
  const uploadLimitPattern = /You have reached your upload limit/;
306
- if (payload && payload.title && uploadLimitPattern.exec(payload.title)) {
307
+ if (
308
+ payload &&
309
+ payload.title &&
310
+ uploadLimitPattern.exec(payload.title) &&
311
+ !uploadBundleAgain
312
+ ) {
307
313
  return { themeLimitReached: true };
308
314
  }
309
315
 
@@ -7,6 +7,7 @@ const fsModule = require('fs');
7
7
  const axios = require('axios');
8
8
 
9
9
  const { PACKAGE_INFO } = require('../../constants');
10
+ const stencilCLISettings = require('../StencilCLISettings');
10
11
 
11
12
  const defaultHttpsAgent = new https.Agent({ rejectUnauthorized: false });
12
13
 
@@ -16,11 +17,13 @@ class NetworkUtils {
16
17
  httpsAgent = defaultHttpsAgent,
17
18
  reqLibrary = axios,
18
19
  packageInfo = PACKAGE_INFO,
20
+ logger = console,
19
21
  } = {}) {
20
22
  this._fs = fs;
21
23
  this._httpsAgent = httpsAgent;
22
24
  this._reqLibrary = reqLibrary;
23
25
  this._packageInfo = packageInfo;
26
+ this._logger = logger;
24
27
  }
25
28
 
26
29
  /** Used to send request to our (Bigcommerce) servers only.
@@ -50,6 +53,10 @@ class NetworkUtils {
50
53
  reqConfig.headers['x-auth-token'] = accessToken;
51
54
  }
52
55
 
56
+ if (stencilCLISettings.isVerbose()) {
57
+ this.log(reqConfig);
58
+ }
59
+
53
60
  return this._reqLibrary(reqConfig);
54
61
  }
55
62
 
@@ -71,6 +78,11 @@ class NetworkUtils {
71
78
  .on('error', reject);
72
79
  });
73
80
  }
81
+
82
+ log(config) {
83
+ const method = config.method || 'GET';
84
+ this._logger.info(`Upcoming request ${method.green}: ${config.url.green}`);
85
+ }
74
86
  }
75
87
 
76
88
  module.exports = NetworkUtils;