Skip to content

Instantly share code, notes, and snippets.

@pjlamb12
Last active April 6, 2016 15:49
Show Gist options
  • Save pjlamb12/55c88a865b40408be6fc5919455bb969 to your computer and use it in GitHub Desktop.
Save pjlamb12/55c88a865b40408be6fc5919455bb969 to your computer and use it in GitHub Desktop.
/**
* Gulpfile
*
* This Node script is executed when you run `gulp` or `sails lift`.
* It's purpose is to load the Gulp tasks in your project's `tasks`
* folder, and allow you to add and remove tasks as you see fit.
* For more information on how this works, check out the `README.md`
* file that was generated in your `tasks` folder. Module gulp-load-plugins is now needed.
*
* WARNING:
* Unless you know what you're doing, you shouldn't change this file.
* Check out the `tasks` directory instead.
*/
var gulp = require('gulp'),
plugins = require('gulp-load-plugins')({
pattern: ['gulp-*', 'merge-*', 'run-*', 'main-*'], // the glob to search for
replaceString: /\bgulp[\-.]|run[\-.]|merge[\-.]|main[\-.]/, // what to remove from the name of the module when adding it to the context
camelizePluginName: true, // if true, transforms hyphenated plugins names to camel case
lazy: true // whether the plugins should be lazy loaded on demand
}),
path = require('path'),
growl = false;
//module.exports = function(gulp) {
// Load the include-all library in order to require all of our grunt
// configurations and task registrations dynamically.
var includeAll;
try {
includeAll = require('include-all');
} catch (e0) {
try {
includeAll = require('sails/node_modules/include-all');
}
catch(e1) {
console.error('Could not find `include-all` module.');
console.error('Skipping grunt tasks...');
console.error('To fix this, please run:');
console.error('npm install include-all --save`');
console.error();
gulp.task('default', []);
return;
}
}
/**
* Loads Gulp configuration modules from the specified
* relative path. These modules should export a function
* that, when run, should either load/configure or register
* a Gulp task.
*/
function loadTasks(relPath) {
return includeAll({
dirname: require('path').resolve(__dirname, relPath),
filter: /(.+)\.js$/
}) || {};
}
/**
* Invokes the function from a Grunt configuration module with
* a single argument - the `grunt` object.
*/
function invokeConfigFn(tasks) {
for (var taskName in tasks) {
if (tasks.hasOwnProperty(taskName)) {
tasks[taskName](gulp, plugins, growl, path);
}
}
}
// Load task functions
var taskConfigurations = loadTasks('./tasks-gulp/config'),
registerDefinitions = loadTasks('./tasks-gulp/register');
// (ensure that a default task exists)
if (!registerDefinitions.default) {
registerDefinitions.default = function (gulp) { gulp.task('default', []); };
}
// Run task functions to configure Gulp.
invokeConfigFn(taskConfigurations);
invokeConfigFn(registerDefinitions);
//};
/path/to/project/folder/subfolder/tasks-gulp/config/watch.js:27
server.changed(file.path);
^
TypeError: server.changed is not a function
at EventEmitter.<anonymous> (/Users/pjlamb12/projects/System/portal.service/tasks-gulp/config/watch.js:27:13)
at emitOne (events.js:90:13)
at EventEmitter.emit (events.js:182:7)
at Gaze.<anonymous> (/Users/pjlamb12/projects/System/portal.service/node_modules/glob-watcher/index.js:17:11)
at emitTwo (events.js:100:13)
at Gaze.emit (events.js:185:7)
at Gaze.emit (/Users/pjlamb12/projects/System/portal.service/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:129:32)
at /Users/pjlamb12/projects/System/portal.service/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:415:16
at StatWatcher._pollers.(anonymous function) (/Users/pjlamb12/projects/System/portal.service/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:326:7)
at emitTwo (events.js:100:13)
at StatWatcher.emit (events.js:185:7)
at StatWatcher._handle.onchange (fs.js:1369:10)
/**
* Run predefined tasks whenever watched file patterns are added, changed or deleted.
*
* ---------------------------------------------------------------
*
* Watch for changes on
* - files in the `assets` folder
* - the `tasks/pipeline.js` file
* and re-run the appropriate tasks.
*
*
*/
module.exports = function(gulp, plugins, growl) {
var server = plugins.livereload();
gulp.task('watch:api', function() {
// Watch Style files
return gulp.watch('api/**/*', ['syncAssets'])
.on('change', function(file) {
server.changed(file.path);
});
});
gulp.task('watch:assets', function() {
// Watch assets
return gulp.watch(['assets/**/*', 'tasks/pipeline.js'], ['syncAssets'])
.on('change', function(file) {
server.changed(file.path);
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment