0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Removed installAppByName method

no-issue

Only external apps needed the install step, we can safely remove this now.
This commit is contained in:
Fabien O'Carroll 2019-04-15 12:15:48 +02:00
parent ad9d142174
commit 4b74c11abb
2 changed files with 0 additions and 86 deletions

View file

@ -1,51 +0,0 @@
var _ = require('lodash'),
fs = require('fs-extra'),
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;

View file

@ -5,7 +5,6 @@ const config = require('../../config');
const common = require('../../lib/common');
const AppProxy = require('./proxy');
const Sandbox = require('./sandbox');
const AppDependencies = require('./dependencies');
const AppPermissions = require('./permissions');
// Get the full path to an app by name
@ -49,40 +48,6 @@ function getAppByName(name, permissions) {
}
module.exports = {
// Load a app and return the instantiated app
installAppByName: function (name) {
// Install the apps dependencies first
const appPath = getAppAbsolutePath(name);
const deps = new AppDependencies(appPath);
return deps.install()
.then(function () {
// Load app permissions
const perms = new AppPermissions(appPath);
return perms.read().catch(function (err) {
// Provide a helpful error about which app
return Promise.reject(new Error(common.i18n.t('errors.apps.permissionsErrorLoadingApp.error', {
name: name,
message: err.message
})));
});
})
.then(function (appPerms) {
const {app, proxy} = getAppByName(name, appPerms);
// Check for an install() method on the app.
if (!_.isFunction(app.install)) {
return Promise.reject(new Error(common.i18n.t('errors.apps.noInstallMethodLoadingApp.error', {name: name})));
}
// Run the app.install() method
// Wrapping the install() with a when because it's possible
// to not return a promise from it.
return Promise.resolve(app.install(proxy)).return(app);
});
},
// Activate a app and return it
activateAppByName: function (name) {
const perms = new AppPermissions(getAppAbsolutePath(name));