@strapi/strapi 4.2.1-alpha.0 → 4.2.2

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/bin/strapi.js CHANGED
@@ -230,7 +230,13 @@ program
230
230
  // `$ strapi opt-out-telemetry`
231
231
  program
232
232
  .command('telemetry:disable')
233
- .description('Stop Strapi from sending anonymous telemetry and metadata')
233
+ .description('Disable anonymous telemetry and metadata sending to Strapi analytics')
234
234
  .action(getLocalScript('opt-out-telemetry'));
235
235
 
236
+ // `$ strapi opt-in-telemetry`
237
+ program
238
+ .command('telemetry:enable')
239
+ .description('Enable anonymous telemetry and metadata sending to Strapi analytics')
240
+ .action(getLocalScript('opt-in-telemetry'));
241
+
236
242
  program.parseAsync(process.argv);
@@ -0,0 +1,100 @@
1
+ 'use strict';
2
+
3
+ const { resolve } = require('path');
4
+ const fse = require('fs-extra');
5
+ const chalk = require('chalk');
6
+ const fetch = require('node-fetch');
7
+ const { v4: uuidv4 } = require('uuid');
8
+ const machineID = require('../utils/machine-id');
9
+
10
+ const readPackageJSON = async path => {
11
+ try {
12
+ const packageObj = await fse.readJson(path);
13
+ return packageObj;
14
+ } catch (err) {
15
+ console.error(`${chalk.red('Error')}: ${err.message}`);
16
+ }
17
+ };
18
+
19
+ const writePackageJSON = async (path, file, spacing) => {
20
+ try {
21
+ await fse.writeJson(path, file, { spaces: spacing });
22
+ return true;
23
+ } catch (err) {
24
+ console.error(`${chalk.red('Error')}: ${err.message}`);
25
+ console.log(
26
+ `${chalk.yellow(
27
+ 'Warning'
28
+ )}: There has been an error, please set "telemetryDisabled": false in the "strapi" object of your package.json manually.`
29
+ );
30
+ return false;
31
+ }
32
+ };
33
+
34
+ const generateNewPackageJSON = packageObj => {
35
+ if (!packageObj.strapi) {
36
+ return {
37
+ ...packageObj,
38
+ strapi: {
39
+ uuid: uuidv4(),
40
+ telemetryDisabled: false,
41
+ },
42
+ };
43
+ } else {
44
+ return {
45
+ ...packageObj,
46
+ strapi: {
47
+ ...packageObj.strapi,
48
+ uuid: packageObj.strapi.uuid ? packageObj.strapi.uuid : uuidv4(),
49
+ telemetryDisabled: false,
50
+ },
51
+ };
52
+ }
53
+ };
54
+
55
+ const sendEvent = async uuid => {
56
+ try {
57
+ await fetch('https://analytics.strapi.io/track', {
58
+ method: 'POST',
59
+ body: JSON.stringify({
60
+ event: 'didOptInTelemetry',
61
+ uuid,
62
+ deviceId: machineID(),
63
+ }),
64
+ headers: { 'Content-Type': 'application/json' },
65
+ });
66
+ } catch (e) {
67
+ //...
68
+ }
69
+ };
70
+
71
+ module.exports = async function optInTelemetry() {
72
+ const packageJSONPath = resolve(process.cwd(), 'package.json');
73
+ const exists = await fse.pathExists(packageJSONPath);
74
+
75
+ if (!exists) {
76
+ console.log(`${chalk.yellow('Warning')}: could not find package.json`);
77
+ process.exit(0);
78
+ }
79
+
80
+ const packageObj = await readPackageJSON(packageJSONPath);
81
+
82
+ if (packageObj.strapi && packageObj.strapi.uuid) {
83
+ if (packageObj.strapi.telemetryDisabled === false) {
84
+ console.log(`${chalk.yellow('Warning:')} telemetry is already enabled`);
85
+ process.exit(0);
86
+ }
87
+ }
88
+
89
+ const updatedPackageJSON = generateNewPackageJSON(packageObj);
90
+
91
+ const write = await writePackageJSON(packageJSONPath, updatedPackageJSON, 2);
92
+
93
+ if (!write) {
94
+ process.exit(0);
95
+ }
96
+
97
+ await sendEvent(updatedPackageJSON.strapi.uuid);
98
+ console.log(`${chalk.green('Successfully opted into and enabled Strapi telemetry')}`);
99
+ process.exit(0);
100
+ };
@@ -4,12 +4,14 @@ const path = require('path');
4
4
  const fs = require('fs');
5
5
  const loadFile = require('./load-config-file');
6
6
 
7
+ const VALID_EXTENSIONS = ['.js', '.json'];
8
+
7
9
  module.exports = dir => {
8
10
  if (!fs.existsSync(dir)) return {};
9
11
 
10
12
  return fs
11
13
  .readdirSync(dir, { withFileTypes: true })
12
- .filter(file => file.isFile())
14
+ .filter(file => file.isFile() && VALID_EXTENSIONS.includes(path.extname(file.name)))
13
15
  .reduce((acc, file) => {
14
16
  const key = path.basename(file.name, path.extname(file.name));
15
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/strapi",
3
- "version": "4.2.1-alpha.0",
3
+ "version": "4.2.2",
4
4
  "description": "An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MySQL, MariaDB, PostgreSQL, SQLite",
5
5
  "keywords": [
6
6
  "strapi",
@@ -80,16 +80,16 @@
80
80
  "dependencies": {
81
81
  "@koa/cors": "3.1.0",
82
82
  "@koa/router": "10.1.1",
83
- "@strapi/admin": "4.2.1-alpha.0",
84
- "@strapi/database": "4.2.1-alpha.0",
85
- "@strapi/generate-new": "4.2.1-alpha.0",
86
- "@strapi/generators": "4.2.1-alpha.0",
87
- "@strapi/logger": "4.2.1-alpha.0",
88
- "@strapi/plugin-content-manager": "4.2.1-alpha.0",
89
- "@strapi/plugin-content-type-builder": "4.2.1-alpha.0",
90
- "@strapi/plugin-email": "4.2.1-alpha.0",
91
- "@strapi/plugin-upload": "4.2.1-alpha.0",
92
- "@strapi/utils": "4.2.1-alpha.0",
83
+ "@strapi/admin": "4.2.2",
84
+ "@strapi/database": "4.2.2",
85
+ "@strapi/generate-new": "4.2.2",
86
+ "@strapi/generators": "4.2.2",
87
+ "@strapi/logger": "4.2.2",
88
+ "@strapi/plugin-content-manager": "4.2.2",
89
+ "@strapi/plugin-content-type-builder": "4.2.2",
90
+ "@strapi/plugin-email": "4.2.2",
91
+ "@strapi/plugin-upload": "4.2.2",
92
+ "@strapi/utils": "4.2.2",
93
93
  "bcryptjs": "2.4.3",
94
94
  "boxen": "5.1.2",
95
95
  "chalk": "4.1.2",
@@ -137,5 +137,5 @@
137
137
  "node": ">=14.19.1 <=16.x.x",
138
138
  "npm": ">=6.0.0"
139
139
  },
140
- "gitHead": "90bd3b9e294a69cd9538bde4e2e853e6de60f238"
140
+ "gitHead": "376ff3133c13f6eb10d0c90f4b5eb701592aff97"
141
141
  }