Skip to content

Commit b5c8c63

Browse files
hanslkara
authored andcommitted
feat(packaging): move packaging to a single "@angular/material" (#1286)
1 parent 06a6076 commit b5c8c63

File tree

86 files changed

+343
-1039
lines changed

Some content is hidden

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

86 files changed

+343
-1039
lines changed

scripts/ci/forbidden-identifiers.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const blocked_statements = [
2929
];
3030

3131
const sourceFolders = ['./src', './e2e'];
32-
const scopePackages = glob('src/lib/*');
32+
const libRoot = 'src/lib';
3333
const blockedRegex = new RegExp(blocked_statements.join('|'), 'g');
3434
const importRegex = /from\s+'(.*)';/g;
3535

@@ -58,7 +58,9 @@ findTestFiles()
5858
lineCount++;
5959

6060
let matches = line.match(blockedRegex);
61-
let scopeImport = isRelativeScopeImport(fileName, line);
61+
let scopeImport = path.relative(libRoot, fileName).startsWith('..')
62+
? isRelativeScopeImport(fileName, line)
63+
: false;
6264

6365
if (matches || scopeImport) {
6466

@@ -155,6 +157,10 @@ function findChangedFiles() {
155157
* @param line Line to be checked.
156158
*/
157159
function isRelativeScopeImport(fileName, line) {
160+
if (fileName.startsWith(libRoot)) {
161+
return false;
162+
}
163+
158164
let importMatch = importRegex.exec(line);
159165

160166
// We have to reset the last index of the import regex, otherwise we
@@ -184,8 +190,7 @@ function isRelativeScopeImport(fileName, line) {
184190
if (fileScope.path !== importScope.path) {
185191

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

190195
return {
191196
fileScope: fileScope.name,
@@ -200,9 +205,7 @@ function isRelativeScopeImport(fileName, line) {
200205
filePath = path.normalize(filePath);
201206

202207
// Iterate through all scope paths and try to find them inside of the file path.
203-
var scopePath = scopePackages
204-
.filter(scope => filePath.indexOf(path.normalize(scope)) !== -1)
205-
.pop();
208+
var scopePath = filePath.indexOf(path.normalize(libRoot)) == -1 ? libRoot : filePath;
206209

207210
// Return an object containing the name of the scope and the associated path.
208211
return {

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({

src/demo-app/portal/portal-demo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
Portal,
44
ComponentPortal,
55
TemplatePortalDirective,
6-
} from '@angular2-material/core';
6+
} from '@angular/material';
77

88

99
@Component({

src/demo-app/ripple/ripple-demo.ts

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

44

55
@Component({

src/demo-app/system-config.ts

Lines changed: 25 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,34 @@
1-
/***********************************************************************************************
2-
* User Configuration.
3-
**********************************************************************************************/
4-
5-
const components = [
6-
'all',
7-
'button',
8-
'card',
9-
'checkbox',
10-
'dialog',
11-
'grid-list',
12-
'icon',
13-
'input',
14-
'list',
15-
'menu',
16-
'progress-bar',
17-
'progress-circle',
18-
'radio',
19-
'select',
20-
'sidenav',
21-
'slider',
22-
'slide-toggle',
23-
'button-toggle',
24-
'tabs',
25-
'toolbar',
26-
'tooltip',
27-
];
28-
29-
30-
/** User packages configuration. */
31-
const packages: any = {
32-
'@angular2-material/core': {
33-
format: 'cjs',
34-
main: 'core.umd.js'
35-
},
36-
// Set the default extension for the root package, because otherwise the demo-app can't
37-
// be built within the production mode. Due to missing file extensions.
38-
'.': {
39-
defaultExtension: 'js'
40-
}
41-
};
42-
components.forEach(name => {
43-
packages[`@angular2-material/${name}`] = {
44-
format: 'cjs',
45-
main: `${name}.umd.js`
46-
};
47-
});
48-
49-
50-
////////////////////////////////////////////////////////////////////////////////////////////////
51-
/***********************************************************************************************
52-
* Everything underneath this line is managed by the CLI.
53-
**********************************************************************************************/
54-
const angularPackages = {
55-
// Angular specific barrels.
56-
'@angular/core': { main: 'bundles/core.umd.js'},
57-
'@angular/core/testing': { main: 'bundles/core-testing.umd.js'},
58-
'@angular/common': { main: 'bundles/common.umd.js'},
59-
'@angular/compiler': { main: 'bundles/compiler.umd.js'},
60-
'@angular/http': { main: 'bundles/http.umd.js'},
61-
'@angular/forms': { main: 'bundles/forms.umd.js'},
62-
'@angular/router': { main: 'bundles/router.umd.js'},
63-
'@angular/platform-browser': { main: 'bundles/platform-browser.umd.js'},
64-
'@angular/platform-browser-dynamic': { main: 'bundles/platform-browser-dynamic.umd.js'},
65-
'@angular/platform-browser-dynamic/testing': {
66-
main: 'bundles/platform-browser-dynamic-testing.umd.js'
67-
},
68-
};
69-
70-
const barrels: string[] = [
71-
// Thirdparty barrels.
72-
'rxjs',
73-
74-
// App specific barrels.
75-
'demo-app',
76-
'button-toggle',
77-
'gestures',
78-
'live-announcer',
79-
'portal',
80-
'overlay',
81-
...components
82-
/** @cli-barrel */
83-
];
84-
85-
const _cliSystemConfig: any = angularPackages;
86-
barrels.forEach((barrelName: string) => {
87-
_cliSystemConfig[barrelName] = { main: 'index' };
88-
});
89-
901
/** Type declaration for ambient System. */
912
declare var System: any;
923

934
// Apply the CLI SystemJS configuration.
945
System.config({
956
map: {
96-
'@angular': 'vendor/@angular',
977
'rxjs': 'vendor/rxjs',
98-
'main': 'main.js'
8+
'main': 'main.js',
9+
10+
// Angular specific mappings.
11+
'@angular/core': 'vendor/@angular/core/bundles/core.umd.js',
12+
'@angular/common': 'vendor/@angular/common/bundles/common.umd.js',
13+
'@angular/compiler': 'vendor/@angular/compiler/bundles/compiler.umd.js',
14+
'@angular/http': 'vendor/@angular/http/bundles/http.umd.js',
15+
'@angular/forms': 'vendor/@angular/forms/bundles/forms.umd.js',
16+
'@angular/router': 'vendor/@angular/router/bundles/router.umd.js',
17+
'@angular/platform-browser': 'vendor/@angular/platform-browser/bundles/platform-browser.umd.js',
18+
'@angular/platform-browser-dynamic':
19+
'vendor/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
9920
},
100-
packages: _cliSystemConfig
21+
packages: {
22+
// Thirdparty barrels.
23+
'rxjs': { main: 'index' },
24+
'@angular/material': {
25+
format: 'cjs',
26+
main: 'material.umd.js'
27+
},
28+
// Set the default extension for the root package, because otherwise the demo-app can't
29+
// be built within the production mode. Due to missing file extensions.
30+
'.': {
31+
defaultExtension: 'js'
32+
}
33+
}
10134
});
102-
103-
// Apply the user's configuration.
104-
System.config({ packages });

src/demo-app/tooltip/tooltip-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 {TooltipPosition} from '@angular2-material/tooltip';
2+
import {TooltipPosition} from '@angular/material';
33

44

55
@Component({

src/demo-app/tsconfig.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
"stripInternal": true,
1616
"baseUrl": "",
1717
"typeRoots": [
18-
"../../node_modules/@types",
19-
"../../node_modules"
18+
"../../node_modules/@types"
2019
],
2120
"paths": {
22-
"@angular2-material/*": [
23-
"../../dist/@angular2-material/*"
21+
"@angular/material": [
22+
"../../dist/@angular/material"
2423
]
2524
},
2625
"types": [

0 commit comments

Comments
 (0)