@graphprotocol/graph-cli
Version:
CLI for building for and deploying to The Graph
32 lines (31 loc) • 1.44 kB
JavaScript
import immutable from 'immutable';
import yaml from 'js-yaml';
import { loadManifest } from '../migrations/util/load-manifest.js';
// Loads manifest from file path and returns all:
// - data sources
// - templates
// In a single list.
export const fromFilePath = async (manifestPath) => {
const { dataSources = [], templates = [] } = await loadManifest(manifestPath);
return dataSources.concat(templates);
};
// Loads manifest from file path and returns all:
// - data sources
// - templates
// In a single list.
export function fromManifestString(manifest) {
// TODO: can we make it typesafe?
const { dataSources = [], templates = [] } = (yaml.load(manifest) || {});
return dataSources.concat(templates);
}
const extractDataSourceByType = (manifest, dataSourceType, protocol) => manifest
.get(dataSourceType, immutable.List())
.reduce((dataSources, dataSource, dataSourceIndex) => protocol.isValidKindName(dataSource.get('kind'))
? dataSources.push(immutable.Map({ path: [dataSourceType, dataSourceIndex], dataSource }))
: dataSources, immutable.List());
// Extracts data sources and templates from a immutable manifest data structure
export const fromManifest = (manifest, protocol) => {
const dataSources = extractDataSourceByType(manifest, 'dataSources', protocol);
const templates = extractDataSourceByType(manifest, 'templates', protocol);
return dataSources.concat(templates);
};