buildModel function
This is the main function for API usage. Returns a Model object.
-
rootDir
-- The root directory (required). -
ignoreGlob
-- A glob pattern of files/folders to ignore. -
showTree
-- Show the directory tree? -
showMetrics
-- Show metrics? -
showNodeMetrics
-- Show node metrics?
Throws FileSystemException if rootDir doesn't exist.
Throws PubspecYamlNotFoundException if pubspec.yaml can't be found in or above the rootDir.
Throws FormatException if ignoreGlob is invalid.
Implementation
Model buildModel(Directory rootDir,
{String ignoreGlob = '!**',
bool showTree = true,
bool showMetrics = false,
bool showNodeMetrics = false}) {
// Convert relative to absolute path.
if (!rootDir.isAbsolute) {
rootDir = Directory(normalize(rootDir.absolute.path));
}
// Always use forward slashes
rootDir = Directory(rootDir.path.replaceAll('\\', '/'));
var pubspecYaml = findPubspecYaml(rootDir);
if (pubspecYaml == null) {
throw PubspecYamlNotFoundException(
'pubspec.yaml not found in or above the root directory.');
}
var model = Model(rootDir: rootDir.path)
..nodes =
getDartFileNodes(rootDir, ignoreGlob, showNodeMetrics && showMetrics);
if (showTree) {
model.subgraphs = getDirTree(rootDir, ignoreGlob);
}
model.edges.addAll(
getEdges(rootDir, ignoreGlob, pubspecYaml, model.nodes.keys.toList()));
if (showMetrics) {
model.metrics = computeMetrics(model);
}
return model;
}