This repository has been archived by the owner on Mar 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
121 lines (106 loc) · 2.5 KB
/
index.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
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
const edi = require('electron-devtools-installer')
const { default: installExtension } = edi
const devtron = require('devtron')
const { BrowserWindow } = require('electron')
const series = require('run-series')
const tools = {
ember: {
installer: 'edi',
id: edi.EMBER_INSPECTOR,
longName: 'Ember Inspector'
},
react: {
installer: 'edi',
id: edi.REACT_DEVELOPER_TOOLS,
longName: 'React Developer Tools'
},
backbone: {
installer: 'edi',
id: edi.BACKBONE_DEBUGGER,
longName: 'Backbone Debugger'
},
jquery: {
installer: 'edi',
id: edi.JQUERY_DEBUGGER,
longName: 'jQuery Debugger'
},
angular: {
installer: 'edi',
id: edi.ANGULARJS_BATARANG,
longName: 'AngularJS Batarang'
},
vuejs: {
installer: 'edi',
id: edi.VUEJS_DEVTOOLS,
longName: 'Vue.js devtools'
},
redux: {
installer: 'edi',
id: edi.REDUX_DEVTOOLS,
longName: 'Redux DevTools'
},
reactPerf: {
installer: 'edi',
id: edi.REACT_PERF,
longName: 'React Perf'
},
devtron: {
installer: 'devtron',
longName: 'devtron'
}
}
exports.tools = tools
const longNames = {}
for (const key in tools) {
longNames[tools[key].longName] = key
}
exports.longNames = longNames
const installers = {
devtron: installDevtron,
edi: installEDI
}
function installDevtron (toolObj, cb) {
devtron.install()
process.nextTick(cb)
}
function installEDI (toolObj, cb) {
installExtension(toolObj.id, true).then(name => {
console.log(`installed ${name}`)
return cb(null)
}).catch(err => {
return cb(err)
})
}
function makeInstallers (t, cb) {
if (!t) return []
return t.map(tool => {
const toolObj = tools[tool]
if (!toolObj) {
console.log(`${tool} is not an available devtool`)
return null
}
const installer = installers[toolObj.installer]
return installer.bind(null, toolObj)
}).filter(installer => typeof installer === 'function')
}
function installed () {
return BrowserWindow.getDevToolsExtensions()
}
exports.installed = installed
function install (t, cb) {
const seriesWorkers = makeInstallers(t, cb)
series(seriesWorkers, cb)
}
exports.install = install
function uninstall (shortNames) {
if (!shortNames) shortNames = []
shortNames.map(name => tools[name] ? tools[name].longName : name).forEach(longName => {
try {
BrowserWindow.removeDevToolsExtension(longName)
console.log(`Uninstalled ${longName}`)
} catch (e) {
console.error(e)
}
})
}
exports.uninstall = uninstall