Skip to content

Commit e710eaf

Browse files
author
Evan Jacobs
committed
Update overall structure, add babel static class method plugin
1. added `src/` at the root of every project to keep your working files clean and separate from everything else 2. merged the sanitize stylesheet into the top-level `style.styl` 3. updated various files with newer ES6+ conveniences 4. added the babel "transform-class-properties" plugin to enable static class property shortcuts (part of the enhancements in #3) 5. removed the `LICENSE` file in favor of the simple license field in `package.json` 6. reorganized where static assets are meant to live; place your images, fonts, etc in `src/static/assets` and they will be copied over to `/dist` during the build process 7. switched the dev server (budo) invocation from the CLI to using it as a library; see `scripts/budo.js`
1 parent 18b1e54 commit e710eaf

File tree

14 files changed

+134
-103
lines changed

14 files changed

+134
-103
lines changed

generators/app/index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,29 +82,29 @@ module.exports = yeoman.Base.extend({
8282
writing: function() {
8383
var copier = copy.bind(this);
8484

85-
mkdirp('example/__tests__');
8685
mkdirp('dist/assets');
86+
mkdirp('scripts');
87+
mkdirp('src/example/__tests__');
88+
mkdirp('src/static/assets/images');
8789

8890
copier([
8991
['_eslintignore', '.eslintignore'],
9092
['_eslintrc', '.eslintrc'],
9193
['_gitignore', '.gitignore'],
92-
'_sanitize.styl',
9394
'CONTRIBUTING.md',
94-
'example/index.js',
95-
'example/style.styl',
96-
'example/__tests__/index.js',
97-
'index.js',
98-
'parallelize.sh',
99-
'style.styl',
95+
'scripts/parallelize.sh',
96+
'src/example/index.js',
97+
'src/example/style.styl',
98+
'src/example/__tests__/index.js',
99+
'src/index.js',
100+
'src/style.styl',
100101
]);
101102

102103
copier([
103-
'package.json',
104-
'index.html',
105104
'CHANGELOG.md',
106-
'LICENSE',
107-
'README.md'
105+
'package.json',
106+
'README.md',
107+
'src/static/index.html'
108108
], this.answers);
109109
},
110110

generators/app/templates/LICENSE

Lines changed: 0 additions & 25 deletions
This file was deleted.

generators/app/templates/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
11
# <%= appName %>
2+
3+
## getting started
4+
5+
```bash
6+
npm i
7+
```
8+
9+
## running the development server
10+
11+
```bash
12+
npm start
13+
```
14+
15+
Add files, edit your code, etc and the browser will automatically refresh with the appropriate changes.
16+
17+
## shipping code
18+
19+
```bash
20+
npm run release
21+
```
22+
23+
Then simply copy the contents of `dist/` to your final destination.

generators/app/templates/example/__tests__/index.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

generators/app/templates/package.json

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "<%= appName %>",
33
"description": "<%= appDescription %>",
4+
"license": "MIT",
45
"private": true,
56
"version": "0.1.0",
67
"author": {
@@ -15,6 +16,7 @@
1516
"autoprefixer-stylus": "^0.9.2",
1617
"babel-eslint": "^6.0.0",
1718
"babel-jest": "^12.0.2",
19+
"babel-plugin-transform-class-properties": "^6.6.0",
1820
"babel-preset-es2015": "^6.6.0",
1921
"babel-preset-react": "^6.5.0",
2022
"babel-preset-stage-2": "^6.5.0",
@@ -24,31 +26,42 @@
2426
"eslint": "^2.7.0",
2527
"eslint-plugin-react": "^4.2.3",
2628
"jest-cli": "^12.0.2",
29+
"mkdirp": "latest",
2730
"stylus": "^0.54.2",
2831
"uglify-js": "^2.6.2",
2932
"watchify": "^3.7.0"
3033
},
3134
"babel": {
35+
"plugins": [
36+
"transform-class-properties"
37+
],
3238
"presets": [
3339
"es2015",
3440
"react",
3541
"stage-2"
3642
]
3743
},
44+
"browserify": {
45+
"transform": [
46+
"babelify"
47+
]
48+
},
3849
"jest": {
3950
"automock": false
4051
},
4152
"scripts": {
42-
"js": "browserify index.js -t babelify --debug > dist/assets/bundle.js",
43-
"js:release": "NODE_ENV=production browserify index.js -t babelify | uglifyjs -mc drop_console > dist/assets/bundle.min.js",
44-
"js:watch": "budo index.js:dist/assets/bundle.js -H 0.0.0.0 --live --open --iw -- --debug -t babelify",
45-
"css": "stylus -m -u autoprefixer-stylus style.styl -o dist/assets/style.css --sourcemap-inline",
46-
"css:release": "stylus -c -u autoprefixer-stylus style.styl -o dist/assets/style.min.css",
53+
"postinstall": "mkdirp dist/assets",
54+
"js": "browserify src/index.js --debug > dist/assets/bundle.js",
55+
"js:release": "NODE_ENV=production browserify src/index.js | uglifyjs -mc drop_console > dist/assets/bundle.min.js",
56+
"js:watch": "node scripts/budo.js",
57+
"css": "stylus -m -u autoprefixer-stylus src/style.styl -o dist/assets/style.css --sourcemap-inline",
58+
"css:release": "stylus -c -u autoprefixer-stylus src/style.styl -o dist/assets/style.min.css",
4759
"css:watch": "npm run css -- -w",
48-
"html:release": "cp -f index.html dist/ && sed -e 's/bundle.js/bundle.min.js/g' -e 's/style.css/style.min.css/g' -e 's/dist\\///g' < index.html > dist/index.html",
60+
"assets:copy": "cp -rf src/static/* dist/",
61+
"html:release": "sed -e 's/bundle.js/bundle.min.js/g' -e 's/style.css/style.min.css/g' < src/static/index.html > dist/index.html",
4962
"build": "npm run js && npm run css",
50-
"release": "npm run css:release && npm run html:release && npm run js:release",
51-
"start": "sh parallelize.sh \"npm run css:watch\" \"npm run js:watch\"",
63+
"release": "npm run assets:copy && npm run html:release && npm run css:release && npm run js:release",
64+
"start": "sh scripts/parallelize.sh \"npm run css:watch\" \"npm run js:watch\"",
5265
"lint": "eslint --quiet *.js **/*.js",
5366
"test": "jest --verbose",
5467
"coverage": "jest --coverage"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require('budo')('src/index.js', {
2+
browserify: {
3+
debug: true,
4+
},
5+
6+
dir: ['src/static', 'dist'],
7+
host: '0.0.0.0',
8+
live: true,
9+
open: true,
10+
portfind: true,
11+
pushstate: true,
12+
serve: 'assets/bundle.js',
13+
stream: process.stdout,
14+
15+
watchGlob: [
16+
'src/**/*.{html,css,json}'
17+
]
18+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* eslint no-unused-expressions:0 */
2+
3+
import React from 'react';
4+
import {render, unmountComponentAtNode as cleanup} from 'react-dom';
5+
import Example from '../index';
6+
7+
describe('Example', () => {
8+
const testingRootNode = document.body.appendChild(document.createElement('div'));
9+
const r = vdom => render(vdom, testingRootNode);
10+
11+
afterEach(() => cleanup(testingRootNode));
12+
13+
it('renders successfully', () => {
14+
expect(r(<Example />)).not.toBe(undefined);
15+
});
16+
17+
it('accepts a title', () => {
18+
const element = r(<Example title='Hello World!' />);
19+
20+
expect(element.refs.title).not.toBe(undefined);
21+
expect(element.refs.title.textContent).toBe('Hello World!');
22+
});
23+
24+
it('accepts a description', () => {
25+
const element = r(<Example description='Party time!' />);
26+
27+
expect(element.refs.description).not.toBe(undefined);
28+
expect(element.refs.description.textContent).toBe('Party time!');
29+
});
30+
});

generators/app/templates/example/index.js renamed to generators/app/templates/src/example/index.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
import React from 'react';
22

3-
class Example extends React.Component {
3+
export default class Example extends React.Component {
4+
static propTypes = {
5+
title: React.PropTypes.string,
6+
description: React.PropTypes.string,
7+
}
8+
49
renderTitle() {
510
if (this.props.title) {
611
return (
7-
<h1 ref='title' className='ui-example-title'>{this.props.title}</h1>
12+
<h1 ref='title' className='ui-example-title'>
13+
{this.props.title}
14+
</h1>
815
);
916
}
1017
}
1118

1219
renderDescription() {
1320
if (this.props.description) {
1421
return (
15-
<p ref='description' className='ui-example-desc'>{this.props.description}</p>
22+
<p ref='description' className='ui-example-desc'>
23+
{this.props.description}
24+
</p>
1625
);
1726
}
1827
}
@@ -26,10 +35,3 @@ class Example extends React.Component {
2635
);
2736
}
2837
}
29-
30-
Example.propTypes = {
31-
title: React.PropTypes.string,
32-
description: React.PropTypes.string,
33-
};
34-
35-
export default Example;

0 commit comments

Comments
 (0)