Skip to content

Instantly share code, notes, and snippets.

@kelchm
Last active June 18, 2019 03:30
Show Gist options
  • Save kelchm/692f290fc16e18be725707a14588efe8 to your computer and use it in GitHub Desktop.
Save kelchm/692f290fc16e18be725707a14588efe8 to your computer and use it in GitHub Desktop.
babel-plugin-codgen dynamic named exports troublshooting
const questionFactory = require('./questionFactory');
const generalQuestionConfig = require('./generalConfig');
const processedConfig = questionFactory('general', generalQuestionConfig);
module.exports = Object.keys(processedConfig)
.map(key => `export const ${key} = ${JSON.stringify(processedConfig[key])}`)
.join(';');
import codegen from 'babel-plugin-codegen/macro';
codegen.require('./codegen.js');
import SomeInput from '@/components/inputs/SomeInput';
import SomeOtherInput from '@/components/inputs/SomeOtherInput';
module.exports = {
input1: {
title: 'Input 1 Title',
component: SomeInput,
},
input2: {
title: 'Input 2 Title',
component: SomeOtherInput,
},
};
const getQuestionId = (questionId, groupIdentifier) => `${groupIdentifier}.${questionId}`;
const getTestId = id => `${id}Label`;
const questionFactory = (groupIdentifier, configuration) => {
const processedConfiguration = {};
Object.keys(configuration).forEach(key => {
const { title, component } = configuration[key];
processedConfiguration[getQuestionKey(key)] = {
id: getQuestionId(key, groupIdentifier),
testId: getTestId(key),
Component: component,
title,
};
});
return processedConfiguration;
};
module.exports = questionFactory;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment