Skip to content

Commit 017abf3

Browse files
Merge pull request #22 from AnkitSharma-007/master
Added the option to select the bundle to analyze
2 parents 4eda8db + dcb4091 commit 017abf3

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

analyze/index.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Schema } from './schema';
44
import util from 'util';
55
import { exec } from 'child_process';
66
import fs from 'fs';
7+
import inquirer from 'inquirer';
78

89
export const execAsync = util.promisify(exec);
910

@@ -17,10 +18,9 @@ export default createBuilder<any>(
1718

1819
const overrides = {
1920
// this is an example how to override the workspace set of options
20-
...({ sourceMap: true })
21+
...({ sourceMap: true })
2122
};
2223

23-
2424
const build = await context.scheduleTarget({
2525
target: 'build',
2626
project: context?.target?.project || '',
@@ -30,12 +30,31 @@ export default createBuilder<any>(
3030
const result = await build.result;
3131

3232
if (result.success) {
33-
const file = fs.readdirSync(builderConfig.outputPath).filter(f => f.includes('main-es2015'));
34-
const mainFile = file.find(f => f.endsWith('.js'));
35-
console.log(mainFile);
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'));
3636

37-
const explorerCommand = `source-map-explorer ${builderConfig.outputPath}/${mainFile}`;
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+
});
3853

54+
mainFile = promptAvailableBundles.bundleName;
55+
}
56+
57+
const explorerCommand = `source-map-explorer ${builderConfig.outputPath}/${mainFile}`;
3958
const { stdout, stderr } = await execAsync(explorerCommand);
4059
context.logger.info(stdout);
4160
context.logger.info(stderr);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"dependencies": {
3838
"@angular-devkit/architect": "^0.901.0",
3939
"@angular-devkit/core": "^9.1.0",
40+
"inquirer": "^7.1.0",
4041
"schematics-utilities": "^2.0.1"
4142
}
4243
}

0 commit comments

Comments
 (0)