Rewrite GitHub NPM plugin names to full GitHub tarball links
This allows those plugins to be installed from GitHub even without having Git installed.cshd
parent
623ec15d13
commit
37cba80ed9
|
@ -16,11 +16,25 @@ 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...`);
|
||||||
|
|
||||||
|
// 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 = "";
|
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", ...plugins],
|
["install", "--verbose", "--no-save", ...rewrittenPluginNames],
|
||||||
{ cwd: process.cwd() }
|
{ cwd: process.cwd() }
|
||||||
);
|
);
|
||||||
npmProcess.stderr.on("data", data => { stderr += String(data) });
|
npmProcess.stderr.on("data", data => { stderr += String(data) });
|
||||||
|
|
Loading…
Reference in New Issue