From 7ea4665acf47f5481cdb95cee3a6fdca261fba7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Smyrek?= Date: Mon, 18 May 2020 08:24:09 +0200 Subject: [PATCH 1/5] 369: Support theme configuration via CLI --- local.config.js | 68 ++++++++++++++++++++++++++++++++ local.json | 32 --------------- package.json | 7 +++- scripts/generate-local-config.js | 40 +++++++++++++++++++ 4 files changed, 113 insertions(+), 34 deletions(-) create mode 100644 local.config.js delete mode 100644 local.json create mode 100644 scripts/generate-local-config.js diff --git a/local.config.js b/local.config.js new file mode 100644 index 000000000..eb785d866 --- /dev/null +++ b/local.config.js @@ -0,0 +1,68 @@ +const merge = require('lodash/merge') +const semverSatisfies = require('semver/functions/satisfies') + +/** + * This is the base configuration for Capybara theme that is common and valid + * for all supported Vue Storefront versions. Any new configuration options + * which will be used in all installations regardless of Vue Storefront + * version should be added here. + */ +const configBase = { + 'theme': '@vue-storefront/theme-capybara', + 'products': { + 'thumbnails': { + 'width': 324, + 'height': 489 + } + }, + 'cart': { + 'thumbnails': { + 'width': 210, + 'height': 300 + } + }, + 'entities': { + 'category': { + 'categoriesDynamicPrefetch': false + } + }, + 'quicklink': { + 'enabled': false + } +} + +/** + * This object contains key-value pairs of custom/specific configuration options + * per matching Vue storefront version. Each key is a semver range about Vue + * Storefront version which supports these new options. Each value is a separate + * object cloned from base config and optionally extended by new configuration + * options supported by that particular Vue Storefront version. + */ +const configVariants = { + '~1.11.0': merge({}, configBase), + '^1.12.0': merge({}, configBase, { + 'server': { + 'api': 'api-search-query' + }, + 'entities': { + 'attribute': { + 'loadByAttributeMetadata': true + } + }, + 'urlModule': { + 'enableMapFallbackUrl': true + } + }) +} + +/** + * Find and return first configuration that satisfies semver range for current + * Vue Storefront version. + */ +module.exports = function (vsfVersion) { + const matchedConfigVersion = Object + .keys(configVariants) + .find(configVersion => semverSatisfies(vsfVersion, configVersion, { includePrerelease: true })) + + return matchedConfigVersion ? configVariants[matchedConfigVersion] : null +}; diff --git a/local.json b/local.json deleted file mode 100644 index b4f282c55..000000000 --- a/local.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "theme": "@vue-storefront/theme-capybara", - "server": { - "api": "api-search-query" - }, - "products": { - "thumbnails": { - "width": 324, - "height": 489 - } - }, - "cart": { - "thumbnails": { - "width": 210, - "height": 300 - } - }, - "entities": { - "category": { - "categoriesDynamicPrefetch": false - }, - "attribute": { - "loadByAttributeMetadata": true - } - }, - "urlModule": { - "enableMapFallbackUrl": true - }, - "quicklink": { - "enabled": false - } -} \ No newline at end of file diff --git a/package.json b/package.json index 6be11b797..f8030ace7 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,9 @@ "scripts": { "test:unit": "echo \"No test specified yet\" && exit 0", "lint": "cd ../../../ && yarn lint", - "dev": "cd ../../../ && yarn dev" + "dev": "cd ../../../ && yarn dev", + "generate-local-config": "node ./scripts/generate-local-config", + "generate-local-config:next": "yarn generate-local-config --next" }, "license": "MIT", "dependencies": { @@ -25,7 +27,8 @@ }, "devDependencies": { "husky": "^3.1.0", - "postcss-filter-stream": "^0.0.6" + "postcss-filter-stream": "^0.0.6", + "semver": "^7.3.2" }, "sideEffects": [ "*.(sc|sa|c)?ss", diff --git a/scripts/generate-local-config.js b/scripts/generate-local-config.js new file mode 100644 index 000000000..74f47e846 --- /dev/null +++ b/scripts/generate-local-config.js @@ -0,0 +1,40 @@ +#!/usr/bin/env node + +const fs = require('fs') +const path = require('path') +const semverInc = require('semver/functions/inc') + +const vsfInstallationDir = path.resolve(__dirname, '..', '..', '..', '..'); +const vsfPackageJsonPath = path.resolve(vsfInstallationDir, 'package.json'); +const themeInstallationDir = path.resolve(__dirname, '..'); +const themeLocalConfigJsPath = path.resolve(themeInstallationDir, 'local.config.js'); +const themeLocalJsonPath = path.resolve(themeInstallationDir, 'local.json'); + +/** + * Supported parameters: + * (no parameter) - Takes Vue Storefront version from package.json from installation directory + * directly as it is defined there and creates local.json configuration. + * --next - Increments Vue Storefront version from package.json to next minor version + * (this is useful if installed Vue Storefront already contains latest changes + * but they are not officially released yet, so version is package.json is still + * the previous one). Incremented Vue Storefront version is then used during + * creation of local.json configuration. + */ +const parameter = process.argv[2] + +try { + const vsfVersionFromPackageJson = JSON.parse(fs.readFileSync(vsfPackageJsonPath)).version + const vsfVersion = parameter === '--next' + ? semverInc(vsfVersionFromPackageJson, 'minor') + : vsfVersionFromPackageJson + + const themeLocalJson = fs.existsSync(themeLocalConfigJsPath) + ? require(themeLocalConfigJsPath)(vsfVersion) + : null + + if (themeLocalJson) { + fs.writeFileSync(themeLocalJsonPath, JSON.stringify(themeLocalJson, null, 2)) + } +} catch (e) { + console.error(`Problem with generating local.json configuration\n`, e) +} From 718dcf3eca0fab4873a45506d9c5d14376b81077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Smyrek?= Date: Mon, 18 May 2020 08:45:11 +0200 Subject: [PATCH 2/5] 369: Changelog update --- CHANGELOG.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b716f731..3f4f9705b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [1.0.0-rc.2] - UNRELEASED +## [1.0.0-rc.3] - UNRELEASED + +### Added +### Changed / Improved + +- Support theme configuration via CLI (#369) + +## [1.0.0-rc.2] - 2020-05-13 ### Added From 0003007955131bda43e975bf0098b005447426be Mon Sep 17 00:00:00 2001 From: tkostuch Date: Thu, 28 May 2020 12:05:59 +0200 Subject: [PATCH 3/5] update typing for price helper --- helpers/price.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpers/price.ts b/helpers/price.ts index d7d41b6ae..bb58c2360 100644 --- a/helpers/price.ts +++ b/helpers/price.ts @@ -7,7 +7,7 @@ function calculateBundleOptionsPrice (product) { const allBundleOptions = product.bundle_options || [] const selectedBundleOptions = Object.values(get(product, 'product_option.extension_attributes.bundle_options', {})) const price = getBundleOptionPrice( - getBundleOptionsValues(selectedBundleOptions, allBundleOptions) + getBundleOptionsValues(selectedBundleOptions as any[], allBundleOptions) ) return price.priceInclTax From 7c3146d7ddb067f201b17bf8471ae858aaacbcab Mon Sep 17 00:00:00 2001 From: tkostuch Date: Thu, 28 May 2020 12:11:26 +0200 Subject: [PATCH 4/5] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f4f9705b..8eae1cc2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed / Improved - Support theme configuration via CLI (#369) +- Update types for `getBundleOptionsValues` (#371) ## [1.0.0-rc.2] - 2020-05-13 From 6fed66b09f246b13bb3ed53ae983b1da68288efb Mon Sep 17 00:00:00 2001 From: tkostuch Date: Tue, 2 Jun 2020 09:25:00 +0200 Subject: [PATCH 5/5] bump version --- CHANGELOG.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8eae1cc2e..ab38d40c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [1.0.0-rc.3] - UNRELEASED +## [1.0.0] - 2020.06.02 ### Added ### Changed / Improved diff --git a/package.json b/package.json index f8030ace7..14fd1bbd4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@vue-storefront/theme-capybara", - "version": "1.0.0-rc.2", + "version": "1.0.0", "description": "New theme for Vue Storefront based on Storefront UI", "main": "index.js", "scripts": {