-
Notifications
You must be signed in to change notification settings - Fork 6.8k
build: move inline resources script to tools #4894
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
build: move inline resources script to tools #4894
Conversation
* Moves the inline resources script to the `tools/gulp/packaging` folder. This is necessary when exposing the build tools (e.g for flex-layout) * This also makes the packaging more clean because no external script is referenced (also switched to TypeScript and improved code)
jelbourn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want to do a bit of refactoring while already touching this file?
| import {sync as glob} from 'glob'; | ||
|
|
||
| /** Finds all JavaScript files and inlines all external resources of Angular components. */ | ||
| export function inlineResourcesFolder(folderPath: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about just inlineAllResources?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about that but AllResources sounds like it inlines all resources a given file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then maybe inlineAllResourceForDirectory (and then inlineResourcesForFile)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah inlineAllResourceForDirectory sounds good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually why not just inlineResourcesForDirectory?
| } | ||
|
|
||
| /** Inlines the templates of Angular components for a specified source file. */ | ||
| function inlineTemplate(fileContent: string, filePath: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the inlined resources here minified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the minifying happens before by Gulp.
| /** Inlines the external styles of Angular components for a specified source file. */ | ||
| function inlineStyles(fileContent: string, filePath: string) { | ||
| return fileContent.replace(/styleUrls:\s*(\[[\s\S]*?])/gm, (match, styleUrls) => { | ||
| // The RegExp matches the array of external style files. This is a string right now and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expand comment to include something like
// styleUrls will be a string that looks something like "['button.css', 'other.css']"|
|
||
| /** Inlines the external styles of Angular components for a specified source file. */ | ||
| function inlineStyles(fileContent: string, filePath: string) { | ||
| return fileContent.replace(/styleUrls:\s*(\[[\s\S]*?])/gm, (match, styleUrls) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename styleUrls to styleUrlsValue to make it more clear that it's just yet the real array of styleUrl strings. Then prsedUrls below could just change to styleUrls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I like that.
| const stylePath = join(dirname(filePath), styleUrl); | ||
| const styleContent = loadResourceFile(stylePath); | ||
| return `"${styleContent}"`; | ||
| }).join(',\n') + ']'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe refactor this to
const styles = parsedUrls
.map(url => join(dirname(filePath), url))
.map(path => loadResourceFile(path));
return `styles: [${styleContents.join(',')}]`;(the newline shouldn't be necessary AFAICT)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that. Not sure about the line break. I didn't write it but I will test it.
| function inlineTemplate(fileContent: string, filePath: string) { | ||
| return fileContent.replace(/templateUrl:\s*'([^']+?\.html)'/g, (match, templateUrl) => { | ||
| const templateFile = join(dirname(filePath), templateUrl); | ||
| const templateContent = loadResourceFile(templateFile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename variables to templatePath and template?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
templatePath sounds good. For the template I'd like to keep the content to indicate it's the text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine too
10e7552 to
3d7a8a3
Compare
|
@jelbourn Addressed your comments. The |
jelbourn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just one tiny comment; can add merge-ready when done
| function inlineStyles(fileContent: string, filePath: string) { | ||
| return fileContent.replace(/styleUrls:\s*(\[[\s\S]*?])/gm, (match, styleUrlsValue) => { | ||
| // The RegExp matches the array of external style files. This is a string right now and | ||
| // can to be parsed using the `eval` method. The value looks like "['AAA.css', 'BBB.css"]" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That second-to-last " should be a '
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
tools/gulp/packagingfolder. This is necessary when exposing the build tools (e.g for flex-layout)