Skip to content

Commit 9acc77d

Browse files
committed
clean up
1 parent 13c90f5 commit 9acc77d

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/index.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ const fs = require('fs');
22
const path = require('path');
33
const lassoUnpack = require('lasso-unpack');
44
const Tree = require('./tree');
5-
const borderX = `${Array(30).join('-')}\n`;
6-
75

86
function bundleAnalyzer(fileName, bundleName) {
97
// load lasso-unpack and create lasso-stats.json
@@ -22,11 +20,22 @@ function bundleAnalyzer(fileName, bundleName) {
2220
const html = generateHTML(tree);
2321
if (!bundleName) bundleName = "lasso-analyze";
2422
fs.writeFileSync(getOutputHTML(bundleName), html);
23+
// clean files
24+
cleanFiles(bundleName);
25+
};
26+
27+
function cleanFiles(bundleName) {
28+
const jsFile = process.cwd() + '/' + bundleName + '.js';
29+
const jsonFile = process.cwd() + '/lasso-stats.json';
2530
// remove bundle js
26-
fs.unlinkSync(process.cwd() + '/' + bundleName + '.js');
31+
if (fs.existsSync(jsFile)) {
32+
fs.unlinkSync(jsFile);
33+
}
2734
// remove lasso-stats.json
28-
fs.unlinkSync(process.cwd() + '/lasso-stats.json');
29-
};
35+
if (fs.existsSync(jsonFile)) {
36+
fs.unlinkSync(jsonFile);
37+
}
38+
}
3039

3140
function getOutputHTML(bundleName) {
3241
return process.cwd() + '/' + bundleName + ".html";

0 commit comments

Comments
 (0)