@@ -3,14 +3,11 @@ import {
3
3
Rule ,
4
4
externalSchematic ,
5
5
} from '@angular-devkit/schematics' ;
6
- import {
7
- updateWorkspace ,
8
- } from '@nrwl/workspace' ;
9
6
10
7
import { spawn } from 'cross-spawn' ;
11
8
import * as path from 'path' ;
12
9
13
- import { createConfig } from '../../create-config' ;
10
+ import { createConfig } from '../../utils/ create-config' ;
14
11
import { prodConfig } from './prod-config' ;
15
12
import { MfSchematicSchema } from './schema' ;
16
13
@@ -50,6 +47,25 @@ export function add(options: MfSchematicSchema): Rule {
50
47
return config ( options ) ;
51
48
}
52
49
50
+
51
+ function makeMainAsync ( main : string ) : Rule {
52
+ return async function ( tree , context ) {
53
+
54
+ const mainPath = path . dirname ( main ) ;
55
+ const bootstrapName = path . join ( mainPath , 'bootstrap.ts' ) ;
56
+
57
+ if ( tree . exists ( bootstrapName ) ) {
58
+ console . info ( `${ bootstrapName } already exists.` ) ;
59
+ return ;
60
+ }
61
+
62
+ const mainContent = tree . read ( main ) ;
63
+ tree . create ( bootstrapName , mainContent ) ;
64
+ tree . overwrite ( main , "import('./bootstrap');" )
65
+
66
+ }
67
+ }
68
+
53
69
export default function config ( options : MfSchematicSchema ) : Rule {
54
70
55
71
return async function ( tree ) {
@@ -77,12 +93,21 @@ export default function config (options: MfSchematicSchema): Rule {
77
93
const configPath = path . join ( projectRoot , 'webpack.config.js' ) . replace ( / \\ / g, '/' ) ;
78
94
const configProdPath = path . join ( projectRoot , 'webpack.prod.config.js' ) . replace ( / \\ / g, '/' ) ;
79
95
const port = parseInt ( options . port ) ;
96
+ const main = projectConfig . architect . build . options . main ;
97
+
98
+ const relWorkspaceRoot = path . relative ( projectRoot , '' ) ;
99
+ const tsConfigName = tree . exists ( 'tsconfig.base.json' ) ?
100
+ 'tsconfig.base.json' : 'tsconfig.json' ;
101
+
102
+ const relTsConfigPath = path
103
+ . join ( relWorkspaceRoot , tsConfigName )
104
+ . replace ( / \\ / g, '/' ) ;
80
105
81
106
if ( isNaN ( port ) ) {
82
107
throw new Error ( `Port must be a number!` ) ;
83
108
}
84
109
85
- const webpackConfig = createConfig ( projectName , projectRoot , port ) ;
110
+ const webpackConfig = createConfig ( projectName , relTsConfigPath , projectRoot , port ) ;
86
111
87
112
tree . create ( configPath , webpackConfig ) ;
88
113
tree . create ( configProdPath , prodConfig ) ;
@@ -97,6 +122,7 @@ export default function config (options: MfSchematicSchema): Rule {
97
122
tree . overwrite ( 'angular.json' , JSON . stringify ( workspace , null , '\t' ) ) ;
98
123
99
124
return chain ( [
125
+ makeMainAsync ( main ) ,
100
126
externalSchematic ( 'ngx-build-plus' , 'ng-add' , { project : options . project } ) ,
101
127
// updateWorkspace((workspace) => {
102
128
// const proj = workspace.projects.get(options.project);
0 commit comments