"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tools_1 = require("@angular-devkit/schematics/tools");
const path_1 = require("path");
const export_ref_1 = require("./export-ref");
const file_system_engine_host_base_1 = require("./file-system-engine-host-base");
/**
 * A simple EngineHost that uses NodeModules to resolve collections.
 */
class NodeModulesEngineHost extends file_system_engine_host_base_1.FileSystemEngineHostBase {
    _resolveCollectionPath(name) {
        const pkgJsonSchematics = require(path_1.join(name, 'package.json'))['schematics'];
        if (!pkgJsonSchematics) {
            throw new tools_1.CollectionCannotBeResolvedException(name);
        }
        return require.resolve(path_1.join(name, pkgJsonSchematics));
    }
    _resolveReferenceString(refString, parentPath) {
        const ref = new export_ref_1.ExportStringRef(refString, parentPath);
        if (!ref.ref) {
            return null;
        }
        return { ref: ref.ref, path: ref.module };
    }
    _transformCollectionDescription(name, desc) {
        if (!desc.schematics || typeof desc.schematics != 'object') {
            throw new tools_1.CollectionMissingSchematicsMapException(name);
        }
        const version = require(path_1.join(name, 'package.json'))['version'];
        return Object.assign({}, desc, { name,
            version });
    }
    _transformSchematicDescription(name, _collection, desc) {
        if (!desc.factoryFn || !desc.path || !desc.description) {
            throw new tools_1.SchematicMissingFieldsException(name);
        }
        return desc;
    }
}
exports.NodeModulesEngineHost = NodeModulesEngineHost;
//# sourceMappingURL=data:application/json;base64,[encoded data, 4968 characters]