|
1 | | -import { BuilderOutput, createBuilder, BuilderContext } from '@angular-devkit/architect'; |
2 | | -import { json } from '@angular-devkit/core'; |
3 | | -import { Schema } from './schema'; |
4 | | -import util from 'util'; |
5 | | -import { exec } from 'child_process'; |
| 1 | +import { |
| 2 | + BuilderOutput, |
| 3 | + createBuilder, |
| 4 | + BuilderContext, |
| 5 | +} from "@angular-devkit/architect"; |
| 6 | +import { Schema } from "./schema"; |
| 7 | +import util from "util"; |
| 8 | +import { exec } from "child_process"; |
6 | 9 |
|
7 | 10 | export const execAsync = util.promisify(exec); |
8 | 11 |
|
9 | 12 | export default createBuilder<any>( |
10 | | - async (builderConfig: Schema, context: BuilderContext): Promise<BuilderOutput> => { |
| 13 | + async ( |
| 14 | + builderConfig: Schema, |
| 15 | + context: BuilderContext |
| 16 | + ): Promise<BuilderOutput> => { |
11 | 17 | try { |
12 | | - context.reportStatus(`Starting Build`); |
13 | | - // const child = childProcess.spawn(options.command, options.args, { stdio: 'pipe' }); |
| 18 | + context.reportStatus(`Starting Report generation...🚀`); |
14 | 19 |
|
15 | | - const configuration = 'production'; |
16 | | - |
17 | | - const overrides = { |
18 | | - // this is an example how to override the workspace set of options |
19 | | - ...({ sourceMap: true, budgets: [] }) |
20 | | - }; |
21 | | - |
22 | | - const build = await context.scheduleTarget({ |
23 | | - target: 'build', |
24 | | - project: context?.target?.project || '', |
25 | | - configuration |
26 | | - }, overrides as json.JsonObject); |
27 | | - |
28 | | - const result = await build.result; |
29 | | - |
30 | | - if (result.success) { |
31 | | - const mainFile = builderConfig.diffLoading ? '*es2015.*.js' : '*.js'; |
32 | | - let explorerCommand = `npx source-map-explorer ${builderConfig.outputPath}/${mainFile}`; |
33 | | - if (builderConfig.gzip) { |
34 | | - explorerCommand = `${explorerCommand} --gzip`; |
35 | | - } |
36 | | - const { stdout, stderr } = await execAsync(explorerCommand); |
37 | | - context.logger.info(stdout); |
38 | | - context.logger.info(stderr); |
| 20 | + const mainFile = "*.js"; |
| 21 | + let explorerCommand = `npx source-map-explorer ${builderConfig.outputPath}/${mainFile}`; |
| 22 | + if (builderConfig.gzip) { |
| 23 | + explorerCommand = `${explorerCommand} --gzip`; |
| 24 | + } |
| 25 | + if(builderConfig.reportPath) { |
| 26 | + const reportFormat = builderConfig.reportFormat || 'html'; |
| 27 | + explorerCommand = `${explorerCommand} --${reportFormat} ${builderConfig.reportPath}/${context?.target?.project}.html`; |
39 | 28 | } |
| 29 | + const { stdout, stderr } = await execAsync(explorerCommand); |
| 30 | + context.logger.info(stdout); |
| 31 | + context.logger.info(stderr); |
40 | 32 |
|
41 | 33 | context.reportStatus(`Done.`); |
42 | 34 | return { |
43 | | - success: true |
| 35 | + success: true, |
44 | 36 | }; |
45 | | - } |
46 | | - catch (e:any) { |
| 37 | + } catch (e: any) { |
47 | 38 | return { |
48 | 39 | error: e.message, |
49 | | - success: true |
| 40 | + success: true, |
50 | 41 | }; |
51 | 42 | } |
52 | | - }); |
53 | | - |
| 43 | + } |
| 44 | +); |
0 commit comments