Skip to content

Commit aff83bf

Browse files
committed
Merge pull request #7 from JedWatson/happiness
Add Happiness
2 parents 615c63b + bc5d8bb commit aff83bf

File tree

11 files changed

+102
-126
lines changed

11 files changed

+102
-126
lines changed

.editorconfig

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

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: node_js
2+
before_install:
3+
- "npm install npm -g"
4+
node_js:
5+
- "0.12"
6+
- "0.11"
7+
- "0.10"
8+
env:
9+
- TEST_SUITE=lint
10+
- TEST_SUITE=unit
11+
script: "npm run-script $TEST_SUITE"
12+

example_config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = {
1818
path: 'less'
1919
}
2020
},
21-
21+
2222
example: {
2323
src: 'example/src',
2424
dist: 'example/dist',
@@ -33,5 +33,4 @@ module.exports = {
3333
'app.less'
3434
]
3535
}
36-
3736
};

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
var defaults = require('defaults')
2-
var capitalize = require('capitalize')
3-
var camelCase = require('camelcase')
1+
var defaults = require('defaults');
2+
var capitalize = require('capitalize');
3+
var camelCase = require('camelcase');
44

55
// Extract package.json metadata
66
function readPackageJSON () {
@@ -21,9 +21,9 @@ function readPackageJSON () {
2121
*/
2222
function initTasks (gulp, config) {
2323
var pkg = readPackageJSON();
24-
var name = capitalize(camelCase(config.component.pkgName || pkg.name))
24+
var name = capitalize(camelCase(config.component.pkgName || pkg.name));
2525

26-
config = defaults(config, { aliasify: pkg.aliasify })
26+
config = defaults(config, { aliasify: pkg.aliasify });
2727
config.component = defaults(config.component, {
2828
pkgName: pkg.name,
2929
dependencies: pkg.deps,

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@
3434
"vinyl-source-stream": "^1.1.0",
3535
"watchify": "^3.2.1"
3636
},
37+
"devDependencies": {
38+
"happiness": "*"
39+
},
3740
"peerDependencies": {
3841
"gulp": "^3.8.0"
3942
},
4043
"scripts": {
41-
"test": "echo \"no tests yet\" && exit 0"
44+
"lint": "happiness",
45+
"unit": "echo \"no tests yet\"",
46+
"test": "npm run lint && npm run unit"
4247
},
4348
"keywords": [
4449
"react",

tasks/bump.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
var bump = require('gulp-bump');
22

3-
module.exports = function(gulp, config) {
4-
5-
function getBumpTask(type) {
6-
return function() {
3+
module.exports = function (gulp, config) {
4+
function getBumpTask (type) {
5+
return function () {
76
return gulp.src(['./package.json', './bower.json'])
87
.pipe(bump({ type: type }))
98
.pipe(gulp.dest('./'));
@@ -13,5 +12,4 @@ module.exports = function(gulp, config) {
1312
gulp.task('bump', getBumpTask('patch'));
1413
gulp.task('bump:minor', getBumpTask('minor'));
1514
gulp.task('bump:major', getBumpTask('major'));
16-
17-
}
15+
};

tasks/dev.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
var connect = require('gulp-connect');
22
var path = require('path');
33

4-
module.exports = function(gulp, config) {
5-
6-
gulp.task('dev:server', function() {
4+
module.exports = function (gulp, config) {
5+
gulp.task('dev:server', function () {
76
connect.server({
87
root: config.example.dist,
98
fallback: path.join(config.example.dist, 'index.html'),
@@ -12,9 +11,5 @@ module.exports = function(gulp, config) {
1211
});
1312
});
1413

15-
gulp.task('dev', [
16-
'dev:server',
17-
'watch:examples'
18-
]);
19-
20-
}
14+
gulp.task('dev', ['dev:server', 'watch:examples']);
15+
};

tasks/dist.js

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,47 @@
1-
var del = require('del');
2-
var browserify = require('browserify');
31
var babelify = require('babelify');
4-
var shim = require('browserify-shim');
2+
var browserify = require('browserify');
3+
var del = require('del');
54
var gutil = require('gulp-util');
65
var less = require('gulp-less');
7-
var source = require('vinyl-source-stream');
86
var rename = require('gulp-rename');
7+
var shim = require('browserify-shim');
8+
var source = require('vinyl-source-stream');
99
var streamify = require('gulp-streamify');
1010
var uglify = require('gulp-uglify');
1111

12-
module.exports = function(gulp, config) {
13-
14-
gulp.task('clean:dist', function(done) {
12+
module.exports = function (gulp, config) {
13+
gulp.task('clean:dist', function (done) {
1514
del([config.component.dist], done);
1615
});
1716

18-
gulp.task('build:dist:scripts', function() {
19-
17+
gulp.task('build:dist:scripts', function () {
2018
var standalone = browserify('./' + config.component.src + '/' + config.component.file, {
21-
standalone: config.component.name
22-
})
23-
.transform(babelify.configure({
24-
plugins: [require('babel-plugin-object-assign')]
25-
}))
26-
.transform(shim);
27-
28-
config.component.dependencies.forEach(function(pkg) {
19+
standalone: config.component.name
20+
})
21+
.transform(babelify.configure({
22+
plugins: [require('babel-plugin-object-assign')]
23+
}))
24+
.transform(shim);
25+
26+
config.component.dependencies.forEach(function (pkg) {
2927
standalone.exclude(pkg);
3028
});
3129

3230
return standalone.bundle()
33-
.on('error', function(e) {
31+
.on('error', function (e) {
3432
gutil.log('Browserify Error', e);
3533
})
3634
.pipe(source(config.component.pkgName + '.js'))
3735
.pipe(gulp.dest(config.component.dist))
3836
.pipe(rename(config.component.pkgName + '.min.js'))
3937
.pipe(streamify(uglify()))
4038
.pipe(gulp.dest(config.component.dist));
41-
4239
});
4340

4441
var buildTasks = ['build:dist:scripts'];
4542

4643
if (config.component.less && config.component.less.entry) {
47-
gulp.task('build:dist:css', ['clean:dist'], function() {
44+
gulp.task('build:dist:css', ['clean:dist'], function () {
4845
return gulp.src(config.component.less.path + '/' + config.component.less.entry)
4946
.pipe(less())
5047
.pipe(gulp.dest('dist'));
@@ -53,5 +50,4 @@ module.exports = function(gulp, config) {
5350
}
5451

5552
gulp.task('build:dist', buildTasks);
56-
57-
}
53+
};

tasks/examples.js

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,63 @@
11
var aliasify = require('aliasify');
2-
var browserify = require('browserify');
3-
var shim = require('browserify-shim');
42
var babelify = require('babelify');
3+
var browserify = require('browserify');
54
var chalk = require('chalk');
6-
var del = require('del');
75
var connect = require('gulp-connect');
8-
var less = require('gulp-less');
6+
var del = require('del');
97
var gutil = require('gulp-util');
8+
var less = require('gulp-less');
109
var merge = require('merge-stream');
10+
var shim = require('browserify-shim');
1111
var source = require('vinyl-source-stream');
1212
var watchify = require('watchify');
1313

14-
module.exports = function(gulp, config) {
15-
16-
var doBundle = function(target, name, dest) {
14+
module.exports = function (gulp, config) {
15+
function doBundle (target, name, dest) {
1716
return target.bundle()
18-
.on('error', function(e) {
17+
.on('error', function (e) {
1918
gutil.log('Browserify Error', e);
2019
})
2120
.pipe(source(name))
2221
.pipe(gulp.dest(dest))
2322
.pipe(connect.reload());
2423
}
2524

26-
var watchBundle = function(target, name, dest) {
25+
function watchBundle (target, name, dest) {
2726
return watchify(target)
2827
.on('update', function (scriptIds) {
2928
scriptIds = scriptIds
30-
.filter(function(i) { return i.substr(0,2) !== './' })
31-
.map(function(i) { return chalk.blue(i.replace(__dirname, '')) });
29+
.filter(function (x) { return x.substr(0, 2) !== './'; })
30+
.map(function (x) { return chalk.blue(x.replace(__dirname, '')); });
31+
3232
if (scriptIds.length > 1) {
3333
gutil.log(scriptIds.length + ' Scripts updated:\n* ' + scriptIds.join('\n* ') + '\nrebuilding...');
3434
} else {
3535
gutil.log(scriptIds[0] + ' updated, rebuilding...');
3636
}
37+
3738
doBundle(target, name, dest);
3839
})
3940
.on('time', function (time) {
4041
gutil.log(chalk.green(name + ' built in ' + (Math.round(time / 10) / 100) + 's'));
4142
});
4243
}
4344

44-
function buildExampleScripts(dev) {
45-
45+
function buildExampleScripts (dev) {
4646
var dest = config.example.dist;
47-
4847
var opts = dev ? watchify.args : {};
49-
opts.debug = dev ? true : false;
48+
opts.debug = !!dev;
5049
opts.hasExports = true;
5150

52-
return function() {
53-
51+
return function () {
5452
var common = browserify(opts);
55-
53+
5654
var bundle = browserify(opts);
5755
bundle.transform(babelify.configure({
5856
plugins: [require('babel-plugin-object-assign')]
5957
}));
6058
config.aliasify && bundle.transform(aliasify);
6159
bundle.require('./' + config.component.src + '/' + config.component.file, { expose: config.component.pkgName });
62-
60+
6361
var standalone = false;
6462
if (config.example.standalone) {
6563
standalone = browserify('./' + config.component.src + '/' + config.component.file, { standalone: config.component.name });
@@ -70,7 +68,7 @@ module.exports = function(gulp, config) {
7068
standalone.transform(shim);
7169
}
7270

73-
var examples = config.example.scripts.map(function(file) {
71+
var examples = config.example.scripts.map(function (file) {
7472
var fileBundle = browserify(opts);
7573
fileBundle.exclude(config.component.pkgName);
7674
fileBundle.add('./' + config.example.src + '/' + file);
@@ -84,11 +82,11 @@ module.exports = function(gulp, config) {
8482
};
8583
});
8684

87-
config.component.dependencies.forEach(function(pkg) {
85+
config.component.dependencies.forEach(function (pkg) {
8886
common.require(pkg);
8987
bundle.exclude(pkg);
9088
if (standalone) standalone.exclude(pkg);
91-
examples.forEach(function(eg) {
89+
examples.forEach(function (eg) {
9290
eg.bundle.exclude(pkg);
9391
});
9492
});
@@ -97,7 +95,7 @@ module.exports = function(gulp, config) {
9795
watchBundle(common, 'common.js', dest);
9896
watchBundle(bundle, 'bundle.js', dest);
9997
if (standalone) watchBundle(standalone, 'standalone.js', dest);
100-
examples.forEach(function(eg) {
98+
examples.forEach(function (eg) {
10199
watchBundle(eg.bundle, eg.file, dest);
102100
});
103101
}
@@ -111,35 +109,31 @@ module.exports = function(gulp, config) {
111109
bundles.push(doBundle(standalone, 'standalone.js', dest));
112110
}
113111

114-
return merge(bundles.concat(examples.map(function(eg) {
112+
return merge(bundles.concat(examples.map(function (eg) {
115113
return doBundle(eg.bundle, eg.file, dest);
116114
})));
115+
};
116+
}
117117

118-
}
119-
120-
};
121-
122-
gulp.task('clean:examples', function(done) {
123-
del([config.example.dist], done);
124-
});
125-
118+
gulp.task('clean:examples', function (done) { del([config.example.dist], done); });
126119
gulp.task('watch:example:scripts', buildExampleScripts(true));
127120
gulp.task('build:example:scripts', buildExampleScripts());
128121

129-
gulp.task('build:example:files', function() {
122+
gulp.task('build:example:files', function () {
130123
return gulp.src(config.example.files, { cwd: config.example.src, base: config.example.src })
131124
.pipe(gulp.dest(config.example.dist))
132125
.pipe(connect.reload());
133126
});
134127

135-
gulp.task('build:example:css', function() {
128+
gulp.task('build:example:css', function () {
136129
if (!config.example.less) return;
130+
137131
return gulp.src(config.example.src + '/' + config.example.less)
138132
.pipe(less())
139133
.pipe(gulp.dest(config.example.dist))
140134
.pipe(connect.reload());
141135
});
142-
136+
143137
gulp.task('build:examples', [
144138
'build:example:files',
145139
'build:example:css',
@@ -149,17 +143,21 @@ module.exports = function(gulp, config) {
149143
gulp.task('watch:examples', [
150144
'build:example:files',
151145
'build:example:css'
152-
], function() {
146+
], function () {
153147
buildExampleScripts(true)();
154-
gulp.watch(config.example.files.map(function(i) { return config.example.src + '/' + i }), ['build:example:files']);
148+
gulp.watch(config.example.files.map(function (i) {
149+
return config.example.src + '/' + i;
150+
}), ['build:example:files']);
151+
155152
var watchLESS = [];
156153
if (config.example.less) {
157154
watchLESS.push(config.example.src + '/' + config.example.less);
158155
}
156+
159157
if (config.component.less && config.component.less.path) {
160158
watchLESS.push(config.component.less.path + '/**/*.less');
161159
}
160+
162161
gulp.watch(watchLESS, ['build:example:css']);
163162
});
164-
165-
}
163+
};

0 commit comments

Comments
 (0)