Skip to content

Commit 9955c95

Browse files
committed
First draft of the all package
1 parent d81c9cf commit 9955c95

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+339
-930
lines changed

scripts/ci/forbidden-identifiers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ function isRelativeScopeImport(fileName, line) {
185185

186186
// Creates a valid import statement, which uses the correct scope package.
187187
let importFilePath = path.relative(importScope.path, importPath);
188-
let validImportPath = `@angular2-material/${importScope.name}/${importFilePath}`;
188+
let validImportPath = `@angular/material/${importScope.name}/${importFilePath}`;
189189

190190
return {
191191
fileScope: fileScope.name,

scripts/release/inline-resources.js

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ const writeFile = promiseify(fs.writeFile);
3030

3131

3232
function inlineResources(globs) {
33+
if (typeof globs == 'string') {
34+
globs = [globs];
35+
}
36+
3337
/**
3438
* For every argument, inline the templates and styles under it and write the new file.
3539
*/
36-
for (let pattern of globs) {
40+
return Promise.all(globs.map(pattern => {
3741
if (pattern.indexOf('*') < 0) {
3842
// Argument is a directory target, add glob patterns to include every files.
3943
pattern = path.join(pattern, '**', '*');
@@ -43,17 +47,32 @@ function inlineResources(globs) {
4347
.filter(name => /\.js$/.test(name)); // Matches only JavaScript files.
4448

4549
// Generate all files content with inlined templates.
46-
files.forEach(filePath => {
47-
readFile(filePath, 'utf-8')
48-
.then(content => inlineTemplate(filePath, content))
49-
.then(content => inlineStyle(filePath, content))
50-
.then(content => removeModuleId(filePath, content))
50+
return Promise.all(files.map(filePath => {
51+
return readFile(filePath, 'utf-8')
52+
.then(content => inlineResourcesFromString(content, url => {
53+
return path.join(path.dirname(filePath), url);
54+
}))
5155
.then(content => writeFile(filePath, content))
5256
.catch(err => {
5357
console.error('An error occured: ', err);
5458
});
55-
});
56-
}
59+
}));
60+
}));
61+
}
62+
63+
/**
64+
* Inline resources from a string content.
65+
* @param content {string} The source file's content.
66+
* @param urlResolver {Function} A resolver that takes a URL and return a path.
67+
* @returns {string} The content with resources inlined.
68+
*/
69+
function inlineResourcesFromString(content, urlResolver) {
70+
// Curry through the inlining functions.
71+
return [
72+
inlineTemplate,
73+
inlineStyle,
74+
removeModuleId
75+
].reduce((content, fn) => fn(content, urlResolver), content);
5776
}
5877

5978
if (require.main === module) {
@@ -64,13 +83,13 @@ if (require.main === module) {
6483
/**
6584
* Inline the templates for a source file. Simply search for instances of `templateUrl: ...` and
6685
* replace with `template: ...` (with the content of the file included).
67-
* @param filePath {string} The path of the source file.
6886
* @param content {string} The source file's content.
87+
* @param urlResolver {Function} A resolver that takes a URL and return a path.
6988
* @return {string} The content with all templates inlined.
7089
*/
71-
function inlineTemplate(filePath, content) {
90+
function inlineTemplate(content, urlResolver) {
7291
return content.replace(/templateUrl:\s*'([^']+?\.html)'/g, function(m, templateUrl) {
73-
const templateFile = path.join(path.dirname(filePath), templateUrl);
92+
const templateFile = urlResolver(templateUrl);
7493
const templateContent = fs.readFileSync(templateFile, 'utf-8');
7594
const shortenedTemplate = templateContent
7695
.replace(/([\n\r]\s*)+/gm, ' ')
@@ -83,16 +102,16 @@ function inlineTemplate(filePath, content) {
83102
/**
84103
* Inline the styles for a source file. Simply search for instances of `styleUrls: [...]` and
85104
* replace with `styles: [...]` (with the content of the file included).
86-
* @param filePath {string} The path of the source file.
105+
* @param urlResolver {Function} A resolver that takes a URL and return a path.
87106
* @param content {string} The source file's content.
88107
* @return {string} The content with all styles inlined.
89108
*/
90-
function inlineStyle(filePath, content) {
109+
function inlineStyle(content, urlResolver) {
91110
return content.replace(/styleUrls:\s*(\[[\s\S]*?\])/gm, function(m, styleUrls) {
92111
const urls = eval(styleUrls);
93112
return 'styles: ['
94113
+ urls.map(styleUrl => {
95-
const styleFile = path.join(path.dirname(filePath), styleUrl);
114+
const styleFile = urlResolver(styleUrl);
96115
const styleContent = fs.readFileSync(styleFile, 'utf-8');
97116
const shortenedStyle = styleContent
98117
.replace(/([\n\r]\s*)+/gm, ' ')
@@ -107,13 +126,13 @@ function inlineStyle(filePath, content) {
107126

108127
/**
109128
* Remove every mention of `moduleId: module.id`.
110-
* @param _ {string} The file path of the source file, currently ignored.
111129
* @param content {string} The source file's content.
112130
* @returns {string} The content with all moduleId: mentions removed.
113131
*/
114-
function removeModuleId(_, content) {
132+
function removeModuleId(content) {
115133
return content.replace(/\s*moduleId:\s*module\.id\s*,?\s*/gm, '');
116134
}
117135

118136

119137
module.exports = inlineResources;
138+
module.exports.inlineResourcesFromString = inlineResourcesFromString;

src/demo-app/button-toggle/button-toggle-demo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {MdUniqueSelectionDispatcher} from '@angular2-material/core';
2+
import {MdUniqueSelectionDispatcher} from '@angular/material';
33

44
@Component({
55
moduleId: module.id,

src/demo-app/demo-app-module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {HttpModule} from '@angular/http';
44
import {FormsModule} from '@angular/forms';
55
import {DemoApp, Home} from './demo-app/demo-app';
66
import {RouterModule} from '@angular/router';
7-
import {MaterialModule} from '@angular2-material/all';
7+
import {MaterialModule} from '@angular/material';
88
import {DEMO_APP_ROUTES} from './demo-app/routes';
99
import {ProgressBarDemo} from './progress-bar/progress-bar-demo';
1010
import {JazzDialog, DialogDemo} from './dialog/dialog-demo';

src/demo-app/dialog/dialog-demo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component, ViewContainerRef} from '@angular/core';
2-
import {MdDialog, MdDialogConfig, MdDialogRef} from '@angular2-material/dialog';
2+
import {MdDialog, MdDialogConfig, MdDialogRef} from '@angular/material';
33

44
@Component({
55
moduleId: module.id,

src/demo-app/grid-list/grid-list-demo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {MdIconRegistry} from '@angular2-material/icon';
2+
import {MdIconRegistry} from '@angular/material';
33

44

55
@Component({

src/demo-app/icon/icon-demo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component, ViewEncapsulation} from '@angular/core';
2-
import {MdIconRegistry} from '@angular2-material/icon';
2+
import {MdIconRegistry} from '@angular/material';
33

44
@Component({
55
moduleId: module.id,

src/demo-app/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<link rel="icon" type="image/x-icon" href="favicon.ico">
1010
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
11-
<link href="@angular2-material/core/theming/prebuilt/indigo-pink.css" rel="stylesheet">
11+
<link href="@angular/material/core/theming/prebuilt/indigo-pink.css" rel="stylesheet">
1212

1313
<!-- FontAwesome for md-icon demo. -->
1414
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">

src/demo-app/live-announcer/live-announcer-demo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {MdLiveAnnouncer} from '@angular2-material/core';
2+
import {MdLiveAnnouncer} from '@angular/material';
33

44
@Component({
55
moduleId: module.id,

src/demo-app/overlay/overlay-demo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
ComponentPortal,
1414
Portal,
1515
TemplatePortalDirective,
16-
} from '@angular2-material/core';
16+
} from '@angular/material';
1717

1818

1919
@Component({

0 commit comments

Comments
 (0)