Skip to content

cleanup: migrate migration tool to schematics #10736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 11, 2018
Merged
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
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ filegroup(
"rxjs",
"tsickle",
"tslib",
"tslint",
"tsutils",
"typescript",
"zone.js",
Expand Down
31 changes: 13 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular-devkit/core": "^0.4.5",
"@angular-devkit/schematics": "^0.4.5",
"@angular-devkit/core": "^0.5.5",
"@angular-devkit/schematics": "^0.5.5",
"@angular/bazel": "6.0.0-rc.3",
"@angular/compiler-cli": "6.0.0-rc.3",
"@angular/http": "6.0.0-rc.3",
Expand All @@ -51,7 +51,7 @@
"@angular/upgrade": "6.0.0-rc.3",
"@bazel/ibazel": "0.3.1",
"@google-cloud/storage": "^1.1.1",
"@schematics/angular": "^0.4.5",
"@schematics/angular": "^0.5.5",
"@types/chalk": "^0.4.31",
"@types/fs-extra": "^4.0.3",
"@types/glob": "^5.0.33",
Expand Down Expand Up @@ -104,8 +104,8 @@
"karma-firefox-launcher": "^1.0.1",
"karma-jasmine": "^1.1.0",
"karma-sauce-launcher": "^1.2.0",
"karma-spec-reporter": "^0.0.32",
"karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "^0.0.32",
"madge": "^2.2.0",
"magic-string": "^0.22.4",
"minimatch": "^3.0.4",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/schematics/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ npm_package(
name = "npm_package",
srcs = [
":collection.json",
] + glob(["**/files/**/*", "**/schema.json"]),
] + glob(["**/files/**/*", "**/data/**/*", "**/schema.json"]),
deps = [":schematics"],
)
17 changes: 17 additions & 0 deletions src/lib/schematics/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@
"schema": "./shell/schema.json",
"aliases": ["material-shell"]
},

// Group of schematics used to update Angular CDK and Angular Material.
"ng-update": {
"description": "Updates API usage for the most recent major version of Angular CDK and Angular Material",
"factory": "./update/update"
},
"ng-post-update": {
"description": "Performs cleanup after ng-update.",
"factory": "./update/update#postUpdate",
"private": true
},
"ng-post-post-update": {
"description": "Logs completion message for ng-update after ng-post-update.",
"factory": "./update/update#postPostUpdate",
"private": true
},

