mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	refactor: prompt.get already returns promise
This commit is contained in:
		| @@ -3,10 +3,6 @@ | |||||||
| const prompt = require('prompt'); | const prompt = require('prompt'); | ||||||
| const winston = require('winston'); | const winston = require('winston'); | ||||||
|  |  | ||||||
| const util = require('util'); |  | ||||||
|  |  | ||||||
| const promptGet = util.promisify((schema, callback) => prompt.get(schema, callback)); |  | ||||||
|  |  | ||||||
| const questions = { | const questions = { | ||||||
| 	redis: require('../src/database/redis').questions, | 	redis: require('../src/database/redis').questions, | ||||||
| 	mongo: require('../src/database/mongo').questions, | 	mongo: require('../src/database/mongo').questions, | ||||||
| @@ -28,17 +24,17 @@ async function getDatabaseConfig(config) { | |||||||
| 		if (config['redis:host'] && config['redis:port']) { | 		if (config['redis:host'] && config['redis:port']) { | ||||||
| 			return config; | 			return config; | ||||||
| 		} | 		} | ||||||
| 		return await promptGet(questions.redis); | 		return await prompt.get(questions.redis); | ||||||
| 	} else if (config.database === 'mongo') { | 	} else if (config.database === 'mongo') { | ||||||
| 		if ((config['mongo:host'] && config['mongo:port']) || config['mongo:uri']) { | 		if ((config['mongo:host'] && config['mongo:port']) || config['mongo:uri']) { | ||||||
| 			return config; | 			return config; | ||||||
| 		} | 		} | ||||||
| 		return await promptGet(questions.mongo); | 		return await prompt.get(questions.mongo); | ||||||
| 	} else if (config.database === 'postgres') { | 	} else if (config.database === 'postgres') { | ||||||
| 		if (config['postgres:host'] && config['postgres:port']) { | 		if (config['postgres:host'] && config['postgres:port']) { | ||||||
| 			return config; | 			return config; | ||||||
| 		} | 		} | ||||||
| 		return await promptGet(questions.postgres); | 		return await prompt.get(questions.postgres); | ||||||
| 	} | 	} | ||||||
| 	throw new Error(`unknown database : ${config.database}`); | 	throw new Error(`unknown database : ${config.database}`); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -7,7 +7,6 @@ const semver = require('semver'); | |||||||
| const fs = require('fs'); | const fs = require('fs'); | ||||||
| const path = require('path'); | const path = require('path'); | ||||||
| const nconf = require('nconf'); | const nconf = require('nconf'); | ||||||
| const util = require('util'); |  | ||||||
|  |  | ||||||
| const { paths, pluginNamePattern } = require('../constants'); | const { paths, pluginNamePattern } = require('../constants'); | ||||||
|  |  | ||||||
| @@ -138,9 +137,8 @@ async function upgradePlugins() { | |||||||
| 		prompt.message = ''; | 		prompt.message = ''; | ||||||
| 		prompt.delimiter = ''; | 		prompt.delimiter = ''; | ||||||
|  |  | ||||||
| 		const promptGet = util.promisify((schema, callback) => prompt.get(schema, callback)); |  | ||||||
| 		prompt.start(); | 		prompt.start(); | ||||||
| 		const result = await promptGet({ | 		const result = await prompt.get({ | ||||||
| 			name: 'upgrade', | 			name: 'upgrade', | ||||||
| 			description: '\nProceed with upgrade (y|n)?'.reset, | 			description: '\nProceed with upgrade (y|n)?'.reset, | ||||||
| 			type: 'string', | 			type: 'string', | ||||||
|   | |||||||
| @@ -7,9 +7,6 @@ const prompt = require('prompt'); | |||||||
| const winston = require('winston'); | const winston = require('winston'); | ||||||
| const nconf = require('nconf'); | const nconf = require('nconf'); | ||||||
| const _ = require('lodash'); | const _ = require('lodash'); | ||||||
| const util = require('util'); |  | ||||||
|  |  | ||||||
| const promptGet = util.promisify((schema, callback) => prompt.get(schema, callback)); |  | ||||||
|  |  | ||||||
| const utils = require('./utils'); | const utils = require('./utils'); | ||||||
|  |  | ||||||
| @@ -147,7 +144,7 @@ async function setupConfig() { | |||||||
| 			} | 			} | ||||||
| 		}); | 		}); | ||||||
| 	} else { | 	} else { | ||||||
| 		config = await promptGet(questions.main); | 		config = await prompt.get(questions.main); | ||||||
| 	} | 	} | ||||||
| 	await configureDatabases(config); | 	await configureDatabases(config); | ||||||
| 	await completeConfigSetup(config); | 	await completeConfigSetup(config); | ||||||
| @@ -298,7 +295,7 @@ async function createAdmin() { | |||||||
|  |  | ||||||
| 	async function retryPassword(originalResults) { | 	async function retryPassword(originalResults) { | ||||||
| 		// Ask only the password questions | 		// Ask only the password questions | ||||||
| 		const results = await promptGet(passwordQuestions); | 		const results = await prompt.get(passwordQuestions); | ||||||
|  |  | ||||||
| 		// Update the original data with newly collected password | 		// Update the original data with newly collected password | ||||||
| 		originalResults.password = results.password; | 		originalResults.password = results.password; | ||||||
| @@ -312,7 +309,7 @@ async function createAdmin() { | |||||||
| 	questions = questions.concat(passwordQuestions); | 	questions = questions.concat(passwordQuestions); | ||||||
|  |  | ||||||
| 	if (!install.values) { | 	if (!install.values) { | ||||||
| 		const results = await promptGet(questions); | 		const results = await prompt.get(questions); | ||||||
| 		return await success(results); | 		return await success(results); | ||||||
| 	} | 	} | ||||||
| 	// If automated setup did not provide a user password, generate one, | 	// If automated setup did not provide a user password, generate one, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user