Skip to content

Commit

Permalink
fix(cli): url gets repeated twice if shopware plugins configuration r…
Browse files Browse the repository at this point in the history
…eturn full path (#1077)
  • Loading branch information
Matteo Rigoni authored Sep 9, 2020
1 parent aa7c08b commit c2c1457
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/cli/src/extensions/plugins-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,21 @@ module.exports = (toolbox: GluegunToolbox) => {
};

toolbox.fetchPluginsConfig = async ({ config }: { config: string }) => {
const pluginsConfigResponse = await axios.get(
`${toolbox.inputParameters.shopwareEndpoint}/${config}`
);
const endpoint = toolbox.inputParameters.shopwareEndpoint;
const url =
config.indexOf(endpoint) >= 0
? config
: `${toolbox.inputParameters.shopwareEndpoint}/${config}`;
const pluginsConfigResponse = await axios.get(url);
return pluginsConfigResponse.data;
};

toolbox.loadPluginsAssetFile = async ({ asset }: { asset: string }) => {
const fileUrl = `${toolbox.inputParameters.shopwareEndpoint}/${asset}`;
const endpoint = toolbox.inputParameters.shopwareEndpoint;
const fileUrl =
asset.indexOf(endpoint) >= 0
? asset
: `${toolbox.inputParameters.shopwareEndpoint}/${asset}`;

const request = require("request");
const loadFile = function () {
Expand Down Expand Up @@ -224,6 +231,7 @@ module.exports = (toolbox: GluegunToolbox) => {
...toolbox.inputParameters,
authToken,
});

const pluginsConfig = await toolbox.fetchPluginsConfig(buildArtifact);

await toolbox.filesystem.removeAsync(`.shopware-pwa/pwa-bundles.json`);
Expand All @@ -239,12 +247,12 @@ module.exports = (toolbox: GluegunToolbox) => {
await toolbox.loadPluginsAssetFile(buildArtifact);
await toolbox.unzipPluginsAssetsFile();
} catch (e) {
if (e && e.response && e.response.status === 401) {
if (e?.response?.status === 401) {
toolbox.print.error(
`You provided bad cridentials for your shopware instance: ${toolbox.inputParameters.shopwareEndpoint} - plugins will not be added`
);
} else {
console.error("UNEXPECTED ERROR", e ? e.response : e);
toolbox.print.error(`UNEXPECTED ERROR ${e?.response ? e.response : e}`);
}
return;
}
Expand Down

1 comment on commit c2c1457

@vercel
Copy link

@vercel vercel bot commented on c2c1457 Sep 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.