1
1
import {
2
- BuilderContext ,
3
2
createBuilder ,
4
- targetFromTargetString
3
+ targetFromTargetString ,
5
4
} from '@angular-devkit/architect' ;
6
- import {
7
- ExecutionTransformer ,
8
- executeDevServerBuilder
9
- } from '@angular-devkit/build-angular' ;
10
- import {
5
+ import type { BuilderContext } from '@angular-devkit/architect' ;
6
+ import { executeDevServerBuilder } from '@angular-devkit/build-angular' ;
7
+ import type { ExecutionTransformer } from '@angular-devkit/build-angular' ;
8
+ import type {
11
9
DevServerBuilderOptions ,
12
- DevServerBuilderOutput
10
+ DevServerBuilderOutput ,
13
11
} from '@angular-devkit/build-angular/src/dev-server' ;
14
- import { IndexHtmlTransform } from '@angular-devkit/build-angular/src/utils/index-file/write- index-html' ;
12
+ import type { IndexHtmlTransform } from '@angular-devkit/build-angular/src/utils/index-file/index-html-generator ' ;
15
13
import { ScriptsWebpackPlugin } from '@angular-devkit/build-angular/src/webpack/plugins' ;
16
- import { json } from '@angular-devkit/core' ;
14
+ import type { json } from '@angular-devkit/core' ;
17
15
import * as CopyWebpackPlugin from 'copy-webpack-plugin' ;
18
16
import { basename } from 'path' ;
19
- import { Observable , from } from 'rxjs' ;
17
+ import { from } from 'rxjs' ;
18
+ import type { Observable } from 'rxjs' ;
20
19
import { switchMap } from 'rxjs/operators' ;
21
- import { Configuration } from 'webpack' ;
20
+ import type { Configuration } from 'webpack' ;
22
21
23
- import { FormattedAssets , prepareServerConfig } from '../utils' ;
22
+ import { prepareServerConfig } from '../utils' ;
23
+ import type { FormattedAssets } from '../utils' ;
24
24
import { augmentIndexHtml } from '../utils/append-scripts' ;
25
25
26
26
import { createConsoleLogServer } from './log-server' ;
27
- import { CordovaServeBuilderSchema } from './schema' ;
27
+ import type { CordovaServeBuilderSchema } from './schema' ;
28
28
29
29
export type CordovaDevServerBuilderOptions = CordovaServeBuilderSchema &
30
30
json . JsonObject ;
31
31
32
32
export function serveCordova (
33
33
options : CordovaServeBuilderSchema ,
34
- context : BuilderContext
34
+ context : BuilderContext ,
35
35
) : Observable < DevServerBuilderOutput > {
36
36
const { devServerTarget, port, host, ssl } = options ;
37
37
const root = context . workspaceRoot ;
38
38
const devServerTargetSpec = targetFromTargetString ( devServerTarget ) ;
39
39
40
40
async function setup ( ) {
41
- const devServerTargetOptions = ( await context . getTargetOptions ( devServerTargetSpec ) ) as DevServerBuilderOptions ;
42
- const devServerName = await context . getBuilderNameForTarget ( devServerTargetSpec ) ;
41
+ const devServerTargetOptions = ( await context . getTargetOptions (
42
+ devServerTargetSpec ,
43
+ ) ) as DevServerBuilderOptions ;
44
+ const devServerName = await context . getBuilderNameForTarget (
45
+ devServerTargetSpec ,
46
+ ) ;
43
47
44
48
devServerTargetOptions . port = port ;
45
49
devServerTargetOptions . host = host ;
46
50
devServerTargetOptions . ssl = ssl ;
47
51
// tslint:disable-next-line: no-unnecessary-type-assertion
48
- const formattedOptions = await context . validateOptions ( devServerTargetOptions , devServerName ) as DevServerBuilderOptions ;
52
+ const formattedOptions = ( await context . validateOptions (
53
+ devServerTargetOptions ,
54
+ devServerName ,
55
+ ) ) as DevServerBuilderOptions ;
49
56
const formattedAssets = prepareServerConfig ( options , root ) ;
50
57
if ( options . consolelogs && options . consolelogsPort ) {
51
58
await createConsoleLogServer ( host , options . consolelogsPort ) ;
@@ -58,14 +65,17 @@ export function serveCordova(
58
65
executeDevServerBuilder (
59
66
formattedOptions ,
60
67
context ,
61
- getTransforms ( formattedAssets , context )
62
- )
63
- )
68
+ getTransforms ( formattedAssets , context ) ,
69
+ ) ,
70
+ ) ,
64
71
) ;
65
72
}
66
73
export default createBuilder < CordovaDevServerBuilderOptions , any > ( serveCordova ) ;
67
74
68
- function getTransforms ( formattedAssets : FormattedAssets , context : BuilderContext ) {
75
+ function getTransforms (
76
+ formattedAssets : FormattedAssets ,
77
+ context : BuilderContext ,
78
+ ) {
69
79
return {
70
80
webpackConfiguration : cordovaServeTransform ( formattedAssets , context ) ,
71
81
indexHtml : indexHtmlTransformFactory ( formattedAssets , context ) ,
@@ -74,10 +84,10 @@ function getTransforms(formattedAssets: FormattedAssets, context: BuilderContext
74
84
75
85
const cordovaServeTransform : (
76
86
formattedAssets : FormattedAssets ,
77
- context : BuilderContext
87
+ context : BuilderContext ,
78
88
) => ExecutionTransformer < Configuration > = (
79
89
formattedAssets ,
80
- { workspaceRoot }
90
+ { workspaceRoot } ,
81
91
) => browserWebpackConfig => {
82
92
const scriptExtras = formattedAssets . globalScriptsByBundleName . map (
83
93
( script : { bundleName : any ; paths : any } ) => {
@@ -89,30 +99,30 @@ const cordovaServeTransform: (
89
99
scripts : script . paths ,
90
100
basePath : workspaceRoot ,
91
101
} ) ;
92
- }
102
+ } ,
93
103
) ;
94
104
95
105
const copyWebpackPluginInstance = new CopyWebpackPlugin ( {
96
- patterns : formattedAssets . copyWebpackPluginPatterns ,
106
+ patterns : formattedAssets . copyWebpackPluginPatterns ,
97
107
} ) ;
98
108
99
- // tslint: disable-next-line: no-non-null-assertion
109
+ // eslint- disable-next-line @typescript-eslint/ no-non-null-assertion
100
110
browserWebpackConfig . plugins ! . push (
101
111
...scriptExtras ,
102
- copyWebpackPluginInstance
112
+ copyWebpackPluginInstance ,
103
113
) ;
104
114
return browserWebpackConfig ;
105
115
} ;
106
116
107
117
export const indexHtmlTransformFactory : (
108
118
formattedAssets : FormattedAssets ,
109
- context : BuilderContext
119
+ context : BuilderContext ,
110
120
) => IndexHtmlTransform = ( { globalScriptsByBundleName } ) => (
111
- indexTransform : string
121
+ indexTransform : string ,
112
122
) => {
113
123
const augmentedHtml = augmentIndexHtml (
114
124
indexTransform ,
115
- globalScriptsByBundleName
125
+ globalScriptsByBundleName ,
116
126
) ;
117
127
return Promise . resolve ( augmentedHtml ) ;
118
128
} ;
0 commit comments