mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-13 14:39:52 +03:00
e3affff713
- Spawns an npm install command from the App root - Has some special OS checks for windows command spawning
52 lines
1.4 KiB
JavaScript
52 lines
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; |