Sha256: 4bb6e128310ddaefff361ecd655bd82b6f7796b31f3d1696d001b93a06c56545

Contents?: true

Size: 1.32 KB

Versions: 69

Compression:

Stored size: 1.32 KB

Contents

var path = require('path');
var bowerJson = require('bower-json');
var Q = require('q');

// The valid options are the same as bower-json#readFile.
// If the "assume" option is passed, it will be used if no json file was found

// This promise is resolved with [json, deprecated, assumed]
// - json: The read json
// - deprecated: The deprecated filename being used or false otherwise
// - assumed: True if a dummy json was returned if no json file was found, false otherwise
function readJson(file, options) {
    options = options || {};

    // Read
    return Q.nfcall(bowerJson.read, file, options)
    .spread(function (json, jsonFile) {
        var deprecated;

        jsonFile = path.basename(jsonFile);
        deprecated = jsonFile === 'component.json' ? jsonFile : false;

        return [json, deprecated, false];
    }, function (err) {
        // No json file was found, assume one
        if (err.code === 'ENOENT' && options.assume) {
            return [bowerJson.parse(options.assume, options), false, true];
        }

        err.details = err.message;

        if (err.file) {
            err.message = 'Failed to read ' + err.file;
            err.data = { filename: err.file };
        } else {
            err.message = 'Failed to read json from ' + file;
        }

        throw err;
    });
}

module.exports = readJson;

Version data entries

69 entries across 69 versions & 2 rubygems

Version Path
trusty-festivity-extension-2.6.3 node_modules/bower/lib/util/readJson.js
trusty-festivity-extension-2.6.2 node_modules/bower/lib/util/readJson.js
trusty-festivity-extension-2.6.1 node_modules/bower/lib/util/readJson.js
trusty-festivity-extension-2.6 node_modules/bower/lib/util/readJson.js
trusty-festivity-extension-2.5.19 node_modules/bower/lib/util/readJson.js
trusty-festivity-extension-2.5.18 node_modules/bower/lib/util/readJson.js
trusty-festivity-extension-2.5.17 node_modules/bower/lib/util/readJson.js
trusty-festivity-extension-2.5.16 node_modules/bower/lib/util/readJson.js
trusty-festivity-extension-2.5.15 node_modules/bower/lib/util/readJson.js
trusty-festivity-extension-2.5.14 node_modules/bower/lib/util/readJson.js
trusty-festivity-extension-2.5.13 node_modules/bower/lib/util/readJson.js
trusty-festivity-extension-2.5.12 node_modules/bower/lib/util/readJson.js
trusty-festivity-extension-2.5.11 node_modules/bower/lib/util/readJson.js
trusty-festivity-extension-2.5.10 node_modules/bower/lib/util/readJson.js
trusty-festivity-extension-2.5.9 node_modules/bower/lib/util/readJson.js
trusty-festivity-extension-2.5.8 node_modules/bower/lib/util/readJson.js
trusty-festivity-extension-2.5.7 node_modules/bower/lib/util/readJson.js
trusty-festivity-extension-2.5.6 node_modules/bower/lib/util/readJson.js
trusty-festivity-extension-2.5.5 node_modules/bower/lib/util/readJson.js
trusty-festivity-extension-2.5.4 node_modules/bower/lib/util/readJson.js