Skip to content

feat(@angular/cli): add flag to not delete output path #6186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.