Skip to content

Commit

Permalink
feat(schematics): migration rule for imports
Browse files Browse the repository at this point in the history
  • Loading branch information
pimenovoleg committed Apr 19, 2020
1 parent f0f346b commit 605b6da
Show file tree
Hide file tree
Showing 47 changed files with 1,088 additions and 580 deletions.
17 changes: 16 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@
"options": {
"buildTarget": "packagr",
"versionPlaceholder": "{{VERSION}}",
"ngVersionPlaceholder": "{{NG_VERSION}}"
"ngVersionPlaceholder": "{{NG_VERSION}}",
"additionalTargets": ["schematics:build"]
}
},
"test": {
Expand Down Expand Up @@ -264,6 +265,20 @@
}
}
},
"schematics": {
"projectType": "library",
"root": "packages/mosaic/schematics",
"sourceRoot": "packages/mosaic/schematics",
"architect": {
"build": {
"builder": "@ptsecurity/builders:typescript",
"options": {
"tsConfig": "packages/mosaic/schematics/tsconfig.lib.json",
"outDir": "dist/mosaic/schematics"
}
}
}
},
"dev-alert": {
"projectType": "application",
"root": "packages/mosaic-dev/alert",
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"requiredAngularVersion": ">=9.0.0",
"dependencies": {
"@angular/animations": "^9.1.0",
"@angular/cdk": "^9.1.0",
"@angular/cdk": "^9.2.1",
"@angular/common": "^9.1.0",
"@angular/compiler": "^9.1.0",
"@angular/core": "^9.1.0",
Expand All @@ -31,9 +31,9 @@
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.901.0",
"@angular-devkit/build-ng-packagr": "^0.901.0",
"@angular-devkit/build-ng-packagr": "^0.901.1",
"@angular-devkit/core": "^9.1.0",
"@angular-devkit/schematics": "^9.1.0",
"@angular-devkit/schematics": "^9.1.1",
"@angular/cli": "^9.1.0",
"@angular/compiler-cli": "^9.1.0",
"@angular/platform-browser-dynamic": "^9.1.0",
Expand All @@ -44,7 +44,7 @@
"@octokit/rest": "^16.2.0",
"@ptsecurity/commitlint-config": "^1.0.0",
"@ptsecurity/tslint-config": "^0.13.1",
"@schematics/angular": "^8.2.1",
"@schematics/angular": "^9.1.1",
"@types/chalk": "^2.2.0",
"@types/fs-extra": "^5.0.4",
"@types/glob": "^5.0.36",
Expand All @@ -64,6 +64,7 @@
"fs-extra": "^5.0.0",
"glob": "^7.1.3",
"gulp": "^4.0.0",
"gulp-clean": "^0.4.0",
"gulp-clean-css": "^3.10.0",
"gulp-cli": "^2.0.1",
"gulp-flatten": "^0.3.1",
Expand Down Expand Up @@ -106,7 +107,7 @@
"ts-node": "^7.0.1",
"tsconfig-paths": "^3.9.0",
"tsickle": "0.38.1",
"tslint": "^5.18.0",
"tslint": "^5.20.1",
"typescript": "~3.8.3",
"typescript-tslint-plugin": "^0.5.5",
"wallaby-webpack": "^3.9.13",
Expand Down
2 changes: 1 addition & 1 deletion packages/mosaic/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ module.exports = function(config) {
config.set({
coverageIstanbulReporter: {
dir: `${config.coverageIstanbulReporter.dir}/mosaic`
},
}
});
};
8 changes: 7 additions & 1 deletion packages/mosaic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,11 @@
"@ptsecurity/mosaic-icons": "^3.0.0",
"tslib": "^1.7.1"
},
"schematics": "./schematics/collection.json"
"schematics": "./schematics/collection.json",
"ng-update": {
"migrations": "./schematics/migration.json",
"packageGroup": [
"@ptsecurity/mosaic"
]
}
}
34 changes: 34 additions & 0 deletions packages/mosaic/schematics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Mosaic schematics

## ng update

The angular cli provides an interface to run automatic update scripts with
`ng update` for library authors. To achieve this we are using the
`collection.json` file to specify the schematics that need to run for each
version individually.

### Testing

There are tests for the update schematics that create a virtual demo app that is
used to check whether the schematic changes the correct things.

If you want to test the schematic on a real world app you should perform the
following steps:

- Run `ng build` - this builds the library including the schematics and puts it
into the `dist/mosaic` folder
- Link the npm dependency of the `@ptsecurity/mosaic` to the
`dist/mosaic` folder
- run
`ng update @ptsecurity/mosaic --migrateOnly=true --from="8.0.0" --to="9.0.0"`
with the correct versions respectively

## ng add

The ng-add schematics is used to add the **mosaic components** to a new angular
project with all its dependencies

### Testing

To run the unit tests with jest you can leverage the angular CLI with:
`ng test schematics` or in the watch mode `ng test schematics --watch`
19 changes: 1 addition & 18 deletions packages/mosaic/schematics/collection.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
// This is the root config file where the schematics are defined.
{
"$schema": "./node_modules/@angular-devkit/schematics/collection-schema.json",
"$schema": "../../../node_modules/@angular-devkit/schematics/collection-schema.json",
"schematics": {
// Adds Mosaic to an application without changing any templates
"ng-add": {
"description": "Adds Mosaic to the application without affecting any templates",
"factory": "./ng-add/index",
"schema": "./ng-add/schema.json",
"aliases": [
"mosaic-shell",
"install"
]
},
"ng-add-setup-project": {
"description": "Sets up the specified project after the ng-add dependencies have been installed.",
"private": true,
"factory": "./ng-add/setup-project",
"schema": "./ng-add/schema.json"
}
}
}
10 changes: 10 additions & 0 deletions packages/mosaic/schematics/migration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "../../../node_modules/@angular-devkit/schematics/collection-schema.json",
"schematics": {
"update-9.0.0": {
"version": "9.0.0",
"description": "Updates Mosaic to 9.0.0",
"factory": "./ng-update/index#updateToV9"
}
}
}
17 changes: 0 additions & 17 deletions packages/mosaic/schematics/ng-add/fonts/roboto-fonts.ts

This file was deleted.

27 changes: 0 additions & 27 deletions packages/mosaic/schematics/ng-add/index.ts

This file was deleted.

45 changes: 0 additions & 45 deletions packages/mosaic/schematics/ng-add/package-config.ts

This file was deleted.

45 changes: 0 additions & 45 deletions packages/mosaic/schematics/ng-add/schema.json

This file was deleted.

14 changes: 0 additions & 14 deletions packages/mosaic/schematics/ng-add/schema.ts

This file was deleted.

Loading

0 comments on commit 605b6da

Please sign in to comment.