From eff49beb366f9c9a4ede7fc2448cd683d407a7d7 Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Fri, 14 Dec 2018 13:56:11 +0200 Subject: [PATCH] Wait for the device type compatibility check before showing the form Also now fetches the device type from the image/API only once. Signed-off-by: Thodoris Greasidis --- lib/actions/os.coffee | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/actions/os.coffee b/lib/actions/os.coffee index ca13e905..4a0df4f2 100644 --- a/lib/actions/os.coffee +++ b/lib/actions/os.coffee @@ -147,23 +147,28 @@ exports.download = console.info('The image was downloaded successfully') .nodeify(done) -buildConfig = (image, deviceType, advanced = false) -> - Promise = require('bluebird') +buildConfigForDeviceType = (deviceType, advanced = false) -> form = require('resin-cli-form') helpers = require('../utils/helpers') - Promise.resolve(helpers.getManifest(image, deviceType)) - .get('options') - .then (questions) -> - if not advanced - advancedGroup = _.find questions, - name: 'advanced' - isGroup: true + questions = deviceType.options + if not advanced + advancedGroup = _.find questions, + name: 'advanced' + isGroup: true - if advancedGroup? - override = helpers.getGroupDefaults(advancedGroup) + if advancedGroup? + override = helpers.getGroupDefaults(advancedGroup) - return form.run(questions, { override }) + return form.run(questions, { override }) + +buildConfig = (image, deviceTypeSlug, advanced = false) -> + Promise = require('bluebird') + helpers = require('../utils/helpers') + + Promise.resolve(helpers.getManifest(image, deviceTypeSlug)) + .then (deviceTypeManifest) -> + buildConfigForDeviceType(deviceTypeManifest, advanced) exports.buildConfig = signature: 'os build-config ' @@ -305,7 +310,9 @@ exports.configure = if options.config return readFileAsync(options.config, 'utf8') .then(JSON.parse) - return buildConfig(params.image, deviceType, options.advanced) + return manifestPromise.then (deviceTypeManifest) -> + buildConfigForDeviceType(deviceTypeManifest, options.advanced) + Promise.join answersPromise, manifestPromise, (answers, manifest) -> answers.version = options.version