Skip to content

Commit

Permalink
feat(devkit): add builder as a library
Browse files Browse the repository at this point in the history
Recreate NgPackgrSchematics as a library.
Publish a rc version and point is as a LinkingTool builder.
  • Loading branch information
MaciejSikorski committed Jul 9, 2020
1 parent 780598c commit c199b5b
Show file tree
Hide file tree
Showing 36 changed files with 6,200 additions and 2,660 deletions.
48 changes: 46 additions & 2 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,10 @@
"prefix": "valueadd",
"architect": {
"build": {
"builder": "./libs/devkit/builders/build-ng-packagr-and-schematics:build",
"builder": "@valueadd/ng-packagr-schematics:build",
"options": {
"tsConfig": "libs/linking-tool/tsconfig.lib.json",
"tsConfigRuntime": "libs/linking-tool/tsconfig.lib.json",
"tsConfigSchematics": "libs/linking-tool/tsconfig.lib.json",
"project": "libs/linking-tool/ng-package.json"
}
},
Expand Down Expand Up @@ -252,6 +253,49 @@
}
},
"schematics": {}
},
"devkit-builders-ng-packagr-schematics": {
"root": "libs/devkit/builders/ng-packagr-schematics",
"sourceRoot": "libs/devkit/builders/ng-packagr-schematics/src",
"projectType": "library",
"schematics": {},
"architect": {
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"libs/devkit/builders/ng-packagr-schematics/tsconfig.lib.json",
"libs/devkit/builders/ng-packagr-schematics/tsconfig.spec.json"
],
"exclude": ["**/node_modules/**", "!libs/devkit/builders/ng-packagr-schematics/**"]
}
},
"test": {
"builder": "@nrwl/jest:jest",
"options": {
"jestConfig": "libs/devkit/builders/ng-packagr-schematics/jest.config.js",
"tsConfig": "libs/devkit/builders/ng-packagr-schematics/tsconfig.spec.json"
}
},
"build": {
"builder": "@nrwl/node:package",
"options": {
"outputPath": "dist/libs/devkit/builders/ng-packagr-schematics",
"tsConfig": "libs/devkit/builders/ng-packagr-schematics/tsconfig.lib.json",
"packageJson": "libs/devkit/builders/ng-packagr-schematics/package.json",
"main": "libs/devkit/builders/ng-packagr-schematics/src/index.ts",
"assets": [
"libs/devkit/builders/ng-packagr-schematics/*.md",
"libs/devkit/builders/ng-packagr-schematics/builders.json",
{
"glob": "schema.json",
"input": "libs/devkit/builders/ng-packagr-schematics/src/lib/build/",
"output": "lib/build"
}
]
}
}
}
}
},
"cli": {
Expand Down
10 changes: 10 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
transform: {
'^.+\\.(ts|js|html)$': 'ts-jest'
},
resolver: '@nrwl/jest/plugins/resolver',
moduleFileExtensions: ['ts', 'js', 'html'],
coverageReporters: ['html'],
passWithNoTests: true
};

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

7 changes: 7 additions & 0 deletions libs/devkit/builders/ng-packagr-schematics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# devkit-builders-ng-packagr-schematics

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `ng test devkit-builders-ng-packagr-schematics` to execute the unit tests via [Jest](https://jestjs.io).
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"$schema": "http://json-schema.org/schema",
"builders": {
"build": {
"implementation": "./src/build/index",
"schema": "./src/build/schema.json",
"implementation": "./lib/build/index",
"schema": "./lib/build/schema.json",
"description": "Build a library with ng-packagr."
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = {
name: 'devkit-builders-build-ng-packagr-and-schematics',
name: 'devkit-builders-ng-packagr-schematics',
preset: '../../../../jest.config.js',
transform: {
'^.+\\.[tj]sx?$': 'ts-jest'
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
coverageDirectory: '../../../../coverage/libs/devkit/builders/build-ng-packagr-and-schematics'
coverageDirectory: '../../../../coverage/libs/devkit/builders/ng-packagr-schematics'
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@valueadd-devkit/build-ng-packagr-and-schematics",
"version": "0.0.0",
"name": "@valueadd/ng-packagr-schematics",
"version": "0.0.0-rc1",
"description": "ng-packagr builder with support for schematics inside library",
"experimental": true,
"main": "src/index.js",
Expand All @@ -11,21 +11,21 @@
},
"repository": {
"type": "git",
"url": "https://github.com/valueadd-poland/valueadd/tree/master/libs/devkit/builders/build-ng-packagr-and-schematics"
"url": "https://github.com/valueadd-poland/valueadd/tree/master/libs/devkit/builders/ng-packagr-schematics"
},
"author": "ValueAdd sp. z o.o",
"license": "MIT",
"dependencies": {
"@angular-devkit/architect": "0.0.0",
"@angular-devkit/architect": "^0.1000.0",
"rxjs": "6.5.3"
},
"peerDependencies": {
"ng-packagr": "^4.0.0 || ^5.0.0"
},
"devDependencies": {
"@angular-devkit/core": "^10.0.0",
"@angular/compiler": "9.0.0-next.10",
"@angular/compiler-cli": "9.0.0-next.10",
"@angular-devkit/core": "0.0.0",
"ng-packagr": "~5.6.0",
"tslib": "^1.10.0"
}
Expand Down
1 change: 1 addition & 0 deletions libs/devkit/builders/ng-packagr-schematics/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/build';
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface Builder {
build(): Promise<void>;

watch(): Promise<void>;
}
29 changes: 29 additions & 0 deletions libs/devkit/builders/ng-packagr-schematics/src/lib/build/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { BuilderContext, BuilderOutput, createBuilder } from '@angular-devkit/architect';
import { combineLatest, from, Observable } from 'rxjs';
import { last, mapTo, switchMap } from 'rxjs/operators';
import { initialize as initializeNgPackagrBuilder } from './ng-packagr-build';
import { initialize as initializeSchematicsBuilder } from './schematics.build';
import { JsonObject } from '@angular-devkit/core';

interface Options extends JsonObject {
project: string;
tsConfigRuntime: string;
tsConfigSchematics: string;
watch?: boolean;
}

export function execute(options: Options, context: BuilderContext): Observable<BuilderOutput> {
return combineLatest([
from(
initializeNgPackagrBuilder(
{ ...options, tsConfig: options.tsConfigRuntime },
context.workspaceRoot
)
).pipe(switchMap(packager => (options.watch ? packager.watch() : packager.build()))),
from(initializeSchematicsBuilder(options, context.workspaceRoot)).pipe(
switchMap(builder => (options.watch ? builder.watch() : builder.build()))
)
]).pipe(last(), mapTo({ success: true }));
}

export default createBuilder(execute);
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
"type": "string",
"description": "The file path for the ng-packagr configuration file, relative to the current workspace."
},
"tsConfig": {
"tsConfigRuntime": {
"type": "string",
"description": "The full path for the TypeScript configuration file, relative to the current workspace."
},
"tsConfigSchematics": {
"type": "string",
"description": "The full path for the TypeScript configuration file, relative to the current workspace."
},
Expand Down
Loading

0 comments on commit c199b5b

Please sign in to comment.