From 52cb8cff4bfe72b4df931d03f1f8588f19fab254 Mon Sep 17 00:00:00 2001 From: Jonathan Buchanan Date: Thu, 1 Jan 2015 11:16:53 +0000 Subject: [PATCH] Update project layout/build to use insin/templates/react-module --- .gitignore | 4 +- .npmignore | 4 +- LICENSE.md | 4 +- gulpfile.js | 91 +++++++++++++++++++------------------- package.json | 49 +++++++++++--------- index.jsx => src/index.jsx | 0 6 files changed, 82 insertions(+), 70 deletions(-) rename index.jsx => src/index.jsx (100%) diff --git a/.gitignore b/.gitignore index cd4211e..a9f4ed5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -node_modules -index.js \ No newline at end of file +lib +node_modules \ No newline at end of file diff --git a/.npmignore b/.npmignore index d2bbee5..9b079aa 100644 --- a/.npmignore +++ b/.npmignore @@ -1,9 +1,9 @@ demo dist node_modules +src .gitignore .jshintrc .npmignore bootstrap-example.png -gulpfile.js -index.jsx \ No newline at end of file +gulpfile.js \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md index 0a7aa96..e9cf52b 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,6 @@ -Copyright (c) 2014 Jonny Buchanan +## react-filtered-multiselect + +Copyright (c) 2015 Jonny Buchanan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/gulpfile.js b/gulpfile.js index df7448f..684e73d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,73 +1,74 @@ -var beep = require('beepbeep') var browserify = require('browserify') +var del = require('del') var gulp = require('gulp') var source = require('vinyl-source-stream') var header = require('gulp-header') var jshint = require('gulp-jshint') -var react = require('gulp-react') var rename = require('gulp-rename') +var plumber = require('gulp-plumber') +var react = require('gulp-react') var streamify = require('gulp-streamify') var uglify = require('gulp-uglify') +var gutil = require('gulp-util') var pkg = require('./package.json') -var srcHeader = '/**\n\ - * <%= pkg.name %> <%= pkg.version %> - https://github.com/insin/<%= pkg.name %>\n\ - * MIT Licensed\n\ +var devBuild = gutil.env.production ? '' : ' (dev build at ' + (new Date()).toUTCString() + ')' +var distHeader = '/*!\n\ + * <%= pkg.name %> <%= pkg.version %><%= devBuild %> - <%= pkg.homepage %>\n\ + * <%= pkg.license %> Licensed\n\ */\n' -gulp.task('transpile-jsx', function() { - return gulp.src('./index.jsx') - .pipe(react({ - harmony: true - })) - .pipe(gulp.dest('./')) +var jsSrcPaths = './src/**/*.js*' +var jsLibPaths = './lib/**/*.js' + +gulp.task('clean-dist', function(cb) { + del('./dist/*.js', cb) }) -gulp.task('lint', ['transpile-jsx'], function() { - return gulp.src('./build/*.js') +gulp.task('clean-lib', function(cb) { + del(jsLibPaths, cb) +}) + +gulp.task('transpile-js', ['clean-lib'], function() { + return gulp.src(jsSrcPaths) + .pipe(plumber()) + .pipe(react({harmony: true})) + .pipe(gulp.dest('./lib')) +}) + +gulp.task('lint-js', ['transpile-js'], function() { + return gulp.src(jsLibPaths) .pipe(jshint('./.jshintrc')) .pipe(jshint.reporter('jshint-stylish')) }) -var broken = false -var needsFixed = false - -gulp.task('browserify', ['lint'], function() { - var b = browserify('./index.js', { - detectGlobals: false - , standalone: 'FilteredMultiSelect' +gulp.task('bundle-js', ['clean-dist', 'lint-js'], function() { + var b = browserify(pkg.main, { + debug: !!gutil.env.debug + , standalone: pkg.standalone + , detectGlobals: false }) b.transform('browserify-shim') - return b.bundle() - .on('error', function(err) { - gutil.log(err.message) - beep(2, 0) - broken = true - this.emit('end') - }) - .on('end', function() { - if (broken) { - needsFixed = true - } - else if (needsFixed) { - beep() - needsFixed = false - } - broken = false - }) - .pipe(source('react-filtered-multiselect.js')) - .pipe(streamify(header(srcHeader, {pkg: pkg}))) - .pipe(gulp.dest('./dist')) - .pipe(rename('react-filtered-multiselect.min.js')) - .pipe(streamify(uglify())) - .pipe(streamify(header(srcHeader, {pkg: pkg}))) + var stream = b.bundle() + .pipe(source(pkg.name + '.js')) + .pipe(streamify(header(distHeader, {pkg: pkg, devBuild: devBuild}))) .pipe(gulp.dest('./dist')) + + if (gutil.env.production) { + stream = stream + .pipe(rename(pkg.name + '.min.js')) + .pipe(streamify(uglify())) + .pipe(streamify(header(distHeader, {pkg: pkg, devBuild: devBuild}))) + .pipe(gulp.dest('./dist')) + } + + return stream }) gulp.task('watch', function() { - gulp.watch('./index.jsx', ['browserify']) + gulp.watch(jsSrcPaths, ['bundle-js']) }) -gulp.task('default', ['browserify', 'watch']) +gulp.task('default', ['bundle-js', 'watch']) \ No newline at end of file diff --git a/package.json b/package.json index 4efe335..a8d7174 100644 --- a/package.json +++ b/package.json @@ -2,40 +2,49 @@ "name": "react-filtered-multiselect", "description": "Filtered multi-select React component", "version": "0.3.0", + "main": "./lib/index.js", + "homepage": "https://github.com/insin/react-filtered-multiselect", + "standalone": "FilteredMultiSelect", + "license": "MIT", "author": "Jonny Buchanan (https://github.com/insin)", - "keywords": [ - "react", - "react-component", - "filtered", - "multiselect", - "select-multiple" - ], - "main": "./index.js", - "repository": { - "type": "git", - "url": "http://github.com/insin/react-filtered-multiselect.git" - }, "dependencies": { }, + "peerDependencies": { + "react": ">=0.12.0" + }, "devDependencies": { - "beepbeep": "^1.2.0", - "browserify": "^6.3.2", - "browserify-shim": "^3.8.0", + "browserify": "^7.1.0", + "browserify-shim": "^3.8.1", + "del": "^1.1.1", "gulp": "^3.8.10", "gulp-header": "^1.2.2", "gulp-jshint": "^1.9.0", + "gulp-plumber": "^0.6.6", "gulp-react": "^2.0.0", "gulp-rename": "^1.2.0", "gulp-streamify": "0.0.5", - "gulp-uglify": "^1.0.1", + "gulp-uglify": "^1.0.2", + "gulp-util": "^3.0.1", "jshint-stylish": "^1.0.0", "vinyl-source-stream": "^1.0.0" }, - "peerDependencies": { - "react": ">=0.12.0" + "scripts": { + "debug": "gulp --debug", + "dist": "gulp bundle-js --production", + "watch": "gulp" }, - "scripts": {}, "browserify-shim": { "react": "global:React" - } + }, + "repository": { + "type": "git", + "url": "http://github.com/insin/react-filtered-multiselect.git" + }, + "keywords": [ + "react", + "react-component", + "filtered", + "multiselect", + "select-multiple" + ] } diff --git a/index.jsx b/src/index.jsx similarity index 100% rename from index.jsx rename to src/index.jsx