Add option: useGitForGitHubPlugins

cshd
Dragory 2021-01-07 21:13:45 +02:00
parent 811dbb23f5
commit d48c21f608
No known key found for this signature in database
GPG Key ID: 5F387BA66DF8AAC1
4 changed files with 27 additions and 12 deletions

View File

@ -410,6 +410,11 @@ URL to use for attachment and log links. Defaults to `http://IP:PORT`.
**Default:** `off` **Default:** `off`
If enabled, mod replies will use their nicknames (on the inbox server) instead of their usernames 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 ## Advanced options
#### extraIntents #### extraIntents

View File

@ -75,6 +75,7 @@
* @property {*} [logOptions.allowAttachmentUrlFallback=false] * @property {*} [logOptions.allowAttachmentUrlFallback=false]
* @property {number} [port=8890] * @property {number} [port=8890]
* @property {string} [url] * @property {string} [url]
* @property {boolean} [useGitForGitHubPlugins=false]
* @property {array} [extraIntents=[]] * @property {array} [extraIntents=[]]
* @property {*} [dbType="sqlite"] * @property {*} [dbType="sqlite"]
* @property {object} [sqliteOptions] * @property {object} [sqliteOptions]

View File

@ -409,6 +409,11 @@
"type": "string" "type": "string"
}, },
"useGitForGitHubPlugins": {
"$ref": "#/definitions/customBoolean",
"default": false
},
"extraIntents": { "extraIntents": {
"$ref": "#/definitions/stringArray", "$ref": "#/definitions/stringArray",
"default": [] "default": []

View File

@ -10,6 +10,7 @@ const path = require("path");
const threads = require("./data/threads"); const threads = require("./data/threads");
const displayRoles = require("./data/displayRoles"); const displayRoles = require("./data/displayRoles");
const { PluginInstallationError } = require("./PluginInstallationError"); const { PluginInstallationError } = require("./PluginInstallationError");
const config = require("./cfg");
const pluginSources = { const pluginSources = {
npm: { npm: {
@ -17,12 +18,14 @@ const pluginSources = {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
console.log(`Installing ${plugins.length} plugins from NPM...`); console.log(`Installing ${plugins.length} plugins from NPM...`);
let finalPluginNames = plugins;
if (! config.useGitForGitHubPlugins) {
// Rewrite GitHub npm package names to full GitHub tarball links to avoid // Rewrite GitHub npm package names to full GitHub tarball links to avoid
// needing to have Git installed to install these plugins. // needing to have Git installed to install these plugins.
// $1 package author, $2 package name, $3 branch (optional) // $1 package author, $2 package name, $3 branch (optional)
const npmGitHubPattern = /^([a-z0-9_.-]+)\/([a-z0-9_.-]+)(?:#([a-z0-9_.-]+))?$/i; const npmGitHubPattern = /^([a-z0-9_.-]+)\/([a-z0-9_.-]+)(?:#([a-z0-9_.-]+))?$/i;
const rewrittenPluginNames = plugins.map(pluginName => { finalPluginNames = plugins.map(pluginName => {
const gitHubPackageParts = pluginName.match(npmGitHubPattern); const gitHubPackageParts = pluginName.match(npmGitHubPattern);
if (! gitHubPackageParts) { if (! gitHubPackageParts) {
return pluginName; return pluginName;
@ -30,12 +33,13 @@ const pluginSources = {
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 = ""; let stderr = "";
const npmProcessName = /^win/.test(process.platform) ? "npm.cmd" : "npm"; const npmProcessName = /^win/.test(process.platform) ? "npm.cmd" : "npm";
const npmProcess = childProcess.spawn( const npmProcess = childProcess.spawn(
npmProcessName, npmProcessName,
["install", "--verbose", "--no-save", ...rewrittenPluginNames], ["install", "--verbose", "--no-save", ...finalPluginNames],
{ cwd: process.cwd() } { cwd: process.cwd() }
); );
npmProcess.stderr.on("data", data => { stderr += String(data) }); npmProcess.stderr.on("data", data => { stderr += String(data) });