Skip to content

Commit 1ee579f

Browse files
committed
Initial commit
0 parents  commit 1ee579f

19 files changed

+484
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bower_components
2+
node_modules
3+
4+
www/compiled

Gulpfile.es6.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
2+
import gulp from 'gulp';
3+
import gutil from 'gulp-util';
4+
import livereload from 'gulp-livereload';
5+
import filter from 'gulp-filter';
6+
import react from 'gulp-react';
7+
import webpack from 'gulp-webpack';
8+
import webpackConfig from './webpack-config';
9+
10+
import sourcemaps from 'gulp-sourcemaps';
11+
12+
13+
var outputDestination = './www/compiled';
14+
var jsOutputDestination = `${outputDestination}/js`;
15+
var cssOutputDestination = `${outputDestination}/css`;
16+
17+
var cssFile = 'main.css';
18+
19+
20+
gulp.task('build-js', () => {
21+
gulp
22+
.src('src/js/app.jsx')
23+
.pipe(webpack(webpackConfig()))
24+
.on('error', gutil.log)
25+
.pipe(gulp.dest(jsOutputDestination));
26+
});
27+
28+
29+
gulp.task(
30+
'build',
31+
[
32+
'build-js'
33+
],
34+
() => {
35+
if (process.env.NODE_ENV === 'production' && !process.env.NO_MINIFY) {
36+
gulp.start('minify-public', function () {
37+
return gutil.log('Build done');
38+
});
39+
} else {
40+
return gutil.log('Build done');
41+
}
42+
}
43+
);
44+
45+
46+
gulp.task('build-prod', () => {
47+
process.env.NODE_ENV = 'production';
48+
gulp.start('build');
49+
});
50+
51+
52+
gulp.task('watch', () => {
53+
livereload.listen();
54+
55+
var webpackConfigObj = webpackConfig();
56+
webpackConfigObj.watch = true;
57+
gulp
58+
.src('src/js/app.jsx')
59+
.pipe(webpack(webpackConfigObj))
60+
.on('error', gutil.log)
61+
.pipe(gulp.dest(jsOutputDestination));
62+
63+
gulp
64+
.watch(`${outputDestination}/**`)
65+
.on('change', livereload.changed);
66+
67+
});
68+
69+
70+
71+
72+
gulp.task('default', () => {});

Gulpfile.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require('babel/register');
2+
module.exports = require('./Gulpfile.es6');

README.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Test assignment
2+
3+
4+
## Installation:
5+
Clone this repository
6+
7+
Change into repository root directory
8+
9+
10+
`npm install && npm run build`
11+
12+
13+
## Run:
14+
Open `www/index.html` in browser
15+
16+
17+
## Development:
18+
JS source code is inside directory `src/` with an entry point `src/js/application/bootstrap.js`
19+
20+
JS code is built using Webpack as CommonJS builder and Gulp as a command runner. Code is separated into vendors and app bundles for faster rebuild when developing.
21+
22+
23+
## Build the JS code
24+
`npm build`
25+
26+
27+
### For development - starts a LiveReload server and rebuilds files on change:
28+
`npm run build && npm run watch`
29+
30+
### Production build - minifies the end result:
31+
`npm run build-prod`
32+
33+
Built CSS and JS is placed in `www/compiled` directory.
34+
35+
36+

dev-server.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var webpack = require('webpack');
2+
var WebpackDevServer = require('webpack-dev-server');
3+
var config = require('./webpack-config.js');
4+
5+
6+
new WebpackDevServer(webpack(config), {
7+
publicPath: config.output.publicPath,
8+
hot: true
9+
}).listen(
10+
3000,
11+
'localhost',
12+
(err, result) => {
13+
if (err) {
14+
console.log(err);
15+
}
16+
17+
console.log('Listening at localhost:3000');
18+
}
19+
);

karma.conf.es6.js

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
export default function(config) {
2+
config.set({
3+
4+
// base path that will be used to resolve all patterns (eg. files, exclude)
5+
basePath: '',
6+
7+
// frameworks to use
8+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
9+
frameworks: ['jasmine'],
10+
11+
// list of files / patterns to load in the browser
12+
files: [
13+
'src/js/**/__tests__/*.js'
14+
],
15+
16+
// list of files to exclude
17+
exclude: [
18+
],
19+
20+
21+
preprocessors: {
22+
'src/js/**/__tests__/*.js': ['webpack']
23+
},
24+
25+
26+
webpack: {
27+
progress: false,
28+
stats: false,
29+
debug: false,
30+
quiet: true,
31+
cache: true,
32+
'module': {
33+
loaders: [
34+
{
35+
test: /\.js$/,
36+
exclude: /node_modules/,
37+
loader: 'babel-loader?experimental'
38+
},
39+
{
40+
test: /\.jsx$/,
41+
loaders: [
42+
//'react-hot',
43+
'babel-loader?experimental'
44+
],
45+
exclude: /node_modules/
46+
}
47+
],
48+
noParse: []
49+
},
50+
resolve: {
51+
alias: {
52+
underscore: 'lodash'
53+
}
54+
}
55+
},
56+
57+
58+
webpackMiddleware: {
59+
stats: {
60+
colors: true
61+
},
62+
noInfo: true,
63+
quiet: true,
64+
},
65+
66+
// test results reporter to use
67+
// possible values: 'dots', 'progress'
68+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
69+
reporters: ['mocha'],
70+
71+
72+
// web server port
73+
port: 9876,
74+
75+
76+
// enable / disable colors in the output (reporters and logs)
77+
colors: true,
78+
79+
80+
// level of logging
81+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
82+
logLevel: config.LOG_INFO,
83+
84+
85+
// enable / disable watching file and executing tests whenever any file changes
86+
autoWatch: true,
87+
88+
89+
// start these browsers
90+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
91+
browsers: [
92+
'Chrome',
93+
// 'Firefox',
94+
// 'PhantomJS',
95+
// 'Safari'
96+
],
97+
98+
99+
// Continuous Integration mode
100+
// if true, Karma captures browsers, runs the tests and exits
101+
singleRun: false
102+
});
103+
};

