-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(misc): a/b different messages during migration to next major
- Loading branch information
Showing
6 changed files
with
192 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import axios from 'axios'; | ||
import { isCI } from './output'; | ||
|
||
export class PromptMessages { | ||
private messages = { | ||
nxCloudCreation: [ | ||
{ | ||
code: 'set-up-distributed-caching-ci', | ||
message: `Enable distributed caching to make your CI faster`, | ||
}, | ||
], | ||
nxCloudMigration: [ | ||
{ | ||
code: 'we-noticed', | ||
message: `We noticed you are migrating to a new major version, but are not taking advantage of Nx Cloud. Nx Cloud can make your CI up to 10 times faster. Learn more about it here: nx.app. Would you like to add it?`, | ||
}, | ||
{ | ||
code: 'not-leveraging-caching', | ||
message: `You're not leveraging distributed caching yet. Do you want to enable it and speed up your CI?`, | ||
}, | ||
{ | ||
code: 'make-ci-faster', | ||
message: `Enable distributed caching to make your CI faster?`, | ||
}, | ||
], | ||
}; | ||
|
||
private selectedMessages = {}; | ||
|
||
getPromptMessage(key: string): string { | ||
if (this.selectedMessages[key] === undefined) { | ||
if (process.env.NX_GENERATE_DOCS_PROCESS === 'true') { | ||
this.selectedMessages[key] = 0; | ||
} else { | ||
this.selectedMessages[key] = Math.floor( | ||
Math.random() * this.messages[key].length | ||
); | ||
} | ||
} | ||
return this.messages[key][this.selectedMessages[key]].message; | ||
} | ||
|
||
codeOfSelectedPromptMessage(key: string): string { | ||
if (this.selectedMessages[key] === undefined) return null; | ||
return this.messages[key][this.selectedMessages[key]].code; | ||
} | ||
} | ||
|
||
export const messages = new PromptMessages(); | ||
|
||
/** | ||
* We are incrementing a counter to track how often create-nx-workspace is used in CI | ||
* vs dev environments. No personal information is collected. | ||
*/ | ||
export async function recordStat(opts: { | ||
command: string; | ||
nxVersion: string; | ||
useCloud: boolean; | ||
meta: string; | ||
}) { | ||
try { | ||
const major = Number(opts.nxVersion.split('.')[0]); | ||
if (process.env.NX_VERBOSE_LOGGING === 'true') { | ||
console.log(`Record stat. Major: ${major}`); | ||
} | ||
if (major < 10 || major > 14) return; // test version, skip it | ||
await axios | ||
.create({ | ||
baseURL: 'https://cloud.nx.app', | ||
timeout: 400, | ||
}) | ||
.post('/nx-cloud/stats', { | ||
command: opts.command, | ||
isCI: isCI(), | ||
useCloud: opts.useCloud, | ||
meta: opts.meta, | ||
}); | ||
} catch (e) { | ||
if (process.env.NX_VERBOSE_LOGGING === 'true') { | ||
console.error(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import axios from 'axios'; | ||
import { isCI } from './is-ci'; | ||
|
||
export class PromptMessages { | ||
private messages = { | ||
nxCloudCreation: [ | ||
{ | ||
code: 'set-up-distributed-caching-ci', | ||
message: `Enable distributed caching to make your CI faster`, | ||
}, | ||
], | ||
nxCloudMigration: [ | ||
{ | ||
code: 'we-noticed', | ||
message: `We noticed you are migrating to a new major version, but are not taking advantage of Nx Cloud. Nx Cloud can make your CI up to 10 times faster. Learn more about it here: nx.app. Would you like to add it?`, | ||
}, | ||
{ | ||
code: 'not-leveraging-caching', | ||
message: `You're not leveraging distributed caching yet. Do you want to enable it and speed up your CI?`, | ||
}, | ||
{ | ||
code: 'make-ci-faster', | ||
message: `Enable distributed caching to make your CI faster?`, | ||
}, | ||
], | ||
}; | ||
|
||
private selectedMessages = {}; | ||
|
||
getPromptMessage(key: string): string { | ||
if (this.selectedMessages[key] === undefined) { | ||
if (process.env.NX_GENERATE_DOCS_PROCESS === 'true') { | ||
this.selectedMessages[key] = 0; | ||
} else { | ||
this.selectedMessages[key] = Math.floor( | ||
Math.random() * this.messages[key].length | ||
); | ||
} | ||
} | ||
return this.messages[key][this.selectedMessages[key]].message; | ||
} | ||
|
||
codeOfSelectedPromptMessage(key: string): string { | ||
if (this.selectedMessages[key] === undefined) return null; | ||
return this.messages[key][this.selectedMessages[key]].code; | ||
} | ||
} | ||
|
||
export const messages = new PromptMessages(); | ||
|
||
/** | ||
* We are incrementing a counter to track how often create-nx-workspace is used in CI | ||
* vs dev environments. No personal information is collected. | ||
*/ | ||
export async function recordStat(opts: { | ||
command: string; | ||
nxVersion: string; | ||
useCloud: boolean; | ||
meta: string; | ||
}) { | ||
try { | ||
const major = Number(opts.nxVersion.split('.')[0]); | ||
if (process.env.NX_VERBOSE_LOGGING === 'true') { | ||
console.log(`Record stat. Major: ${major}`); | ||
} | ||
if (major < 10 || major > 14) return; // test version, skip it | ||
await axios | ||
.create({ | ||
baseURL: 'https://cloud.nx.app', | ||
timeout: 400, | ||
}) | ||
.post('/nx-cloud/stats', { | ||
command: opts.command, | ||
isCI: isCI(), | ||
useCloud: opts.useCloud, | ||
meta: opts.meta, | ||
}); | ||
} catch (e) { | ||
if (process.env.NX_VERBOSE_LOGGING === 'true') { | ||
console.error(e); | ||
} | ||
} | ||
} |