-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(igx-ts,ng-update): attempt to migrate summaries operand change …
…from #425
- Loading branch information
1 parent
dc136d2
commit ba84705
Showing
3 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import * as path from "path"; | ||
|
||
// tslint:disable:no-implicit-dependencies | ||
import { EmptyTree } from "@angular-devkit/schematics"; | ||
// tslint:disable-next-line:no-submodule-imports | ||
import { SchematicTestRunner, UnitTestTree } from "@angular-devkit/schematics/testing"; | ||
|
||
describe("Update 3.2.0", () => { | ||
let appTree: UnitTestTree; | ||
const schematicRunner = new SchematicTestRunner("ig-migrate", path.join(__dirname, "../migration-collection.json")); | ||
const configJson = { | ||
defaultProject: "testProj", | ||
projects: { | ||
testProj: { | ||
sourceRoot: "/src" | ||
} | ||
} | ||
}; | ||
|
||
beforeEach(() => { | ||
appTree = new UnitTestTree(new EmptyTree()); | ||
appTree.create("/angular.json", JSON.stringify(configJson)); | ||
}); | ||
|
||
it("should update CustomDateSummary summaryResult assignment", done => { | ||
const summaryFile = "/src/app/grid-summaries/grid-summaries.component.ts"; | ||
appTree.create(summaryFile, | ||
`class CustomDateSummary extends IgxDateSummaryOperand { | ||
constructor() { | ||
super(); | ||
} | ||
public operate(data?: any[]): IgxSummaryResult[] { | ||
const result = []; | ||
result.push({ | ||
key: 'earliest', | ||
label: 'Earliest Date', | ||
summaryResult: (IgxDateSummaryOperand.earliest(data)).toLocaleDateString() | ||
}); | ||
result.push({ | ||
key: 'latest', | ||
label: 'Latest Date', | ||
summaryResult: (IgxDateSummaryOperand.latest(data)).toLocaleDateString() | ||
}); | ||
return result; | ||
} | ||
}` | ||
); | ||
|
||
schematicRunner.runSchematic("migration-03", {}, appTree); | ||
expect(appTree.readContent(summaryFile)) | ||
.toEqual( | ||
`class CustomDateSummary extends IgxDateSummaryOperand { | ||
constructor() { | ||
super(); | ||
} | ||
public operate(data?: any[]): IgxSummaryResult[] { | ||
const result = []; | ||
result.push({ | ||
key: 'earliest', | ||
label: 'Earliest Date', | ||
summaryResult: data.length ? (IgxDateSummaryOperand.earliest(data)).toLocaleDateString() : null | ||
}); | ||
result.push({ | ||
key: 'latest', | ||
label: 'Latest Date', | ||
summaryResult: data.length ? (IgxDateSummaryOperand.latest(data)).toLocaleDateString() : null | ||
}); | ||
return result; | ||
} | ||
}` | ||
); | ||
done(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// tslint:disable:no-implicit-dependencies | ||
import { Rule, SchematicContext, Tree } from "@angular-devkit/schematics"; | ||
// tslint:disable-next-line:no-submodule-imports | ||
import { getWorkspace } from "@schematics/angular/utility/config"; | ||
|
||
const summaryEarliestAssignment = | ||
`summaryResult: (IgxDateSummaryOperand.earliest(data)).toLocaleDateString()`; | ||
const summaryEarliestReplacement = | ||
`summaryResult: data.length ? (IgxDateSummaryOperand.earliest(data)).toLocaleDateString() : null`; | ||
|
||
const summaryLatestAssignment = | ||
`summaryResult: (IgxDateSummaryOperand.latest(data)).toLocaleDateString()`; | ||
const summaryLatestReplacement = | ||
`summaryResult: data.length ? (IgxDateSummaryOperand.latest(data)).toLocaleDateString() : null`; | ||
|
||
export default function(): Rule { | ||
return (host: Tree, context: SchematicContext) => { | ||
const workspace = getWorkspace(host); | ||
const project = workspace.defaultProject ? | ||
workspace.projects[workspace.defaultProject] : | ||
workspace.projects[0]; | ||
|
||
const sourceDir = host.getDir(project.sourceRoot || "./src"); | ||
const ext = ".ts"; | ||
|
||
context.logger.info(`Applying migration for Ignite UI CLI 3.2.0 related to custom IgxSummaryOperand.`); | ||
context.logger.info(`See https://github.com/IgniteUI/igniteui-angular/issues/3414`); | ||
|
||
sourceDir.visit((path, entry) => { | ||
if (path.endsWith(ext)) { | ||
let content = entry.content.toString(); | ||
if (content.indexOf(summaryEarliestAssignment) !== -1) { | ||
content = content.replace(summaryEarliestAssignment, summaryEarliestReplacement); | ||
host.overwrite(path, content); | ||
} | ||
if (content.indexOf(summaryLatestAssignment) !== -1) { | ||
content = content.replace(summaryLatestAssignment, summaryLatestReplacement); | ||
host.overwrite(path, content); | ||
} | ||
} | ||
}); | ||
}; | ||
} |