Skip to content

Commit

Permalink
add abe processes for plugin integration
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Sep 29, 2016
1 parent 4e2756e commit 46c46b7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
26 changes: 26 additions & 0 deletions dist/cli/helpers/abe-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ var Plugins = function () {
plugin.templates = null;
}

// has process
var plugProcess = _path2.default.join(plugin.path, 'process');
if (_.folderUtils.isFolder(plugProcess)) {
plugin.process = {};
var processFiles = _.FileParser.getFiles(plugProcess, true, 0);
Array.prototype.forEach.call(processFiles, function (processFile) {
plugin.process[processFile.cleanNameNoExt] = processFile.path;
});
} else {
plugin.process = null;
}

// has routes
var plugRoutes = _path2.default.join(plugin.path, 'routes');
if (_.folderUtils.isFolder(plugRoutes)) {
Expand Down Expand Up @@ -98,6 +110,20 @@ var Plugins = function () {
}

_createClass(Plugins, [{
key: 'getProcess',
value: function getProcess(fn) {
var proc = null;
if (typeof this._plugins !== 'undefined' && this._plugins !== null) {
Array.prototype.forEach.call(this._plugins, function (plugin) {
if (typeof plugin.process !== 'undefined' && plugin.process !== null && typeof plugin.process[fn] !== 'undefined' && plugin.process[fn] !== null) {
proc = plugin.process[fn];
}
});
}

return proc;
}
}, {
key: 'hooks',
value: function hooks() {
var _this = this;
Expand Down
36 changes: 29 additions & 7 deletions dist/cli/helpers/abe-process.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,48 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
value: true
});

var _child_process = require('child_process');

var _child_process2 = _interopRequireDefault(_child_process);

var _fsExtra = require('fs-extra');

var _fsExtra2 = _interopRequireDefault(_fsExtra);

var _ = require('../');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function prepend(value, array) {
var newArray = array.slice(0);
newArray.unshift(value);
return newArray;
var newArray = array.slice(0);
newArray.unshift(value);
return newArray;
}

var abeProcess = function abeProcess(name, args) {
args = prepend('ABE_WEBSITE=' + _.config.root, args);
var publishAll = _child_process2.default.fork(__dirname + '/../../cli/process/' + name + '.js', args);
var abeProcess = function abeProcess(name) {
var args = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];

args = prepend('ABE_WEBSITE=' + _.config.root, args);
args = prepend('ABEJS_PATH=' + __dirname + '/../../../dist', args);

var file = __dirname + '/../../cli/process/' + name + '.js';
try {
var stats = _fsExtra2.default.statSync(file);
if (stats.isFile()) {
_child_process2.default.fork(file, args);
}
} catch (err) {
try {
file = _.Plugins.instance.getProcess(name);
var stats = _fsExtra2.default.statSync(file);
if (stats.isFile()) {
_child_process2.default.fork(file, args);
}
} catch (err) {}
}
};

exports.default = abeProcess;

0 comments on commit 46c46b7

Please sign in to comment.