Skip to content

Commit f98c29d

Browse files
authored
Merge pull request magesuite#63 from Igloczek/feature/theme-glob-pattern
Add support for bundling only themes defined by glob pattern
2 parents 53431ef + e03b097 commit f98c29d

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ magepack bundle
8989

9090
This command will iterate over each deployed locale (excluding Magento/blank) and prepare bundles for each of them.
9191

92+
There is one optional param you can set:
93+
`-g, --glob` - [Glob pattern](https://facelessuser.github.io/wcmatch/glob/#syntax) defining where to look for locales to bundle.
94+
9295
### Enabling
9396

9497
Once you made sure [Magepack Magento module](https://github.com/magesuite/magepack-magento) is installed, what is left is to enable it via admin panel under Stores->Configuration->Advanced->Developer or CLI:

cli.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ program
3838
'Configuration file path.',
3939
'magepack.config.js'
4040
)
41+
.option('-g, --glob <path>', 'Glob pattern of themes to bundle.')
4142
.option('-d, --debug', 'Enable logging of debugging information.')
4243
.action(({ config, debug }) => {
4344
if (debug) {

lib/bundle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ const checkMinifyOn = require('./bundle/checkMinifyOn');
1111
const moduleWrapper = require('./bundle/moduleWrapper');
1212
const modulePathMapper = require('./bundle/moduleMapResolver');
1313

14-
module.exports = async (bundlingConfigPath) => {
14+
module.exports = async (bundlingConfigPath, localesGlobPattern) => {
1515
const bundlingConfigRealPath = path.resolve(bundlingConfigPath);
1616

1717
logger.info(`Using bundling config from "${bundlingConfigRealPath}".`);
1818

1919
const bundlingConfig = require(bundlingConfigRealPath);
2020

21-
const localesPaths = getLocales();
21+
const localesPaths = getLocales(localesGlobPattern);
2222

2323
const isMinifyOn = checkMinifyOn(localesPaths);
2424

lib/bundle/getLocales.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ const path = require('path');
77
*
88
* @returns {string[]}
99
*/
10-
const getLocales = () => {
10+
const getLocales = (localesGlobPattern = 'pub/static/frontend/*/*/*') => {
1111
const locales = glob
12-
.sync('pub/static/frontend/*/*/*')
12+
.sync(localesGlobPattern)
1313
.filter((locale) => !locale.includes('Magento/blank'))
1414
.filter(
1515
(locale) =>

lib/bundle/getLocales.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ describe('getLocales utility', () => {
2727
expect(getLocales()).toEqual(['pub/static/frontend/Magento/luma']);
2828
});
2929

30+
test('returns found locales when using custom glob', () => {
31+
glob.sync.mockReturnValue([
32+
'pub/static/frontend/Magento/luma'
33+
]);
34+
fs.existsSync.mockReturnValue(true);
35+
36+
expect(getLocales('pub/static/frontend/Magento/luma')).toEqual(
37+
['pub/static/frontend/Magento/luma']
38+
);
39+
});
40+
3041
test('throws error when locales are found but have no requirejs-config.js file', () => {
3142
glob.sync.mockReturnValue([]);
3243
fs.existsSync.mockReturnValue(false);

0 commit comments

Comments
 (0)