Skip to content

Commit 7efedaf

Browse files
committed
refactor(cli): Adding pagination and reorder questions
1 parent b35b4bb commit 7efedaf

File tree

1 file changed

+27
-30
lines changed

1 file changed

+27
-30
lines changed

templates/cli/lib/questions.js.twig

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const { databasesList } = require('./commands/databases');
1111
const { checkDeployConditions } = require('./utils');
1212
const JSONbig = require("json-bigint")({ storeAsString: false });
1313

14-
const whenOverride = (answers)=> answers.override === undefined ? true : answers.override;
14+
const whenOverride = (answers) => answers.override === undefined ? true : answers.override;
1515

1616
const getIgnores = (runtime) => {
1717
const languge = runtime.split('-')[0];
@@ -123,6 +123,22 @@ const questionsInitProject = [
123123
return Object.keys(localConfig.getProject()).length !== 0;
124124
}
125125
},
126+
{
127+
type: "list",
128+
name: "start",
129+
when: whenOverride,
130+
message: "How would you like to start?",
131+
choices: [
132+
{
133+
name: "Create a new {{ spec.title|caseUcfirst }} project",
134+
value: "new"
135+
},
136+
{
137+
name: "Link this directory to an existing {{ spec.title|caseUcfirst }} project",
138+
value: "existing"
139+
}
140+
]
141+
},
126142
{
127143
type: "list",
128144
name: "organization",
@@ -149,27 +165,6 @@ const questionsInitProject = [
149165
},
150166
when: whenOverride
151167
},
152-
{
153-
type: "list",
154-
name: "start",
155-
when(answers) {
156-
if (answers.override == undefined) {
157-
return true
158-
}
159-
return answers.override;
160-
},
161-
message: "How would you like to start?",
162-
choices: [
163-
{
164-
name: "Create a new {{ spec.title|caseUcfirst }} project",
165-
value: "new"
166-
},
167-
{
168-
name: "Link this directory to an existing {{ spec.title|caseUcfirst }} project",
169-
value: "existing"
170-
}
171-
]
172-
},
173168
{
174169
type: "input",
175170
name: "project",
@@ -189,12 +184,14 @@ const questionsInitProject = [
189184
name: "project",
190185
message: "Choose your {{ spec.title|caseUcfirst }} project.",
191186
choices: async (answers) => {
192-
let response = await projectsList({
193-
parseOutput: false,
194-
queries: [JSON.stringify({ method: 'equal', attribute: 'teamId', values: [answers.organization.id] })],
195-
})
196-
let projects = response["projects"]
197-
let choices = projects.map((project, idx) => {
187+
const queries = [
188+
JSON.stringify({ method: 'equal', attribute: 'teamId', values: [answers.organization.id] }),
189+
JSON.stringify({ method: 'orderDesc', attribute: 'Id' })
190+
]
191+
192+
const { projects } = await paginate(projectsList, { parseOutput: false, queries, }, 100, 'projects');
193+
194+
let choices = projects.map((project) => {
198195
return {
199196
name: `${project.name} (${project['$id']})`,
200197
value: {
@@ -238,7 +235,7 @@ const questionsPullFunctions = [
238235
choices: async () => {
239236
const { functions } = await paginate(functionsList, { parseOutput: false }, 100, 'functions');
240237

241-
if(functions.length === 0){
238+
if (functions.length === 0) {
242239
throw "We couldn't find any functions in your {{ spec.title|caseUcfirst }} project";
243240
}
244241

@@ -298,7 +295,7 @@ const questionsCreateFunctionSelectTemplate = (templates) => {
298295
name: "template",
299296
message: "What template would you like to use?",
300297
choices: templates.map((template) => {
301-
const name =`${template[0].toUpperCase()}${template.split('').slice(1).join('')}`.replace(/[-_]/g,' ');
298+
const name = `${template[0].toUpperCase()}${template.split('').slice(1).join('')}`.replace(/[-_]/g, ' ');
302299

303300
return { value: template, name }
304301
})

0 commit comments

Comments
 (0)