From 080124942cf144782a5e71105482b2a646d424b7 Mon Sep 17 00:00:00 2001 From: kucukkanat Date: Thu, 22 Feb 2018 22:04:12 +0100 Subject: [PATCH] Add readme when creating component for styleguide now --- src/javascript/components/Navbar/index.js | 57 ------------------- tasks/new.component.js | 37 ++++++------ .../Navbar => tasks/templates}/readme.md | 11 +++- 3 files changed, 29 insertions(+), 76 deletions(-) delete mode 100644 src/javascript/components/Navbar/index.js rename {src/javascript/components/Navbar => tasks/templates}/readme.md (53%) diff --git a/src/javascript/components/Navbar/index.js b/src/javascript/components/Navbar/index.js deleted file mode 100644 index 6a28320..0000000 --- a/src/javascript/components/Navbar/index.js +++ /dev/null @@ -1,57 +0,0 @@ -/** - * This is the Navbar react component. - * Following parameters are props to pass to the component - * - * @summary Navbar Component - * @class Navbar - * @author Hilmi Tolga SAHIN (htolgasahin@gmail.com) - * @copyright htolgasahin@gmail.com - * @requires react - * @requires react-redux - * @requires prop-types - */ - -import React from 'react' -import PropTypes from 'prop-types' -import {connect} from 'react-redux' - - -class Navbar extends React.Component { - constructor (props) { - super(props) - this.state = {} - } - componentWillMount () { - - } - componentDidMount () { - - } - - render () { - return ( -
-
- I am Navbar component -
-
- ) - } -} - -Navbar.defaultProps = {} -Navbar.propTypes = {} - -const mapStateToProps = function (state) { - return { - // ... - } -} -const mapDispatchToProps = dispatch => { - return { - // .. some prop to call dispatch - } -} - -export default connect(mapStateToProps,mapDispatchToProps)(Navbar) - diff --git a/tasks/new.component.js b/tasks/new.component.js index 8f364ae..50253a9 100644 --- a/tasks/new.component.js +++ b/tasks/new.component.js @@ -4,30 +4,35 @@ const consolidate = require('gulp-consolidate') const rename = require('gulp-rename') module.exports = (done) => { - inquirer.prompt([ - { - 'type':'input', - 'name':'componentName', - 'message':'What is your component name ? (Component name should start with a Capital letter)' - }, - { - 'type':'confirm', - 'name':'reduxEnabled', - 'message':'Enable redux for component ? ' - } + inquirer.prompt([{ + 'type': 'input', + 'name': 'componentName', + 'message': 'What is your component name ? (Component name should start with a Capital letter)' + }, + { + 'type': 'confirm', + 'name': 'reduxEnabled', + 'message': 'Enable redux for component ? ' + } ]) .then(response => { const initial = response.componentName[0] const uppercase = initial.toUpperCase() == initial - let params = Object.assign({},response) + let params = Object.assign({}, response) params.componentName_lowercase = params.componentName.toLowerCase() - - if(!uppercase) throw new Error('Component name should start with an uppercase letter!') - + + if (!uppercase) throw new Error('Component name should start with an uppercase letter!') + // Create component file gulp.src('./tasks/templates/react.component.js') - .pipe(consolidate('mustache',params)) + .pipe(consolidate('mustache', params)) .pipe(rename(`index.js`)) .pipe(gulp.dest(`src/javascript/components/${response.componentName}`)) + + // Create styleguide file + gulp.src('./tasks/templates/readme.md') + .pipe(consolidate('mustache', params)) + .pipe(rename(`readme.md`)) + .pipe(gulp.dest(`src/javascript/components/${response.componentName}`)) }) .catch(e => { console.log(e) diff --git a/src/javascript/components/Navbar/readme.md b/tasks/templates/readme.md similarity index 53% rename from src/javascript/components/Navbar/readme.md rename to tasks/templates/readme.md index 0b7bc16..34adfa9 100644 --- a/src/javascript/components/Navbar/readme.md +++ b/tasks/templates/readme.md @@ -1,10 +1,15 @@ -Navbar example +{{componentName}} example ```jsx +{{#reduxEnabled}} const store = require('./../../store').default; const { Provider } = require('react-redux'); - - +{{/reduxEnabled}} + +<{{componentName}} /> + +{{#reduxEnabled}} +{{/reduxEnabled}} ``` \ No newline at end of file