Skip to content

Commit f64000e

Browse files
committed
refactor: Asking unanswered questions
1 parent fb8e08a commit f64000e

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

templates/cli/lib/commands/init.js.twig

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,22 @@ const initProject = async ({ organizationId, projectId, projectName } = {}) => {
4040
log('You must login first')
4141
await loginCommand();
4242
}
43+
4344
let answers = {};
4445

45-
if (organizationId && projectId && projectName) {
46-
answers = {
47-
project: { id: projectId, name: projectName },
48-
organization: { id: organizationId },
49-
start: 'existing'
46+
if (!organizationId && !projectId && !projectName) {
47+
answers = await inquirer.prompt(questionsInitProject)
48+
if (answers.override === false) {
49+
process.exit(1)
5050
}
51+
} else {
52+
answers.start = 'existing';
53+
answers.project = {};
54+
answers.organization = {};
55+
56+
answers.organization.id = organizationId ?? (await inquirer.prompt(questionsInitProject[2])).organization;
57+
answers.project.name = projectName ?? (await inquirer.prompt(questionsInitProject[3])).project;
58+
answers.project.id = projectId ?? (await inquirer.prompt(questionsInitProject[4])).id;
5159

5260
try {
5361
await projectsGet({ projectId, parseOutput: false });
@@ -60,15 +68,8 @@ const initProject = async ({ organizationId, projectId, projectName } = {}) => {
6068
throw e;
6169
}
6270
}
63-
64-
} else {
65-
answers = await inquirer.prompt(questionsInitProject)
66-
if (answers.override === false) {
67-
process.exit(1)
68-
}
6971
}
7072

71-
7273
if (answers.start === 'new') {
7374
response = await projectsCreate({
7475
projectId: answers.id,
@@ -170,7 +171,6 @@ const initFunction = async () => {
170171
}
171172

172173

173-
174174
fs.mkdirSync(functionDir, "777");
175175
fs.mkdirSync(templatesDir, "777");
176176

templates/cli/lib/questions.js.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,14 @@ const questionsInitProject = [
171171
name: "project",
172172
message: "What would you like to name your project?",
173173
default: "My Awesome Project",
174-
when: (answer) => answer.start === 'new'
174+
when: (answer) => answer.start !== 'existing'
175175
},
176176
{
177177
type: "input",
178178
name: "id",
179179
message: "What ID would you like to have for your project?",
180180
default: "unique()",
181-
when: (answer) => answer.start === 'new'
181+
when: (answer) => answer.start !== 'existing'
182182
},
183183
{
184184
type: "list",

0 commit comments

Comments
 (0)