Skip to content
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

Add support for Node v14 #901

Merged
merged 8 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/usage-data-prompt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ With your permission, the kit can send useful anonymous usage data
for analysis to help the team improve the service. Read more here:
https://govuk-prototype-kit.herokuapp.com/docs/usage-data

Do you give permission for the kit to send anonymous usage data? (y/n)
Do you give permission for the kit to send anonymous usage data?
37 changes: 9 additions & 28 deletions lib/usage_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fs = require('fs')
const os = require('os')

// NPM dependencies
const prompt = require('prompt')
const inquirer = require('inquirer')
const universalAnalytics = require('universal-analytics')
const uuidv4 = require('uuid/v4')

Expand Down Expand Up @@ -37,34 +37,15 @@ exports.setUsageDataConfig = function (usageDataConfig) {
// returns a Promise with the user's answer
exports.askForUsageDataPermission = function () {
return new Promise(function (resolve, reject) {
// Set up prompt settings
prompt.colors = false
prompt.start()
prompt.message = ''
prompt.delimiter = ''
const description = fs.readFileSync(path.join(__dirname, 'usage-data-prompt.txt'), 'utf8').trim()

const description = fs.readFileSync(path.join(__dirname, 'usage-data-prompt.txt'), 'utf8')

prompt.get([{
name: 'answer',
description: description,
required: true,
type: 'string',
pattern: /y(es)?|no?/i,
message: 'Please enter y or n',
ask: function () {
return process.stdout.isTTY
}
}], function (err, result) {
if (err) {
reject(err)
hannalaakso marked this conversation as resolved.
Show resolved Hide resolved
}
if (result.answer.match(/y(es)?/i)) {
resolve('yes')
} else {
resolve('no')
}
})
inquirer.prompt([{
name: 'usageData',
message: description,
type: 'confirm',
when: () => process.stdout.isTTY,
default: false
}]).then(answers => resolve(answers.usageData))
})
}

Expand Down
15 changes: 6 additions & 9 deletions start.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ const usageDataConfig = usageData.getUsageDataConfig()
if (usageDataConfig.collectUsageData === undefined) {
// No recorded answer, so ask for permission
const promptPromise = usageData.askForUsageDataPermission()
promptPromise.then(function (answer) {
if (answer === 'yes') {
usageDataConfig.collectUsageData = true
usageData.setUsageDataConfig(usageDataConfig)
promptPromise.then(function (permissionGranted) {
usageDataConfig.collectUsageData = permissionGranted
usageData.setUsageDataConfig(usageDataConfig)

if (permissionGranted) {
usageData.startTracking(usageDataConfig)
} else if (answer === 'no') {
usageDataConfig.collectUsageData = false
usageData.setUsageDataConfig(usageDataConfig)
} else {
console.error(answer)
}

runGulp()
})
} else if (usageDataConfig.collectUsageData === true) {
Expand Down