Exemple #1
0
        findUp.one(IGNORE, function (err, file) {
            var ignore = [];

            try {
                ignore = file && loadIgnore(file.filePath());
            } catch (err) { /* Empty. */ }

            ignore = defaultIgnore.concat(ignore || []);

            /*
             * Search for rc files.
             */

            findUp.all([PACKAGE, RC], function (err, configs) {
                var allow = [];
                var length = configs && configs.length;
                var index = -1;
                var file;
                var contents;

                while (++index < length) {
                    file = configs[index];
                    file.contents = readFile(file.filePath(), ENCODING);
                    file.quiet = true;

                    try {
                        contents = JSON.parse(file.contents);

                        if (file.basename() === PACKAGE) {
                            contents = contents[PACKAGE_FIELD] || {};
                        }

                        allow = [].concat.apply(allow, contents.allow);
                    } catch (err) {
                        file.warn(err);
                        files.push(file);
                    }
                }

                findDown.all(
                    filterFactory(ignore, given),
                    filePaths,
                    processFactory(files, allow)
                );
            });
        });
Exemple #2
0
/**
 * Get a local configuration object, by walking from
 * `directory` upwards and merging all configurations.
 * If no configuration was found by walking upwards, the
 * current user's config (at `~`) is used.
 *
 * @example
 *   var configuration = new Configuration();
 *   var config = getLocalConfiguration(configuration, '~/bar');
 *
 * @param {Configuration} context - Configuration object to use.
 * @param {string} directory - Location to search.
 * @param {Function} callback - Invoked with `files`.
 */
function getLocalConfiguration(context, directory, callback) {
    findUp.all([
        RC_NAME,
        RCJS_NAME,
        PACKAGE_FILENAME
    ], directory, function (err, files) {
        var configuration = {};
        var index = files && files.length;
        var file;
        var local;
        var found;

        while (index--) {
            file = files[index];

            local = load(file.filePath());

            if (
                file.filename === PACKAGE_NAME &&
                file.extension === PACKAGE_EXTENSION
            ) {
                local = local[PACKAGE_FIELD] || {};
            }

            found = true;

            debug('Using ' + file.filePath());

            merge(configuration, local);
        }

        if (!found) {
            debug('Using personal configuration');

            merge(configuration, getUserConfiguration());
        }

        callback(err, configuration);
    });
}