Skip to content

Commit 07fa657

Browse files
committed
feature: allow custom result types
adds built-in result types: html, jsx and plain. Default is html. new example using react.js Fixes #9
1 parent ea2a5a4 commit 07fa657

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1066
-193
lines changed

bin/startExpressApp.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
__DIRNAME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3+
$__DIRNAME/../examples/express-app-using-result-json/bin/www

bin/startReactTutorial.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
__DIRNAME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3+
node "$__DIRNAME/../examples/react-tutorial/server.js"
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// default result type is "html"
2+
3+
module.exports = {
4+
bundle: {
5+
base: {
6+
scripts: './scripts/base.js',
7+
styles: './styles/base.css',
8+
options: {
9+
rev: false,
10+
uglify: false, // this has to be false, otherwise uglify will blow up when trying to parse a .jsx file
11+
result: {
12+
type: {
13+
scripts: 'jsx',
14+
styles: 'html'
15+
}
16+
}
17+
}
18+
},
19+
default: {
20+
scripts: './scripts/default.js',
21+
styles: './styles/default.css',
22+
options: {
23+
rev: false,
24+
result: {
25+
type: 'html' // applies to both scripts and styles
26+
}
27+
}
28+
},
29+
plain: {
30+
scripts: './scripts/plain.js',
31+
styles: './styles/plain.css',
32+
options: {
33+
rev: false,
34+
result: {
35+
type: 'plain'
36+
}
37+
}
38+
},
39+
custom: {
40+
scripts: './scripts/custom.js',
41+
styles: './styles/custom.css',
42+
options: {
43+
rev: false,
44+
result: {
45+
type: {
46+
scripts: function xJavascript(path) {
47+
return "<script async src='" + path + "' type='application/javascript'></script>";
48+
},
49+
styles: function html(path) {
50+
return "<link href='" + path + "' type='text/html'/>";
51+
}
52+
}
53+
}
54+
}
55+
}
56+
}
57+
};
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"base": {
3+
"scripts": "<script src='/public/base.js' type='text/jsx'></script>",
4+
"styles": "<link href='/public/base.css' media='screen' rel='stylesheet' type='text/css'/>"
5+
},
6+
"plain": {
7+
"scripts": "/public/plain.js",
8+
"styles": "/public/plain.css"
9+
},
10+
"default": {
11+
"styles": "<link href='/public/default.css' media='screen' rel='stylesheet' type='text/css'/>",
12+
"scripts": "<script src='/public/default.js' type='text/javascript'></script>"
13+
},
14+
"custom": {
15+
"scripts": "<script async src='/public/custom.js' type='application/javascript'></script>",
16+
"styles": "<link href='/public/custom.css' type='text/html'/>"
17+
}
18+
}

examples/custom-result/gulpfile.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var gulp = require('gulp'),
2+
rimraf = require('gulp-rimraf'),
3+
bundle = require('../../');
4+
5+
gulp.task('bundle', ['clean'], function () {
6+
return gulp.src('./bundle.config.js')
7+
.pipe(bundle())
8+
.pipe(bundle.results({
9+
pathPrefix: '/public/'
10+
}))
11+
.pipe(gulp.dest('./public'));
12+
});
13+
14+
gulp.task('clean', function () {
15+
return gulp.src('./public', { read: false })
16+
.pipe(rimraf());
17+
});

examples/custom-result/package.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "custom-result",
3+
"version": "0.0.0",
4+
"description": "",
5+
"main": "",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "MIT",
11+
"devDependencies": {
12+
"gulp": "^3.8.7",
13+
"gulp-rimraf": "^0.1.0"
14+
}
15+
}

