-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLA-263 Update telemetry options, add JSDoc comments
- Loading branch information
Showing
10 changed files
with
137 additions
and
56 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
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
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,6 @@ | ||
export interface IWithTelemetryReportUrl { | ||
/** | ||
* URL used for telemetry. | ||
*/ | ||
readonly telemetryReportUrl?: string | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export {collectTelemetry} from './collect-telemetry' | ||
export {IWithTelemetryReportUrl} from './i-with-telemetry-report-url' | ||
export {setupTelemetry} from './setup-telemetry' | ||
export {IWithTelemetryReportUrl, TelemetryOptions, WithTelemetry} from './with-telemetry' | ||
export {WithTelemetry} from './with-telemetry' |
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 |
---|---|---|
@@ -1,19 +1,34 @@ | ||
import type {NodeProject} from 'projen/lib/javascript' | ||
import type {IWithTelemetryReportUrl} from './i-with-telemetry-report-url' | ||
import {TelemetryWorkflow, TelemetryWorkflowOptions} from './telemetry-workflow' | ||
import type {IWithTelemetryReportUrl, WithTelemetry} from './with-telemetry' | ||
import type {WithTelemetry} from './with-telemetry' | ||
|
||
type Writeable<T extends object> = {-readonly [P in keyof T]: T[P]} | ||
|
||
/** | ||
* Check options for telemetry being requested | ||
* and configure the project to have: | ||
* - a URL available for telemetry code; | ||
* - a special GitHub workflow that runs telemetry collection and sends the data to the predefined URL. | ||
*/ | ||
export const setupTelemetry = ( | ||
project: NodeProject & Writeable<IWithTelemetryReportUrl>, | ||
options: WithTelemetry & TelemetryWorkflowOptions, | ||
) => { | ||
const reportUrl = options.telemetry?.reportUrl | ||
const {isTelemetryEnabled = false, telemetryUrl} = options | ||
|
||
if (!reportUrl) { | ||
if (!isTelemetryEnabled && telemetryUrl) { | ||
throw Error('Telemetry is disabled, thus "telemetryUrl" won\'t have any effect.') | ||
} | ||
|
||
if (!isTelemetryEnabled) { | ||
return | ||
} | ||
|
||
project.telemetryReportUrl = reportUrl | ||
if (!telemetryUrl) { | ||
throw Error('A valid URL is required to be set for telemetry.') | ||
} | ||
|
||
project.telemetryReportUrl = telemetryUrl | ||
TelemetryWorkflow.addToProject(project, options) | ||
} |
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 |
---|---|---|
@@ -1,11 +1,15 @@ | ||
export interface TelemetryOptions { | ||
readonly reportUrl: string | ||
} | ||
|
||
export interface WithTelemetry { | ||
readonly telemetry?: TelemetryOptions | ||
} | ||
/** | ||
* Enable template usage telemetry. | ||
* Collects the data on the template package version, connected git remotes, | ||
* applied escape hatches, configured GitHub workflows. | ||
* | ||
* @default false | ||
*/ | ||
readonly isTelemetryEnabled?: boolean | ||
|
||
export interface IWithTelemetryReportUrl { | ||
readonly telemetryReportUrl?: string | ||
/** | ||
* Endpoint URL to send telemetry data to. | ||
*/ | ||
readonly telemetryUrl?: string | ||
} |