@tinacms/metrics 1.0.9 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +51 -88
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1,46 +1,11 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
|
|
29
|
-
// src/index.ts
|
|
30
|
-
var index_exports = {};
|
|
31
|
-
__export(index_exports, {
|
|
32
|
-
Telemetry: () => Telemetry
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(index_exports);
|
|
35
|
-
|
|
36
1
|
// src/telemetry/telemetry.ts
|
|
37
|
-
|
|
2
|
+
import { createHash } from "crypto";
|
|
38
3
|
|
|
39
4
|
// src/telemetry/getId.ts
|
|
40
|
-
|
|
5
|
+
import { execSync } from "child_process";
|
|
41
6
|
function _getProjectIdByGit() {
|
|
42
7
|
try {
|
|
43
|
-
const originBuffer =
|
|
8
|
+
const originBuffer = execSync(
|
|
44
9
|
`git config --local --get remote.origin.url`,
|
|
45
10
|
{
|
|
46
11
|
timeout: 1e3,
|
|
@@ -57,15 +22,15 @@ function getID() {
|
|
|
57
22
|
}
|
|
58
23
|
|
|
59
24
|
// src/telemetry/telemetry.ts
|
|
60
|
-
|
|
25
|
+
import fetch from "isomorphic-fetch";
|
|
61
26
|
|
|
62
27
|
// src/telemetry/getVersion.ts
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
28
|
+
import fse from "fs-extra";
|
|
29
|
+
import { execSync as execSync2 } from "child_process";
|
|
30
|
+
import { join } from "path";
|
|
66
31
|
function _executeCommand(cmd) {
|
|
67
32
|
try {
|
|
68
|
-
const originBuffer = (
|
|
33
|
+
const originBuffer = execSync2(cmd, {
|
|
69
34
|
timeout: 1e3,
|
|
70
35
|
stdio: `pipe`
|
|
71
36
|
});
|
|
@@ -77,24 +42,20 @@ function _executeCommand(cmd) {
|
|
|
77
42
|
var _getPack = (rootDir) => {
|
|
78
43
|
let pack = {};
|
|
79
44
|
try {
|
|
80
|
-
const rawJSON = (
|
|
81
|
-
(0, import_path.join)(rootDir, "package.json")
|
|
82
|
-
).toString();
|
|
45
|
+
const rawJSON = fse.readFileSync(join(rootDir, "package.json")).toString();
|
|
83
46
|
pack = JSON.parse(rawJSON);
|
|
84
47
|
} catch (_e) {
|
|
85
48
|
}
|
|
86
49
|
return pack;
|
|
87
50
|
};
|
|
88
51
|
var getTinaVersion = () => {
|
|
89
|
-
var _a;
|
|
90
52
|
const pack = _getPack(process.cwd());
|
|
91
|
-
const version =
|
|
53
|
+
const version = pack?.dependencies?.tinacms;
|
|
92
54
|
return version || "";
|
|
93
55
|
};
|
|
94
56
|
var getTinaCliVersion = () => {
|
|
95
|
-
var _a, _b;
|
|
96
57
|
const pack = _getPack(process.cwd());
|
|
97
|
-
const version =
|
|
58
|
+
const version = pack?.devDependencies?.["@tinacms/cli"] || pack?.dependencies?.["@tinacms/cli"];
|
|
98
59
|
return version || "";
|
|
99
60
|
};
|
|
100
61
|
var getYarnVersion = () => {
|
|
@@ -107,54 +68,56 @@ var getNpmVersion = () => {
|
|
|
107
68
|
// src/telemetry/telemetry.ts
|
|
108
69
|
var TINA_METRICS_ENDPOINT = "https://metrics.tina.io/record";
|
|
109
70
|
var Telemetry = class {
|
|
71
|
+
// private config: Conf<Record<string, unknown>>
|
|
72
|
+
projectIDRaw;
|
|
73
|
+
_disabled;
|
|
110
74
|
constructor({ disabled }) {
|
|
111
|
-
this.oneWayHash = (payload) => {
|
|
112
|
-
const hash = (0, import_crypto.createHash)("sha256");
|
|
113
|
-
hash.update(payload);
|
|
114
|
-
return hash.digest("hex");
|
|
115
|
-
};
|
|
116
|
-
this.submitRecord = async ({ event }) => {
|
|
117
|
-
if (this.isDisabled) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
try {
|
|
121
|
-
const id = this.projectId;
|
|
122
|
-
const body = {
|
|
123
|
-
partitionKey: id,
|
|
124
|
-
data: {
|
|
125
|
-
anonymousId: id,
|
|
126
|
-
event: event.name,
|
|
127
|
-
properties: {
|
|
128
|
-
...event,
|
|
129
|
-
nodeVersion: process.version,
|
|
130
|
-
tinaCliVersion: getTinaCliVersion(),
|
|
131
|
-
tinaVersion: getTinaVersion(),
|
|
132
|
-
yarnVersion: getYarnVersion(),
|
|
133
|
-
npmVersion: getNpmVersion(),
|
|
134
|
-
CI: Boolean(process.env.CI)
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
await (0, import_isomorphic_fetch.default)(TINA_METRICS_ENDPOINT, {
|
|
139
|
-
method: "POST",
|
|
140
|
-
body: JSON.stringify(body),
|
|
141
|
-
headers: { "content-type": "application/json" }
|
|
142
|
-
});
|
|
143
|
-
} catch (_e) {
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
75
|
this.projectIDRaw = getID();
|
|
147
76
|
const { NO_TELEMETRY } = process.env;
|
|
148
77
|
this._disabled = NO_TELEMETRY === "1" || NO_TELEMETRY === "true" || Boolean(disabled);
|
|
149
78
|
}
|
|
79
|
+
oneWayHash = (payload) => {
|
|
80
|
+
const hash = createHash("sha256");
|
|
81
|
+
hash.update(payload);
|
|
82
|
+
return hash.digest("hex");
|
|
83
|
+
};
|
|
150
84
|
get projectId() {
|
|
151
85
|
return this.oneWayHash(this.projectIDRaw);
|
|
152
86
|
}
|
|
153
87
|
get isDisabled() {
|
|
154
88
|
return this._disabled;
|
|
155
89
|
}
|
|
90
|
+
submitRecord = async ({ event }) => {
|
|
91
|
+
if (this.isDisabled) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
const id = this.projectId;
|
|
96
|
+
const body = {
|
|
97
|
+
partitionKey: id,
|
|
98
|
+
data: {
|
|
99
|
+
anonymousId: id,
|
|
100
|
+
event: event.name,
|
|
101
|
+
properties: {
|
|
102
|
+
...event,
|
|
103
|
+
nodeVersion: process.version,
|
|
104
|
+
tinaCliVersion: getTinaCliVersion(),
|
|
105
|
+
tinaVersion: getTinaVersion(),
|
|
106
|
+
yarnVersion: getYarnVersion(),
|
|
107
|
+
npmVersion: getNpmVersion(),
|
|
108
|
+
CI: Boolean(process.env.CI)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
await fetch(TINA_METRICS_ENDPOINT, {
|
|
113
|
+
method: "POST",
|
|
114
|
+
body: JSON.stringify(body),
|
|
115
|
+
headers: { "content-type": "application/json" }
|
|
116
|
+
});
|
|
117
|
+
} catch (_e) {
|
|
118
|
+
}
|
|
119
|
+
};
|
|
156
120
|
};
|
|
157
|
-
|
|
158
|
-
0 && (module.exports = {
|
|
121
|
+
export {
|
|
159
122
|
Telemetry
|
|
160
|
-
}
|
|
123
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinacms/metrics",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"typings": "dist/index.d.ts",
|
|
6
7
|
"files": [
|
|
7
8
|
"dist",
|
|
@@ -25,7 +26,7 @@
|
|
|
25
26
|
"fs-extra": "^11.3.0",
|
|
26
27
|
"jest": "^29.7.0",
|
|
27
28
|
"typescript": "^5.7.3",
|
|
28
|
-
"@tinacms/scripts": "1.
|
|
29
|
+
"@tinacms/scripts": "1.4.1"
|
|
29
30
|
},
|
|
30
31
|
"publishConfig": {
|
|
31
32
|
"registry": "https://registry.npmjs.org"
|