feat: extensions check + resolver

This commit is contained in:
NGPixel
2020-05-18 00:45:51 -04:00
committed by Nicolas Giard
parent abc9e4e1d4
commit e1382771cf
14 changed files with 200 additions and 258 deletions

21
server/core/extensions.js Normal file
View File

@@ -0,0 +1,21 @@
const fs = require('fs-extra')
const path = require('path')
/* global WIKI */
module.exports = {
ext: {},
async init () {
const extDirs = await fs.readdir(path.join(WIKI.SERVERPATH, 'modules/extensions'))
WIKI.logger.info(`Checking for installed optional extensions...`)
for (let dir of extDirs) {
WIKI.extensions.ext[dir] = require(path.join(WIKI.SERVERPATH, 'modules/extensions', dir, 'ext.js'))
const isInstalled = await WIKI.extensions.ext[dir].check()
if (isInstalled) {
WIKI.logger.info(`Optional extension ${dir} is installed. [ OK ]`)
} else {
WIKI.logger.info(`Optional extension ${dir} was not found on this system. [ SKIPPED ]`)
}
}
}
}

View File

@@ -40,6 +40,7 @@ module.exports = {
inbound: new EventEmitter(),
outbound: new EventEmitter()
}
WIKI.extensions = require('./extensions')
} catch (err) {
WIKI.logger.error(err)
process.exit(1)
@@ -76,6 +77,8 @@ module.exports = {
await WIKI.models.searchEngines.refreshSearchEnginesFromDisk()
await WIKI.models.storage.refreshTargetsFromDisk()
await WIKI.extensions.init()
await WIKI.auth.activateStrategies()
await WIKI.models.commentProviders.initProvider()
await WIKI.models.searchEngines.initEngine()

View File

@@ -34,7 +34,14 @@ module.exports = {
result.push({ key, value })
}, [])
},
async info() { return {} }
async info () { return {} },
async extensions () {
const exts = Object.values(WIKI.extensions.ext).map(ext => _.pick(ext, ['key', 'title', 'description', 'isInstalled']))
for (let ext of exts) {
ext.isCompatible = await WIKI.extensions.ext[ext.key].isCompatible()
}
return exts
}
},
SystemMutation: {
async updateFlags (obj, args, context) {

View File

@@ -17,6 +17,7 @@ extend type Mutation {
type SystemQuery {
flags: [SystemFlag] @auth(requires: ["manage:system"])
info: SystemInfo
extensions: [SystemExtension]! @auth(requires: ["manage:system"])
}
# -----------------------------------------------
@@ -112,3 +113,11 @@ type SystemImportUsersResponseFailed {
email: String
error: String
}
type SystemExtension {
key: String!
title: String!
description: String!
isInstalled: Boolean!
isCompatible: Boolean!
}

View File

@@ -45,9 +45,9 @@ module.exports = class CommentProvider extends Model {
const dbProviders = await WIKI.models.commentProviders.query()
// -> Fetch definitions from disk
const authDirs = await fs.readdir(path.join(WIKI.SERVERPATH, 'modules/comments'))
const commentDirs = await fs.readdir(path.join(WIKI.SERVERPATH, 'modules/comments'))
let diskProviders = []
for (let dir of authDirs) {
for (let dir of commentDirs) {
const def = await fs.readFile(path.join(WIKI.SERVERPATH, 'modules/comments', dir, 'definition.yml'), 'utf8')
diskProviders.push(yaml.safeLoad(def))
}

View File

@@ -0,0 +1,20 @@
const cmdExists = require('command-exists')
module.exports = {
key: 'git',
title: 'Git',
description: 'Distributed version control system. Required for the Git storage module.',
isInstalled: false,
async isCompatible () {
return true
},
async check () {
try {
await cmdExists('git')
this.isInstalled = true
} catch (err) {
this.isInstalled = false
}
return this.isInstalled
}
}

View File

@@ -0,0 +1,21 @@
const cmdExists = require('command-exists')
const os = require('os')
module.exports = {
key: 'pandoc',
title: 'Pandoc',
description: 'Convert between markup formats. Required for converting from other formats such as MediaWiki, AsciiDoc, Textile and other wikis.',
async isCompatible () {
return os.arch() === 'x64'
},
isInstalled: false,
async check () {
try {
await cmdExists('pandoc')
this.isInstalled = true
} catch (err) {
this.isInstalled = false
}
return this.isInstalled
}
}

View File

@@ -0,0 +1,21 @@
const cmdExists = require('command-exists')
const os = require('os')
module.exports = {
key: 'puppeteer',
title: 'Puppeteer',
description: 'Headless chromium browser for server-side rendering. Required for generating PDF versions of pages and render content elements on the server (e.g. Mermaid diagrams)',
async isCompatible () {
return os.arch() === 'x64'
},
isInstalled: false,
async check () {
try {
await cmdExists('pandoc')
this.isInstalled = true
} catch (err) {
this.isInstalled = false
}
return this.isInstalled
}
}

View File

@@ -0,0 +1,19 @@
const fs = require('fs-extra')
const os = require('os')
const path = require('path')
/* global WIKI */
module.exports = {
key: 'sharp',
title: 'Sharp',
description: 'Process and transform images. Required to generate thumbnails of uploaded images and perform transformations.',
async isCompatible () {
return os.arch() === 'x64'
},
isInstalled: false,
async check () {
this.isInstalled = await fs.pathExists(path.join(WIKI.ROOTPATH, 'node_modules/sharp'))
return this.isInstalled
}
}