2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00
Ghost/core/server/apps/dependencies.js
Jacob Gable e3affff713 Install App Dependencies
- Spawns an npm install command from the App root
- Has some special OS checks for windows command spawning
2014-02-08 16:58:13 -06:00

52 lines
No EOL
1.4 KiB
JavaScript

var _ = require('lodash'),
fs = require('fs'),
path = require('path'),
when = require('when'),
spawn = require('child_process').spawn,
win32 = process.platform === 'win32';
function AppDependencies(appPath) {
this.appPath = appPath;
}
AppDependencies.prototype.install = function installAppDependencies() {
var def = when.defer(),
spawnOpts;
fs.exists(path.join(this.appPath, 'package.json'), function (exists) {
if (!exists) {
// Nothing to do, resolve right away?
def.resolve();
} else {
// Run npm install in the app directory
spawnOpts = {
cwd: this.appPath
};
this.spawnCommand('npm', ['install', '--production'], spawnOpts)
.on('error', def.reject)
.on('exit', function (err) {
if (err) {
def.reject(err);
}
def.resolve();
});
}
}.bind(this));
return def.promise;
};
// Normalize a command across OS and spawn it; taken from yeoman/generator
AppDependencies.prototype.spawnCommand = function (command, args, opt) {
var winCommand = win32 ? 'cmd' : command,
winArgs = win32 ? ['/c'].concat(command, args) : args;
opt = opt || {};
return spawn(winCommand, winArgs, _.defaults({ stdio: 'inherit' }, opt));
};
module.exports = AppDependencies;