Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(storefront): bctheme-1064 Modify Stencil bundle for using Components UI Library #904

Merged
merged 1 commit into from
Jun 20, 2022

Conversation

yurytut1993
Copy link
Contributor

What?

This PR provides functionality of adding templates from external lib to the theme bundle. The main idea is that script can understand is used template consist in the theme or inside external node_modules library.

IMPORTANT
It should be merged only after bctheme-1063

Tickets / Documentation

bctheme-1064

Screenshots (if appropriate)

TBD

@yurytut1993 yurytut1993 added the draft Ready for initial review label Apr 7, 2022
@yurytut1993 yurytut1993 force-pushed the BCTHEME-1064 branch 2 times, most recently from 96094e8 to c440b56 Compare April 14, 2022 16:43
lib/stencil-bundle.js Outdated Show resolved Hide resolved
lib/stencil-bundle.js Outdated Show resolved Hide resolved
@@ -6,6 +6,44 @@ const upath = require('upath');

const partialRegex = /\{\{>\s*([_|\-|a-zA-Z0-9/]+)[^{]*?}}/g;
const dynamicComponentRegex = /\{\{\s*?dynamicComponent\s*(?:'|")([_|\-|a-zA-Z0-9/]+)(?:'|").*?}}/g;
const includeRegex = /{{2}>\s*([_|\-|a-zA-Z0-9/]+)[^{]*?}{2}/g;
const packageMarker = 'external/';
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's better to consolidate this name with externalTemplatesPath in stencil-bundle?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We removed externalTemplatesPath
If your comment is still valid please can you add more details:)

const includeRegex = /{{2}>\s*([_|\-|a-zA-Z0-9/]+)[^{]*?}{2}/g;
const packageMarker = 'external/';

const isExternalTemplate = (templateName) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add here and below doc types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

console.log('Template Parsing Started...');
const internalTemplatesList = await recursiveReadDir(this.templatesPath, ['!*.html']);
const searchExternalLib = (content) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mind moving searchExternalLib and checkTemplate to class functions (and maybe renaming to make more sense in class domain).
Maybe you can think also about extracting this functionality into separate file, while you are here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}
let externalLibs;
try {
externalLibs = (await async.map(internalTemplatesList, checkTemplate)).flat();
Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend not to use async library, where you can implement it in vanilla js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

});

// eslint-disable-next-line no-unused-vars
const checkResult = await async.parallel([
Copy link
Contributor

Choose a reason for hiding this comment

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

Here also. I know, that it was in the legacy code, but while you are working on this part, it would really helpful to reduce dependency from async

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


console.log(`${'ok'.green} -- Template Parsing Finished`);

return ret;
Copy link
Contributor

Choose a reason for hiding this comment

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

did you try to use return callback(null, ret) here? What happened?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we received task object with field templates undefined which prevented us to create bundle

);
}
async
.series(this.tasks)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it because you removed the callback invocation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

returned parallel function


return res;
};
return externalTemplatesImports.map((_import) => _import.split('/')[1]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason using underscore in _import?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you have any good name suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean, that's an old style to declare private class members, while this is not a class and not a member of it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

np, updated

Copy link
Contributor

@jairo-bc jairo-bc left a comment

Choose a reason for hiding this comment

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

LGTM

@yurytut1993 yurytut1993 merged commit 28f766d into bigcommerce:master Jun 20, 2022
@jairo-bc jairo-bc mentioned this pull request Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
draft Ready for initial review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants