Skip to content

Commit

Permalink
feature(add-template): map template files to actually generated files
Browse files Browse the repository at this point in the history
[Delivers #30]
  • Loading branch information
Inumidun Amao committed Jun 13, 2017
1 parent e221996 commit 21ece62
Show file tree
Hide file tree
Showing 28 changed files with 288 additions and 6 deletions.
3 changes: 3 additions & 0 deletions example/dist/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
margin: auto;
}
1 change: 1 addition & 0 deletions example/dist/images/images.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
All images will be stored in this folder
10 changes: 10 additions & 0 deletions example/dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>(title)</title>
</head>
<body>
<div id="app"></div>
<script src="/bundle.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions example/dist/js/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// This is a custom javascript file
1 change: 1 addition & 0 deletions example/dist/vendor/vendor.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
All vendors will be placed in this directory
8 changes: 4 additions & 4 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"version": "1.0.0",
"description": "React app",
"main": "index.js",
"description": "m",
"main": "m",
"scripts": {
"test": ""
},
"keywords": [],
"author": "emma",
"license": "MIT",
"author": "a",
"license": "I",
"dependencies": {
"axios": "^0.16.2",
"babel-cli": "^6.24.1",
Expand Down
3 changes: 3 additions & 0 deletions example/src/actions/actionTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {

}
22 changes: 22 additions & 0 deletions example/src/components/Home.component.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';

/**
* Home page view
* @class Home
* @extends {React.Component}
*/
class Home extends React.Component {

/**
* Renders the view of the component
* @returns {Object} react component to render
* @memberOf Home
*/
render() {
return (
<h2>Home page</h2>
);
}
}

export default Home;
34 changes: 34 additions & 0 deletions example/src/components/Routes.component.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import { Router, Route, IndexRoute, browserHistory } from 'react-router';
import Common from './common/Common.component';
import Home from './Home.component';
import About from './static/About.component';

const routes = (
<Route path="/" component={Common}>
<IndexRoute component={Home} />
<Route path="/about" component={About} />
</Route>
);


/**
* Declare and define all routes in the application
* @class Routes
* @extends {React.Component}
*/
class Routes extends React.Component {

/**
* Renders the view of the component
* @returns {Object} react component to render
* @memberOf Routes
*/
render() {
return (
<Router history={browserHistory} routes={routes} />
);
}
}

export default Routes;
27 changes: 27 additions & 0 deletions example/src/components/common/Common.component.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';

/**
* Component to persist across all routes
* @class Common
* @extends {React.Component}
*/
class Common extends React.Component {

/**
* Renders the view of the component
* @returns {Object} react component to render
* @memberOf Common
*/
render() {
return (
<div>
<nav>
<h2>Navbar</h2>
</nav>
{this.props.children}
</div>
);
}
}

export default Common;
22 changes: 22 additions & 0 deletions example/src/components/static/About.component.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';

/**
* About page view
* @class About
* @extends {React.Component}
*/
class About extends React.Component {

/**
* Renders the view of the component
* @returns {Object} react component to render
* @memberOf About
*/
render() {
return (
<h2>About page</h2>
);
}
}

export default About;
16 changes: 16 additions & 0 deletions example/src/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import ReactDom from 'react-dom';
import { Provider } from 'react-redux';
import store from './store';
import Routes from './components/Routes.component';

require('./sass/style.scss');
require('./sass/style.less');


ReactDom.render(
<Provider store={store}>
<Routes />
</Provider>,
document.getElementById('app')
);
8 changes: 8 additions & 0 deletions example/src/reducers/root.reducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { combineReducers } from 'redux';
import reduceReducers from 'reduce-reducers';

const combinedReducers = combineReducers({

});

export default reduceReducers(combinedReducers);
11 changes: 11 additions & 0 deletions example/src/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { applyMiddleware, createStore, compose } from 'redux';
import thunk from 'redux-thunk';
import reducers from './reducers/root.reducer';

const middleware = [thunk];

const finalCreateStore = compose(
applyMiddleware(...middleware)
)(createStore);

export default finalCreateStore(reducers);
45 changes: 45 additions & 0 deletions example/src/utils/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import axios from 'axios';

/**
* Set the a value inside localStorage
* @export
* @param {String} key - key to store value with in localStorage
* @param {String} value - item to store inside localStorage
* @returns {Promise} returns a promise and resolves it with the stored value
*/
export function setLocalstorage(key, value) {
let storedValue;
return new Promise((resolve) => {
window.localStorage.setItem(key, value);
storedValue = window.localStorage.getItem(key);
if (storedValue) {
resolve(storedValue);
}
});
}

/**
* set a default header in axios
* @export
* @param {String} header - header name to set
* @param {String} value - value to set header as
* @returns {Void} does not have a return value
*/
export function setDefaultHeader(header, value) {
axios.defaults.headers.common.Authorization = value;
}


/**
* clear or remove one or all items from localStorage
* @export
* @param {String} key - item to remove in localStorage
* @returns {Void} does not have a return value
*/
export function clearStorage(key) {
if (!key) {
window.localStorage.clear();
} else {
window.localStorage.removeItem(key);
}
}
7 changes: 7 additions & 0 deletions example/test/actions/actionTypes.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import actionTypes from '../../src/actions/actionTypes';

describe('actionTypes', () => {
it('should return an object of actions', () => {
expect(actionTypes).to.be.an.object;
});
});
16 changes: 16 additions & 0 deletions example/test/components/Home.component.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* global expect:true */
/* global shallow:true */
/* global mount:true */

import React from 'react';//eslint-disable-line

import Home from '../../src/components/Home.component';

describe('<Home />', () => {
it('should have a heading text', () => {
const wrapper = shallow(
<Home />
);
expect(wrapper.find('.heading')).to.have.length(1);
});
});
1 change: 1 addition & 0 deletions example/test/e2e/e2e.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// write e2e tests here
45 changes: 45 additions & 0 deletions example/test/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import axios from 'axios';

/**
* Set the a value inside localStorage
* @export
* @param {String} key - key to store value with in localStorage
* @param {String} value - item to store inside localStorage
* @returns {Promise} returns a promise and resolves it with the stored value
*/
export function setLocalstorage(key, value) {
let storedValue;
return new Promise((resolve) => {
window.localStorage.setItem(key, value);
storedValue = window.localStorage.getItem(key);
if (storedValue) {
resolve(storedValue);
}
});
}

/**
* set a default header in axios
* @export
* @param {String} header - header name to set
* @param {String} value - value to set header as
* @returns {Void} does not have a return value
*/
export function setDefaultHeader(header, value) {
axios.defaults.headers.common.Authorization = value;
}


/**
* clear or remove one or all items from localStorage
* @export
* @param {String} key - item to remove in localStorage
* @returns {Void} does not have a return value
*/
export function clearStorage(key) {
if (!key) {
window.localStorage.clear();
} else {
window.localStorage.removeItem(key);
}
}
Empty file removed example/test/mocha-helper.js
Empty file.
3 changes: 3 additions & 0 deletions example/test/reducers/root.reducer.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe('Root Reducer', () => {

});
6 changes: 5 additions & 1 deletion lib/Structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Structure {
constructor(extend = '', schema) {
this.schema = schema || structureSchema;
this.filepath = `${baseDir.getCurrentWorkingDir()}/${extend}`;
this.mainpath = path.join(__dirname, '../');
}

/**
Expand All @@ -40,11 +41,14 @@ class Structure {
path.join(this.filepath, `/example/${pathname.join('/')}`));
this.traverse(root[Object.keys(root)[0]], pathname);
} else {
const template = fs.readFileSync(
path.join(this.mainpath, `/sample/${root}.sample`))
.toString();
fs.writeFile(
path.join(
this.filepath,
`/example/${pathname.join('/')}/${root}`),
'');
template);
if (index === parent.length - 1) {
pathname.pop();
}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion sample/folder-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = [
src: [
{
components: [
{ common: ['Button.component.jsx'] },
{ common: ['Common.component.jsx'] },
{ static: ['About.component.jsx'] },
'Routes.component.jsx',
'Home.component.jsx'
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions sample/red.txt.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test file
1 change: 1 addition & 0 deletions sample/text.txt.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test file
File renamed without changes.

0 comments on commit 21ece62

Please sign in to comment.