Project.prototype.prepare = function()

in src/server/project.js [183:230]


Project.prototype.prepare = function () {
    if (!this._preparePromise) {
        this._preparePromise = new Promise((resolve, reject) => {
            let currentProjectState;
    
            this._lastPlatform = this.platform;
    
            this._getProjectState()
                .then(function (currentState) {
                    currentProjectState = currentState;
    
                    if (this._shouldPrepare(currentProjectState)) {
                        let platform = this._lastPlatform;
                        return prepareUtil.execCordovaPrepare(this.projectRoot, platform)
                            .catch(function (err) {
                                log.warning('Preparing platform \'' + platform + '\' failed: ' + utils.stripErrorColon(err));
                            }).then(function () {
                                // Note that we return true even if we caught an error (in case the error
                                // was in a hook, for example, and the prepare actually succeeded).
                                return true;
                            });
                    }
    
                    return Promise.resolve(false);
                }.bind(this))
                .then(function (didPrepare) {
                    if (didPrepare || this._shouldInitPlugins(currentProjectState)) {
                        this._previousPrepareStates[this.platform] = currentProjectState;
                        this.initPlugins();
                    }
    
                    resolve();
                }.bind(this))
                .catch(function (err) {
                    reject(err);
                })
                .finally(function () {
                    this._lastPlatform = null;
                    this._preparePromise = null;
                }.bind(this));
        });
    } else if (this.platform !== this._lastPlatform) {
        // Sanity check to verify we never queue prepares for different platforms
        throw new Error('Unexpected request to prepare \'' + this.platform + '\' while prepare of \'' + this._lastPlatform + '\' still pending.');
    }

    return this._preparePromise;
};