-
Notifications
You must be signed in to change notification settings - Fork 427
Expand file tree
/
Copy pathinteractive.ts
More file actions
126 lines (121 loc) · 3.8 KB
/
interactive.ts
File metadata and controls
126 lines (121 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import inquirer from "inquirer";
const BIGQUERY_VALID_CHARACTERS = /^[a-zA-Z0-9_]+$/;
const FIRESTORE_VALID_CHARACTERS = /^[^\/]+$/;
const GCP_PROJECT_VALID_CHARACTERS = /^[a-z][a-z0-9-]{0,29}$/;
const validateInput = (value: any, name: string, regex: RegExp) => {
if (!value || value === "" || value.trim() === "") {
return `Please supply a ${name}`;
}
if (!value.match(regex)) {
return `The ${name} must only contain letters or spaces`;
}
return true;
};
export const questions = [
{
message: "What is your Firebase project ID?",
name: "projectId",
type: "input",
validate: (value) =>
validateInput(value, "project ID", FIRESTORE_VALID_CHARACTERS),
},
{
message:
"What is your Google Cloud Project ID for BigQuery? (can be the same as the Firebase project ID)",
name: "bigQueryProjectId",
type: "input",
validate: (value) =>
validateInput(value, "BigQuery project ID", GCP_PROJECT_VALID_CHARACTERS),
},
{
message:
"What is the ID of the BigQuery dataset the raw changelog lives in? (The dataset and the raw changelog must already exist!)",
name: "datasetId",
type: "input",
validate: (value) =>
validateInput(value, "dataset ID", BIGQUERY_VALID_CHARACTERS),
},
{
message:
"What prefix is used for the names of the tables and views generated by the extension?",
name: "tableNamePrefix",
type: "input",
validate: (value) =>
validateInput(value, "table name prefix", BIGQUERY_VALID_CHARACTERS),
},
{
message:
"What is your Firestore database ID? (Leave as default '(default)' for the default database)",
name: "databaseId",
type: "input",
default: "(default)",
},
{
message:
"Would you like to use a Gemini to automatically analyze your data and generate a draft schema?",
name: "useGemini",
type: "confirm",
default: false,
},
{
message:
"Where should this script look for schema definitions? (Enter a comma-separated list of, optionally globbed, paths to files or directories).",
name: "schemaFiles",
type: "input",
when: (answers) => !answers.useGemini,
},
{
message: "Please provide your Google AI API Key:",
name: "googleAiKey",
type: "password",
when: (answers) => answers.useGemini,
validate: (value) => {
if (!value || value.trim() === "") {
return "Google AI API Key is required";
}
return true;
},
},
{
message:
"What is the Firestore collection path you want Gemini to analyze?",
name: "geminiAnalyzeCollectionPath",
type: "input",
when: (answers) => answers.useGemini,
validate: (value) =>
validateInput(value, "collection path", FIRESTORE_VALID_CHARACTERS),
},
{
message: "Where should the generated schema files be stored?",
name: "schemaDirectory",
type: "input",
when: (answers) => answers.useGemini,
default: "./schemas",
},
{
message:
"What name should be used for the generated schema json file (without .json extension)?",
name: "geminiSchemaFileName",
type: "input",
when: (answers) => answers.useGemini,
default: "schema",
},
];
export const promptInquirer = () => {
return inquirer.prompt(questions);
};