examples/custom-result/public/base.css

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom-result/public/base.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom-result/public/custom.css

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom-result/public/custom.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom-result/public/default.css

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom-result/public/default.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom-result/public/maps/base.css.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom-result/public/maps/base.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom-result/public/maps/custom.css.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom-result/public/maps/custom.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom-result/public/maps/default.css.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom-result/public/maps/default.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom-result/public/maps/plain.css.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom-result/public/maps/plain.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom-result/public/plain.css

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom-result/public/plain.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom-result/readme.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Custom Results
2+
3+
You can define, down to each bundle file line, how your `bundle.result.json` is created. Either use the built in
4+
result type functions or use a custom one to change or add attributes.
5+
6+
### Built-in
7+
8+
Options: `jsx | html | plain`
9+
10+
Default: `html`
11+
12+
```js
13+
bundle: {
14+
base: {
15+
scripts: './scripts/base.js',
16+
styles: './styles/base.css',
17+
options: {
18+
rev: false,
19+
uglify: false, // this has to be false, otherwise uglify will blow up when trying to parse a .jsx file
20+
result: {
21+
type: {
22+
scripts: 'jsx',
23+
styles: 'plain'
24+
}
25+
}
26+
}
27+
}
28+
}
29+
```
30+
31+
### External
32+
33+
Your function can do whatever you want, just make sure it has the following api
34+
35+
Param: `{string} path - url path to the bundle`
36+
37+
Returns: `{string} result line for this bundle`
38+
39+
```js
40+
bundle: {
41+
custom: {
42+
scripts: './scripts/custom.js',
43+
styles: './styles/custom.css',
44+
options: {
45+
rev: false,
46+
result: {
47+
type: {
48+
scripts: function xJavascript(path) {
49+
return "<script async src='" + path + "' type='application/javascript'></script>";
50+
},
51+
styles: function html(path) {
52+
return "<link href='" + path + "' type='text/html'/>";
53+
}
54+
}
55+
}
56+
}
57+
}
58+
}
59+
```
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var app = <Nav color="blue" />;
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("custom")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("default")
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("plain")
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.base {
2+
background-color: blue;
3+
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.custom {
2+
background-color: blue;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.default {
2+
background-color: blue;
3+
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.plain {
2+
background-color: blue;
3+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"article": {
3-
"styles": "<link href='/public/article-103b3ca5.css' media='screen' rel='stylesheet' type='text/css'/>",
3+
"styles": "<link href='/public/article-fb3e673f.css' media='screen' rel='stylesheet' type='text/css'/>",
44
"scripts": "<script src='/public/article-0e717735.js' type='text/javascript'></script>"
55
}
66
}

examples/custom-transforms/public/article-103b3ca5.css examples/custom-transforms/public/article-fb3e673f.css

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom-transforms/public/maps/article-103b3ca5.css.map

-1
This file was deleted.

examples/custom-transforms/public/maps/article-fb3e673f.css.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/react-tutorial/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# React comment box example
2+
3+
This is the React comment box example from [the React tutorial](http://facebook.github.io/react/docs/tutorial.html).
4+
5+
## To use
6+
7+
```
8+
npm install
9+
node server.js
10+
```
11+
12+
And visit http://localhost:3000/. Try opening multiple tabs!
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
bundle: {
3+
base: {
4+
scripts: './scripts/example.js',
5+
styles: './css/base.css',
6+
options: {
7+
rev: false,
8+
uglify: false,
9+
result: {
10+
type: {
11+
scripts: 'jsx',
12+
styles: 'html'
13+
}
14+
}
15+
}
16+
}
17+
}
18+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"base": {
3+
"styles": "<link href='/public/base.css' media='screen' rel='stylesheet' type='text/css'/>",
4+
"scripts": "<script src='/public/base.js' type='text/jsx'></script>"
5+
}
6+
}

examples/react-tutorial/css/base.css

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
body {
2+
background: #fff;
3+
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;;
4+
font-size: 15px;
5+
line-height: 1.7;
6+
margin: 0;
7+
padding: 30px;
8+
}
9+
10+
a {
11+
color: #4183c4;
12+
text-decoration: none;
13+
}
14+
15+
a:hover {
16+
text-decoration: underline;
17+
}
18+
19+
code {
20+
background-color: #f8f8f8;
21+
border: 1px solid #ddd;
22+
border-radius: 3px;
23+
font-family: "Bitstream Vera Sans Mono", Consolas, Courier, monospace;
24+
font-size: 12px;
25+
margin: 0 2px;
26+
padding: 0px 5px;
27+
}
28+
29+
h1, h2, h3, h4 {
30+
font-weight: bold;
31+
margin: 0 0 15px;
32+
padding: 0;
33+
}
34+
35+
h1 {
36+
border-bottom: 1px solid #ddd;
37+
font-size: 2.5em;
38+
font-weight: bold;
39+
margin: 0 0 15px;
40+
padding: 0;
41+
}
42+
43+
h2 {
44+
border-bottom: 1px solid #eee;
45+
font-size: 2em;
46+
}
47+
48+
h3 {
49+
font-size: 1.5em;
50+
}
51+
52+
h4 {
53+
font-size: 1.2em;
54+
}
55+
56+
p, ul {
57+
margin: 15px 0;
58+
}
59+
60+
ul {
61+
padding-left: 30px;
62+
}

0 commit comments

Comments
 (0)