// Create a dashboard component
"materialDashboard": {
"description": "Create a card-based dashboard component",
Expand Down
15 changes: 15 additions & 0 deletions src/lib/schematics/update/material/color.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {bold, green, red} from 'chalk';

const colorFns = {
'b': bold,
'g': green,
'r': red,
};

export function color(message: string): string {
// 'r{{text}}' with red 'text', 'g{{text}}' with green 'text', and 'b{{text}}' with bold 'text'.
return message.replace(/(.)\{\{(.*?)\}\}/g, (m, fnName, text) => {
const fn = colorFns[fnName];
return fn ? fn(text) : text;
});
}
135 changes: 135 additions & 0 deletions src/lib/schematics/update/material/component-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
export interface MaterialExportAsNameData {
/** The exportAs name to replace. */
replace: string;
/** The new exportAs name. */
replaceWith: string;
}

export interface MaterialElementSelectorData {
/** The element name to replace. */
replace: string;
/** The new name for the element. */
replaceWith: string;
}

export interface MaterialCssNameData {
/** The CSS name to replace. */
replace: string;
/** The new CSS name. */
replaceWith: string;
/** Whitelist where this replacement is made. If omitted it is made in all files. */
whitelist: {
/** Replace this name in CSS files. */
css?: boolean,
/** Replace this name in HTML files. */
html?: boolean,
/** Replace this name in TypeScript strings. */
strings?: boolean
}
}

export interface MaterialAttributeSelectorData {
/** The attribute name to replace. */
replace: string;
/** The new name for the attribute. */
replaceWith: string;
}

export interface MaterialPropertyNameData {
/** The property name to replace. */
replace: string;
/** The new name for the property. */
replaceWith: string;
/** Whitelist where this replacement is made. If omitted it is made for all Classes. */
whitelist: {
/** Replace the property only when its type is one of the given Classes. */
classes?: string[];
}
}

export interface MaterialClassNameData {
/** The Class name to replace. */
replace: string;
/** The new name for the Class. */
replaceWith: string;
}

export interface MaterialInputNameData {
/** The @Input() name to replace. */
replace: string;
/** The new name for the @Input(). */
replaceWith: string;
/** Whitelist where this replacement is made. If omitted it is made in all HTML & CSS */
whitelist?: {
/** Limit to elements with any of these element tags. */
elements?: string[],
/** Limit to elements with any of these attributes. */
attributes?: string[],
/** Whether to ignore CSS attribute selectors when doing this replacement. */
css?: boolean,
}
}

export interface MaterialOutputNameData {
/** The @Output() name to replace. */
replace: string;
/** The new name for the @Output(). */
replaceWith: string;
/** Whitelist where this replacement is made. If omitted it is made in all HTML & CSS */
whitelist?: {
/** Limit to elements with any of these element tags. */
elements?: string[],
/** Limit to elements with any of these attributes. */
attributes?: string[],
/** Whether to ignore CSS attribute selectors when doing this replacement. */
css?: boolean,
}
}

export interface MaterialMethodCallData {
className: string;
method: string;
invalidArgCounts: {
count: number,
message: string
}[]
}

type Changes<T> = {
pr: string;
changes: T[]
}

function getChanges<T>(allChanges: Changes<T>[]): T[] {
return allChanges.reduce((result, changes) => result.concat(changes.changes), []);
}

/** Export the class name data as part of a module. This means that the data is cached. */
export const classNames = getChanges<MaterialClassNameData>(require('./data/class-names.json'));

/** Export the input names data as part of a module. This means that the data is cached. */
export const inputNames = getChanges<MaterialInputNameData>(require('./data/input-names.json'));

/** Export the output names data as part of a module. This means that the data is cached. */
export const outputNames = getChanges<MaterialOutputNameData>(require('./data/output-names.json'));

/** Export the element selectors data as part of a module. This means that the data is cached. */
export const elementSelectors =
getChanges<MaterialElementSelectorData>(require('./data/element-selectors.json'));

/** Export the attribute selectors data as part of a module. This means that the data is cached. */
export const exportAsNames =
getChanges<MaterialExportAsNameData>(require('./data/export-as-names.json'));

/** Export the attribute selectors data as part of a module. This means that the data is cached. */
export const attributeSelectors =
getChanges<MaterialAttributeSelectorData>(require('./data/attribute-selectors.json'));

/** Export the property names as part of a module. This means that the data is cached. */
export const propertyNames =
getChanges<MaterialPropertyNameData>(require('./data/property-names.json'));

export const methodCallChecks =
getChanges<MaterialMethodCallData>(require('./data/method-call-checks.json'));

export const cssNames = getChanges<MaterialCssNameData>(require('./data/css-names.json'));
15 changes: 15 additions & 0 deletions src/lib/schematics/update/material/data/attribute-selectors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
{
"pr": "https://github.com/angular/material2/pull/10257",
"changes": [
{
"replace": "cdkPortalHost",
"replaceWith": "cdkPortalOutlet"
},
{
"replace": "portalHost",
"replaceWith": "cdkPortalOutlet"
}
]
}
]
56 changes: 56 additions & 0 deletions src/lib/schematics/update/material/data/class-names.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[
{
"pr": "https://github.com/angular/material2/pull/10161",
"changes": [
{
"replace": "ConnectedOverlayDirective",
"replaceWith": "CdkConnectedOverlay"
},
{
"replace": "OverlayOrigin",
"replaceWith": "CdkOverlayOrigin"
}
]
},


{
"pr": "https://github.com/angular/material2/pull/10267",
"changes": [
{
"replace": "ObserveContent",
"replaceWith": "CdkObserveContent"
}
]
},


{
"pr": "https://github.com/angular/material2/pull/10291",
"changes": [
{
"replace": "FloatPlaceholderType",
"replaceWith": "FloatLabelType"
},
{
"replace": "MAT_PLACEHOLDER_GLOBAL_OPTIONS",
"replaceWith": "MAT_LABEL_GLOBAL_OPTIONS"
},
{
"replace": "PlaceholderOptions",
"replaceWith": "LabelOptions"
}
]
},


{
"pr": "https://github.com/angular/material2/pull/10325",
"changes": [
{
"replace": "FocusTrapDirective",
"replaceWith": "CdkTrapFocus"
}
]
}
]
Loading