Skip to content

Commit a18c06a

Browse files
feat: remove build from analyze
1 parent b445981 commit a18c06a

File tree

8 files changed

+52
-125
lines changed

8 files changed

+52
-125
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*.js
22
*.map
33
node_modules
4-
package-lock.json
4+
package-lock.json
5+
dist

analyze/index.ts

+29-38
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,44 @@
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";
69

710
export const execAsync = util.promisify(exec);
811

912
export default createBuilder<any>(
10-
async (builderConfig: Schema, context: BuilderContext): Promise<BuilderOutput> => {
13+
async (
14+
builderConfig: Schema,
15+
context: BuilderContext
16+
): Promise<BuilderOutput> => {
1117
try {
12-
context.reportStatus(`Starting Build`);
13-
// const child = childProcess.spawn(options.command, options.args, { stdio: 'pipe' });
18+
context.reportStatus(`Starting Report generation...🚀`);
1419

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`;
3928
}
29+
const { stdout, stderr } = await execAsync(explorerCommand);
30+
context.logger.info(stdout);
31+
context.logger.info(stderr);
4032

4133
context.reportStatus(`Done.`);
4234
return {
43-
success: true
35+
success: true,
4436
};
45-
}
46-
catch (e:any) {
37+
} catch (e: any) {
4738
return {
4839
error: e.message,
49-
success: true
40+
success: true,
5041
};
5142
}
52-
});
53-
43+
}
44+
);

analyze/index_spec.ts

-60
This file was deleted.

analyze/schema.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export interface Schema {
22
outputPath: string;
33
gzip?: boolean;
4-
diffLoading?:boolean;
4+
reportPath?: string;
5+
reportFormat: 'html' | 'json' | 'tsv' ;
56
}

analyze/schema.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
"outputPath": {
1010
"type": "string"
1111
},
12-
"diffLoading": {
13-
"type":"boolean",
14-
"default": false
12+
"reportPath": {
13+
"type": "string"
14+
},
15+
"reportFormat": {
16+
"type": "string",
17+
"default": "html"
1518
}
1619
}
1720
}

ng-add/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function ngAdd(options: NgAddOptions): Rule {
1414
options.project = workspace.extensions.defaultProject as string;
1515
} else {
1616
throw new SchematicsException(
17-
'No Angular project selected and no default project in the workspace'
17+
'No Angular project selected or you are in a Nx workspace'
1818
);
1919
}
2020
}

package.json

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ngx-builders/analyze",
3-
"version": "3.0.1",
3+
"version": "4.0.0",
44
"description": "Angular Builder To Run Source Map Explorer",
55
"main": "index.js",
66
"builders": "./builders.json",
@@ -9,8 +9,9 @@
99
"save": "devDependencies"
1010
},
1111
"scripts": {
12-
"build": "tsc",
13-
"test": "ts-node node_modules/jasmine/bin/jasmine analyze/index_spec.ts"
12+
"copy:pacakge": "cp package.json dist",
13+
"copy:json": "cp ng-add/schema.json dist/ng-add/schema.json && cp builders.json dist/builders.json && cp collection.json dist/collection.json && cp README.md dist/README.md && cp analyze/schema.json dist/analyze/schema.json",
14+
"build": "tsc && npm run copy:pacakge && npm run copy:json"
1415
},
1516
"repository": {
1617
"type": "git",
@@ -33,16 +34,13 @@
3334
"author": "Santosh Yadav <[email protected]>",
3435
"license": "MIT",
3536
"devDependencies": {
36-
"@types/jasmine": "3.10.2",
3737
"@types/node": "16.11.11",
38-
"jasmine": "3.10.0",
39-
"jasmine-node": "3.0.0",
40-
"ts-node": "10.4.0",
41-
"typescript": "~4.5.2"
38+
"ts-node": "10.9.1",
39+
"typescript": "~5.0.0"
4240
},
4341
"dependencies": {
44-
"@angular-devkit/architect": "0.1300.0",
45-
"@angular-devkit/core": "13.0.0",
46-
"@angular-devkit/schematics": "^13.0.0"
42+
"@angular-devkit/architect": "0.1502.6",
43+
"@angular-devkit/core": "15.2.6",
44+
"@angular-devkit/schematics": "15.2.6"
4745
}
4846
}

tsconfig.json

+3-10
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@
22
"compilerOptions": {
33
"moduleResolution": "node",
44
"module": "commonjs",
5-
"target": "es2015",
5+
"target": "ES2020",
6+
"outDir": "dist",
67
"lib": [
7-
"es2015",
8-
"dom",
9-
"es2015.promise",
10-
"es2015.collection",
11-
"es2015.iterable"
8+
"es2018"
129
],
1310
"strict": true,
1411
"allowSyntheticDefaultImports": true,
15-
"suppressImplicitAnyIndexErrors": true,
1612
"forceConsistentCasingInFileNames": true,
17-
"strictPropertyInitialization": false,
18-
"strictNullChecks": true,
1913
"sourceMap": false,
2014
"declaration": false,
2115
"inlineSources": false,
@@ -32,6 +26,5 @@
3226
"angularCompilerOptions": {
3327
"skipTemplateCodegen": true,
3428
"strictMetadataEmit": true,
35-
"enableSummariesForJit": false
3629
}
3730
}

0 commit comments

Comments
 (0)