Skip to content

Conversation

@devversion
Copy link
Member

  • 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)

* 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)
@devversion devversion requested a review from jelbourn May 31, 2017 16:22
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label May 31, 2017
Copy link
Member

@jelbourn jelbourn left a 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) {
Copy link
Member

Choose a reason for hiding this comment

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

how about just inlineAllResources?

Copy link
Member Author

@devversion devversion May 31, 2017

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.

Copy link
Member

@jelbourn jelbourn May 31, 2017

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)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah inlineAllResourceForDirectory sounds good

Copy link
Member Author

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) {
Copy link
Member

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?

Copy link
Member Author

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
Copy link
Member

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) => {
Copy link
Member

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.

Copy link
Member Author

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') + ']';
Copy link
Member

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)

Copy link
Member Author

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);
Copy link
Member

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?

Copy link
Member Author

@devversion devversion May 31, 2017

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.

Copy link
Member

Choose a reason for hiding this comment

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

That's fine too

@devversion devversion force-pushed the build/move-inline-resources-script branch from 10e7552 to 3d7a8a3 Compare May 31, 2017 18:05
@devversion
Copy link
Member Author

devversion commented May 31, 2017

@jelbourn Addressed your comments. The inlineStyles method now looks way better. Thanks

Copy link
Member

@jelbourn jelbourn left a 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"]"
Copy link
Member

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 '

@devversion devversion added the action: merge The PR is ready for merge by the caretaker label May 31, 2017
@mmalerba mmalerba merged commit 52b6692 into angular:master May 31, 2017
@devversion devversion deleted the build/move-inline-resources-script branch November 11, 2017 10:23
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants