Skip to content

Commit

Permalink
Add support for bundling themes defined by glob pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Igloczek committed Nov 6, 2020
1 parent 53431ef commit f42b5c9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ program
'Configuration file path.',
'magepack.config.js'
)
.option('-g, --glob <path>', 'Glob pattern of themes to bundle.')
.option('-d, --debug', 'Enable logging of debugging information.')
.action(({ config, debug }) => {
if (debug) {
Expand Down
4 changes: 2 additions & 2 deletions lib/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ const checkMinifyOn = require('./bundle/checkMinifyOn');
const moduleWrapper = require('./bundle/moduleWrapper');
const modulePathMapper = require('./bundle/moduleMapResolver');

module.exports = async (bundlingConfigPath) => {
module.exports = async (bundlingConfigPath, localesGlobPattern) => {
const bundlingConfigRealPath = path.resolve(bundlingConfigPath);

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

const bundlingConfig = require(bundlingConfigRealPath);

const localesPaths = getLocales();
const localesPaths = getLocales(localesGlobPattern);

const isMinifyOn = checkMinifyOn(localesPaths);

Expand Down
4 changes: 2 additions & 2 deletions lib/bundle/getLocales.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const path = require('path');
*
* @returns {string[]}
*/
const getLocales = () => {
const getLocales = (localesGlobPattern = 'pub/static/frontend/*/*/*') => {
const locales = glob
.sync('pub/static/frontend/*/*/*')
.sync(localesGlobPattern)
.filter((locale) => !locale.includes('Magento/blank'))
.filter(
(locale) =>
Expand Down
11 changes: 11 additions & 0 deletions lib/bundle/getLocales.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ describe('getLocales utility', () => {
expect(getLocales()).toEqual(['pub/static/frontend/Magento/luma']);
});

test('returns found locales when using custom glob', () => {
glob.sync.mockReturnValue([
'pub/static/frontend/Magento/luma'
]);
fs.existsSync.mockReturnValue(true);

expect(getLocales('pub/static/frontend/Magento/luma')).toEqual(
['pub/static/frontend/Magento/luma']
);
});

test('throws error when locales are found but have no requirejs-config.js file', () => {
glob.sync.mockReturnValue([]);
fs.existsSync.mockReturnValue(false);
Expand Down

0 comments on commit f42b5c9

Please sign in to comment.