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 4 commits
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
25 changes: 8 additions & 17 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const getKeypath = require('keypather/get')
const marked = require('marked')
const path = require('path')
const portScanner = require('portscanner')
const prompt = require('prompt')
const inquirer = require('inquirer')
const request = require('sync-request')

// Local dependencies
Expand Down Expand Up @@ -86,26 +86,17 @@ exports.findAvailablePort = function (app, callback) {
} else {
// Port in use - offer to change to available port
console.error('ERROR: Port ' + port + ' in use - you may have another prototype running.\n')
// Set up prompt settings
prompt.colors = false
prompt.start()
prompt.message = ''
prompt.delimiter = ''

// Ask user if they want to change port
prompt.get([{
name: 'answer',
description: 'Change to an available port? (y/n)',
required: true,
type: 'string',
pattern: /y(es)?|no?/i,
message: 'Please enter y or n'
}], function (err, result) {
if (err) { throw err }
if (result.answer.match(/y(es)?/i)) {
inquirer.prompt([{
name: 'changePort',
message: 'Change to an available port?',
type: 'confirm'
}]).then(answers => {
if (answers.changePort) {
// User answers yes
port = availablePort
fs.writeFileSync(path.join(__dirname, '/../.port.tmp'), port)
fs.writeFileSync(path.join(__dirname, '/../.port.tmp'), port.toString())
console.log('Changed to port ' + port)

callback(port)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"gulp-nodemon": "^2.5.0",
"gulp-sass": "^4.0.1",
"gulp-sourcemaps": "^2.6.0",
"inquirer": "^7.1.0",
"keypather": "^3.0.0",
"marked": "^0.8.2",
"notifications-node-client": "^4.7.2",
Expand All @@ -54,7 +55,7 @@
"devDependencies": {
"glob": "^7.1.4",
"jest": "^25.2.7",
"node-sass": "^4.12.0",
"node-sass": "^4.14.1",
"standard": "^14.3.3",
"supertest": "^4.0.2"
}
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