Skip to content

Instantly share code, notes, and snippets.

@adamrneary
Last active March 13, 2020 07:20
Show Gist options
  • Save adamrneary/f34806385d354567c166adfa68b93762 to your computer and use it in GitHub Desktop.
Save adamrneary/f34806385d354567c166adfa68b93762 to your computer and use it in GitHub Desktop.
const COMPONENT_TEMPLATE = 'component.tsx.template';
const STORY_TEMPLATE = 'story.jsx.template';
const TEST_TEMPLATE = 'test.jsx.template';
const SECTION_TYPES = 'frontend/luxury-guest/src/apps/PdpFramework/constants/SectionTypes.js';
const SECTION_MAPPING = 'frontend/luxury-guest/src/components/PdpFramework/Sections.tsx';
const COMPONENT_DIR = 'frontend/luxury-guest/src/components/PdpFramework/sections';
const STORY_DIR = 'frontend/luxury-guest/stories/PdpFramework/sections';
const TEST_DIR = 'frontend/luxury-guest/tests/components/PdpFramework/sections';
module.exports = class ComponentGenerator extends Generator {
_writeFile(templatePath, destinationPath, params) {
if (!this.fs.exists(destinationPath)) {
this.fs.copyTpl(templatePath, destinationPath, params);
}
}
prompting() {
return this.prompt([
{
type: 'input',
name: 'componentName',
required: true,
message:
'Yo! What is the section component name? (e.g. SuperFlyFullBleed or ThreeImagesWithFries)',
},
]).then(data => {
this.data = data;
});
}
writing() {
const { componentName, componentPath } = this.data;
const componentConst = _.snakeCase(componentName).toUpperCase();
this._writeFile(
this.templatePath(COMPONENT_TEMPLATE),
this.destinationPath(COMPONENT_DIR, `${componentName}.tsx`),
{ componentConst, componentName }
);
this._writeFile(
this.templatePath(STORY_TEMPLATE),
this.destinationPath(STORY_DIR, `${componentName}VariationProvider.jsx`),
{ componentName, componentPath }
);
this._writeFile(
this.templatePath(TEST_TEMPLATE),
this.destinationPath(TEST_DIR, `${componentName}.test.jsx`),
{ componentName }
);
this._addToSectionTypes();
this._addToSectionMapping();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment