Skip to content

Commit

Permalink
Better swDest default value when using workbox-cli wizard (#1105)
Browse files Browse the repository at this point in the history
* Use the previous globDirectory value when offering a default for swDest.

* JSDoc.

* Explicitly default to the current directory
  • Loading branch information
jeffposnick authored Dec 5, 2017
1 parent cf372f0 commit 626435d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/workbox-cli/src/lib/questions/ask-questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const askSWDest = require('./ask-sw-dest');
module.exports = async () => {
const globDirectory = await askRootOfWebApp();
const globPatterns = await askExtensionsToCache(globDirectory);
const swDest = await askSWDest();
const swDest = await askSWDest(globDirectory);
const configLocation = await askConfigLocation();
const config = {
globDirectory,
Expand Down
13 changes: 7 additions & 6 deletions packages/workbox-cli/src/lib/questions/ask-sw-dest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,28 @@

const assert = require('assert');
const inquirer = require('inquirer');
const ol = require('common-tags').oneLine;
const path = require('path');

const errors = require('../errors');

// The key used for the question/answer.
const name = 'swDest';

/**
* @param {string} defaultDir
* @return {Promise<Object>} The answers from inquirer.
*/
function askQuestion() {
function askQuestion(defaultDir) {
return inquirer.prompt([{
name,
message: ol`Where would you like your service worker file to be saved?`,
message: `Where would you like your service worker file to be saved?`,
type: 'input',
default: 'build/sw.js',
default: path.join(defaultDir, 'sw.js'),
}]);
}

module.exports = async () => {
const answers = await askQuestion();
module.exports = async (defaultDir = '.') => {
const answers = await askQuestion(defaultDir);
const swDest = answers[name].trim();

assert(swDest, errors['invalid-sw-dest']);
Expand Down

0 comments on commit 626435d

Please sign in to comment.