Skip to content

Commit 5b76009

Browse files
Merge pull request #43 from ngx-builders/feat--allow-to-analyze-all-bundles
Feat: allow to analyze all bundles
2 parents abb9e2d + 7a8b626 commit 5b76009

File tree

4 files changed

+11
-37
lines changed

4 files changed

+11
-37
lines changed

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,12 @@ Now whenever you want to analyze your angular project just run a command `ng run
2929

3030
## 📦 Options <a name="options"></a>
3131

32-
#### --configuration <a name="configuration"></a>
3332

34-
#### --no-build <a name="no-build"></a>
33+
#### --gzip <a name="gzip"></a>
3534
- **optional**
36-
- Default: `false` (string)
35+
- Default: `false` (boolean)
3736
- Example:
38-
- `ng run [YOUR_PROJECT_NAME]:analyze --no-build` – Angular project is NOT built
39-
40-
Skip build process during analysis.
41-
This can be used when you are sure that you haven't changed anything and want to analyze the bundle
37+
- `ng run [YOUR_PROJECT_NAME]:analyze --gzip` – Give the stats of gzip bundle.
4238

4339
# License
4440
[MIT](https://github.com/ngx-builders/source-map-analyzer/blob/master/LICENSE)

analyze/index.ts

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,20 @@ import { json } from '@angular-devkit/core';
33
import { Schema } from './schema';
44
import util from 'util';
55
import { exec } from 'child_process';
6-
import fs from 'fs';
7-
import inquirer from 'inquirer';
86

97
export const execAsync = util.promisify(exec);
108

119
export default createBuilder<any>(
1210
async (builderConfig: Schema, context: BuilderContext): Promise<BuilderOutput> => {
1311
try {
14-
context.reportStatus(`Executing "${builderConfig.noBuild}"...`);
12+
context.reportStatus(`Starting Build`);
1513
// const child = childProcess.spawn(options.command, options.args, { stdio: 'pipe' });
1614

1715
const configuration = 'production';
1816

1917
const overrides = {
2018
// this is an example how to override the workspace set of options
21-
...({ sourceMap: true })
19+
...({ sourceMap: true, budgets: [] })
2220
};
2321

2422
const build = await context.scheduleTarget({
@@ -30,31 +28,11 @@ export default createBuilder<any>(
3028
const result = await build.result;
3129

3230
if (result.success) {
33-
const file = fs.readdirSync(builderConfig.outputPath).filter(f => f.includes('es2015'));
34-
const filesToRemove = file.filter(f => f.includes('polyfills') || f.includes('runtime'));
35-
let filesToShow = file.filter(f => !filesToRemove.includes(f) && f.endsWith('.js'));
36-
37-
let mainFile = filesToShow[0];
38-
let promptAvailableBundles;
39-
40-
if (filesToShow.length > 1) {
41-
promptAvailableBundles = await inquirer
42-
.prompt([
43-
{
44-
type: 'list',
45-
name: 'bundleName',
46-
message: 'Select the bundle to run the analyzer?',
47-
choices: filesToShow,
48-
},
49-
])
50-
.catch(error => {
51-
context.logger.info(error);
52-
});
53-
54-
mainFile = promptAvailableBundles.bundleName;
31+
const mainFile = '*es2015.*.js';
32+
let explorerCommand = `npx source-map-explorer ${builderConfig.outputPath}/${mainFile}`;
33+
if (builderConfig.gzip) {
34+
explorerCommand = `${explorerCommand} --gzip`;
5535
}
56-
57-
const explorerCommand = `npx source-map-explorer ${builderConfig.outputPath}/${mainFile}`;
5836
const { stdout, stderr } = await execAsync(explorerCommand);
5937
context.logger.info(stdout);
6038
context.logger.info(stderr);

analyze/schema.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export interface Schema {
2-
noBuild?: boolean;
32
outputPath: string;
3+
gzip?: boolean;
44
}

analyze/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "http://json-schema.org/schema",
33
"type": "object",
44
"properties": {
5-
"noBuild": {
5+
"gzip": {
66
"type": "boolean"
77
},
88
"outputPath": {

0 commit comments

Comments
 (0)