Skip to content

Commit

Permalink
feat(@angular/cli): add flag to not delete output path
Browse files Browse the repository at this point in the history
Fix #5925
Fix #6193
  • Loading branch information
filipesilva committed May 8, 2017
1 parent d76d8fd commit 8bf040b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 14 deletions.
7 changes: 7 additions & 0 deletions packages/@angular/cli/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ export const baseBuildCommandOptions: any = [
type: String,
aliases: ['a'],
description: 'Specifies app name or index to use.'
},
{
name: 'delete-output-path',
type: Boolean,
default: true,
aliases: ['dop'],
description: 'Delete output path before build.'
}
];

Expand Down
2 changes: 1 addition & 1 deletion packages/@angular/cli/models/build-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ export interface BuildOptions {
outputHashing?: string;
poll?: number;
app?: string;

deleteOutputPath?: boolean;
}
4 changes: 3 additions & 1 deletion packages/@angular/cli/tasks/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export default Task.extend({
if (config.project && config.project.ejected) {
throw new SilentError('An ejected project cannot use the build command anymore.');
}
rimraf.sync(path.resolve(project.root, outputPath));
if (runTaskOptions.deleteOutputPath) {
rimraf.sync(path.resolve(project.root, outputPath));
}

const webpackConfig = new NgCliWebpackConfig(runTaskOptions, app).buildConfig();
const webpackCompiler = webpack(webpackConfig);
Expand Down
4 changes: 3 additions & 1 deletion packages/@angular/cli/tasks/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export default Task.extend({
if (projectConfig.project && projectConfig.project.ejected) {
throw new SilentError('An ejected project cannot use the build command anymore.');
}
rimraf.sync(path.resolve(this.project.root, outputPath));
if (serveTaskOptions.deleteOutputPath) {
rimraf.sync(path.resolve(this.project.root, outputPath));
}

const serveDefaults = {
// default deployUrl to '' on serve to prevent the default from .angular-cli.json
Expand Down
21 changes: 21 additions & 0 deletions tests/e2e/tests/build/delete-output-path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {ng} from '../../utils/process';
import {expectToFail} from '../../utils/utils';
import {deleteFile, expectFileToExist} from '../../utils/fs';
import {getGlobalVariable} from '../../utils/env';

export default function() {
// Skip this in ejected tests.
if (getGlobalVariable('argv').eject) {
return Promise.resolve();
}

return ng('build')
// This is supposed to fail since there's a missing file
.then(() => deleteFile('src/app/app.component.ts'))
// The build fails but we don't delete the output of the previous build.
.then(() => expectToFail(() => ng('build', '--no-delete-output-path')))
.then(() => expectFileToExist('dist'))
// By default, output path is always cleared.
.then(() => expectToFail(() => ng('build')))
.then(() => expectToFail(() => expectFileToExist('dist')));
}
11 changes: 0 additions & 11 deletions tests/e2e/tests/build/fail-build.ts

This file was deleted.

0 comments on commit 8bf040b

Please sign in to comment.