Skip to content

Commit 3d7a8a3

Browse files
committed
Address comments
1 parent 280f2af commit 3d7a8a3

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

tools/gulp/packaging/build-tasks-gulp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {SOURCE_ROOT, DIST_ROOT, HTML_MINIFIER_OPTIONS} from '../build-config';
55
import {sequenceTask, sassBuildTask, copyTask, triggerLivereload} from '../util/task_helpers';
66
import {composeRelease} from './build-release';
77
import {buildPackageBundles} from './build-bundles';
8-
import {inlineResourcesFolder} from './inline-resources';
8+
import {inlineResourcesForDirectory} from './inline-resources';
99

1010
// There are no type definitions available for these imports.
1111
const htmlmin = require('gulp-htmlmin');
@@ -84,7 +84,7 @@ export function createPackageBuildTasks(packageName: string, requiredPackages: s
8484
return src(htmlGlob).pipe(htmlmin(HTML_MINIFIER_OPTIONS)).pipe(dest(packageOut));
8585
});
8686

87-
task(`${packageName}:assets:inline`, () => inlineResourcesFolder(packageOut));
87+
task(`${packageName}:assets:inline`, () => inlineResourcesForDirectory(packageOut));
8888

8989
/**
9090
* Watch tasks, that will rebuild the package whenever TS, SCSS, or HTML files change.

tools/gulp/packaging/inline-resources.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {dirname, join} from 'path';
44
import {readFileSync, writeFileSync} from 'fs';
55
import {sync as glob} from 'glob';
66

7-
/** Finds all JavaScript files and inlines all external resources of Angular components. */
8-
export function inlineResourcesFolder(folderPath: string) {
7+
/** Finds all JavaScript files in a directory and inlines all resources of Angular components. */
8+
export function inlineResourcesForDirectory(folderPath: string) {
99
glob(join(folderPath, '**/*.js')).forEach(filePath => inlineResources(filePath));
1010
}
1111

@@ -23,25 +23,24 @@ export function inlineResources(filePath: string) {
2323
/** Inlines the templates of Angular components for a specified source file. */
2424
function inlineTemplate(fileContent: string, filePath: string) {
2525
return fileContent.replace(/templateUrl:\s*'([^']+?\.html)'/g, (match, templateUrl) => {
26-
const templateFile = join(dirname(filePath), templateUrl);
27-
const templateContent = loadResourceFile(templateFile);
26+
const templatePath = join(dirname(filePath), templateUrl);
27+
const templateContent = loadResourceFile(templatePath);
2828
return `template: "${templateContent}"`;
2929
});
3030
}
3131

32-
3332
/** Inlines the external styles of Angular components for a specified source file. */
3433
function inlineStyles(fileContent: string, filePath: string) {
35-
return fileContent.replace(/styleUrls:\s*(\[[\s\S]*?])/gm, (match, styleUrls) => {
34+
return fileContent.replace(/styleUrls:\s*(\[[\s\S]*?])/gm, (match, styleUrlsValue) => {
3635
// The RegExp matches the array of external style files. This is a string right now and
37-
// can to be parsed using the `eval` method.
38-
const parsedUrls = eval(styleUrls) as string[];
39-
40-
return 'styles: [' + parsedUrls.map(styleUrl => {
41-
const stylePath = join(dirname(filePath), styleUrl);
42-
const styleContent = loadResourceFile(stylePath);
43-
return `"${styleContent}"`;
44-
}).join(',\n') + ']';
36+
// can to be parsed using the `eval` method. The value looks like "['AAA.css', 'BBB.css"]"
37+
const styleUrls = eval(styleUrlsValue) as string[];
38+
39+
const styleContents = styleUrls
40+
.map(url => join(dirname(filePath), url))
41+
.map(path => loadResourceFile(path));
42+
43+
return `styles: ["${styleContents.join(',')}"]`;
4544
});
4645
}
4746

0 commit comments

Comments
 (0)