nubes
nubes copied to clipboard
Provide a pipeline API
What is a pipeline ?
It's a way to transform resources either at runtime (dev environment) or at startup or at build time (and then the framework doesn't care).
We could offer a pipeline API which would associate a resource to its built equivalent and map it to one single path. And then would transform it or not dependeing on the context.
Example
If we're on a dev environment :
When the user asks for assets/*.css, look for web/styles/*.scss, then send invoke my transform function and return the result.
If we're on a production environment :
Look for every file in web/styles/*.scss, if you fin their equivalent into dist/styles/*.css then it's OK, serve directly those files when assets/*.css is asked. If some are missing, please invoke my transformation function and save the result.
Pretty complicated to explain, not that easy to implement, but very useful.
So the pipeline interface could look like this :
public interface Pipeline {
public String rawPattern();
public String distDir();
public String transformName(String originalName);
public Buffer transform(Buffer originalContent);
}
In case of sass files for instance :
public class SassPipeline implements Pipeline {
public String rawPattern() {
return "web/raw/styles/*.scss";
}
public String distDir() {
return "web/dist/styles":
}
public String transformName(String originalName) {
return originalName.replace(".scss", ".css");
}
public Buffer transform(Buffer originalContent) {
// invoke sass compiler
return ...
}
}