-
Notifications
You must be signed in to change notification settings - Fork 232
feat(ng-add): adicionar opção de telemetria anônima no schematic ng-add #2757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,13 +8,15 @@ import { addPackageToPackageJson } from '@po-ui/ng-schematics/package-config'; | |||||||||||||||||
| * - Imports PoModule to app root module; | ||||||||||||||||||
| * - Install dependencies; | ||||||||||||||||||
| * - Configure theme style in project workspace; | ||||||||||||||||||
| * - Configure telemetry if enabled; | ||||||||||||||||||
| */ | ||||||||||||||||||
| export default function (options: any): Rule { | ||||||||||||||||||
| return chain([ | ||||||||||||||||||
| addPoPackageAndInstall(), | ||||||||||||||||||
| schematic('ng-add-setup-project', { | ||||||||||||||||||
| ...options | ||||||||||||||||||
| }) | ||||||||||||||||||
| }), | ||||||||||||||||||
| configureTelemetry(options) | ||||||||||||||||||
| ]); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -26,3 +28,17 @@ function addPoPackageAndInstall(): Rule { | |||||||||||||||||
| context.addTask(new NodePackageInstallTask()); | ||||||||||||||||||
| }; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| function configureTelemetry(options: any): Rule { | ||||||||||||||||||
| return (tree: Tree) => { | ||||||||||||||||||
| const telemetryConfig = { | ||||||||||||||||||
| enabled: options.enableTelemetry === true, | ||||||||||||||||||
| consentDate: new Date().toISOString(), | ||||||||||||||||||
| version: '0.0.0-PLACEHOLDER' | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| tree.create('.po-ui-telemetry.json', JSON.stringify(telemetryConfig, null, 2)); | ||||||||||||||||||
|
|
||||||||||||||||||
|
Comment on lines
+32
to
+41
|
||||||||||||||||||
| tree.create('.po-ui-telemetry.json', JSON.stringify(telemetryConfig, null, 2)); | |
| const telemetryConfigContent = JSON.stringify(telemetryConfig, null, 2); | |
| if (tree.exists('.po-ui-telemetry.json')) { | |
| tree.overwrite('.po-ui-telemetry.json', telemetryConfigContent); | |
| } else { | |
| tree.create('.po-ui-telemetry.json', telemetryConfigContent); | |
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,22 +1,26 @@ | ||||||||||||||
| { | ||||||||||||||
| "$schema": "http://json-schema.org/schema", | ||||||||||||||
| "$id": "SchematicsNgAdd", | ||||||||||||||
| "title": "Ng Add Options Schema", | ||||||||||||||
| "$id": "SchematicsPONgAdd", | ||||||||||||||
| "title": "PO UI ng-add Options Schema", | ||||||||||||||
| "type": "object", | ||||||||||||||
| "properties": { | ||||||||||||||
| "project": { | ||||||||||||||
| "type": "string", | ||||||||||||||
| "description": "Name of the project.", | ||||||||||||||
| "description": "The name of the project.", | ||||||||||||||
| "$default": { | ||||||||||||||
| "$source": "projectName" | ||||||||||||||
| } | ||||||||||||||
| }, | ||||||||||||||
| "configSideMenu": { | ||||||||||||||
| "type": "boolean", | ||||||||||||||
| "description": "When true create a app.component with po-toolbar and po-menu configured.", | ||||||||||||||
| "default": true, | ||||||||||||||
| "x-prompt": "Would you like to configure Sidemenu?", | ||||||||||||||
| "x-user-analytics": 17 | ||||||||||||||
| "description": "Configure side menu layout", | ||||||||||||||
| "default": false | ||||||||||||||
|
||||||||||||||
| "default": false | |
| "default": true, | |
| "x-prompt": "Deseja configurar o layout de menu lateral?", | |
| "x-user-analytics": { | |
| "featureName": "configSideMenu" | |
| } |
Copilot
AI
Mar 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new enableTelemetry prompt text is in PT-BR, but existing schematic x-prompt messages in this repo are in English (e.g. projects/ui/schematics/ng-generate/po-page-*/schema.json). To keep CLI prompts consistent, consider using English here as well (or standardize prompts repo-wide if PT-BR is the new desired convention).
| "x-prompt": "Deseja habilitar telemetria anônima para ajudar a equipe do PO UI a melhorar os componentes?" | |
| "x-prompt": "Enable anonymous telemetry to help the PO UI team improve components?" |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,35 @@ | ||||||||||
| #!/usr/bin/env node | ||||||||||
| 'use strict'; | ||||||||||
|
|
||||||||||
| // Não exibir mensagem em CI ou quando stdin não é interativo | ||||||||||
| const isCI = | ||||||||||
| process.env.CI || | ||||||||||
| process.env.CONTINUOUS_INTEGRATION || | ||||||||||
| process.env.BUILD_NUMBER || | ||||||||||
| process.env.GITHUB_ACTIONS || | ||||||||||
| process.env.TRAVIS || | ||||||||||
| process.env.CIRCLECI || | ||||||||||
| process.env.JENKINS_URL; | ||||||||||
|
|
||||||||||
| if (isCI) { | ||||||||||
|
||||||||||
| if (isCI) { | |
| const isNonInteractive = !process.stdin.isTTY || process.env.npm_config_yes; | |
| if (isCI || isNonInteractive) { |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,64 @@ | ||||||||||||||||||||||||||||||||||||||
| #!/usr/bin/env node | ||||||||||||||||||||||||||||||||||||||
| 'use strict'; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const readline = require('readline'); | ||||||||||||||||||||||||||||||||||||||
| const fs = require('fs'); | ||||||||||||||||||||||||||||||||||||||
| const path = require('path'); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const isCI = process.env.CI || process.env.CONTINUOUS_INTEGRATION || process.env.GITHUB_ACTIONS || process.env.TRAVIS; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if (isCI || !process.stdin.isTTY) { | ||||||||||||||||||||||||||||||||||||||
| process.exit(0); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const rl = readline.createInterface({ | ||||||||||||||||||||||||||||||||||||||
| input: process.stdin, | ||||||||||||||||||||||||||||||||||||||
| output: process.stdout | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| rl.question('\n\uD83D\uDD0D Deseja habilitar telemetria anônima para ajudar a equipe do PO UI? (s/N): ', answer => { | ||||||||||||||||||||||||||||||||||||||
| const enabled = answer.trim().toLowerCase() === 's' || answer.trim().toLowerCase() === 'y'; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Tenta gravar na raiz do projeto do consumidor | ||||||||||||||||||||||||||||||||||||||
| const projectRoot = findProjectRoot(); | ||||||||||||||||||||||||||||||||||||||
| if (projectRoot) { | ||||||||||||||||||||||||||||||||||||||
| const configPath = path.join(projectRoot, '.po-ui-telemetry.json'); | ||||||||||||||||||||||||||||||||||||||
| const config = { | ||||||||||||||||||||||||||||||||||||||
| enabled, | ||||||||||||||||||||||||||||||||||||||
| consentDate: new Date().toISOString() | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
| fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if (enabled) { | ||||||||||||||||||||||||||||||||||||||
| console.log('\u2705 Telemetria habilitada. Obrigado por ajudar!'); | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| console.log('Telemetria não habilitada. Você pode habilitar depois com: ng add @po-ui/ng-components'); | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+30
to
+35
|
||||||||||||||||||||||||||||||||||||||
| fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); | |
| if (enabled) { | |
| console.log('\u2705 Telemetria habilitada. Obrigado por ajudar!'); | |
| } else { | |
| console.log('Telemetria não habilitada. Você pode habilitar depois com: ng add @po-ui/ng-components'); | |
| try { | |
| const configJson = JSON.stringify(config, null, 2); | |
| fs.writeFileSync(configPath, configJson); | |
| if (enabled) { | |
| console.log('\u2705 Telemetria habilitada. Obrigado por ajudar!'); | |
| } else { | |
| console.log('Telemetria não habilitada. Você pode habilitar depois com: ng add @po-ui/ng-components'); | |
| } | |
| } catch (err) { | |
| // Falha ao gravar o arquivo de configuração não deve quebrar a instalação | |
| console.warn('Aviso: não foi possível salvar a preferência de telemetria.', err && err.message ? `Detalhes: ${err.message}` : ''); |
Copilot
AI
Mar 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 30s setTimeout is never cleared when the user answers the question. This keeps the process alive for 30 seconds even after input, and will later print the timeout message / call process.exit(0) after the prompt already completed. Store the timeout handle and clearTimeout(...) before closing the readline interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These telemetry tests are added under an
xdescribe(...)suite, so they will be skipped by Jasmine and won’t run in CI (including vianpm run test:ui:schematics). If these tests are meant to validate the new behavior, switch todescribe(...)so the suite executes.