This repository was archived by the owner on Jan 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathpostinstall.js
More file actions
75 lines (65 loc) · 3.01 KB
/
Copy pathpostinstall.js
File metadata and controls
75 lines (65 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const os = require('os')
const {cli} = require('cli-ux')
const chalk = require('chalk')
const path = require('path')
const fs = require('fs-extra')
const isCI = require('is-ci')
const pjson = require('../package.json');
const windowsHomedriveHome = () => process.env.HOMEDRIVE && process.env.HOMEPATH && path.join(process.env.HOMEDRIVE, process.env.HOMEPATH)
const windowsUserprofileHome = () => process.env.USERPROFILE
const windowsHome = () => windowsHomedriveHome() || windowsUserprofileHome()
const packageName = pjson.name
const platform = os.platform()
const isWindows = platform === 'win32'
const home = process.env.HOME || (isWindows && windowsHome()) || os.homedir() || os.tmpdir()
const getConfigDir = (isWindows, home, pname) => {
const base = process.env[`XDG_CONFIG_HOME`]
|| (isWindows && process.env.LOCALAPPDATA)
|| path.join(home, '.config')
return path.join(base, pname)
}
const pathToConfigJson = getConfigDir(isWindows, home, packageName)
const getUserConfig = async () => {
if (fs.existsSync(path.join(pathToConfigJson, 'config.json'))) {
return await fs.readJSON(path.join(pathToConfigJson, 'config.json'))
} else {
return {
telemetry: null,
}
}
}
const promptTelemetry = async () => {
try {
const userConfig = await getUserConfig()
userConfig.lastVersionCheck = new Date()
if (!process.env.BF_CLI_TELEMETRY &&
!isCI &&
userConfig.telemetry === null) {
const disableTelemetry = await cli.prompt(chalk.red('Help us improve products by allowing Microsoft to collect anonymous command and flags usage: (Y/N)'))
if (disableTelemetry === 'Y' || disableTelemetry === 'y') {
userConfig.telemetry = true
console.log(chalk.blue('Telemetry has been enabled. You can disable at any time by running bf config:set:telemetry --disable'))
console.log(chalk.blue('You can find Microsoft Privacy Statement at https://privacy.microsoft.com/en-US/privacystatement'))
console.log(chalk.blue('we will gather some usage data as follows:'))
console.log(chalk.blue('Command group calls'))
console.log(chalk.blue('Flags used **excluding** specific values (i.e. if used parameter _--folder=name_, we will only gather the use of _--folder_ but will not capture _name_)'))
} else {
userConfig.telemetry = false
console.log(chalk.blue('Telemetry will remain disabled'))
console.log(chalk.blue('At any time you may enable collect anonymous command and flags usage by changing the configuration using command:'))
console.log(chalk.blue('bf config:set:telemetry --enable'))
}
await fs.mkdirp(pathToConfigJson)
await fs.writeFile(path.join(pathToConfigJson, 'config.json'), JSON.stringify(userConfig, null, 2))
}
/* tslint:disable:no-unused */
} catch (err) {
// swallow the exception; we don't want to crash the app
// on a failed attempt to set telemetry
}
}
const init = async () => {
await promptTelemetry()
process.exit(0)
}
init()