source: trip-planner-front/node_modules/@angular/cli/models/analytics.js@ 1ad8e64

Last change on this file since 1ad8e64 was e29cc2e, checked in by Ema <ema_spirova@…>, 3 years ago

primeNG components

  • Property mode set to 100644
File size: 15.0 KB
Line 
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10 if (k2 === undefined) k2 = k;
11 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
12}) : (function(o, m, k, k2) {
13 if (k2 === undefined) k2 = k;
14 o[k2] = m[k];
15}));
16var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17 Object.defineProperty(o, "default", { enumerable: true, value: v });
18}) : function(o, v) {
19 o["default"] = v;
20});
21var __importStar = (this && this.__importStar) || function (mod) {
22 if (mod && mod.__esModule) return mod;
23 var result = {};
24 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25 __setModuleDefault(result, mod);
26 return result;
27};
28var __importDefault = (this && this.__importDefault) || function (mod) {
29 return (mod && mod.__esModule) ? mod : { "default": mod };
30};
31Object.defineProperty(exports, "__esModule", { value: true });
32exports.getSharedAnalytics = exports.getWorkspaceAnalytics = exports.hasWorkspaceAnalyticsConfiguration = exports.getGlobalAnalytics = exports.hasGlobalAnalyticsConfiguration = exports.promptProjectAnalytics = exports.promptGlobalAnalytics = exports.setAnalyticsConfig = exports.isPackageNameSafeForAnalytics = exports.analyticsPackageSafelist = exports.AnalyticsProperties = void 0;
33const core_1 = require("@angular-devkit/core");
34const debug_1 = __importDefault(require("debug"));
35const inquirer = __importStar(require("inquirer"));
36const uuid_1 = require("uuid");
37const version_1 = require("../models/version");
38const color_1 = require("../utilities/color");
39const config_1 = require("../utilities/config");
40const tty_1 = require("../utilities/tty");
41const analytics_collector_1 = require("./analytics-collector");
42/* eslint-disable no-console */
43const analyticsDebug = debug_1.default('ng:analytics'); // Generate analytics, including settings and users.
44let _defaultAngularCliPropertyCache;
45exports.AnalyticsProperties = {
46 AngularCliProd: 'UA-8594346-29',
47 AngularCliStaging: 'UA-8594346-32',
48 get AngularCliDefault() {
49 if (_defaultAngularCliPropertyCache) {
50 return _defaultAngularCliPropertyCache;
51 }
52 const v = version_1.VERSION.full;
53 // The logic is if it's a full version then we should use the prod GA property.
54 if (/^\d+\.\d+\.\d+$/.test(v) && v !== '0.0.0') {
55 _defaultAngularCliPropertyCache = exports.AnalyticsProperties.AngularCliProd;
56 }
57 else {
58 _defaultAngularCliPropertyCache = exports.AnalyticsProperties.AngularCliStaging;
59 }
60 return _defaultAngularCliPropertyCache;
61 },
62};
63/**
64 * This is the ultimate safelist for checking if a package name is safe to report to analytics.
65 */
66exports.analyticsPackageSafelist = [
67 /^@angular\//,
68 /^@angular-devkit\//,
69 /^@ngtools\//,
70 '@schematics/angular',
71];
72function isPackageNameSafeForAnalytics(name) {
73 return exports.analyticsPackageSafelist.some((pattern) => {
74 if (typeof pattern == 'string') {
75 return pattern === name;
76 }
77 else {
78 return pattern.test(name);
79 }
80 });
81}
82exports.isPackageNameSafeForAnalytics = isPackageNameSafeForAnalytics;
83/**
84 * Set analytics settings. This does not work if the user is not inside a project.
85 * @param level Which config to use. "global" for user-level, and "local" for project-level.
86 * @param value Either a user ID, true to generate a new User ID, or false to disable analytics.
87 */
88function setAnalyticsConfig(level, value) {
89 analyticsDebug('setting %s level analytics to: %s', level, value);
90 const [config, configPath] = config_1.getWorkspaceRaw(level);
91 if (!config || !configPath) {
92 throw new Error(`Could not find ${level} workspace.`);
93 }
94 const cli = config.get(['cli']);
95 if (cli !== undefined && !core_1.json.isJsonObject(cli)) {
96 throw new Error(`Invalid config found at ${configPath}. CLI should be an object.`);
97 }
98 if (value === true) {
99 value = uuid_1.v4();
100 }
101 config.modify(['cli', 'analytics'], value);
102 config.save();
103 analyticsDebug('done');
104}
105exports.setAnalyticsConfig = setAnalyticsConfig;
106/**
107 * Prompt the user for usage gathering permission.
108 * @param force Whether to ask regardless of whether or not the user is using an interactive shell.
109 * @return Whether or not the user was shown a prompt.
110 */
111async function promptGlobalAnalytics(force = false) {
112 analyticsDebug('prompting global analytics.');
113 if (force || tty_1.isTTY()) {
114 const answers = await inquirer.prompt([
115 {
116 type: 'confirm',
117 name: 'analytics',
118 message: core_1.tags.stripIndents `
119 Would you like to share anonymous usage data with the Angular Team at Google under
120 Google’s Privacy Policy at https://policies.google.com/privacy? For more details and
121 how to change this setting, see https://angular.io/analytics.
122 `,
123 default: false,
124 },
125 ]);
126 setAnalyticsConfig('global', answers.analytics);
127 if (answers.analytics) {
128 console.log('');
129 console.log(core_1.tags.stripIndent `
130 Thank you for sharing anonymous usage data. If you change your mind, the following
131 command will disable this feature entirely:
132
133 ${color_1.colors.yellow('ng analytics off')}
134 `);
135 console.log('');
136 // Send back a ping with the user `optin`.
137 const ua = new analytics_collector_1.AnalyticsCollector(exports.AnalyticsProperties.AngularCliDefault, 'optin');
138 ua.pageview('/telemetry/optin');
139 await ua.flush();
140 }
141 else {
142 // Send back a ping with the user `optout`. This is the only thing we send.
143 const ua = new analytics_collector_1.AnalyticsCollector(exports.AnalyticsProperties.AngularCliDefault, 'optout');
144 ua.pageview('/telemetry/optout');
145 await ua.flush();
146 }
147 return true;
148 }
149 else {
150 analyticsDebug('Either STDOUT or STDIN are not TTY and we skipped the prompt.');
151 }
152 return false;
153}
154exports.promptGlobalAnalytics = promptGlobalAnalytics;
155/**
156 * Prompt the user for usage gathering permission for the local project. Fails if there is no
157 * local workspace.
158 * @param force Whether to ask regardless of whether or not the user is using an interactive shell.
159 * @return Whether or not the user was shown a prompt.
160 */
161async function promptProjectAnalytics(force = false) {
162 analyticsDebug('prompting user');
163 const [config, configPath] = config_1.getWorkspaceRaw('local');
164 if (!config || !configPath) {
165 throw new Error(`Could not find a local workspace. Are you in a project?`);
166 }
167 if (force || tty_1.isTTY()) {
168 const answers = await inquirer.prompt([
169 {
170 type: 'confirm',
171 name: 'analytics',
172 message: core_1.tags.stripIndents `
173 Would you like to share anonymous usage data about this project with the Angular Team at
174 Google under Google’s Privacy Policy at https://policies.google.com/privacy? For more
175 details and how to change this setting, see https://angular.io/analytics.
176
177 `,
178 default: false,
179 },
180 ]);
181 setAnalyticsConfig('local', answers.analytics);
182 if (answers.analytics) {
183 console.log('');
184 console.log(core_1.tags.stripIndent `
185 Thank you for sharing anonymous usage data. Should you change your mind, the following
186 command will disable this feature entirely:
187
188 ${color_1.colors.yellow('ng analytics project off')}
189 `);
190 console.log('');
191 // Send back a ping with the user `optin`.
192 const ua = new analytics_collector_1.AnalyticsCollector(exports.AnalyticsProperties.AngularCliDefault, 'optin');
193 ua.pageview('/telemetry/project/optin');
194 await ua.flush();
195 }
196 else {
197 // Send back a ping with the user `optout`. This is the only thing we send.
198 const ua = new analytics_collector_1.AnalyticsCollector(exports.AnalyticsProperties.AngularCliDefault, 'optout');
199 ua.pageview('/telemetry/project/optout');
200 await ua.flush();
201 }
202 return true;
203 }
204 return false;
205}
206exports.promptProjectAnalytics = promptProjectAnalytics;
207async function hasGlobalAnalyticsConfiguration() {
208 try {
209 const globalWorkspace = await config_1.getWorkspace('global');
210 const analyticsConfig = globalWorkspace && globalWorkspace.getCli() && globalWorkspace.getCli()['analytics'];
211 if (analyticsConfig !== null && analyticsConfig !== undefined) {
212 return true;
213 }
214 }
215 catch { }
216 return false;
217}
218exports.hasGlobalAnalyticsConfiguration = hasGlobalAnalyticsConfiguration;
219/**
220 * Get the global analytics object for the user. This returns an instance of UniversalAnalytics,
221 * or undefined if analytics are disabled.
222 *
223 * If any problem happens, it is considered the user has been opting out of analytics.
224 */
225async function getGlobalAnalytics() {
226 analyticsDebug('getGlobalAnalytics');
227 const propertyId = exports.AnalyticsProperties.AngularCliDefault;
228 if ('NG_CLI_ANALYTICS' in process.env) {
229 if (process.env['NG_CLI_ANALYTICS'] == 'false' || process.env['NG_CLI_ANALYTICS'] == '') {
230 analyticsDebug('NG_CLI_ANALYTICS is false');
231 return undefined;
232 }
233 if (process.env['NG_CLI_ANALYTICS'] === 'ci') {
234 analyticsDebug('Running in CI mode');
235 return new analytics_collector_1.AnalyticsCollector(propertyId, 'ci');
236 }
237 }
238 // If anything happens we just keep the NOOP analytics.
239 try {
240 const globalWorkspace = await config_1.getWorkspace('global');
241 const analyticsConfig = globalWorkspace && globalWorkspace.getCli() && globalWorkspace.getCli()['analytics'];
242 analyticsDebug('Client Analytics config found: %j', analyticsConfig);
243 if (analyticsConfig === false) {
244 analyticsDebug('Analytics disabled. Ignoring all analytics.');
245 return undefined;
246 }
247 else if (analyticsConfig === undefined || analyticsConfig === null) {
248 analyticsDebug('Analytics settings not found. Ignoring all analytics.');
249 // globalWorkspace can be null if there is no file. analyticsConfig would be null in this
250 // case. Since there is no file, the user hasn't answered and the expected return value is
251 // undefined.
252 return undefined;
253 }
254 else {
255 let uid = undefined;
256 if (typeof analyticsConfig == 'string') {
257 uid = analyticsConfig;
258 }
259 else if (typeof analyticsConfig == 'object' && typeof analyticsConfig['uid'] == 'string') {
260 uid = analyticsConfig['uid'];
261 }
262 analyticsDebug('client id: %j', uid);
263 if (uid == undefined) {
264 return undefined;
265 }
266 return new analytics_collector_1.AnalyticsCollector(propertyId, uid);
267 }
268 }
269 catch (err) {
270 analyticsDebug('Error happened during reading of analytics config: %s', err.message);
271 return undefined;
272 }
273}
274exports.getGlobalAnalytics = getGlobalAnalytics;
275async function hasWorkspaceAnalyticsConfiguration() {
276 try {
277 const globalWorkspace = await config_1.getWorkspace('local');
278 const analyticsConfig = globalWorkspace && globalWorkspace.getCli() && globalWorkspace.getCli()['analytics'];
279 if (analyticsConfig !== undefined) {
280 return true;
281 }
282 }
283 catch { }
284 return false;
285}
286exports.hasWorkspaceAnalyticsConfiguration = hasWorkspaceAnalyticsConfiguration;
287/**
288 * Get the workspace analytics object for the user. This returns an instance of AnalyticsCollector,
289 * or undefined if analytics are disabled.
290 *
291 * If any problem happens, it is considered the user has been opting out of analytics.
292 */
293async function getWorkspaceAnalytics() {
294 analyticsDebug('getWorkspaceAnalytics');
295 try {
296 const globalWorkspace = await config_1.getWorkspace('local');
297 const analyticsConfig = globalWorkspace === null || globalWorkspace === void 0 ? void 0 : globalWorkspace.getCli()['analytics'];
298 analyticsDebug('Workspace Analytics config found: %j', analyticsConfig);
299 if (analyticsConfig === false) {
300 analyticsDebug('Analytics disabled. Ignoring all analytics.');
301 return undefined;
302 }
303 else if (analyticsConfig === undefined || analyticsConfig === null) {
304 analyticsDebug('Analytics settings not found. Ignoring all analytics.');
305 return undefined;
306 }
307 else {
308 let uid = undefined;
309 if (typeof analyticsConfig == 'string') {
310 uid = analyticsConfig;
311 }
312 else if (typeof analyticsConfig == 'object' && typeof analyticsConfig['uid'] == 'string') {
313 uid = analyticsConfig['uid'];
314 }
315 analyticsDebug('client id: %j', uid);
316 if (uid == undefined) {
317 return undefined;
318 }
319 return new analytics_collector_1.AnalyticsCollector(exports.AnalyticsProperties.AngularCliDefault, uid);
320 }
321 }
322 catch (err) {
323 analyticsDebug('Error happened during reading of analytics config: %s', err.message);
324 return undefined;
325 }
326}
327exports.getWorkspaceAnalytics = getWorkspaceAnalytics;
328/**
329 * Return the usage analytics sharing setting, which is either a property string (GA-XXXXXXX-XX),
330 * or undefined if no sharing.
331 */
332async function getSharedAnalytics() {
333 analyticsDebug('getSharedAnalytics');
334 const envVarName = 'NG_CLI_ANALYTICS_SHARE';
335 if (envVarName in process.env) {
336 if (process.env[envVarName] == 'false' || process.env[envVarName] == '') {
337 analyticsDebug('NG_CLI_ANALYTICS is false');
338 return undefined;
339 }
340 }
341 // If anything happens we just keep the NOOP analytics.
342 try {
343 const globalWorkspace = await config_1.getWorkspace('global');
344 const analyticsConfig = globalWorkspace === null || globalWorkspace === void 0 ? void 0 : globalWorkspace.getCli()['analyticsSharing'];
345 if (!analyticsConfig || !analyticsConfig.tracking || !analyticsConfig.uuid) {
346 return undefined;
347 }
348 else {
349 analyticsDebug('Analytics sharing info: %j', analyticsConfig);
350 return new analytics_collector_1.AnalyticsCollector(analyticsConfig.tracking, analyticsConfig.uuid);
351 }
352 }
353 catch (err) {
354 analyticsDebug('Error happened during reading of analytics sharing config: %s', err.message);
355 return undefined;
356 }
357}
358exports.getSharedAnalytics = getSharedAnalytics;
Note: See TracBrowser for help on using the repository browser.