@bigcommerce/stencil-cli 8.10.0 → 8.10.2
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/lib/stencil-start.js
CHANGED
|
@@ -58,35 +58,38 @@ class StencilStart {
|
|
|
58
58
|
const initialStencilConfig = await this._stencilConfigManager.read();
|
|
59
59
|
// Use initial (before updates) port for BrowserSync
|
|
60
60
|
const browserSyncPort = cliOptions.port || initialStencilConfig.port;
|
|
61
|
-
const
|
|
61
|
+
const channelInfo = await this.getChannelInfo(initialStencilConfig, cliOptions);
|
|
62
62
|
const storeInfoFromAPI = await this._themeApiClient.checkCliVersion({
|
|
63
|
-
storeUrl:
|
|
63
|
+
storeUrl: channelInfo.url,
|
|
64
64
|
});
|
|
65
65
|
const updatedStencilConfig = this.updateStencilConfig(
|
|
66
66
|
initialStencilConfig,
|
|
67
67
|
storeInfoFromAPI,
|
|
68
68
|
browserSyncPort,
|
|
69
69
|
);
|
|
70
|
+
|
|
70
71
|
this._storeSettingsLocale = await this.getStoreSettingsLocale(
|
|
71
72
|
cliOptions,
|
|
72
73
|
updatedStencilConfig,
|
|
74
|
+
channelInfo.channel_id,
|
|
73
75
|
);
|
|
74
76
|
await this.startLocalServer(cliOptions, updatedStencilConfig);
|
|
75
77
|
this._logger.log(this.getStartUpInfo(updatedStencilConfig));
|
|
76
78
|
await this.startBrowserSync(cliOptions, browserSyncPort);
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
async getStoreSettingsLocale(cliOptions, stencilConfig) {
|
|
81
|
+
async getStoreSettingsLocale(cliOptions, stencilConfig, channelId) {
|
|
80
82
|
const { accessToken } = stencilConfig;
|
|
81
83
|
const apiHost = cliOptions.apiHost || stencilConfig.apiHost;
|
|
82
84
|
return this._storeSettingsApiClient.getStoreSettingsLocale({
|
|
83
85
|
storeHash: this.storeHash,
|
|
84
86
|
accessToken,
|
|
85
87
|
apiHost,
|
|
88
|
+
channelId,
|
|
86
89
|
});
|
|
87
90
|
}
|
|
88
91
|
|
|
89
|
-
async
|
|
92
|
+
async getChannelInfo(stencilConfig, cliOptions) {
|
|
90
93
|
const { accessToken } = stencilConfig;
|
|
91
94
|
const apiHost = cliOptions.apiHost || stencilConfig.apiHost;
|
|
92
95
|
this.storeHash = await this._themeApiClient.getStoreHash({
|
|
@@ -106,7 +109,7 @@ class StencilStart {
|
|
|
106
109
|
const foundChannel = channels.find(
|
|
107
110
|
(channel) => channel.channel_id === parseInt(channelId, 10),
|
|
108
111
|
);
|
|
109
|
-
return foundChannel
|
|
112
|
+
return foundChannel || null;
|
|
110
113
|
}
|
|
111
114
|
|
|
112
115
|
/**
|
|
@@ -2,29 +2,50 @@ import 'colors';
|
|
|
2
2
|
import NetworkUtils from './utils/NetworkUtils.js';
|
|
3
3
|
|
|
4
4
|
const networkUtils = new NetworkUtils();
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
async function getStoreSettingsLocaleWithChannel({ apiHost, storeHash, accessToken, channelId }) {
|
|
7
|
+
let url = `${apiHost}/stores/${storeHash}/v3/settings/store/locale`;
|
|
8
|
+
if (channelId) {
|
|
9
|
+
url += `?channel_id=${channelId}`;
|
|
10
|
+
}
|
|
11
|
+
const response = await networkUtils.sendApiRequest({
|
|
12
|
+
url,
|
|
13
|
+
accessToken,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
return response.data.data;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function getStoreSettingsLocale({ apiHost, storeHash, accessToken, channelId }) {
|
|
6
20
|
try {
|
|
7
|
-
|
|
8
|
-
|
|
21
|
+
let data = await getStoreSettingsLocaleWithChannel({
|
|
22
|
+
apiHost,
|
|
23
|
+
storeHash,
|
|
9
24
|
accessToken,
|
|
25
|
+
channelId,
|
|
10
26
|
});
|
|
11
|
-
if
|
|
27
|
+
// if no data available for the channel provided, default to global setting.
|
|
28
|
+
if (!data) {
|
|
29
|
+
data = await getStoreSettingsLocaleWithChannel({ apiHost, storeHash, accessToken });
|
|
30
|
+
}
|
|
31
|
+
if (!data) {
|
|
12
32
|
throw new Error('Received empty store locale in the server response'.red);
|
|
13
|
-
} else if (!
|
|
33
|
+
} else if (!data.default_shopper_language) {
|
|
14
34
|
throw new Error(
|
|
15
35
|
'Received empty default_shopper_language field in the server response'.red,
|
|
16
36
|
);
|
|
17
|
-
} else if (!
|
|
37
|
+
} else if (!data.shopper_language_selection_method) {
|
|
18
38
|
throw new Error(
|
|
19
39
|
'Received empty shopper_language_selection_method field in the server response'.red,
|
|
20
40
|
);
|
|
21
41
|
}
|
|
22
|
-
return
|
|
42
|
+
return data;
|
|
23
43
|
} catch (err) {
|
|
24
44
|
err.name = 'StoreSettingsLocaleError';
|
|
25
45
|
throw err;
|
|
26
46
|
}
|
|
27
47
|
}
|
|
48
|
+
|
|
28
49
|
export { getStoreSettingsLocale };
|
|
29
50
|
export default {
|
|
30
51
|
getStoreSettingsLocale,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigcommerce/stencil-cli",
|
|
3
|
-
"version": "8.10.
|
|
3
|
+
"version": "8.10.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "CLI tool to run BigCommerce Stores locally for theme development.",
|
|
6
6
|
"main": "index.js",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"package-lock.json"
|
|
51
51
|
],
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@bigcommerce/stencil-paper": "5.
|
|
53
|
+
"@bigcommerce/stencil-paper": "5.3.0",
|
|
54
54
|
"@bigcommerce/stencil-styles": "^6.1.1",
|
|
55
55
|
"@hapi/boom": "^10.0.1",
|
|
56
56
|
"@hapi/glue": "^9.0.1",
|
|
@@ -315,14 +315,19 @@ internals.getTemplatePath = (requestPath, data) => {
|
|
|
315
315
|
}
|
|
316
316
|
return templatePath || data.template_file;
|
|
317
317
|
};
|
|
318
|
-
function
|
|
318
|
+
function getRawAcceptLanguageHeader(request) {
|
|
319
319
|
if (
|
|
320
320
|
internals.options.storeSettingsLocale.shopper_language_selection_method ===
|
|
321
321
|
'default_shopper_language'
|
|
322
322
|
) {
|
|
323
323
|
return internals.options.storeSettingsLocale.default_shopper_language;
|
|
324
324
|
}
|
|
325
|
-
return request.headers['accept-language']
|
|
325
|
+
return request.headers['accept-language'];
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function getAcceptLanguageHeader(request) {
|
|
329
|
+
const rawHeader = getRawAcceptLanguageHeader(request);
|
|
330
|
+
return rawHeader.toLowerCase();
|
|
326
331
|
}
|
|
327
332
|
/**
|
|
328
333
|
* Creates a new Pencil Response object and returns it.
|