-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Suggestion] Plugin system #70
Comments
Sounds intriguing! Two thoughts:
That's why I'd rather register and compose them in a const gulp = require('gulp')
const html = require('estatico-html')
const validateHtml = require('estatico-html-validate')
const config = require('./estatico.config.js')
gulp.task('html', gulp.series(
function htmlTask () {
return html.task(config.html)
},
function validateHtmlTask () {
return validateHtml.task(config.validateHtml)
}
)) It might even make sense to skip the external config file and have everything in |
Example: https://github.com/unic/estatico-nou Plugins:
Demo: Writing any invalid HTML should trigger and log an error. |
To register and compose all the stuff in the project itself seems reasonable. How do you plan to implement the watch stuff? |
Did you choose this name on purpose? Lovely catalan suffix! 😍 |
What would be the most reasonable approach regarding task options? Does https://github.com/unic/estatico-nou/blob/bfc86e8fb5650d2b9939212c0463a75b614588f4/gulpfile.js#L12-L28 make sense where we merge the custom config with the exposed defaults of our tasks? Or should we rather initialize the imported tasks with the custom config and then expose the result of the merged settings as Variant 1: const tasks = {
html = require('estatico-html')
}
const config = {
html: merge({}, tasks.html.defaults, {
src: '*.hbs'
})
}
// → Merged html config
console.log(config.html) Variant 2: const customConfig = {
html: merge({}, tasks.html.defaults, {
src: '*.hbs'
})
}
const tasks = {
html = require('estatico-html')(customConfig.html)
}
// → Merged html config
console.log(tasks.html.config) The latter one would slightly simplify things like https://github.com/unic/estatico-nou/blob/bfc86e8fb5650d2b9939212c0463a75b614588f4/gulpfile.js#L39-L51 to something like this: gulp.task('watch', function watchTask () {
Object.keys(config).forEach((taskName) => {
if (config[taskName].watch) {
tasks.watch.fn({
task: tasks[taskName]
}, gulp)
}
})
}) Independent of the approach, the custom config could live in a separate file instead of being part of |
@backflip I would go for Variant 2, so that we have everything which belongs to the html task are in the same object and not something in |
@yannisgu, i just realized you had already suggested this in your proposal. Sorry. :) |
Updated: https://github.com/unic/estatico-nou/blob/79bb6d27232d56a88e40831a1110dfc634b3d630/gulpfile.js PS: You can run |
This sounds like a great idea. Is the plan to strip out all tasks into separate modules and deliver estatico without any core functionality? Personally, I would like to see some tasks remain as the core (for example html, css, clean, serve, livereload, watch, media:copy, js:lint, etc.). Things that don't change depending on the project. I guess, in order to achieve this, core tasks would be first extracted into their own module, and then these modules would be included in the default package.json file so they are available out of the box? Or does this contradict the entire exercise of modularizing? What is the roadmap/game-plan for developing? Should we already start modularizing tasks in separate repos on github.com/unic and test them on estatico-nuo? Then, once we have all tasks in modules, integrate the changes from estatico-nuo into estatico? |
@lbsonley, I could definitely make sense to have some of the tasks in there by default (already part of There is currently no roadmap. We can come up with one if we are sure about the direction we want to go, I guess. |
Also, if anyone has tried to clone this locally and runs into
its probably because your global gulp-cli verson does not support the local gulp 4
You can either update to gulp-cli 4.0.0 globally |
@lbsonley, you can run |
Would this be an acceptable approach to separating the custom configs? |
Absolutely! Though I'd rather use @yannisgu suggestion of a |
@backflip is probably right. We don't gain too much by splitting config from gulpfile, when gulpfile needs to be touched anyway. I made the proposal to have To answer @lbsonley's question: I would try to extract the gulp-tasks to small, reusable packages, however keep the estatico repository as kind of "starter-kit" you can copy and never update again. |
The splitting-up has started and will be tracked in unic/estatico-nou#3 |
@yannisgu, here you go: https://github.com/unic/estatico-nou I'd very much appreciate any feedback! |
Very nice, @backflip! |
@yannisgu, I agree that it is rather long. We'll see how we like it on upcoming projects. |
To achieve a more modular architecture in estatico, I propose to add a simple plugin system to estatico as a first step.
A plugin is basically a Node.js CommonJS which exports a function, which initializes the plugin.
So that estatico is aware of plugins, a configuration file "estatico.config.js" (inspired by webpack) is introduced. The configuration file must export an object in this format:
Example:
When starting, estatico then loads requires every plugin and calls the function with these parameters:
A plugin then should be built similar to how tasks are built today. The
pluginConfiguration
coming from the wrapper function should be merged with thetaskConfig
. Then the gulp-task should be registred withgulp.task()
and an object with the metadata for the task should be returned (same as tasks do today).All these returned objects are then stored in something like a plugin-registry, which then can be used from the watch task, to configure the watch things.
What do you think?
The text was updated successfully, but these errors were encountered: