Skip to content

Commit 83bbfce

Browse files
committed
Added send data
1 parent e46aa7b commit 83bbfce

File tree

4 files changed

+81
-3
lines changed

4 files changed

+81
-3
lines changed

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@angular/compiler-cli": "^10.0.0",
3030
"@angular/core": "^10.0.0",
3131
"chalk": "^2.4.2",
32+
"follow-redirects": "^1.13.0",
3233
"guess-parser": "^0.4.19",
3334
"minimist": "^1.2.0",
3435
"typescript": "~3.9.7"

src/counter.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import {
77
ComponentSymbol
88
} from './deps/ngast';
99
import {ClassRecord} from "@angular/compiler-cli/src/ngtsc/transform";
10-
import {error, info, tryGetsProjectPath} from "./utils";
10+
import { info, tryGetsProjectPath} from "./utils";
1111
import { parseAngularRoutes } from "guess-parser";
12+
import {trySendData, sendData} from "./send";
1213

1314
export function ngcounter() {
1415
const projectPath = tryGetsProjectPath();
@@ -32,16 +33,29 @@ export function ngcounter() {
3233
info(`Classes:`, classes.length);
3334

3435
console.log("\nParse routes...\n");
36+
let lazyRoutesLength = 0;
37+
let allRoutesLength = 0;
3538

3639
try {
3740
const allRoutes = parseAngularRoutes(projectPath) || [];
3841

3942
const lazyRoutes = allRoutes.filter(r => r.lazy);
4043

41-
info(`All routes:`, allRoutes.length);
42-
info(`Lazy routes:`, lazyRoutes.length);
44+
info(`All routes:`, allRoutesLength = allRoutes.length);
45+
info(`Lazy routes:`, lazyRoutesLength = lazyRoutes.length);
4346

4447
} catch (e) {
4548
console.error(e);
4649
}
50+
51+
trySendData({
52+
allModules: allModules.length,
53+
allPipes: allPipes.length,
54+
allDirectives: allDirectives.length,
55+
allComponents: allComponents.length,
56+
allInjectables: allInjectables.length,
57+
classes: classes.length,
58+
allRoutes: allRoutesLength,
59+
lazyRoutes: lazyRoutesLength
60+
});
4761
}

src/send.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const https = require('follow-redirects').https;
2+
3+
export function trySendData(data) {
4+
console.log("\nSend anonymous statistics? y/n (y)")
5+
6+
var stdin = process.stdin;
7+
8+
stdin.setRawMode(true);
9+
10+
stdin.resume();
11+
stdin.setEncoding('ascii');
12+
13+
stdin.on('data', function (key: any) {
14+
if (key === 'N' || key === 'n') {
15+
process.exit();
16+
} else {
17+
sendData(data);
18+
}
19+
});
20+
}
21+
22+
export function sendData(data) {
23+
const options = {
24+
'method': 'POST',
25+
'hostname': 'ng-app-counter.firebaseio.com',
26+
'path': '/counter.json',
27+
'headers': {
28+
'Content-Type': 'application/json'
29+
},
30+
'maxRedirects': 20
31+
};
32+
33+
const req = https.request(options, function (res) {
34+
res.on("data", function (chunk) {
35+
process.exit();
36+
});
37+
38+
res.on("end", function (chunk) {
39+
process.exit();
40+
});
41+
42+
res.on("error", function (error) {
43+
process.exit();
44+
});
45+
});
46+
47+
const postData = JSON.stringify({...data, date: new Date()});
48+
49+
req.write(postData);
50+
51+
req.end();
52+
}
53+

0 commit comments

Comments
 (0)