@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
158 lines • 7.88 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.dataflowSimpleStarCommand = exports.dataflowSimplifiedCommand = exports.dataflowSilentCommand = exports.dataflowAsciiCommand = exports.dataflowStarCommand = exports.dataflowCommand = void 0;
const retriever_1 = require("../../../r-bridge/retriever");
const ansi_1 = require("../../../util/text/ansi");
const core_1 = require("../core");
const vertex_1 = require("../../../dataflow/graph/vertex");
const dfg_ascii_1 = require("../../../util/simple-df/dfg-ascii");
const df_helper_1 = require("../../../dataflow/graph/df-helper");
function formatInfo(out, type, meta) {
return out.formatter.format(`Copied ${type} to clipboard (dataflow: ${meta['.meta'].timing + 'ms'}).`, { color: 7 /* Colors.White */, effect: ansi_1.ColorEffect.Foreground, style: 3 /* FontStyles.Italic */ });
}
exports.dataflowCommand = {
description: `Get mermaid code for the dataflow graph, start with '${retriever_1.fileProtocol}' to indicate a file`,
isCodeCommand: true,
usageExample: ':dataflow',
aliases: ['d', 'df'],
script: false,
argsParser: (args) => (0, core_1.handleString)(args),
fn: async ({ output, analyzer }) => {
const result = await analyzer.dataflow();
const mermaid = df_helper_1.Dataflow.visualize.mermaid.convert({ graph: result.graph, includeEnvironments: false }).string;
output.stdout(mermaid);
try {
const clipboard = await Promise.resolve().then(() => __importStar(require('clipboardy')));
clipboard.default.writeSync(mermaid);
output.stdout(formatInfo(output, 'mermaid code', result));
}
catch { /* do nothing this is a service thing */
}
}
};
exports.dataflowStarCommand = {
description: 'Returns the URL to mermaid.live',
isCodeCommand: true,
usageExample: ':dataflow*',
aliases: ['d*', 'df*'],
script: false,
argsParser: (args) => (0, core_1.handleString)(args),
fn: async ({ output, analyzer }) => {
const result = await analyzer.dataflow();
const mermaid = df_helper_1.Dataflow.visualize.mermaid.url(result.graph, false);
output.stdout(mermaid);
try {
const clipboard = await Promise.resolve().then(() => __importStar(require('clipboardy')));
clipboard.default.writeSync(mermaid);
output.stdout(formatInfo(output, 'mermaid url', result));
}
catch { /* do nothing this is a service thing */ }
}
};
exports.dataflowAsciiCommand = {
description: 'Returns an ASCII representation of the dataflow graph',
isCodeCommand: true,
usageExample: ':dataflowascii',
aliases: ['df!'],
script: false,
argsParser: (args) => (0, core_1.handleString)(args),
fn: async ({ output, analyzer }) => {
const result = await analyzer.dataflow();
output.stdout((0, dfg_ascii_1.dfgToAscii)(result.graph));
}
};
exports.dataflowSilentCommand = {
description: 'Just calculates the DFG, but only prints summary info',
isCodeCommand: true,
usageExample: ':dataflowsilent',
aliases: ['d#', 'df#'],
script: false,
argsParser: (args) => (0, core_1.handleString)(args),
fn: async ({ output, analyzer }) => {
const result = await analyzer.dataflow();
const numOfEdges = Array.from(result.graph.edges().flatMap(e => e[1].entries())).length;
const numOfVertices = Array.from(result.graph.vertices(true)).length;
output.stdout(output.formatter.format(`Dataflow calculated in ${result['.meta'].timing}ms.`, { color: 7 /* Colors.White */, effect: ansi_1.ColorEffect.Foreground, style: 3 /* FontStyles.Italic */ }) + '\n' +
'Edges: ' + output.formatter.format(`${String(numOfEdges).padStart(12)}`, { color: 6 /* Colors.Cyan */, effect: ansi_1.ColorEffect.Foreground }) + '\n' +
// number of vertices and edges
'Vertices: ' + output.formatter.format(`${String(numOfVertices).padStart(12)}`, { color: 6 /* Colors.Cyan */, effect: ansi_1.ColorEffect.Foreground }));
const longestVertexType = Math.max(...Object.keys(vertex_1.VertexType).map(vt => vt.length));
for (const vertType of Object.values(vertex_1.VertexType)) {
const vertsOfType = Array.from(result.graph.verticesOfType(vertType));
const longVertexName = Object.entries(vertex_1.VertexType).find(([, v]) => v === vertType)?.[0] ?? vertType;
output.stdout(` - ${(longVertexName + ':').padEnd(longestVertexType + 1)} ` + output.formatter.format(`${String(vertsOfType.length).padStart(8)}`, { color: 6 /* Colors.Cyan */, effect: ansi_1.ColorEffect.Foreground }).padStart(9, ' '));
}
}
};
exports.dataflowSimplifiedCommand = {
description: `Get mermaid code for the simplified dataflow graph, start with '${retriever_1.fileProtocol}' to indicate a file`,
isCodeCommand: true,
usageExample: ':dataflowsimple',
aliases: ['ds', 'dfs'],
script: false,
argsParser: (args) => (0, core_1.handleString)(args),
fn: async ({ output, analyzer }) => {
const result = await analyzer.dataflow();
const mermaid = df_helper_1.Dataflow.visualize.mermaid.convert({ graph: result.graph, includeEnvironments: false, simplified: true }).string;
output.stdout(mermaid);
try {
const clipboard = await Promise.resolve().then(() => __importStar(require('clipboardy')));
clipboard.default.writeSync(mermaid);
output.stdout(formatInfo(output, 'mermaid code', result));
}
catch { /* do nothing this is a service thing */ }
}
};
exports.dataflowSimpleStarCommand = {
description: 'Returns the URL to mermaid.live',
isCodeCommand: true,
usageExample: ':dataflowsimple*',
aliases: ['ds*', 'dfs*'],
script: false,
argsParser: (args) => (0, core_1.handleString)(args),
fn: async ({ output, analyzer }) => {
const result = await analyzer.dataflow();
const mermaid = df_helper_1.Dataflow.visualize.mermaid.url(result.graph, false, undefined, true);
output.stdout(mermaid);
try {
const clipboard = await Promise.resolve().then(() => __importStar(require('clipboardy')));
clipboard.default.writeSync(mermaid);
output.stdout(formatInfo(output, 'mermaid url', result));
}
catch { /* do nothing this is a service thing */ }
}
};
//# sourceMappingURL=repl-dataflow.js.map