Skip to content

Commit

Permalink
Added value check for "feature" parameter in init (#3449)
Browse files Browse the repository at this point in the history
When the optional feature parameter is provided in a `firebase init
[feature]` command, this checks that its value is a valid choice before
attempting any other initialization.
  • Loading branch information
andrewheard authored Jun 8, 2021
1 parent 44ae32e commit d756f44
Showing 1 changed file with 51 additions and 40 deletions.
91 changes: 51 additions & 40 deletions src/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,61 @@ var _isOutside = function (from, to) {
return path.relative(from, to).match(/^\.\./);
};

const choices = [
{
value: "database",
name:
"Realtime Database: Configure a security rules file for Realtime Database and (optionally) provision default instance",
checked: false,
},
{
value: "firestore",
name: "Firestore: Configure security rules and indexes files for Firestore",
checked: false,
},
{
value: "functions",
name: "Functions: Configure a Cloud Functions directory and its files",
checked: false,
},
{
value: "hosting",
name:
"Hosting: Configure files for Firebase Hosting and (optionally) set up GitHub Action deploys",
checked: false,
},
{
value: "storage",
name: "Storage: Configure a security rules file for Cloud Storage",
checked: false,
},
{
value: "emulators",
name: "Emulators: Set up local emulators for Firebase products",
checked: false,
},
{
value: "remoteconfig",
name: "Remote Config: Configure a template file for Remote Config",
checked: false,
},
];
const featureNames = choices.map((choice) => choice.value);

module.exports = new Command("init [feature]")
.description("set up a Firebase project in the current directory")
.before(requireAuth)
.action(function (feature, options) {
if (feature && !featureNames.includes(feature)) {
return utils.reject(
clc.bold(feature) +
" is not a supported feature; must be one of " +
featureNames.join(", ") +
".",
{ exit: 1 }
);
}

var cwd = options.cwd || process.cwd();

var warnings = [];
Expand Down Expand Up @@ -70,46 +121,6 @@ module.exports = new Command("init [feature]")
}),
};

var choices = [
{
value: "database",
name:
"Realtime Database: Configure a security rules file for Realtime Database and (optionally) provision default instance",
checked: false,
},
{
value: "firestore",
name: "Firestore: Configure security rules and indexes files for Firestore",
checked: false,
},
{
value: "functions",
name: "Functions: Configure a Cloud Functions directory and its files",
checked: false,
},
{
value: "hosting",
name:
"Hosting: Configure files for Firebase Hosting and (optionally) set up GitHub Action deploys",
checked: false,
},
{
value: "storage",
name: "Storage: Configure a security rules file for Cloud Storage",
checked: false,
},
{
value: "emulators",
name: "Emulators: Set up local emulators for Firebase products",
checked: false,
},
{
value: "remoteconfig",
name: "Remote Config: Configure a template file for Remote Config",
checked: false,
},
];

var next;
// HACK: Windows Node has issues with selectables as the first prompt, so we
// add an extra confirmation prompt that fixes the problem
Expand Down

0 comments on commit d756f44

Please sign in to comment.