Skip to content

Instantly share code, notes, and snippets.

@krisselden
Last active August 9, 2021 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisselden/01b9c1559a1adc80c0096e2661809541 to your computer and use it in GitHub Desktop.
Save krisselden/01b9c1559a1adc80c0096e2661809541 to your computer and use it in GitHub Desktop.
/* eslint-env node */
const Project = require('ember-cli/lib/models/project');
const CLI = require('ember-cli/lib/cli/cli');
const UI = require('console-ui');
const ui = new UI();
const cli = new CLI({ ui });
const project = Project.closestSync(__dirname, ui, cli);
const tree = require(`${project.root}/ember-cli-build`)({ project });
module.exports = tree;
printTree(require('./load_broccoli_tree'));
/**
* @param {import('broccoli-node-api').InputNode} node
*/
function printTree(node, seen = new Set(), depth = 0) {
if (typeof node === 'string') {
console.log(' '.repeat(depth), node);
return;
}
// eslint-disable-next-line no-underscore-dangle
const nodeInfo = node.__broccoliGetInfo__();
if (seen.has(node)) {
console.log(' '.repeat(depth), 'REF >', nodeLabel(nodeInfo));
return;
}
seen.add(node);
if (nodeInfo.nodeType === 'transform') {
const { inputNodes } = nodeInfo;
if (inputNodes.length > 0) {
console.log(' '.repeat(depth), 'START', inputNodes.length, nodeLabel(nodeInfo));
// flatten consecutive merge trees into one
for (const child of inputNodes) {
printTree(child, seen, depth + 1);
}
console.log(' '.repeat(depth), 'END', nodeLabel(nodeInfo));
} else {
console.log(' '.repeat(depth), nodeLabel(nodeInfo));
}
} else {
console.log(' '.repeat(depth), nodeLabel(nodeInfo));
}
}
/**
* @param {import('broccoli-node-api').SourceNodeInfo} node
*/
function nodeLabel(node) {
const name = node.nodeType === 'source' ? node.sourceDirectory : node.name;
const { annotation } = node;
if (annotation) {
return `${name} ${annotation}`;
}
return name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment