Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. #! /usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """Create a react app based on create-react-app. python create_react_app.py yourapp."""
  4. import os
  5. import sys
  6.  
  7. PROJECT_NAME = sys.argv[1]
  8. if PROJECT_NAME is None or len(PROJECT_NAME) == 0:
  9. raise ValueError("The project name must be valid.")
  10. ROOT_PATH = "./{}/".format(PROJECT_NAME)
  11.  
  12. print("Creating the project...")
  13. os.system("npm i -g create-react-app @storybook/cli")
  14. os.system("create-react-app {}".format(PROJECT_NAME))
  15. os.system("cd {} && git init && git flow init && cd ..".format(PROJECT_NAME))
  16. os.system("cd {} && getstorybook && cd ..".format(PROJECT_NAME))
  17.  
  18. print("Preparing the project structure...")
  19. with open("{}CHANGELOG.md".format(ROOT_PATH), "w") as f:
  20. cl = """
  21. ---
  22.  
  23. ## v0.1.0
  24.  
  25. **Author**: Guillaume Mousnier, Jeremy Raffin, Jerome Raffin.
  26.  
  27. **Type**: Feature
  28.  
  29. **Changes**:
  30. - Init the repo
  31.  
  32. ---
  33. """
  34. f.write(cl)
  35.  
  36.  
  37. with open("{}.travis.yml".format(ROOT_PATH), "w") as f:
  38. cl = """
  39. ---
  40. language: node_js
  41. node_js:
  42. - 6
  43. cache:
  44. directories:
  45. - node_modules
  46. script:
  47. - npm test
  48. - npm run build
  49. ---
  50. """
  51. f.write(cl)
  52.  
  53.  
  54. os.mkdir("{}src/__tests__".format(ROOT_PATH))
  55. os.mkdir("{}src/components".format(ROOT_PATH))
  56. os.mkdir("{}src/containers".format(ROOT_PATH))
  57. os.mkdir("{}src/assets".format(ROOT_PATH))
  58. os.mkdir("{}src/css".format(ROOT_PATH))
  59.  
  60. with open("{}src/router.js".format(ROOT_PATH), "w") as f:
  61. router = """
  62. import React from 'react'
  63. import ReactDOM from 'react-dom'
  64. import { createStore, combineReducers } from 'redux'
  65. import { Provider } from 'react-redux'
  66. import { Router, Route, browserHistory } from 'react-router'
  67. import { syncHistoryWithStore, routerReducer } from 'react-router-redux'
  68.  
  69. import App from ./containers/App.js
  70. import MyContainer from ./containers/container
  71. import mycontainerReducer from './containers/mycontainer/reducer'
  72.  
  73. const store = createStore(
  74. combineReducers({
  75. mycontainer: mycontainerReducer,
  76. routing: routerReducer
  77. })
  78. )
  79.  
  80. const history = syncHistoryWithStore(browserHistory, store)
  81.  
  82. export default () => (
  83. <Provider store={store}>
  84. <Router history={history}>
  85. <Route path="/" component={App}>
  86. <Route path="mycontainer" component={MyContainer}/>
  87. </Route>
  88. </Router>
  89. </Provider>
  90. )
  91. """
  92.  
  93. print("Installing last dependencies...")
  94. os.system("cd {} && npm i --save redux react-router react-redux react-router-redux styled-components redux-thunk"
  95. .format(ROOT_PATH))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement