Skip to content

Commit

Permalink
feat(nuxt-module): config to enable vuex store
Browse files Browse the repository at this point in the history
  • Loading branch information
patzick committed May 27, 2022
1 parent 5d864b3 commit d484fbd
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 55 deletions.
19 changes: 19 additions & 0 deletions docs/landing/cookbook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,22 @@ defaultsConfigBuilder().replace("useCms.limit", 5);

- `add` would replace value if it's not an object or array, for example with `limit` property
- you could chain methods like `defaultsConfigBuilder().add(...).remove(...).add(...)`

## 10. Enabling Vuex store <a id="no10"></a>

If you need to enable Vuex store in your project, you need to add flag in `nuxt.config.js`:

```js
// example nuxt.config.js
import extendNuxtConfig from "@shopware-pwa/nuxt-module/config";

export default extendNuxtConfig({
head: {
title: "Shopware PWA",
meta: [{ hid: "description", name: "description", content: "" }],
},
shopware: {
enableVuex: true,
},
});
```
19 changes: 19 additions & 0 deletions packages/nuxt-module/__tests__/module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ describe("nuxt-module - ShopwarePWAModule runModule", () => {
beforeEach(() => {
jest.resetAllMocks();

//clean shopware config
moduleObject.options.shopware = null;

mockedUtils.loadConfig.mockResolvedValue({
shopwareEndpoint: "mockedEndpoint",
shopwareAccessToken: "mockedToken",
Expand Down Expand Up @@ -393,6 +396,22 @@ describe("nuxt-module - ShopwarePWAModule runModule", () => {
});
});

describe("vuex store", () => {
it("should enable vuex store", async () => {
moduleObject.options.shopware ??= {};
moduleObject.options.shopware.enableVuex = true;
await runModule(moduleObject, {});
expect(moduleObject.options.store).toEqual(true);
expect(moduleObject.options.features.store).toEqual(true);
});

it("should be disabled by default", async () => {
await runModule(moduleObject, {});
expect(moduleObject.options.store).toEqual(false);
expect(moduleObject.options.features.store).toEqual(false);
});
});

it("should copy target static directory to project root directory after production build", async () => {
moduleObject.options.dev = false;
const afterBuildMethods: any[] = [];
Expand Down
6 changes: 5 additions & 1 deletion packages/nuxt-module/src/extendNuxtConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ const defaultConfig: NuxtConfig = {
};

const configs: NuxtConfig[] = [defaultConfig];
export default function extendNuxtConfig(config: NuxtConfig) {

export type ConfigOptions = NuxtConfig & {
enableVuex?: boolean;
};
export default function extendNuxtConfig(config: ConfigOptions) {
configs.push(config);
return configs.reduce((prev, next) => mergeWith(prev, next, customizer));
}
6 changes: 4 additions & 2 deletions packages/nuxt-module/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export async function runModule(
moduleObject
);

const vuexState = moduleObject.options?.shopware?.enableVuex ?? false;

if (!shopwarePwaConfig.shopwareAccessToken)
console.error("shopwareAccessToken in shopware-pwa.config.js is missing");
if (!shopwarePwaConfig.shopwareEndpoint)
Expand Down Expand Up @@ -72,8 +74,8 @@ export async function runModule(

// Change project source root to Target path
moduleObject.options.srcDir = TARGET_SOURCE;
moduleObject.options.store = false; // disable store generation
moduleObject.options.features.store = false;
moduleObject.options.store = vuexState; // Vuex store generation
moduleObject.options.features.store = vuexState;
// resolve project src aliases
moduleObject.options.alias["~"] = TARGET_SOURCE;
moduleObject.options.alias["@"] = TARGET_SOURCE;
Expand Down
62 changes: 10 additions & 52 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2555,28 +2555,26 @@
dependencies:
"@sinonjs/commons" "^1.7.0"

"@storefront-ui/shared@0.12.3":
version "0.12.3"
resolved "https://registry.yarnpkg.com/@storefront-ui/shared/-/shared-0.12.3.tgz#98bed5975331816f90ded3e05e5c5ec71d80bd49"
integrity sha512-ari13tRJCijnjUPWMt8vrFMYO3bRbi+uVCed95004q1pTExjGzOEV8VJfVMLok4Wo2DnP6wTEKZZbya73tyTcg==
"@storefront-ui/shared@0.13.1":
version "0.13.1"
resolved "https://registry.yarnpkg.com/@storefront-ui/shared/-/shared-0.13.1.tgz#90919fc654e8c34f599bdee5be80677fe4a60049"
integrity sha512-CeBxu0k9OE1Me1amRXNQkjIQQl2uth9j84nQRlzO9fUUVMeHdHS8cN83sljotqHe+1xhIsi0aP92UyHrSqT5JA==

"@storefront-ui/vue@0.12.3":
version "0.12.3"
resolved "https://registry.yarnpkg.com/@storefront-ui/vue/-/vue-0.12.3.tgz#bbb72039bbe11fda8766f2ed5b156b51ca4b03de"
integrity sha512-u+SE6yJeznscnvEyMleB5TwPl+P8ZjIk2rjwXK57+LfvCujP5Mpa/uChZdzUIwLUN/GxLjTr9fSzXyVTIXCZ/A==
"@storefront-ui/vue@0.13.1":
version "0.13.1"
resolved "https://registry.yarnpkg.com/@storefront-ui/vue/-/vue-0.13.1.tgz#c2f7b93beb7c82459f203fd9112fbb846041a9cb"
integrity sha512-aeFPIwv3hmOTaAu5/rt0SbAix8VOjYCaM+ofpnbuO/y+eiUeJtBlWvu90AMdK2Zym00erfJyt39FmDqFXIYuNg==
dependencies:
"@glidejs/glide" "^3.3.0"
"@storefront-ui/shared" "0.12.3"
"@storefront-ui/shared" "0.13.1"
body-scroll-lock "^3.0.1"
cloudinary-build-url "^0.1.1"
core-js "^3.6.5"
glob "^7.1.4"
hammerjs "^2.0.8"
leaflet "^1.5.1"
nouislider "^15.2.0"
sass "^1.32.13"
sass-loader "^10.0.3"
simplebar-vue "^1.4.0"
vue "^2.6.12"
vue2-leaflet "^2.5.2"

Expand Down Expand Up @@ -4827,11 +4825,6 @@ camelcase@^6.0.0, camelcase@^6.2.0:
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.2.0.tgz#924af881c9d525ac9d87f40d964e5cea982a1809"
integrity sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg==

can-use-dom@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/can-use-dom/-/can-use-dom-0.1.0.tgz#22cc4a34a0abc43950f42c6411024a3f6366b45a"
integrity sha1-IsxKNKCrxDlQ9CxkEQJKP2NmtFo=

caniuse-api@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/caniuse-api/-/caniuse-api-3.0.0.tgz#5e4d90e2274961d46291997df599e3ed008ee4c0"
Expand Down Expand Up @@ -5624,7 +5617,7 @@ core-js-pure@^3.20.2:
resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.21.1.tgz#8c4d1e78839f5f46208de7230cebfb72bc3bdb51"
integrity sha512-12VZfFIu+wyVbBebyHmRTuEE/tZrB4tJToWcwAMcsp3h4+sHR+fMJWbKpYiCRWlhFBq+KNyO8rIV9rTkeVmznQ==

core-js@^3.0.1, core-js@^3.6.4, core-js@^3.6.5:
core-js@^3.6.4, core-js@^3.6.5:
version "3.12.1"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.12.1.tgz#6b5af4ff55616c08a44d386f1f510917ff204112"
integrity sha512-Ne9DKPHTObRuB09Dru5AjwKjY4cJHVGu+y5f7coGn1E9Grkc3p2iBwE9AI/nJzsE29mQF7oq+mhYYRqOMFN1Bw==
Expand Down Expand Up @@ -8235,11 +8228,6 @@ gray-matter@^4.0.1:
section-matter "^1.0.0"
strip-bom-string "^1.0.0"

hammerjs@^2.0.8:
version "2.0.8"
resolved "https://registry.yarnpkg.com/hammerjs/-/hammerjs-2.0.8.tgz#04ef77862cff2bb79d30f7692095930222bf60f1"
integrity sha1-BO93hiz/K7edMPdpIJWTAiK/YPE=

handle-thing@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/handle-thing/-/handle-thing-2.0.1.tgz#857f79ce359580c340d43081cc648970d0bb234e"
Expand Down Expand Up @@ -10447,11 +10435,6 @@ lodash.templatesettings@^4.0.0:
dependencies:
lodash._reinterpolate "^3.0.0"

lodash.throttle@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lodash.throttle/-/lodash.throttle-4.1.1.tgz#c23e91b710242ac70c37f1e1cda9274cc39bf2f4"
integrity sha1-wj6RtxAkKscMN/HhzaknTMOb8vQ=

lodash.trim@^4.5.1:
version "4.5.1"
resolved "https://registry.yarnpkg.com/lodash.trim/-/lodash.trim-4.5.1.tgz#36425e7ee90be4aa5e27bcebb85b7d11ea47aa57"
Expand Down Expand Up @@ -13259,11 +13242,6 @@ reselect@^4.0.0:
resolved "https://registry.yarnpkg.com/reselect/-/reselect-4.1.5.tgz#852c361247198da6756d07d9296c2b51eddb79f6"
integrity sha512-uVdlz8J7OO+ASpBYoz1Zypgx0KasCY20H+N8JD13oUMtPvSHQuscrHop4KbXrbsBcdB9Ds7lVK7eRkBIfO43vQ==

resize-observer-polyfill@^1.5.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz#0e9020dd3d21024458d4ebd27e23e40269810464"
integrity sha512-LwZrotdHOo12nQuZlHEmtuXdqGoOD0OhaxopaNFxWzInpEgaLWoVuAMbTzixuosCx2nEG58ngzW3vxdWoxIgdg==

resolve-cwd@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-2.0.0.tgz#00a9f7387556e27038eae232caa372a6a59b665a"
Expand Down Expand Up @@ -13807,26 +13785,6 @@ simple-swizzle@^0.2.2:
dependencies:
is-arrayish "^0.3.1"

simplebar-vue@^1.4.0:
version "1.6.3"
resolved "https://registry.yarnpkg.com/simplebar-vue/-/simplebar-vue-1.6.3.tgz#c2fa3058508fcdb95a6635cb0bbc6d82692ff1b3"
integrity sha512-3uxZXuBIcHmPpkm2YiJN/0lJOyXyZ2KpjMls3hw2PXbm2J2PlJjIbcemTDFrB3ezvZTOBFM/8a2FuqmWvNc/jw==
dependencies:
core-js "^3.0.1"
simplebar "^5.3.3"

simplebar@^5.3.3:
version "5.3.3"
resolved "https://registry.yarnpkg.com/simplebar/-/simplebar-5.3.3.tgz#7d89fa4374a637da96c493b2662ab5af4408d02e"
integrity sha512-OfuSX47Axq9aR6rp9WK3YefAg+1Qw3UKKxS46PdElPpd+FWXMj17/nispYxsHtU3F7mv+ilmqELWmRt7KUgHgg==
dependencies:
can-use-dom "^0.1.0"
core-js "^3.0.1"
lodash.debounce "^4.0.8"
lodash.memoize "^4.1.2"
lodash.throttle "^4.1.1"
resize-observer-polyfill "^1.5.1"

sisteransi@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed"
Expand Down

0 comments on commit d484fbd

Please sign in to comment.