Skip to content

Instantly share code, notes, and snippets.

@rakeshpai
Last active October 13, 2015 15:12
Show Gist options
  • Save rakeshpai/ac9f71164f3d52f16218 to your computer and use it in GitHub Desktop.
Save rakeshpai/ac9f71164f3d52f16218 to your computer and use it in GitHub Desktop.
Browserify + Uglify + Espruino using Gulp
var gulp = require("gulp"),
browserify = require("browserify"),
source = require("vinyl-source-stream"),
buffer = require("vinyl-buffer"),
uglify = require("gulp-uglify"),
through = require("through2"),
port = "/dev/cu.wchusbserial410",
espruino = require("node-espruino").espruino({comPort: port});
var upload = through.obj(function(file, enc, done) {
if (file.isNull()) return done(null, file);
if (file.isStream()) throw new Error('no support');
espruino.open(function() {
espruino.upload(file.contents.toString(), {save: true}, function() {
espruino.close(function() {
done(null, file);
});
});
});
});
gulp.task("upload", function() {
return browserify({entries: ["./index.js"]})
.bundle()
.pipe(source())
.pipe(buffer())
.pipe(uglify())
.pipe(upload);
});
gulp.task("default", ["upload"]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment