diff --git a/package.json b/package.json index 84553b0c3d..99242c1af2 100644 --- a/package.json +++ b/package.json @@ -300,7 +300,8 @@ "string-width": "^4.2.3", "tailwindcss": "3.1.8", "tslib": "^2.3.0", - "weak-napi": "^2.0.2" + "weak-napi": "^2.0.2", + "axios": "0.21.1" }, "resolutions": { "**/xmlhttprequest-ssl": "~1.6.2", diff --git a/packages/create-nx-workspace/bin/create-nx-workspace.ts b/packages/create-nx-workspace/bin/create-nx-workspace.ts index c967c779ad..32aa54fafe 100644 --- a/packages/create-nx-workspace/bin/create-nx-workspace.ts +++ b/packages/create-nx-workspace/bin/create-nx-workspace.ts @@ -5,7 +5,7 @@ import * as path from 'path'; import { dirSync } from 'tmp'; import * as yargs from 'yargs'; import { showNxWarning, unparse } from './shared'; -import { output } from './output'; +import { isCI, output } from './output'; import * as ora from 'ora'; import { detectInvokedPackageManager, @@ -23,6 +23,7 @@ import chalk = require('chalk'); import { ciList } from './ci'; import { join } from 'path'; import { initializeGitRepo } from './git'; +import axios from 'axios'; type Arguments = { name: string; @@ -306,6 +307,8 @@ async function main(parsedArgs: yargs.Arguments) { if (nxCloud && nxCloudInstallRes.code === 0) { printNxCloudSuccessMessage(nxCloudInstallRes.stdout); } + + await recordWorkspaceCreationStats(nxCloud); } async function getConfiguration( @@ -1012,3 +1015,24 @@ function pointToFreeCourseOnEgghead(): string[] { `https://egghead.io/playlists/scale-react-development-with-nx-4038`, ]; } + +/** + * We are incrementing a counter to track how often create-nx-workspace is used in CI + * vs dev environments. No personal information is collected. + */ +async function recordWorkspaceCreationStats(useCloud: boolean) { + try { + const major = Number(nxVersion.split('.')[0]); + if (major < 10 || major > 30) return; // test version, skip it + await axios + .create({ + baseURL: 'https://cloud.nx.app', + timeout: 400, + }) + .post('/nx-cloud/stats', { + command: 'create-nx-workspace', + isCI: isCI(), + useCloud, + }); + } catch (e) {} +} diff --git a/packages/create-nx-workspace/package.json b/packages/create-nx-workspace/package.json index e4a95a9972..618dd135cb 100644 --- a/packages/create-nx-workspace/package.json +++ b/packages/create-nx-workspace/package.json @@ -34,6 +34,7 @@ "ora": "5.3.0", "tmp": "~0.2.1", "tslib": "^2.3.0", - "yargs": "^17.4.0" + "yargs": "^17.4.0", + "axios": "0.21.1" } } diff --git a/yarn.lock b/yarn.lock index 51ffad5ff0..0c6dbf5d39 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7351,6 +7351,13 @@ axe-core@^4.3.5, axe-core@^4.4.3: resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.4.3.tgz#11c74d23d5013c0fa5d183796729bc3482bd2f6f" integrity sha512-32+ub6kkdhhWick/UjvEwRchgoetXqTK14INLqbGm5U2TzBkBNF3nQtLYm8ovxSkQWArjEQvftCKryjZaATu3w== +axios@0.21.1: + version "0.21.1" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8" + integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA== + dependencies: + follow-redirects "^1.10.0" + axios@^0.21.1: version "0.21.4" resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.4.tgz#c67b90dc0568e5c1cf2b0b858c43ba28e2eda575" @@ -11902,7 +11909,7 @@ flush-write-stream@^1.0.0: inherits "^2.0.3" readable-stream "^2.3.6" -follow-redirects@^1.0.0, follow-redirects@^1.14.0: +follow-redirects@^1.0.0, follow-redirects@^1.10.0, follow-redirects@^1.14.0: version "1.15.1" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.1.tgz#0ca6a452306c9b276e4d3127483e29575e207ad5" integrity sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==