Skip to content
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

fix(sandbox): prettify the outputed code #2987

Merged
merged 1 commit into from
Jun 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 9 additions & 41 deletions docs/plugins/sandbox/gatsby-node.js
@@ -1,3 +1,6 @@
const { format } = require("prettier");
const parserTypeScript = require("prettier/parser-typescript");

const { getScope, omitTypes } = require("./helpers");

exports.onCreateNode = async ({ node, actions, loadNodeContent }) => {
Expand All @@ -15,6 +18,11 @@ exports.onCreateNode = async ({ node, actions, loadNodeContent }) => {

const scope = getScope(content);

const code = format(omitTypes(example[0]), {
parser: "typescript",
plugins: [parserTypeScript],
});

createNodeField({
node,
name: "scope",
Expand All @@ -24,7 +32,7 @@ exports.onCreateNode = async ({ node, actions, loadNodeContent }) => {
createNodeField({
node,
name: "example",
value: example ? omitTypes(example[0]) : "",
value: example ? code : "",
});

createNodeField({
Expand All @@ -34,43 +42,3 @@ exports.onCreateNode = async ({ node, actions, loadNodeContent }) => {
});
}
};

/* TODO: This is might be useful for the future sandbox integration,
for current sandbox-examples we decided to left simple iframe with react components inside
no need for external page right now.
*/

// exports.createPages = async ({ graphql, actions }) => {
// const { createPage } = actions;

// const result = await graphql(`
// query {
// allFile(filter: { absolutePath: { regex: "/__examples__/" } }) {
// nodes {
// id
// relativePath
// fields {
// example_id
// example
// scope {
// name
// path
// default
// }
// }
// }
// }
// }
// `);

// result.data.allFile.nodes.forEach(({ id, fields }) => {
// createPage({
// path: `examples/${fields.example_id}`.toLowerCase(),
// component: path.resolve(path.resolve(__dirname, "../../src/templates/Example/index.tsx")),
// context: {
// fields,
// id,
// },
// });
// });
// };