Ghost/core/server/services/apps/dependencies.js
Hannah Wolfe 882a2361ee
Moved apps to /services/ & moved individual tests (#9187)
refs #9178

* Moved app handling code into services/apps
  - Apps is a service, that allows for the App lifecycle 
  - /server/apps = contains internal apps 
   - /server/services/apps = contains code for managing/handling app life cycle, providing the proxy, etc
* Split apps service tests into separate files
* Moved internal app tests into test folders
    - Problem: Not all the tests in apps were unit tests, yet they were treated like they were in Gruntfile.js
    - Unit tests now live in /test/unit/apps
    - Route tests now live in /test/functional/routes/apps
    - Gruntfile.js has been updated to match
* Switch api.read usage for settingsCache
* Add tests to cover the basic App lifecycle
* Simplify some of the init logic
2017-10-30 12:31:04 +00:00

52 lines
1.5 KiB
JavaScript

var _ = require('lodash'),
fs = require('fs'),
path = require('path'),
Promise = require('bluebird'),
spawn = require('child_process').spawn,
win32 = process.platform === 'win32';
function AppDependencies(appPath) {
this.appPath = appPath;
}
AppDependencies.prototype.install = function installAppDependencies() {
var spawnOpts,
self = this;
return new Promise(function (resolve, reject) {
fs.stat(path.join(self.appPath, 'package.json'), function (err) {
if (err) {
// File doesn't exist - nothing to do, resolve right away?
resolve();
} else {
// Run npm install in the app directory
spawnOpts = {
cwd: self.appPath
};
self.spawnCommand('npm', ['install', '--production'], spawnOpts)
.on('error', reject)
.on('exit', function (err) {
if (err) {
reject(err);
}
resolve();
});
}
});
});
};
// 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;