Git Product home page Git Product logo

Comments (10)

phated avatar phated commented on August 29, 2024 1

You don't want to create an undertaker instance in this file, you want to use the .registry() API available on gulp in your gulpfile. Also, registry's are made to share a bunch of common tasks, not 1 per registry, so I am guessing this is going to have really bad startup performance. gulp-hub has a branch where they support the new API. The custom registry API is an advanced feature and I think you are using it where you probably shouldn't be.

from undertaker.

phated avatar phated commented on August 29, 2024

This doesn't make any sense and I don't see what you are trying to achieve that isn't already functional. Gulp is just an instance of undertaker and undertaker forwards all task registration to the custom registry.

from undertaker.

tmcgee123 avatar tmcgee123 commented on August 29, 2024

This must be a defect then, because every task I register with undertaker is not usable through the command line. For instance, if I define an undertaker task like so (where each function in gulp.parallel is already defined and returns a stream):

CommonRegistry.prototype.init = function (takerInstance) {
  takerInstance.task('clean', gulp.parallel(cleanBuild, cleanProd, cleanPublic));
};

Then when I run gulp clean from the command line, I get "Task never defined: clean". Does that make more sense?

from undertaker.

phated avatar phated commented on August 29, 2024

Did you register an instance of the registry with the .registry API?

from undertaker.

tmcgee123 avatar tmcgee123 commented on August 29, 2024

Ahh, that just may be it, I am exporting the CommonRegistry at the end of my file.

module.exports = CommonRegistry;

Do I instead?:

var UnderTaker = require('undertaker');
var taker = new UnderTaker();

...

CommonRegistry.prototype.init = function (takerInstance) {
  takerInstance.task('clean', gulp.parallel(cleanBuild, cleanProd, cleanPublic));
 //or could I possibly register an instance here instead?
};

taker.registry(new CommonRegistry());

Thank you very much for the quick replies :D

from undertaker.

phated avatar phated commented on August 29, 2024

Yes, the last example you posted is how to register your custom registry within undertaker. However, for series/parallel, it is recommended you use the undertaker instance that is passed to init to access those APIs.

If you are using gulp, it works the same way

var gulp = require('gulp');
...

CommonRegistry.prototype.init = function (gulpInst) {
  gulpInst.task('clean', gulpInst.parallel(cleanBuild, cleanProd, cleanPublic));
};

gulp.registry(new CommonRegistry());

from undertaker.

tmcgee123 avatar tmcgee123 commented on August 29, 2024

That's it! Sorry for the confusion and thanks a bunch!! 👍

from undertaker.

phated avatar phated commented on August 29, 2024

No problem. Do you think there is anything that can be added to the documentation to clear this up? The information about .registry() is in both undertaker and gulp documentation.

from undertaker.

tmcgee123 avatar tmcgee123 commented on August 29, 2024

I ended up having to make these changes due to gulp-hub not being updated. Our project utilizes 10 separate JS files (I included some in the example below) that all have many tasks inside of them and then we pull all of the tasks in our Gulpfile.js (now using Undertaker).

It ends up looking something like this:

var UnderTaker = require('undertaker');
var DefaultRegistry = require('undertaker-registry');
var BuildRegistry = require('./gulp/tasks/build.js');
var CleanRegistry = require('./gulp/tasks/clean.js');
var CopyRegistry = require('./gulp/tasks/copy.js');
var DebugRegistry = require('./gulp/tasks/debug.js');
var DocsRegistry = require('./gulp/tasks/docs.js');
...
function ConfigRegistry(config) {
  DefaultRegistry.call(this);
  this.config = config;
}
util.inherits(ConfigRegistry, DefaultRegistry);
ConfigRegistry.prototype.set = function set(name, fn) {
  var task = this._tasks[name] = fn.bind(this.config);
  return task;
};
var taker = new UnderTaker();
taker.registry(new BuildRegistry());
taker.registry(new CleanRegistry());
taker.registry(new CopyRegistry());
taker.registry(new DebugRegistry());
taker.registry(new DocsRegistry());
taker.registry(new DownloadRegistry());
taker.registry(new ConfigRegistry()); 

Whereas with gulp-hub it was more straightforward as it just pulls tasks registered with gulp.task, then registers them directly with gulp.registry(). I was confused on when to use gulp.registry and when to use taker.registry and the sample above was not allowing me to access my tasks via gulp.

For example:

var HubRegistry = require('gulp-hub');
gulp.registry(new HubRegistry(['gulp/tasks/*.js']));

Would it be more clear to register the tasks in the individual files or in the Gulpfile?

Or maybe only use the gulp module in the Gulpfile? Sorry for the long reply, just wanted to fully convey how I came to where I was and possibly shed some light on where I ran into problems trying to sync up with the documentation. Hopefully this gives you some type of insight on what to add to the documentation.

from undertaker.

tmcgee123 avatar tmcgee123 commented on August 29, 2024

You are correct, the startup performance is horrible sometimes 👍 Usually on the first run it takes awhile to load all of the JS files. I picked this up from one of my co-workers that left the company and was wondering why that was happening.

I tried the new gulp-hub branch and failed to get it working, but with the new information you've just given me, I think I might be able to get it work.

Thanks again for all of the help!

from undertaker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.