projects reloader is plugin now

This commit is contained in:
oleg 2016-01-08 22:46:57 +03:00
parent 4332c50bfc
commit 337e681d4f
4 changed files with 3 additions and 59 deletions

2
app.js
View File

@ -234,8 +234,6 @@ Steppy(
notifier.init(app.config.notify, this.slot());
require('./projectsWatcher').init(app, this.slot());
// init resources
require('./resources')(app);
},

View File

@ -1,5 +1,6 @@
# plugins:
plugins:
- nci-projects-reloader
# - nci-mail-notification
# - nci-jabber-notification
# - nci-scheduler

View File

@ -45,7 +45,6 @@
},
"homepage": "https://github.com/node-ci/nci",
"dependencies": {
"chokidar": "1.0.3",
"colors": "1.1.2",
"data.io": "0.3.0",
"nlevel": "1.0.3",
@ -68,6 +67,7 @@
"main-bower-files": "2.7.0",
"memdown": "1.1.0",
"mocha": "1.18.2",
"nci-projects-reloader": "0.1.1",
"nci-yaml-reader": "0.1.0",
"nodemon": "1.3.7",
"nrun": "0.1.4",

View File

@ -1,55 +0,0 @@
'use strict';
var _ = require('underscore'),
path = require('path'),
chokidar = require('chokidar');
exports.init = function(app, callback) {
var logger = app.lib.logger('projects watcher');
// start file watcher for reloading projects on change
var syncProject = function(filename, fileInfo) {
var projectName = path.relative(
app.config.paths.projects,
path.dirname(filename)
);
if (app.projects.get(projectName)) {
logger.log('Unload project: "' + projectName + '"');
app.projects.unload(projectName);
}
// on add or change (info is falsy on unlink)
if (fileInfo) {
logger.log('Load project "' + projectName + '" on change');
app.projects.load(projectName, function(err) {
if (err) {
return logger.error(
'Error during load project "' + projectName + '": ',
err.stack || err
);
}
logger.log(
'Project "' + projectName + '" loaded:',
JSON.stringify(app.projects.get(projectName), null, 4)
);
});
}
};
// NOTE: currently after add remove and then add same file events will
// not be emitted
var watcher = chokidar.watch(
path.join(app.config.paths.projects, '*', 'config.*'),
{ignoreInitial: true, depth: 1}
);
watcher.on('add', syncProject);
watcher.on('change', syncProject);
watcher.on('unlink', syncProject);
watcher.on('error', function(err) {
logger.error('File watcher error occurred: ', err.stack || err);
});
callback();
};