Skip to content

Commit

Permalink
New: Now compresses .gz files using zopfli to make them useful beyond…
Browse files Browse the repository at this point in the history
… being just a reference
  • Loading branch information
dcodeIO committed Dec 21, 2016
1 parent aed134a commit bfee1cc
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 37 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/ea7ba8b83890084d61012cb5386dc11dadfb3908) Fixed release links in README files<br />

## New
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/9078a37fbf7bff8ba829d979073e3df91f1bcfc5) Updated non-bundled common google types folder with field_mask, source_context, type and wrappers<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/aed134aa1cd7edd801de77c736cf5efe6fa61cb0) Updated non-bundled google types folder with missing descriptors and added wrappers to core<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/0b0de2458a1ade1ccd4ceb789697be13290f856b) Replaced the ieee754 implementation for old browsers with a faster, use-case specific one + simple test case<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/99ad9cc08721b834a197d4bbb67fa152d7ad79aa) Added .create to statically generated types and uppercase nested elements to reflection namespaces, see [#576](https://github.com/dcodeIO/protobuf.js/issues/576)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/99ad9cc08721b834a197d4bbb67fa152d7ad79aa) Also added Namespace#getEnum for completeness, see [#576](https://github.com/dcodeIO/protobuf.js/issues/576)<br />
Expand Down
4 changes: 2 additions & 2 deletions dist/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/protobuf.min.js.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions dist/runtime/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/runtime/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/runtime/protobuf.min.js.gz
Binary file not shown.
23 changes: 13 additions & 10 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var gulp = require("gulp"),
gzip = require('gulp-gzip');
var gulp = require("gulp");

var bundle = require("./scripts/bundle");

Expand All @@ -14,14 +13,18 @@ gulp.task("bundle-production" , bundle.bind(this, false, false));
gulp.task("bundle-development-runtime", bundle.bind(this, true , true));
gulp.task("bundle-production-runtime" , bundle.bind(this, false, true));

gulp.task("gzip-production", [ "bundle-production" ], function() {
return gulp.src('./dist/protobuf.min.js')
.pipe(gzip({ gzipOptions: { level: 9 } }))
.pipe(gulp.dest('./dist'));
gulp.task("gzip-production", [ "bundle-production" ], function(cb) {
bundle.compress(
"./dist/protobuf.min.js",
"./dist/protobuf.min.js.gz",
cb
);
});

gulp.task("gzip-production-runtime", [ "bundle-production-runtime" ], function() {
return gulp.src('./dist/runtime/protobuf.min.js')
.pipe(gzip({ gzipOptions: { level: 9 } }))
.pipe(gulp.dest('./dist/runtime'));
gulp.task("gzip-production-runtime", [ "bundle-production-runtime" ], function(cb) {
bundle.compress(
"./dist/runtime/protobuf.min.js",
"./dist/runtime/protobuf.min.js.gz",
cb
);
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"jaguarjs-jsdoc": "dcodeIO/jaguarjs-jsdoc",
"jsdoc": "^3.4.2",
"minimist": "^1.2.0",
"node-zopfli": "^2.0.2",
"tap-spec": "^4.1.1",
"tape": "^4.6.3",
"typescript": "^2.1.4",
Expand Down
48 changes: 31 additions & 17 deletions scripts/bundle.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
module.exports = bundle;

var path = require('path');
var path = require("path");

var browserify = require('browserify');
var browserify = require("browserify");

var header = require('gulp-header');
var gulpif = require('gulp-if');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var gutil = require('gulp-util');
var header = require("gulp-header");
var gulpif = require("gulp-if");
var sourcemaps = require("gulp-sourcemaps");
var uglify = require("gulp-uglify");
var gutil = require("gulp-util");

var buffer = require('vinyl-buffer');
var vinylfs = require('vinyl-fs');
var source = require('vinyl-source-stream');
var buffer = require("vinyl-buffer");
var vinylfs = require("vinyl-fs");
var source = require("vinyl-source-stream");

var pkg = require(__dirname + '/../package.json');
var pkg = require(__dirname + "/../package.json");
var license = [
"/*!",
" * protobuf.js v${version} (c) 2016, Daniel Wirtz",
" * Compiled ${date}",
" * Licensed under the BSD-3-Clause license",
" * Licensed under the BSD-3-Clause License",
" * see: https://github.com/dcodeIO/protobuf.js for details",
" */"
].join('\n') + '\n';
].join("\n") + "\n";

function bundle(compress, runtime) {
var src = runtime
Expand All @@ -40,9 +40,9 @@ function bundle(compress, runtime) {
.external("long")
.exclude("process")
.exclude("_process")
.plugin(require('bundle-collapser/plugin'))
.plugin(require("bundle-collapser/plugin"))
.bundle()
.pipe(source(compress ? 'protobuf.min.js' : 'protobuf.js'))
.pipe(source(compress ? "protobuf.min.js" : "protobuf.js"))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(
Expand All @@ -53,11 +53,25 @@ function bundle(compress, runtime) {
}))
)
.pipe(header(license, {
date: (new Date()).toUTCString().replace('GMT', 'UTC'),
date: (new Date()).toUTCString().replace("GMT", "UTC"),
version: pkg.version
}))
.pipe(sourcemaps.write('.', { sourceRoot: '' }))
.pipe(sourcemaps.write(".", { sourceRoot: "" }))
.pipe(vinylfs.dest(dst))
.on("log", gutil.log)
.on("error", gutil.log);
}

var fs = require("fs");
var zopfli = require("node-zopfli");

bundle.compress = function compress(sourceFile, destinationFile, callback) {
var src = fs.createReadStream(sourceFile);
var dst = fs.createWriteStream(destinationFile);
src.on("error", callback);
dst.on("error", callback);
dst.on("close", function() {
callback(null);
});
src.pipe(zopfli.createGzip()).pipe(dst);
};
3 changes: 2 additions & 1 deletion types/protobuf.js.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// $> pbts --name protobufjs --out types/protobuf.js.d.ts src
// Generated Tue, 20 Dec 2016 21:38:11 UTC
// Generated Wed, 21 Dec 2016 00:40:53 UTC
declare module "protobufjs" {

/**
Expand Down Expand Up @@ -86,6 +86,7 @@ declare module "protobufjs" {
* @property {Object} google/protobuf/empty.proto Empty
* @property {Object} google/protobuf/struct.proto Struct, Value, NullValue and ListValue
* @property {Object} google/protobuf/timestamp.proto Timestamp
* @property {Object} google/protobuf/wrappers.proto Wrappers
*/
function common(name: string, json: Object): void;

Expand Down

0 comments on commit bfee1cc

Please sign in to comment.