Last active
June 18, 2019 03:30
-
-
Save kelchm/692f290fc16e18be725707a14588efe8 to your computer and use it in GitHub Desktop.
babel-plugin-codgen dynamic named exports troublshooting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(';'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import codegen from 'babel-plugin-codegen/macro'; | |
codegen.require('./codegen.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | |
}, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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