Skip to content

Commit

Permalink
support custom output filename
Browse files Browse the repository at this point in the history
  • Loading branch information
pajaydev committed Nov 27, 2019
1 parent 7928f75 commit 712f825
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,19 @@ Creates lasso-analyze.html in your project directory.
1. Bundled file is created under "build/static/" folder. Run the CLI as shown below

```bash
lasso-analyzer <--bundle path-->
lasso-analyzer <--bundle path--> <--outputFilename-->
```
Creates outputFilename.html in your project structure.

For Example:

a. Options to provide direct Output js file.
a. Analyze js bundle file.
``` bash
lasso-analyzer static/build.js
```
or

b. Options to provide Output Folder like this, it iterates entire folder and create lasso-analyze.html.
b. Analyze all the files inside particular folder and create lasso-analyze.html.

``` bash
lasso-analyzer static
Expand Down
8 changes: 6 additions & 2 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ const lassoAnalyzer = require('../src/index');
const { createBundle } = require('bundle-me');
const argv = parseArgs(process.argv.slice(2));
const borderX = `${Array(30).join('-')}\n`;
// extract input file.
const input = argv._ || [];
// extract output file.
let outputFile = parseArgs(process.argv).output;

if (input.length > 0) {
input.map((fileName) => {
createBundle({ path: fileName, outputPath: 'lasso-analyze.js' }).createBundle;
lassoAnalyzer('lasso-analyze.js');
lassoAnalyzer('lasso-analyze.js', outputFile);
});
const startLog = `${borderX}` + `lasso-analyze.html is created \n` +
outputFile = outputFile || 'lasso-analyze';
const startLog = `${borderX}` + `${outputFile}.html is created \n` +
`${borderX}`;
console.log(startLog);
} else {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lasso-analyzer",
"version": "1.3.2",
"version": "1.4.0",
"description": "A tool to analyze the bundle created by Lasso",
"main": "src/index.js",
"bin": {
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ function bundleAnalyzer(fileName, bundleName) {
if (!bundleName) bundleName = "lasso-analyze";
fs.writeFileSync(getOutputHTML(bundleName), html);
// clean files
cleanFiles(bundleName);
cleanFiles();
};

function cleanFiles(bundleName) {
const jsFile = process.cwd() + '/' + bundleName + '.js';
function cleanFiles() {
const jsFile = process.cwd() + '/lasso-analyze.js';
const jsonFile = process.cwd() + '/lasso-stats.json';
// remove bundle js
if (fs.existsSync(jsFile)) {
Expand Down
3 changes: 2 additions & 1 deletion src/lasso-analyzer-plugin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const lasso = require('lasso');
'use strict';

const fs = require('fs');
const path = require('path');
const lassoAnalyzer = require('./index');
Expand Down

0 comments on commit 712f825

Please sign in to comment.