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

Better swDest default value when using workbox-cli wizard #1105

Merged
merged 3 commits into from
Dec 5, 2017
Merged
Show file tree
Hide file tree
Changes from all 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 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