karma.conf.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require('babel/register');
2+
module.exports = require('./karma.conf.es6');

package.json

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "tree",
3+
"version": "0.0.1",
4+
"description": "",
5+
"main": "index.js",
6+
"private": true,
7+
"scripts": {
8+
"postinstall": "rm -rf node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-watcher/node_modules/gaze/node_modules/globule/node_modules/lodash ; ",
9+
"build": "./node_modules/.bin/gulp build",
10+
"build-prod": "./node_modules/.bin/gulp build-prod",
11+
"watch": "./node_modules/.bin/gulp watch",
12+
"test": "./node_modules/karma/bin/karma start --single-run"
13+
},
14+
"author": "Andris Silis",
15+
"license": "",
16+
"devDependencies": {
17+
"babel-core": "^4.0.2",
18+
"babel-loader": "^4.0.0",
19+
"gulp": "^3.8.8",
20+
"gulp-buffer": "0.0.2",
21+
"gulp-declare": "^0.3.0",
22+
"gulp-filter": "^1.0.2",
23+
"gulp-if": "^1.2.5",
24+
"gulp-livereload": "^2.1.1",
25+
"gulp-minify-css": "^0.3.11",
26+
"gulp-plumber": "^0.6.5",
27+
"gulp-preprocess": "^1.1.1",
28+
"gulp-react": "^2.0.0",
29+
"gulp-rename": "^1.2.0",
30+
"gulp-rev": "^2.0.1",
31+
"gulp-rev-collector": "^0.1.2",
32+
"gulp-sourcemaps": "^1.5.0",
33+
"gulp-sym": "0.0.14",
34+
"gulp-uglify": "^1.0.1",
35+
"gulp-util": "^3.0.1",
36+
"gulp-webpack": "^1.1.0",
37+
"gulp-wrap": "^0.3.0",
38+
"imports-loader": "^0.6.3",
39+
"jsx-loader": "^0.12.2",
40+
"null-loader": "^0.1.0",
41+
"webpack": "^1.5.3",
42+
"webpack-dev-server": "^1.7.0"
43+
},
44+
"dependencies": {
45+
"babel": "^4.7.3",
46+
"lodash": "^3.5.0",
47+
"react": "^0.13.3",
48+
"react-tools": "^0.13.0"
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
3+
export default React.createClass({
4+
5+
render() {
6+
return (
7+
<div>
8+
{this.props.children}
9+
</div>
10+
);
11+
}
12+
});

src/js/application/bootstrap.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import renderApp from './renderApp';
2+
import React from 'react';
3+
4+
5+
var bootstrap = () => {
6+
// Shortcuts for development
7+
window.React = React;
8+
window.Perf = React.addons.Perf;
9+
renderApp();
10+
};
11+
12+
13+
document.addEventListener('DOMContentLoaded', bootstrap, false);

src/js/application/renderApp.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
3+
import ApplicationLayoutView from './ApplicationLayoutView.jsx';
4+
import TableView from '../table/TableView.jsx';
5+
6+
7+
export default function (state) {
8+
React.render(
9+
<ApplicationLayoutView>
10+
<TableView />
11+
</ApplicationLayoutView>,
12+
document.querySelector('.content-wrapper')
13+
);
14+
};

src/js/table/TableView.jsx

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React from 'react';
2+
import _ from 'underscore';
3+
4+
export default React.createClass({
5+
getInitialState() {
6+
return {
7+
tableData: []
8+
};
9+
},
10+
11+
componentWillMount() {
12+
// Generate initial table data state
13+
this.setState({
14+
tableData: _.range(0, 10).map(rowIndex => _.range(0, 10))
15+
});
16+
},
17+
18+
onNewDataClick() {
19+
var tableData = this.state.tableData.map(row => {
20+
row[0] = Math.random();
21+
return row;
22+
});
23+
24+
this.setState({
25+
tableData: tableData
26+
});
27+
},
28+
29+
renderCellEl(content, index) {
30+
return (
31+
<td key={index}>{content}</td>
32+
);
33+
},
34+
35+
renderRowEl(contentList, index) {
36+
return (
37+
<tr key={index}>{contentList.map(this.renderCellEl)}</tr>
38+
);
39+
},
40+
41+
render() {
42+
return (
43+
<div>
44+
<table>
45+
{this.state.tableData.map(this.renderRowEl)}
46+
</table>
47+
<button onClick={this.onNewDataClick}>New data plskthnxbye</button>
48+
</div>
49+
);
50+
}
51+
});

0 commit comments

Comments
 (0)