Skip to content

Commit

Permalink
Move CLI-only function to CLI file
Browse files Browse the repository at this point in the history
  • Loading branch information
valscion committed Feb 4, 2018
1 parent 3e60ed1 commit c7c07ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
10 changes: 1 addition & 9 deletions packages/plugin/src/analyzer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const fs = require('fs');
const path = require('path');

const _ = require('lodash');
Expand All @@ -11,8 +10,7 @@ const FILENAME_QUERY_REGEXP = /\?.*$/;
const MULTI_MODULE_REGEXP = /^multi /;

module.exports = {
getChartData,
readStatsFromFile
getChartData
};

function getViewerData(bundleStats, bundleDir, opts) {
Expand Down Expand Up @@ -105,12 +103,6 @@ function getViewerData(bundleStats, bundleDir, opts) {
}, []);
}

function readStatsFromFile(filename) {
return JSON.parse(
fs.readFileSync(filename, 'utf8')
);
}

function assetHasModule(statAsset, statModule) {
return _.some(statModule.chunks, moduleChunk =>
_.includes(statAsset.chunks, moduleChunk)
Expand Down
9 changes: 8 additions & 1 deletion packages/plugin/src/bin/analyzer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#! /usr/bin/env node

const { resolve, dirname } = require('path');
const fs = require('fs');

const _ = require('lodash');
const commander = require('commander');
Expand Down Expand Up @@ -74,7 +75,7 @@ if (!bundleDir) bundleDir = dirname(bundleStatsFile);

let bundleStats;
try {
bundleStats = analyzer.readStatsFromFile(bundleStatsFile);
bundleStats = readStatsFromFile(bundleStatsFile);
} catch (err) {
console.error(`Could't read webpack bundle stats from "${bundleStatsFile}":\n${err}`);
process.exit(1);
Expand Down Expand Up @@ -106,3 +107,9 @@ function showHelp(error) {
function br(str) {
return `\n${_.repeat(' ', 28)}${str}`;
}

function readStatsFromFile(filename) {
return JSON.parse(
fs.readFileSync(filename, 'utf8')
);
}

0 comments on commit c7c07ac

Please sign in to comment.