{"size": 1297, "ext": "js", "max_stars_repo_path": "lib/modules/generate.js", "max_stars_repo_name": "lbke/vulcan-resources-manager", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lib/modules/generate.js", "max_issues_repo_name": "lbke/vulcan-resources-manager", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/modules/generate.js", "max_forks_repo_name": "lbke/vulcan-resources-manager", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 21.9830508475, "max_line_length": 63, "alphanum_fraction": 0.6607555898}
/**
 * Generate collections and routes from a map of schemas
 */
import {
  addRoute,
  createCollection,
  getDefaultResolvers,
  getDefaultMutations
} from "meteor/vulcan:core";
import fs from "fs";
import path from "path";
const schemas = JSON.parse(
  Assets.getText("lib/assets/schemaorg-vulcanized.jsonld")
);

const toUpperFirst = str =>
  str && str.length ? str[0].toUpperCase() + str.slice(1) : "";

const generateCollections = schemas => {
  Object.keys(schemas).forEach(schemaId => {
    const schema = schemas[schemaId];
    const typeName = toUpperFirst(schemaId);
    createCollection({
      collectionName: schemaId,
      typeName,
      schema,
      resolves: getDefaultResolvers(typeName),
      mutations: getDefaultMutations(typeName)
    });
  });
};

const generateRoutes = schemas => {
  Object.keys(schemas).forEach(schemaId => {
    const schema = schemas[schemaId];
    const typeName = toUpperFirst(schemaId);
    addRoute({
      name: schemaId,
      path: "/resources/" + schemaId,
      componentName: "SchemaPage",
      schema
    });
  });
};

const run = () => {
  generateCollections(schemas);
  generateRoutes(schemas);

  addRoute({
    name: "resources",
    path: "/resources",
    componentName: "SchemasList",
    schemas
  });
};

export default run;
