File tree Expand file tree Collapse file tree 6 files changed +35
-14
lines changed Expand file tree Collapse file tree 6 files changed +35
-14
lines changed Original file line number Diff line number Diff line change @@ -118,6 +118,13 @@ export const baseBuildCommandOptions: any = [
118118 type : String ,
119119 aliases : [ 'a' ] ,
120120 description : 'Specifies app name or index to use.'
121+ } ,
122+ {
123+ name : 'delete-output-path' ,
124+ type : Boolean ,
125+ default : true ,
126+ aliases : [ 'dop' ] ,
127+ description : 'Delete output path before build.'
121128 }
122129] ;
123130
Original file line number Diff line number Diff line change @@ -17,5 +17,5 @@ export interface BuildOptions {
1717 outputHashing ?: string ;
1818 poll ?: number ;
1919 app ?: string ;
20-
20+ deleteOutputPath ?: boolean ;
2121}
Original file line number Diff line number Diff line change @@ -27,7 +27,9 @@ export default Task.extend({
2727 if ( config . project && config . project . ejected ) {
2828 throw new SilentError ( 'An ejected project cannot use the build command anymore.' ) ;
2929 }
30- rimraf . sync ( path . resolve ( project . root , outputPath ) ) ;
30+ if ( runTaskOptions . deleteOutputPath ) {
31+ rimraf . sync ( path . resolve ( project . root , outputPath ) ) ;
32+ }
3133
3234 const webpackConfig = new NgCliWebpackConfig ( runTaskOptions , app ) . buildConfig ( ) ;
3335 const webpackCompiler = webpack ( webpackConfig ) ;
Original file line number Diff line number Diff line change @@ -31,7 +31,9 @@ export default Task.extend({
3131 if ( projectConfig . project && projectConfig . project . ejected ) {
3232 throw new SilentError ( 'An ejected project cannot use the build command anymore.' ) ;
3333 }
34- rimraf . sync ( path . resolve ( this . project . root , outputPath ) ) ;
34+ if ( serveTaskOptions . deleteOutputPath ) {
35+ rimraf . sync ( path . resolve ( this . project . root , outputPath ) ) ;
36+ }
3537
3638 const serveDefaults = {
3739 // default deployUrl to '' on serve to prevent the default from .angular-cli.json
Original file line number Diff line number Diff line change 1+ import { ng } from '../../utils/process' ;
2+ import { expectToFail } from '../../utils/utils' ;
3+ import { deleteFile , expectFileToExist } from '../../utils/fs' ;
4+ import { getGlobalVariable } from '../../utils/env' ;
5+
6+ export default function ( ) {
7+ // Skip this in ejected tests.
8+ if ( getGlobalVariable ( 'argv' ) . eject ) {
9+ return Promise . resolve ( ) ;
10+ }
11+
12+ return ng ( 'build' )
13+ // This is supposed to fail since there's a missing file
14+ . then ( ( ) => deleteFile ( 'src/app/app.component.ts' ) )
15+ // The build fails but we don't delete the output of the previous build.
16+ . then ( ( ) => expectToFail ( ( ) => ng ( 'build' , '--no-delete-output-path' ) ) )
17+ . then ( ( ) => expectFileToExist ( 'dist' ) )
18+ // By default, output path is always cleared.
19+ . then ( ( ) => expectToFail ( ( ) => ng ( 'build' ) ) )
20+ . then ( ( ) => expectToFail ( ( ) => expectFileToExist ( 'dist' ) ) ) ;
21+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments