-
Notifications
You must be signed in to change notification settings - Fork 10
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
[RFC] Plugins: Transforms #185
Comments
Looks like we have a new paradigm and opportunity to solve this as part of the work being done #417 with Koa. I think just trying to find the common denominator in terms of things in common when need to resolve / transform files. Things like
(I wouldn't worry about Rather than pass the whole I would say out of the box Greenwood should support all web languages and some friends * out of the box, everything else would be community plugins / packages
Ideally plugins should be decoupled as much as possible. So given the above, I would expect at least 6 different transforms. |
Roadmap as part of #418
|
Had a couple more thoughts on technical direction here that we could achieve as part of trying to integrate our plugins into this system TransformInterace ConstructorI think we should change the signature of the // tranform.interface.js
module.exports = class TransformInterface {
constructor(request, compilation, { extensions = [], contentType = '' }) {
const { context, config } = compilation;
this.extensions = extensions; // ['.foo', '.bar']
this.workspace = context.userWorkspace; // greenwood
this.scratchDir = context.scratchDir;
this.request = request;
this.config = config;
this.contentType = contentType;
}
shouldTransform() {
// do stuff
}
applyTransform() {
// do stuff with path
}
}; And extended like this class JSTransform extends TransformInterface {
constructor(req, compilation) {
super(req, compilation, {
extensions: ['.js'],
contentType: 'text/javascript'
});
}
shouldTransform() {
// stuff
}
...
} And used like this try {
// default transforms
const defaultTransforms = [
new HTMLTransform(request, compilation),
new MarkdownTransform(request, compilation),
new CSSTransform(request, compilation),
new JSTransform(request, compilation),
new JSONTransform(request, compilation),
new AssetTransform(request, compilation)
]; ReduceInstead of a await Promise.all(defaultTransforms.reduce(async (response, plugin) => {
if (plugin instanceof Transform && plugin.shouldTransform()) {
const transformedResponse = await plugin.applyTransform();
response = {
...transformedResponse
};
}
}response)); OrderingI think we should try and work our way up on this, and least try support these two kinds of cases:
I think we can follow a similar model as how we are doing rehype / remark customizations. I think we could do something where we
So in a loose code example, something like const defaultTransforms = [
new HTMLTransform(request, compilationCopy),
new MarkdownTransform(request, compilationCopy),
new CSSTransform(request, compilationCopy),
new JSTransform(request, compilationCopy),
new JSONTransform(request, compilationCopy),
new AssetTransform(request, compilationCopy)
];
const defaultExtensions = [].concat(defaultTransforms.map(transform => return transform.getExtension());
const preProcessTransforms = compilation.config.plugins.filter(plugin => {
return plugin.type === 'transform'
}).filter(plugin => {
!defaultExtensions.includes(return.plugin.getExtension());
});
const postProcessTransforms = compilation.config.plugins.filter(plugin => {
return plugin.type === 'transform'
}).filter(plugin => {
return defaultExtensions.includes(return.plugin.getExtension());
});
const orderedTransforms = [
...preProcessTransforms,
...defaultTransforms,
...postProcessTransforms
]
await Promise.all(orderedTransforms.reduce(async (response, plugin) => {
// reduce response against all transforms
}), response); |
Type of Change
Summary
Taken from a comment in #17 (comment) in regards to a general discussion around the API and capturing the specific action item re: the
lifecycle
plugin type here.Details
This would essentially be enabling potentially different source file types in addition to the default markdown support, like JavaScript or maybe YAML?
At minimum, should probably make sure to support at least .html files out of the box.
The text was updated successfully, but these errors were encountered: