Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions scripts/util/inline-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* tslint:disable:no-eval */

import {dirname, join} from 'path';
import {readFileSync, writeFileSync} from 'fs';
import {readFileSync, writeFileSync, existsSync} from 'fs';
import {sync as glob} from 'glob';
import * as del from 'del';

Expand All @@ -26,7 +26,7 @@ export function inlineResources(filePath: string, deleteResource: boolean = fals
function inlineTemplate(fileContent: string, filePath: string, deleteResource: boolean = false) {
return fileContent.replace(/templateUrl:\s*'([^']+?\.html)'/g, (_match, templateUrl) => {
const templatePath = join(dirname(filePath), templateUrl);
const templateContent = loadResourceFile(templatePath);
const templateContent = loadResourceFile(templatePath) || "";

if (deleteResource === true) {
del.sync(templatePath);
Expand All @@ -46,7 +46,7 @@ function inlineStyles(fileContent: string, filePath: string, deleteResource: boo
const styleContents = styleUrls
.map(url => join(dirname(filePath), url))
.map(path => {
const styleContent = loadResourceFile(path);
const styleContent = loadResourceFile(path) || "";
if (deleteResource === true) {
del.sync(path);
}
Expand All @@ -64,7 +64,11 @@ function removeModuleId(fileContent: string) {

/** Loads the specified resource file and drops line-breaks of the content. */
function loadResourceFile(filePath: string): string {
return readFileSync(filePath, 'utf-8')
.replace(/([\n\r]\s*)+/gm, ' ')
.replace(/"/g, '\\"');

if (existsSync(filePath))
return readFileSync(filePath, 'utf-8')
.replace(/([\n\r]\s*)+/gm, ' ')
.replace(/"/g, '\\"');
else
return null;
}
6 changes: 4 additions & 2 deletions scripts/util/metadata-inlining.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// taken from https://github.com/angular/material2/blob/master/tools/gulp/packaging/metadata-inlining.ts
import {readFileSync, writeFileSync} from 'fs';
import {readFileSync, writeFileSync, existsSync} from 'fs';
import {basename} from 'path';
import {sync as glob} from 'glob';
import {join} from 'path';
Expand All @@ -21,7 +21,9 @@ export function inlineMetadataResources(metadata: any, componentResources: Map<s
metadata.styles = [];
for (const styleUrl of metadata.styleUrls) {
const fullResourcePath = componentResources.get(basename(styleUrl));
metadata.styles.push(readFileSync(fullResourcePath, 'utf-8'));

if ( fullResourcePath && existsSync(fullResourcePath))
metadata.styles.push(readFileSync(fullResourcePath, 'utf-8'));
}
delete metadata.styleUrls;
}
Expand Down