-
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(custom-webpack): add extract-i18n builder (#832)
- Loading branch information
Showing
12 changed files
with
136 additions
and
60 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
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 |
---|---|---|
@@ -1,30 +1,7 @@ | ||
import { BuilderContext, createBuilder, targetFromTargetString } from '@angular-devkit/architect'; | ||
import { | ||
DevServerBuilderOptions, | ||
DevServerBuilderOutput, | ||
executeDevServerBuilder, | ||
} from '@angular-devkit/build-angular'; | ||
import { from, Observable } from 'rxjs'; | ||
import { switchMap } from 'rxjs/operators'; | ||
import { getTransforms } from '../common'; | ||
import { CustomWebpackSchema } from '../custom-webpack-schema'; | ||
import { createBuilder } from '@angular-devkit/architect'; | ||
import { DevServerBuilderOptions, executeDevServerBuilder } from '@angular-devkit/build-angular'; | ||
import { executeBrowserBasedBuilder } from '../generic-browser-builder'; | ||
|
||
export const serveCustomWebpackBrowser = ( | ||
options: DevServerBuilderOptions, | ||
context: BuilderContext | ||
): Observable<DevServerBuilderOutput> => { | ||
async function setup() { | ||
const browserTarget = targetFromTargetString(options.browserTarget); | ||
return (context.getTargetOptions(browserTarget) as unknown) as CustomWebpackSchema; | ||
} | ||
|
||
return from(setup()).pipe( | ||
switchMap(customWebpackOptions => | ||
executeDevServerBuilder(options, context, getTransforms(customWebpackOptions, context)) | ||
) | ||
); | ||
}; | ||
|
||
export default createBuilder<DevServerBuilderOptions, DevServerBuilderOutput>( | ||
serveCustomWebpackBrowser | ||
export default createBuilder<DevServerBuilderOptions>( | ||
executeBrowserBasedBuilder(executeDevServerBuilder) | ||
); |
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,10 @@ | ||
import { createBuilder } from '@angular-devkit/architect'; | ||
import { | ||
executeExtractI18nBuilder, | ||
ExtractI18nBuilderOptions, | ||
} from '@angular-devkit/build-angular'; | ||
import { executeBrowserBasedBuilder } from '../generic-browser-builder'; | ||
|
||
export default createBuilder<ExtractI18nBuilderOptions>( | ||
executeBrowserBasedBuilder(executeExtractI18nBuilder) | ||
); |
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,5 @@ | ||
{ | ||
"title": "Custom webpack extract-i18n schema for Build Facade", | ||
"id": "BuildCustomWebpackExtractI18nSchema", | ||
"description": "Extract i18n target options" | ||
} |
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,44 @@ | ||
import { | ||
BuilderContext, | ||
targetFromTargetString, | ||
BuilderHandlerFn, | ||
} from '@angular-devkit/architect'; | ||
import { ExecutionTransformer } from '@angular-devkit/build-angular'; | ||
import { IndexHtmlTransform } from '@angular-devkit/build-angular/src/angular-cli-files/utilities/index-file/write-index-html'; | ||
import { from } from 'rxjs'; | ||
import { switchMap } from 'rxjs/operators'; | ||
import { Configuration } from 'webpack'; | ||
import { CustomWebpackSchema } from './custom-webpack-schema'; | ||
import { getTransforms } from './transform-factories'; | ||
import { json } from '@angular-devkit/core'; | ||
|
||
export interface BrowserTargetOptions { | ||
browserTarget: string; | ||
} | ||
|
||
export type BuilderExecutor<O extends BrowserTargetOptions & json.JsonObject> = ( | ||
options: O, | ||
context: BuilderContext, | ||
transforms?: { | ||
webpackConfiguration?: ExecutionTransformer<Configuration>; | ||
indexHtml?: IndexHtmlTransform; | ||
} | ||
) => any; | ||
|
||
export const executeBrowserBasedBuilder = <O extends BrowserTargetOptions & json.JsonObject>( | ||
executebBuilder: BuilderExecutor<O> | ||
): BuilderHandlerFn<O> => ( | ||
options: O, | ||
context: BuilderContext | ||
): ReturnType<typeof executebBuilder> => { | ||
async function setup() { | ||
const browserTarget = targetFromTargetString(options.browserTarget); | ||
return (context.getTargetOptions(browserTarget) as unknown) as CustomWebpackSchema; | ||
} | ||
|
||
return from(setup()).pipe( | ||
switchMap(customWebpackOptions => | ||
executebBuilder(options, context, getTransforms(customWebpackOptions, context)) | ||
) | ||
); | ||
}; |
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
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
9 changes: 5 additions & 4 deletions
9
packages/custom-webpack/src/common.ts → ...custom-webpack/src/transform-factories.ts
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