forked from apollographql/react-apollo
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setup tracking, and failing of build based on file size (apollographq…
- Loading branch information
James Baxley
committed
May 12, 2016
1 parent
8623c73
commit 2da1037
Showing
4 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,4 @@ node_modules | |
# don't commit compiled files | ||
lib | ||
test-lib | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
|
||
const Flags = require('minimist')(process.argv.slice(2)), | ||
Fs = require('fs'), | ||
Path = require('path'), | ||
GzipSize = require('gzip-size'), | ||
PrettyBytes = require('pretty-bytes'), | ||
Colors = require('colors'); | ||
|
||
if (!Flags.file) { | ||
process.exit(1); | ||
} | ||
|
||
let totalSize = 0, | ||
totalGzippedSize = 0, | ||
filePath = Path.resolve(process.cwd(), Flags.file); | ||
|
||
const rawSize = Fs.statSync(filePath).size; | ||
totalSize = PrettyBytes(rawSize); | ||
const rawGzippedSize = GzipSize.sync(Fs.readFileSync(filePath, 'utf8')); | ||
totalGzippedSize = PrettyBytes(rawGzippedSize); | ||
|
||
console.log('\n'); | ||
console.log('=============================== FileSize summary ==============================='); | ||
console.log(`The total size of ${Path.basename(filePath)} is ${Colors.green(totalSize)}.`); | ||
console.log(`The total gzipped size of ${Path.basename(filePath)} is ${Colors.green(totalGzippedSize)}.`); | ||
console.log('================================================================================'); | ||
console.log('\n'); | ||
|
||
if (Flags.max) { | ||
const max = Number(Flags.max) * 1000; // kb to bytes | ||
if (max > totalSize) { | ||
process.exitCode = 1; | ||
console.log(Colors.red(`The total size of ${Path.basename(filePath)} exceeds ${PrettyBytes(max)}.`)); | ||
} | ||
} | ||
|
||
if (Flags.maxGzip) { | ||
const maxGzip = Number(Flags.maxGzip) * 1000; // kb to bytes | ||
if (rawGzippedSize > maxGzip) { | ||
process.exitCode = 1; | ||
console.log(Colors.red(`The total gzipped size of ${Path.basename(filePath)} exceeds ${PrettyBytes(maxGzip)}.`)); | ||
} | ||
} |