Skip to content

Commit a97be8a

Browse files
clydinhansl
authored andcommitted
refactor(@angular-devkit/schematics): adjust node-workflow rxjs usage
1 parent bc5a19a commit a97be8a

File tree

1 file changed

+42
-45
lines changed

1 file changed

+42
-45
lines changed

packages/angular_devkit/schematics/tools/workflow/node-workflow.ts

+42-45
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ import {
1616
formats,
1717
workflow,
1818
} from '@angular-devkit/schematics'; // tslint:disable-line:no-implicit-dependencies
19-
import { EMPTY, Observable, Subject, concat, of, throwError } from 'rxjs';
20-
import { reduce, tap } from 'rxjs/internal/operators';
21-
import { concatMap, ignoreElements, map } from 'rxjs/operators';
19+
import { Observable, Subject, concat, of, throwError } from 'rxjs';
20+
import { concatMap, defaultIfEmpty, ignoreElements, last, map, tap } from 'rxjs/operators';
2221
import { NodeModulesEngineHost, validateOptionsWithSchema } from '..';
2322
import { DryRunEvent } from '../../src/sink/dryrun';
2423
import { BuiltinTaskExecutor } from '../../tasks/node';
@@ -129,54 +128,52 @@ export class NodeWorkflow implements workflow.Workflow {
129128
};
130129
this._context.push(context);
131130

132-
return concat(
133-
schematic.call(options.options, of(new HostTree(this._host)), {
134-
logger: context.logger,
135-
}).pipe(
136-
map(tree => Tree.optimize(tree)),
137-
concatMap((tree: Tree) => {
138-
return concat(
139-
dryRunSink.commit(tree).pipe(
140-
ignoreElements(),
141-
),
142-
of(tree),
143-
);
144-
}),
145-
concatMap((tree: Tree) => {
146-
dryRunSubscriber.unsubscribe();
147-
if (error) {
148-
return throwError(new UnsuccessfulWorkflowExecution());
149-
}
150-
if (this._options.dryRun) {
151-
return EMPTY;
152-
}
153-
154-
return fsSink.commit(tree);
155-
}),
156-
),
157-
concat(new Observable<void>(obs => {
158-
if (!this._options.dryRun) {
159-
this._lifeCycle.next({ kind: 'post-tasks-start' });
160-
this._engine.executePostTasks()
161-
.pipe(
162-
reduce(() => {}),
163-
tap(() => this._lifeCycle.next({ kind: 'post-tasks-end' })),
164-
)
165-
.subscribe(obs);
166-
} else {
167-
obs.complete();
131+
return schematic.call(
132+
options.options,
133+
of(new HostTree(this._host)),
134+
{ logger: context.logger },
135+
).pipe(
136+
map(tree => Tree.optimize(tree)),
137+
concatMap((tree: Tree) => {
138+
return concat(
139+
dryRunSink.commit(tree).pipe(ignoreElements()),
140+
of(tree),
141+
);
142+
}),
143+
concatMap((tree: Tree) => {
144+
dryRunSubscriber.unsubscribe();
145+
if (error) {
146+
return throwError(new UnsuccessfulWorkflowExecution());
147+
}
148+
149+
if (this._options.dryRun) {
150+
return of();
151+
}
152+
153+
return fsSink.commit(tree).pipe(last(), defaultIfEmpty());
154+
}),
155+
concatMap(() => {
156+
if (this._options.dryRun) {
157+
return of();
168158
}
169-
})),
170-
concat(new Observable(obs => {
159+
160+
this._lifeCycle.next({ kind: 'post-tasks-start' });
161+
162+
return this._engine.executePostTasks()
163+
.pipe(
164+
tap({ complete: () => this._lifeCycle.next({ kind: 'post-tasks-end' }) }),
165+
last(),
166+
defaultIfEmpty(),
167+
);
168+
}),
169+
tap({ complete: () => {
171170
this._lifeCycle.next({ kind: 'workflow-end' });
172171
this._context.pop();
173172

174173
if (this._context.length == 0) {
175174
this._lifeCycle.next({ kind: 'end' });
176175
}
177-
178-
obs.complete();
179-
})),
180-
).pipe(reduce(() => { }));
176+
}}),
177+
);
181178
}
182179
}

0 commit comments

Comments
 (0)