本文整理汇总了TypeScript中graphlib.Graph.sources方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Graph.sources方法的具体用法?TypeScript Graph.sources怎么用?TypeScript Graph.sources使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphlib.Graph
的用法示例。
在下文中一共展示了Graph.sources方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: fromSchemas
static fromSchemas(dependencies : Array<model.Dependency>, jobs : Array<model.BuildSchema>) : PipelineGraph {
let options = { directed: true, compound: false, multigraph: false };
let graph : Graphlib.Graph<model.BuildSchema, void> = new Graphlib.Graph(options);
jobs.forEach((job : model.BuildSchema) => {
graph.setNode(job._id, job);
});
let jobsByRepo : Map<string, model.BuildSchema> = new Map();
jobs.forEach(job => jobsByRepo.set(job.repo, job));
dependencies.forEach((dependency : model.Dependency) => {
if(jobsByRepo.has(dependency.up) && jobsByRepo.has(dependency.down)) {
graph.setEdge(jobsByRepo.get(dependency.up)._id, jobsByRepo.get(dependency.down)._id);
}
});
if(!Graphlib.alg.isAcyclic(graph)) {
throw new Error('pipeline graph contains circular dependencies:' + JSON.stringify(Graphlib.json.write(graph)));
}
if(graph.sources().length > 1) {
throw new Error('pipeline graph has more than one source nodes: ' + JSON.stringify(Graphlib.json.write(graph)));
}
let pipelineGraph = new PipelineGraph();
pipelineGraph._graph = graph;
pipelineGraph._dependencies = dependencies;
pipelineGraph._builds = jobs;
return pipelineGraph;
}