@@ -4,6 +4,7 @@ import { Schema } from './schema';
4
4
import util from 'util' ;
5
5
import { exec } from 'child_process' ;
6
6
import fs from 'fs' ;
7
+ import inquirer from 'inquirer' ;
7
8
8
9
export const execAsync = util . promisify ( exec ) ;
9
10
@@ -17,10 +18,9 @@ export default createBuilder<any>(
17
18
18
19
const overrides = {
19
20
// this is an example how to override the workspace set of options
20
- ...( { sourceMap : true } )
21
+ ...( { sourceMap : true } )
21
22
} ;
22
23
23
-
24
24
const build = await context . scheduleTarget ( {
25
25
target : 'build' ,
26
26
project : context ?. target ?. project || '' ,
@@ -30,12 +30,31 @@ export default createBuilder<any>(
30
30
const result = await build . result ;
31
31
32
32
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' ) ) ;
36
36
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
+ } ) ;
38
53
54
+ mainFile = promptAvailableBundles . bundleName ;
55
+ }
56
+
57
+ const explorerCommand = `source-map-explorer ${ builderConfig . outputPath } /${ mainFile } ` ;
39
58
const { stdout, stderr } = await execAsync ( explorerCommand ) ;
40
59
context . logger . info ( stdout ) ;
41
60
context . logger . info ( stderr ) ;
0 commit comments