forked from SolidOS/solid-panes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostinstall.js
More file actions
38 lines (35 loc) · 1.2 KB
/
postinstall.js
File metadata and controls
38 lines (35 loc) · 1.2 KB
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
const fs = require('fs')
const path = require('path')
const util = require('util')
const pluginManager = require('./pluginManager')
const config = require('./pluginManager.config.js')
init()
async function init () {
const pathToSearch = path.join(process.cwd(), 'node_modules')
const items = await util.promisify(fs.readdir)(pathToSearch)
try {
const loadingPanes = items
.filter(moduleName => moduleName.match(/solid-pane-/))
.map(name => ({name, module: require(name)}))
.filter(plugin => plugin.module.installAsPane)
.map(async (plugin) => {
await plugin.module.installAsPane(pluginManager)
return {name: plugin.name}
})
const panes = await Promise.all(loadingPanes)
await util.promisify(fs.writeFile)('./pluginManager.config.js', createConfigFile(panes))
} catch (error) {
console.log(error)
}
}
function createConfigFile (panes) {
return `module.exports = ${JSON.stringify({
...config,
panes: panes.map(pane => ({
...pane,
module: `require('./${config.src}/${pane.name}/index.js')`
}))
}, null, 2)}`.replace(/"require\((\S+)/g, (match, filePath) => {
return `require(${filePath.substr(0, filePath.length - 2)})`
})
}