<gh_stars>1-10
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertNxExecutor = void 0;
const tslib_1 = require("tslib");
const rxjs_1 = require("rxjs");
const operators_1 = require("rxjs/operators");
const workspace_1 = require("@nrwl/tao/src/shared/workspace");
/**
 * Convert an Nx Executor into an Angular Devkit Builder
 *
 * Use this to expose a compatible Angular Builder
 */
function convertNxExecutor(executor) {
    const builderFunction = (options, builderContext) => {
        const workspaceConfig = new workspace_1.Workspaces(builderContext.workspaceRoot).readWorkspaceConfiguration();
        const context = {
            root: builderContext.workspaceRoot,
            projectName: builderContext.target.project,
            workspace: workspaceConfig,
            cwd: process.cwd(),
            isVerbose: false,
        };
        if (builderContext.target &&
            builderContext.target.project &&
            builderContext.target.target) {
            context.target =
                workspaceConfig.projects[builderContext.target.project].targets[builderContext.target.target];
        }
        return rxjs_1.from(toPromise(executor(options, context))).pipe(operators_1.map((output) => {
            if (!output) {
                return {
                    success: true,
                };
            }
            else {
                return Object.assign(Object.assign({}, output), { success: true });
            }
        }));
    };
    return require('@angular-devkit/architect').createBuilder(builderFunction);
}
exports.convertNxExecutor = convertNxExecutor;
function toPromise(promiseOrAsyncIterator) {
    var promiseOrAsyncIterator_1, promiseOrAsyncIterator_1_1;
    var e_1, _a;
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        if (typeof promiseOrAsyncIterator.then === 'function')
            return promiseOrAsyncIterator;
        let q;
        try {
            for (promiseOrAsyncIterator_1 = tslib_1.__asyncValues(promiseOrAsyncIterator); promiseOrAsyncIterator_1_1 = yield promiseOrAsyncIterator_1.next(), !promiseOrAsyncIterator_1_1.done;) {
                q = promiseOrAsyncIterator_1_1.value;
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (promiseOrAsyncIterator_1_1 && !promiseOrAsyncIterator_1_1.done && (_a = promiseOrAsyncIterator_1.return)) yield _a.call(promiseOrAsyncIterator_1);
            }
            finally { if (e_1) throw e_1.error; }
        }
        return q;
    });
}
//# sourceMappingURL=convert-nx-executor.js.map