As a locally-run preparation step, I've got some CSV that I want to convert into JSON for a Gatsby site. I know that I can set up my gatsby-config.js
render data from CSV using gatsby-transformer-csv
but what I want to do is use that plugin ± directly outside of my main Gatsby build.
Something like:
import { onCreateNode as csvTransform } from "gatsby-transformer-csv/gatsby-node";
import { createFileNodeFromBuffer } from "gatsby-source-filesystem";
async function convertTheThings(csvContent: Buffer) {
const csvNode = await createFileNodeFromBuffer({
buffer: csvContent
});
await csvTransform({
node: csvNode,
actions // FIXME: how to get these!?
});
// … use the individual JSON nodes …
for (const jsonNode of jsonNodesCreated) {
await writeFile(`data/processed_content/${jsonNode.name}.json`, jsonNode.content);
}
}
But it seems that there is no way to "call into" Gatbsy and use it like a more traditional library? Is there an API that lets me use and manipulate nodes without being part of the main actual static build?