"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jar_1 = require("../../lib/speedray/jar");
const Task = require('../../ember-cli/lib/models/task');
exports.default = Task.extend({
    run: function (runTaskOptions, rebuildDoneCb) {
        const BuildTask = require('../build').default;
        const project = this.cliProject;
        return new Promise((resolve, reject) => {
            const buildTask = new BuildTask({
                cliProject: project,
                ui: this.ui
            });
            let self = this;
            if (runTaskOptions.watch) {
                buildTask.run(runTaskOptions, function rebuildDone(err, stats) {
                    if (err) {
                        return reject(err);
                    }
                    jar_1.jar(project, runTaskOptions).subscribe(written => {
                        if (rebuildDoneCb) {
                            rebuildDoneCb(stats);
                        }
                        else {
                            self.ui.writeLine('\nupdated jar with ' + written + ' bytes\n');
                        }
                    }, error => {
                        reject(error);
                    });
                }).catch((error) => {
                    reject(error);
                });
            }
            else {
                buildTask.run(runTaskOptions).then((results) => {
                    jar_1.jar(project, runTaskOptions).subscribe(written => {
                        self.ui.writeLine('\nupdated jar with ' + written + ' bytes\n');
                        resolve(results);
                    }, error => {
                        reject(error);
                    });
                }).catch((error) => {
                    reject(error);
                });
            }
        });
    }
});
//# sourceMappingURL=/home/ddavis/Projects/xtivia/speedray/speedray-cli/tasks/speedray/jar.js.map