@tsed/cli
Version:
CLI to bootstrap your Ts.ED project
52 lines (51 loc) • 2.1 kB
JavaScript
import { CliHttpClient, ProjectPackageJson } from "@tsed/cli-core";
import { constant, inject, injectable } from "@tsed/di";
import * as os from "os";
import { anonymizePaths } from "./mappers/anonymizePaths.js";
export class CliStats extends CliHttpClient {
constructor() {
super(...arguments);
this.disabled = constant("stats.disabled", false);
this.host = constant("stats.url", "https://api.tsed.dev");
this.projectPackage = inject(ProjectPackageJson);
}
sendInit(opts) {
if (!this.disabled) {
const data = {
features: [],
is_success: true,
...opts,
os: os.type(),
convention: this.projectPackage.preferences.convention === "conv_default" ? "tsed" : "angular",
style: this.projectPackage.preferences.architecture === "arc_default" ? "tsed" : "feature",
platform: this.projectPackage.preferences.platform,
package_manager: this.projectPackage.preferences.packageManager,
runtime: this.projectPackage.preferences.runtime,
channel: opts.channel || "cli",
cli_version: constant("pkg.version", ""),
tsed_version: this.projectPackage.dependencies["@tsed/platform-http"]
};
return this.post("/rest/cli/stats", {
data
}).catch(() => {
return null;
});
}
}
$onFinish(data, er) {
if (data.commandName === "init") {
const sanitizedMessage = anonymizePaths(er?.message || "");
const sanitizedStack = anonymizePaths(er?.stack || "");
return this.sendInit({
channel: "cli",
is_success: !er,
error_name: er?.name || "",
error_message: [sanitizedMessage, sanitizedStack].filter(Boolean).join(" "),
features: data.features
});
}
}
onSuccess(options) { }
onError(error, options) { }
}
injectable(CliStats);