diff --git a/src/plugins.js b/src/plugins.js index b09392e..aca0a98 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -16,11 +16,25 @@ 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. + + // $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; + } + + 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", ...plugins], + ["install", "--verbose", "--no-save", ...rewrittenPluginNames], { cwd: process.cwd() } ); npmProcess.stderr.on("data", data => { stderr += String(data) });