Skip to content

Instantly share code, notes, and snippets.

@Swader
Created Aug 23, 2014
Embed
What would you like to do?
NPM recursive installation fix
<?php
$moduleName = getMissingModule();
while ($moduleName !== false) {
echo 'Installing '.$moduleName.'.\n';
shell_exec('npm install '.$moduleName.' --no-bin-link');
$moduleName = getMissingModule();
}
function tryRun() {
$output = "";
exec('node server.js 2>&1', $output);
return $output;
}
function getMissingModule() {
$output = tryRun();
foreach ($output as $line) {
if (strpos($line, 'Cannot find module')) {
$line = str_replace('Error: Cannot find module ', '', $line);
$line = trim($line, "'");
return $line;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment