-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
151 lines (137 loc) · 3.21 KB
/
main.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import { getDenoVersion, TsInfo, maybeDenoProject } from "./utils/handlers";
import { resolveImports, existManager } from "./utils/importsResolver";
import { velociraptor } from "./utils/velociraptorSupport";
async function entry({
RunningConfig,
StatusBarItem,
Dialog,
Notification,
puffin: { element },
}) {
const DenoVersion = await getDenoVersion();
RunningConfig.data.envs.push({
name: "Deno",
async filter(dir: string) {
let base = {};
// * velociraptor support
base = velociraptor(dir, base);
const { pluginInstalled } = await TsInfo(dir);
// * notification to activate the plugin
if (maybeDenoProject(dir) && !pluginInstalled) {
const notify = new Notification({
title: "Deno",
lifeTime: Infinity,
content: "some files related to deno have been detected, do you want use deno?",
buttons: [
{
label: "yes",
action() {
const diag = new Dialog({
title: "Deno",
content: "Install typescript-deno-plugin and reload graviton",
});
diag.launch();
// * close all
setTimeout(() => {
diag.close();
notify.remove();
}, 10000);
},
},
{
label: "later",
action() {
notify.remove();
// * do noting ignore
},
},
],
});
}
if (existManager(dir)) {
const DenoDeps = resolveImports(dir, Notification);
base = { ...base, ...DenoDeps };
}
return base;
},
});
const DenoErrors = [];
const DenoStatusBarItem = new StatusBarItem({
label: "Deno",
hint: "Deno support",
action: () => {
if (DenoVersion) {
if(DenoErrors.length === 0){
new Dialog({
title: "Deno info",
component(){
return element`
<div>
Status:
<ul>
<li> Deno version: ${DenoVersion} </li>
</ul>
</div>
`
}
}).launch()
}else{
new Dialog({
title: "Deno errors",
component(){
return element`
<div>
Errors:
<ul>
${DenoErrors.map(({ path, msg}) => {
return element`<li>Error: ${msg} found in ${path}</li>`
})}
</ul>
</div>
`
}
}).launch()
}
} else {// * show deno error
new Dialog({
title: "Deno",
content: "Deno is not installed",
}).launch();
}
},
});
// * deno info support
async function main(folderPath: string) {
const { tsconfigOk, denoTsconfigFile, msg, pluginInstalled } = await TsInfo(
folderPath
)
// * if deno is installed
if (DenoVersion) {
// * if typescript-deno-plugin is installed
if (pluginInstalled) {
const allOk = denoTsconfigFile && tsconfigOk
if (!allOk ) {
DenoErrors.push({
msg,
});
}
}
}
RunningConfig.on("removeFolderFromRunningWorkspace", ({ folderPath }) => {
DenoErrors.find(({ path }, i) => {
console.log(path, folderPath)
if(path === folderPath){
DenoErrors.splice(i, 1)
}
})
if(DenoErrors.length === 0){
DenoStatusBarItem.setLabel('Deno')
}
})
}
// * when loading workspace
RunningConfig.on("addFolderToRunningWorkspace", ({ folderPath }) => {
main(folderPath);
});
}
export { entry };