/
index.ts
73 lines (58 loc) · 1.84 KB
/
index.ts
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import { IFileBrowserFactory } from '@jupyterlab/filebrowser';
import { ISettingRegistry } from '@jupyterlab/settingregistry';
import { buildIcon } from '@jupyterlab/ui-components';
import { IExecutor } from './command';
import { showExecutionDialog } from './executor';
import path from "path";
const PLUGIN_ID = '@gavincyi/jupyterlab-executor:executor';
const COMMAND_ID = 'gavincyi/jupyterlab-executor:execute';
/**
* Activate the jupyterlab-executor
*/
function activate(
app: JupyterFrontEnd,
factory: IFileBrowserFactory,
settingRegistry: ISettingRegistry
) {
console.log('JupyterLab extension jupyterlab-executor is activated!');
const { tracker } = factory;
let executors = [] as IExecutor[];
const updateSettings = (settings: ISettingRegistry.ISettings): void => {
executors = settings.composite.executors as IExecutor[];
};
Promise.all([settingRegistry.load(PLUGIN_ID), app.restored]).then(
([settings]) => {
updateSettings(settings);
settings.changed.connect(updateSettings);
}
);
app.commands.addCommand(COMMAND_ID, {
label: 'Execute',
caption: "Execute script",
icon: buildIcon,
execute: () => {
const widget = tracker.currentWidget;
if (!widget) {
return;
}
// Show the execution dialog
const serverRoot = (app as any)?.paths?.directories?.serverRoot;
const localPath = widget.selectedItems().next()!.value.path;
showExecutionDialog(app, path.join(serverRoot, localPath), executors);
},
});
}
/**
* Initialization data for the jupyterlab-executor extension.
*/
const extension: JupyterFrontEndPlugin<void> = {
id: PLUGIN_ID,
autoStart: true,
requires: [IFileBrowserFactory, ISettingRegistry],
activate: activate
};
export default extension;