Skip to content

Commit

Permalink
WIP implement gzipped #3
Browse files Browse the repository at this point in the history
  • Loading branch information
jadjoubran committed Apr 14, 2018
1 parent 502073d commit 5cdca70
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 20 deletions.
49 changes: 32 additions & 17 deletions api.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
const glob = require('glob');
const fs = require("fs");
const glob = require("glob");
const { calculate } = require("gzipped");
const defaultPath = "./dist/*.js";

module.exports = {
routes: {
get: {
'js-size': async (req, res) => {
const config = req.app.locals.config;
routes: {
get: {
"js-size": async (req, res) => {
const config = req.app.locals.config;

const pattern = config.jsBudgetPath || "./dist/*.js";
const pattern = config.jsBudgetPath || defaultPath;

const g = glob(pattern, { stat: true }, (er, files) => { });
const g = glob(pattern, { stat: true }, (er, files) => {});

let size = 0;
g.on('stat', function (path, stat) {
size += stat.size;
})
g.on('end', () => {
res.send({ size });
});
}
}
let size = 0;
g.on("stat", (path, stat) => {
size += stat.size;
});
g.on("end", () => {
res.send({ size });
});
},
gzipped: async (req, rest) => {
/*merge with above endpoint*/
const config = req.app.locals.config;

const pattern = config.jsBudgetPath || defaultPath;

const g = glob(pattern, { stat: true }, (er, files) => {});

g.on("stat", path => {
calculate(fs.createReadStream(path), console.log);
});
}
}
}
}
};
45 changes: 45 additions & 0 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"*.json"
],
"dependencies": {
"glob": "^7.1.2"
"glob": "^7.1.2",
"gzipped": "0.0.5"
},
"devDependencies": {},
"scripts": {
Expand Down
6 changes: 4 additions & 2 deletions webdash-performance-budget.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
<div class="circle" id="chart"></div>
<template is="dom-if" if="{{emptyState}}">
<empty-state-webdash title="No JavaScript files found">
Adjust the <strong>jsBudgetPath</strong> option in your webdash.json configuration file.
Adjust the
<strong>jsBudgetPath</strong> option in your webdash.json configuration file.
</empty-state-webdash>
</template>
</div>
Expand All @@ -65,6 +66,7 @@

this.accent = getComputedStyle(this).getPropertyValue('--accent');

// this.backend.get('gzipped').then(console.log);
this._drawChart();
}

Expand Down Expand Up @@ -117,4 +119,4 @@

window.customElements.define(WebdashPerformanceBudget.is, WebdashPerformanceBudget);
</script>
</dom-module>
</dom-module>

0 comments on commit 5cdca70

Please sign in to comment.