mirror of
https://github.com/strapi/strapi.git
synced 2025-09-23 07:22:51 +00:00
Migrate telemetry action
This commit is contained in:
parent
b9995616c5
commit
a1a2c76ae7
@ -17,7 +17,7 @@ const readPackageJSON = async (path: string) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const writePackageJSON = async (path: string, file: string, spacing: number) => {
|
const writePackageJSON = async (path: string, file: object, spacing: number) => {
|
||||||
try {
|
try {
|
||||||
await fse.writeJson(path, file, { spaces: spacing });
|
await fse.writeJson(path, file, { spaces: spacing });
|
||||||
return true;
|
return true;
|
||||||
|
@ -1,37 +1,51 @@
|
|||||||
'use strict';
|
import { resolve } from 'path';
|
||||||
|
import { randomUUID } from 'crypto';
|
||||||
|
import fse from 'fs-extra';
|
||||||
|
import chalk from 'chalk';
|
||||||
|
import fetch from 'node-fetch';
|
||||||
|
import machineID from '../../../../utils/machine-id';
|
||||||
|
|
||||||
const { resolve } = require('path');
|
type PackageJson = {
|
||||||
const { randomUUID } = require('crypto');
|
strapi?: {
|
||||||
const fse = require('fs-extra');
|
uuid?: string;
|
||||||
const chalk = require('chalk');
|
telemetryDisabled?: boolean;
|
||||||
const fetch = require('node-fetch');
|
};
|
||||||
const machineID = require('../../../../utils/machine-id');
|
};
|
||||||
|
|
||||||
const readPackageJSON = async (path) => {
|
const readPackageJSON = async (path: string) => {
|
||||||
try {
|
try {
|
||||||
const packageObj = await fse.readJson(path);
|
const packageObj = await fse.readJson(path);
|
||||||
return packageObj;
|
return packageObj;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (err instanceof Error) {
|
||||||
console.error(`${chalk.red('Error')}: ${err.message}`);
|
console.error(`${chalk.red('Error')}: ${err.message}`);
|
||||||
|
} else {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const writePackageJSON = async (path, file, spacing) => {
|
const writePackageJSON = async (path: string, file: object, spacing: number) => {
|
||||||
try {
|
try {
|
||||||
await fse.writeJson(path, file, { spaces: spacing });
|
await fse.writeJson(path, file, { spaces: spacing });
|
||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (err instanceof Error) {
|
||||||
console.error(`${chalk.red('Error')}: ${err.message}`);
|
console.error(`${chalk.red('Error')}: ${err.message}`);
|
||||||
console.log(
|
console.log(
|
||||||
`${chalk.yellow(
|
`${chalk.yellow(
|
||||||
'Warning'
|
'Warning'
|
||||||
)}: There has been an error, please set "telemetryDisabled": false in the "strapi" object of your package.json manually.`
|
)}: There has been an error, please set "telemetryDisabled": false in the "strapi" object of your package.json manually.`
|
||||||
);
|
);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateNewPackageJSON = (packageObj) => {
|
const generateNewPackageJSON = (packageObj: PackageJson) => {
|
||||||
if (!packageObj.strapi) {
|
if (!packageObj.strapi) {
|
||||||
return {
|
return {
|
||||||
...packageObj,
|
...packageObj,
|
||||||
@ -51,7 +65,7 @@ const generateNewPackageJSON = (packageObj) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const sendEvent = async (uuid) => {
|
const sendEvent = async (uuid: string) => {
|
||||||
try {
|
try {
|
||||||
const event = 'didOptInTelemetry';
|
const event = 'didOptInTelemetry';
|
||||||
|
|
||||||
@ -72,7 +86,7 @@ const sendEvent = async (uuid) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = async function optInTelemetry() {
|
async function optInTelemetry() {
|
||||||
const packageJSONPath = resolve(process.cwd(), 'package.json');
|
const packageJSONPath = resolve(process.cwd(), 'package.json');
|
||||||
const exists = await fse.pathExists(packageJSONPath);
|
const exists = await fse.pathExists(packageJSONPath);
|
||||||
|
|
||||||
@ -101,4 +115,6 @@ module.exports = async function optInTelemetry() {
|
|||||||
await sendEvent(updatedPackageJSON.strapi.uuid);
|
await sendEvent(updatedPackageJSON.strapi.uuid);
|
||||||
console.log(`${chalk.green('Successfully opted into and enabled Strapi telemetry')}`);
|
console.log(`${chalk.green('Successfully opted into and enabled Strapi telemetry')}`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
};
|
}
|
||||||
|
|
||||||
|
export default optInTelemetry;
|
Loading…
x
Reference in New Issue
Block a user