/
extension.js
50 lines (43 loc) · 1.46 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const vscode = require('vscode')
const runDependencyAnalysis = require('./src/dependencyAnalysis')
const { getFileName, RelativeFilePath } = require('./src/file')
const { openGraph } = require('./src/GraphView')
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
const dependencyCommand = vscode.commands.registerCommand(
'extension.dependencyAnalysis',
async function (file) {
const filePath =
RelativeFilePath.fromFile(file) ||
RelativeFilePath.fromActiveTextEditor()
const options = vscode.workspace.getConfiguration(
'dependencyCruiser'
)
if (filePath) {
process.chdir(vscode.workspace.rootPath)
const graph = await runDependencyAnalysis(filePath, options)
const fileName = getFileName(filePath)
return openGraph({
vscode,
fileName,
graph: graph.toString(),
context,
})
} else {
vscode.window.showWarningMessage(
'No Active Editor tabs, please select a file first'
)
}
}
)
context.subscriptions.push(dependencyCommand)
}
exports.activate = activate
// this method is called when your extension is deactivated
function deactivate() {}
module.exports = {
activate,
deactivate,
}