-
Notifications
You must be signed in to change notification settings - Fork 12
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
Added React-Native templates #29
Open
MrigWed
wants to merge
8
commits into
wednesday-solutions:master
Choose a base branch
from
MrigWed:feature/con-com-template
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
265df79
added react-native template and commands
MrigWed 3aa92f9
added react-native template and commands
MrigWed 5d6bec0
fixed prettier
MrigWed 10dbe65
Merge pull request #1 from MrigWed/feature/con-com-template
MrigWed 818facc
fixed command with --all flag
MrigWed 59a73fa
updated README.md
MrigWed 9c736ff
Merge branch 'master' of https://github.com/MrigWed/react-floki into …
MrigWed 2682120
resolved PR comments
MrigWed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
#! /usr/bin/env node | ||
const shell = require('shelljs'); | ||
const fs = require('fs'); | ||
const childProcess = require('child_process'); | ||
const process = require('process'); | ||
const _ = require('lodash'); | ||
const path = require('path'); | ||
|
||
const COMPONENT = 'component'; | ||
const CONTAINER = 'container'; | ||
const WEBPACK_BASE_BABEL = 'webpackBaseBabel'; | ||
const TEST_UTIL = 'tUtil'; | ||
const INJECT_SAGA = 'injectSaga'; | ||
|
||
const generator = path.join(__dirname, '../generators/react-native/index.js'); | ||
const plopGen = ['--plopfile', generator]; | ||
|
||
const [, , ...args] = process.argv; | ||
let commandLineArgs = args.toString().split(','); | ||
const stdioInherit = { stdio: 'inherit' }; | ||
|
||
function execShell(commandArray) { | ||
childProcess.execFileSync( | ||
path.join(__dirname, '../node_modules/.bin/plop'), | ||
commandArray, | ||
{ ...stdioInherit }, | ||
); | ||
} | ||
|
||
// validate input | ||
if (!commandLineArgs[0]) { | ||
shell.exec( | ||
`echo Sorry! react-native-generate requires an argument to be passed. Run react-native-generate --help for more details`, | ||
); | ||
return; | ||
} | ||
|
||
// get the type of generator | ||
shell.env.GENERATOR_TYPE = _.includes(commandLineArgs[0], 't') | ||
? 'existing' | ||
: 'new'; | ||
let directoryName = 'react-native-template'; | ||
switch (commandLineArgs[0]) { | ||
case 'init': | ||
shell.exec( | ||
`git clone https://github.com/wednesday-solutions/react-native-template`, | ||
); | ||
shell.cd(process.cwd()); | ||
if (commandLineArgs[1]) { | ||
shell.exec(`mkdir ${commandLineArgs[1]}`); | ||
fs.rename(`react-native-template`, commandLineArgs[1], err => { | ||
if (err) { | ||
throw new Error('Error while renaming'); | ||
} | ||
}); | ||
directoryName = commandLineArgs[1]; | ||
const json = path.join(__dirname, '../node_modules/.bin/json'); | ||
|
||
shell.exec( | ||
`${json} -I -f ${directoryName}/package.json -e "this.name='${directoryName}'"`, | ||
); | ||
shell.exec( | ||
`${json} -I -f ${directoryName}/package.json -e "this.homepage='""'"`, | ||
); | ||
shell.exec( | ||
`${json} -I -f ${directoryName}/package.json -e "this.author='""'"`, | ||
); | ||
shell.exec( | ||
`${json} -I -f ${directoryName}/package.json -e "this.repository='{}'"`, | ||
); | ||
|
||
commandLineArgs = _.drop(commandLineArgs); | ||
} | ||
shell.cd(directoryName); | ||
shell.exec(`git remote remove origin`); | ||
execShell([ | ||
'-f', | ||
...plopGen, | ||
WEBPACK_BASE_BABEL, | ||
..._.drop(commandLineArgs), | ||
]); | ||
shell.exec(`npm run initialize`); | ||
break; | ||
case 'gt': | ||
execShell(plopGen); | ||
break; | ||
case 'gtcom': | ||
execShell([...plopGen, COMPONENT, ..._.drop(commandLineArgs)]); | ||
break; | ||
case 'gtcon': | ||
execShell([...plopGen, CONTAINER, ..._.drop(commandLineArgs)]); | ||
break; | ||
case 'gtf': | ||
execShell(['-f', ...plopGen, ..._.drop(commandLineArgs)]); | ||
break; | ||
case 'gtcomf': | ||
execShell(['-f', ...plopGen, COMPONENT, ..._.drop(commandLineArgs)]); | ||
break; | ||
case 'gtconf': | ||
execShell(['-f', ...plopGen, CONTAINER, ..._.drop(commandLineArgs)]); | ||
break; | ||
case 'g': | ||
execShell([...plopGen, ..._.drop(commandLineArgs)]); | ||
break; | ||
case 'gcom': | ||
execShell([...plopGen, COMPONENT, ..._.drop(commandLineArgs)]); | ||
break; | ||
case 'gcon': | ||
execShell([...plopGen, CONTAINER, ..._.drop(commandLineArgs)]); | ||
break; | ||
case 'gf': | ||
execShell(['-f', ...plopGen, ..._.drop(commandLineArgs)]); | ||
break; | ||
case 'gcomf': | ||
execShell(['-f', ...plopGen, COMPONENT, ..._.drop(commandLineArgs)]); | ||
break; | ||
case 'gconf': | ||
execShell(['-f', ...plopGen, CONTAINER, ..._.drop(commandLineArgs)]); | ||
break; | ||
case 'gtutil': | ||
execShell(['-f', ...plopGen, TEST_UTIL, ..._.drop(commandLineArgs)]); | ||
break; | ||
case 'ginjectsaga': | ||
execShell(['-f', ...plopGen, INJECT_SAGA, ..._.drop(commandLineArgs)]); | ||
break; | ||
case '--help': | ||
shell.echo( | ||
`Generate tests for existing and new react native components\n\n` + | ||
`init: Create a new react native application\n` + | ||
`gt: Creating a test for a container or component\n` + | ||
`gtf: Forcefully creating a test for a container or component\n` + | ||
`gtcom: Creating a test for an existing component\n` + | ||
`gtcomf: Forcefully creating a test for an existing component\n` + | ||
`gtcon: Creating a test for an existing container\n` + | ||
`gtconf : Forcefully creating a test for an existing component\n` + | ||
`g: Creating a container or component\n` + | ||
`gf: Forcefully creating a container or component\n` + | ||
`gcom: Creating a component\n` + | ||
`gcomf: Forcefully creating a component\n` + | ||
`gcon: Creating a container\n` + | ||
`gconf: Forcefully creating a container\n` + | ||
`--all: Adding tests for all existing containers or components.\n` + | ||
`gtutil: Create a test util file with some test utility functions.\n` + | ||
`ginjectsaga: Create an injector for sagas that work with hooks.\n\n` + | ||
`-------\n\n` + | ||
`Creating a test by specifying type, path and name: react-native-generate gt component src/app Button\n` + | ||
`Creating a test for an existing component by specifying path and name: react-native-generate gtcon src/app Button\n` + | ||
`Creating a test for an existing container by specifying path and name: react-native-generate gtcom src/app HomePage\n` + | ||
`Creating a component/container by specifying type, path and name: react-native-generate g component src/app Button\n` + | ||
`Creating a component by specifying path and name: react-native-generate gcon src/app Button\n` + | ||
`Creating a container by specifying path and name: react-native-generate gcom src/app HomePage\n` + | ||
`Generate test for all components in directory: react-native-generate --all component src/app/components\n` + | ||
`Generate test for all containers in directory: react-native-generate --all containers src/app/containers`, | ||
); | ||
break; | ||
case '--all': | ||
{ | ||
commandLineArgs = _.drop(commandLineArgs); | ||
if (!commandLineArgs[0] || !commandLineArgs[1] || commandLineArgs[2]) { | ||
shell.exec( | ||
`echo Sorry! react-native-generate --all requires 2 commandLineArgs to be passed. Run react-native-generate --help for more details`, | ||
); | ||
return; | ||
} | ||
let cwd; | ||
let directories; | ||
switch (commandLineArgs[0]) { | ||
case COMPONENT: | ||
cwd = shell.exec('pwd').stdout; | ||
shell.cd(`./${commandLineArgs[1]}`); | ||
directories = shell.ls(); | ||
shell.cd(cwd); | ||
directories.forEach(component => { | ||
if (!_.includes(component, '.')) { | ||
shell.echo(`Component name: ${component}`); | ||
childProcess.execSync( | ||
`react-native-generate gtcomf ${_.drop( | ||
commandLineArgs, | ||
)} ${component}`, | ||
{ | ||
...stdioInherit, | ||
}, | ||
); | ||
} | ||
}); | ||
break; | ||
case CONTAINER: | ||
cwd = shell.exec('pwd').stdout; | ||
shell.cd(`./${commandLineArgs[1]}`); | ||
directories = shell.ls(); | ||
shell.cd(cwd); | ||
directories.forEach(component => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here please, let's make this |
||
if (!_.includes(component, '.')) { | ||
shell.echo(`Container name: ${component}`); | ||
childProcess.execSync( | ||
`react-native-generate gtconf ${_.drop( | ||
commandLineArgs, | ||
)} ${component}`, | ||
{ | ||
...stdioInherit, | ||
}, | ||
); | ||
} | ||
}); | ||
break; | ||
default: | ||
shell.exec(`echo ${commandLineArgs[0]} is not a valid argument`); | ||
} | ||
} | ||
break; | ||
default: | ||
shell.exec(`echo Sorry ${commandLineArgs[0]} is not a valid command`); | ||
break; | ||
} |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* | ||
* {{ properCase name }} | ||
* | ||
*/ | ||
|
||
{{#if memo}} | ||
import React, { memo } from 'react' | ||
{{else}} | ||
import React from 'react' | ||
{{/if}} | ||
import { View, Text } from 'react-native'; | ||
// import PropTypes from 'prop-types' | ||
// import styled from 'styled-components' | ||
|
||
import { FormattedMessage as T } from 'react-intl' | ||
|
||
function {{ properCase name }}() { | ||
return ( | ||
<View> | ||
<Text><T id={'{{lowerCase name}}'} /></Text> | ||
</View> | ||
) | ||
} | ||
|
||
{{ properCase name }}.propTypes = {} | ||
|
||
{{#if memo}} | ||
export default memo({{ properCase name }}) | ||
{{else}} | ||
export default {{ properCase name }} | ||
{{/if}} |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* | ||
* Stories for {{ properCase name }} | ||
* | ||
* @see https://github.com/storybookjs/storybook | ||
* | ||
*/ | ||
|
||
import React from 'react' | ||
import { View } from 'react-native'; | ||
import { storiesOf } from '@storybook/react-native' | ||
import { text } from '@storybook/addon-knobs' | ||
import {{ properCase name }} from '../index' | ||
|
||
|
||
storiesOf('{{properCase name}}').add('simple', () =><View><{{properCase name}} id={text('id', '{{properCase name}}')}/></View>) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* | ||
* Tests for {{ properCase name }} | ||
* | ||
*/ | ||
|
||
import React from 'react' | ||
// import { fireEvent } from '@testing-library/dom' | ||
import { renderWithIntl } from '@utils/testUtils' | ||
import {{ properCase name }} from '../index' | ||
|
||
describe('<{{ properCase name }} />', () => { | ||
|
||
it('should render and match the snapshot', () => { | ||
const { baseElement } = renderWithIntl(<{{ properCase name }} />) | ||
expect(baseElement).toMatchSnapshot() | ||
}) | ||
}) |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* | ||
* {{properCase name }} | ||
* | ||
*/ | ||
|
||
{{#if memo}} | ||
import React, { memo } from 'react' | ||
{{else}} | ||
import React from 'react' | ||
{{/if}} | ||
import { View, Text } from 'react-native'; | ||
// import PropTypes from 'prop-types' | ||
import { connect } from 'react-redux' | ||
import { injectIntl } from 'react-intl' | ||
import { FormattedMessage as T } from 'react-intl' | ||
{{#if wantActionsAndReducer}} | ||
import { createStructuredSelector } from 'reselect' | ||
{{/if}} | ||
import { compose } from 'redux' | ||
{{#if wantActionsAndReducer}} | ||
import makeSelect{{properCase name}} from './selectors' | ||
{{/if}} | ||
|
||
export function {{ properCase name }}() { | ||
|
||
return ( | ||
<View> | ||
<Text><T id={'{{properCase name}}'} /></Text> | ||
</View> | ||
) | ||
} | ||
|
||
{{ properCase name }}.propTypes = { | ||
} | ||
|
||
{{#if wantActionsAndReducer}} | ||
const mapStateToProps = createStructuredSelector({ | ||
{{ camelCase name }}: makeSelect{{properCase name}}(), | ||
}) | ||
{{/if}} | ||
|
||
function mapDispatchToProps(dispatch) { | ||
return { | ||
dispatch, | ||
} | ||
} | ||
|
||
{{#if wantActionsAndReducer}} | ||
const withConnect = connect(mapStateToProps, mapDispatchToProps) | ||
{{else}} | ||
const withConnect = connect(null, mapDispatchToProps) | ||
{{/if}} | ||
|
||
export default compose( | ||
withConnect, | ||
{{#if memo}} | ||
memo, | ||
{{/if}} | ||
)({{ properCase name }}) | ||
|
||
export const {{ properCase name }}Test = compose(injectIntl)({{ properCase name }}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's call this
container
, just for clarification