diff --git a/docs/configuration.md b/docs/configuration.md index 69ce082..92101bd 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -410,6 +410,11 @@ URL to use for attachment and log links. Defaults to `http://IP:PORT`. **Default:** `off` If enabled, mod replies will use their nicknames (on the inbox server) instead of their usernames +#### useGitForGitHubPlugins +**Default:** `off` +If enabled, GitHub plugins will be installed with `git` rather than by downloading the archive's tarball. +This is useful if you are installing plugins from private repositories that require ssh keys for authentication. + ## Advanced options #### extraIntents diff --git a/src/data/cfg.jsdoc.js b/src/data/cfg.jsdoc.js index bd6976a..84e84f5 100644 --- a/src/data/cfg.jsdoc.js +++ b/src/data/cfg.jsdoc.js @@ -75,6 +75,7 @@ * @property {*} [logOptions.allowAttachmentUrlFallback=false] * @property {number} [port=8890] * @property {string} [url] + * @property {boolean} [useGitForGitHubPlugins=false] * @property {array} [extraIntents=[]] * @property {*} [dbType="sqlite"] * @property {object} [sqliteOptions] diff --git a/src/data/cfg.schema.json b/src/data/cfg.schema.json index f24de07..2ef31ab 100644 --- a/src/data/cfg.schema.json +++ b/src/data/cfg.schema.json @@ -409,6 +409,11 @@ "type": "string" }, + "useGitForGitHubPlugins": { + "$ref": "#/definitions/customBoolean", + "default": false + }, + "extraIntents": { "$ref": "#/definitions/stringArray", "default": [] diff --git a/src/plugins.js b/src/plugins.js index 2c32f16..0b95228 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -10,6 +10,7 @@ const path = require("path"); const threads = require("./data/threads"); const displayRoles = require("./data/displayRoles"); const { PluginInstallationError } = require("./PluginInstallationError"); +const config = require("./cfg"); const pluginSources = { npm: { @@ -17,25 +18,28 @@ const pluginSources = { return new Promise((resolve, reject) => { console.log(`Installing ${plugins.length} plugins from NPM...`); - // Rewrite GitHub npm package names to full GitHub tarball links to avoid - // needing to have Git installed to install these plugins. + let finalPluginNames = plugins; + if (! config.useGitForGitHubPlugins) { + // Rewrite GitHub npm package names to full GitHub tarball links to avoid + // needing to have Git installed to install these plugins. - // $1 package author, $2 package name, $3 branch (optional) - const npmGitHubPattern = /^([a-z0-9_.-]+)\/([a-z0-9_.-]+)(?:#([a-z0-9_.-]+))?$/i; - const rewrittenPluginNames = plugins.map(pluginName => { - const gitHubPackageParts = pluginName.match(npmGitHubPattern); - if (! gitHubPackageParts) { - return pluginName; - } + // $1 package author, $2 package name, $3 branch (optional) + const npmGitHubPattern = /^([a-z0-9_.-]+)\/([a-z0-9_.-]+)(?:#([a-z0-9_.-]+))?$/i; + finalPluginNames = plugins.map(pluginName => { + const gitHubPackageParts = pluginName.match(npmGitHubPattern); + if (! gitHubPackageParts) { + return pluginName; + } - return `https://api.github.com/repos/${gitHubPackageParts[1]}/${gitHubPackageParts[2]}/tarball${gitHubPackageParts[3] ? "/" + gitHubPackageParts[3] : ""}`; - }); + return `https://api.github.com/repos/${gitHubPackageParts[1]}/${gitHubPackageParts[2]}/tarball${gitHubPackageParts[3] ? "/" + gitHubPackageParts[3] : ""}`; + }); + } let stderr = ""; const npmProcessName = /^win/.test(process.platform) ? "npm.cmd" : "npm"; const npmProcess = childProcess.spawn( npmProcessName, - ["install", "--verbose", "--no-save", ...rewrittenPluginNames], + ["install", "--verbose", "--no-save", ...finalPluginNames], { cwd: process.cwd() } ); npmProcess.stderr.on("data", data => { stderr += String(data) });