1
1
const chalk = require("chalk");
2
+ const Client = require("./client");
2
3
const { localConfig, globalConfig } = require('./config');
3
4
const { projectsList } = require('./commands/projects');
4
5
const { teamsList } = require('./commands/teams');
@@ -11,7 +12,7 @@ const { databasesList } = require('./commands/databases');
11
12
const { checkDeployConditions } = require('./utils');
12
13
const JSONbig = require("json-bigint")({ storeAsString: false });
13
14
14
- const whenOverride = (answers)=> answers.override === undefined ? true : answers.override;
15
+ const whenOverride = (answers) => answers.override === undefined ? true : answers.override;
15
16
16
17
const getIgnores = (runtime) => {
17
18
const languge = runtime.split('-')[0];
@@ -238,7 +239,7 @@ const questionsPullFunctions = [
238
239
choices: async () => {
239
240
const { functions } = await paginate(functionsList, { parseOutput: false }, 100, 'functions');
240
241
241
- if(functions.length === 0){
242
+ if (functions.length === 0) {
242
243
throw "We couldn't find any functions in your {{ spec .title | caseUcfirst }} project";
243
244
}
244
245
@@ -298,7 +299,7 @@ const questionsCreateFunctionSelectTemplate = (templates) => {
298
299
name: "template",
299
300
message: "What template would you like to use?",
300
301
choices: templates.map((template) => {
301
- const name =`${template[0].toUpperCase()}${template.split('').slice(1).join('')}`.replace(/[-_]/g,' ');
302
+ const name = `${template[0].toUpperCase()}${template.split('').slice(1).join('')}`.replace(/[-_]/g, ' ');
302
303
303
304
return { value: template, name }
304
305
})
@@ -474,9 +475,40 @@ const questionsLogin = [
474
475
},
475
476
when: (answers) => answers.method === 'select'
476
477
},
477
-
478
+ ];
479
+ const questionGetEndpoint = [
480
+ {
481
+ type: "input",
482
+ name: "endpoint",
483
+ message: "Enter the endpoint of your {{ spec .title | caseUcfirst }} server",
484
+ default: "http://localhost/v1",
485
+ async validate(value) {
486
+ if (!value) {
487
+ return "Please enter a valid endpoint.";
488
+ }
489
+ let client = new Client().setEndpoint(value);
490
+ try {
491
+ let response = await client.call('get', '/health/version');
492
+ if (response.version) {
493
+ return true;
494
+ } else {
495
+ throw new Error();
496
+ }
497
+ } catch (error) {
498
+ return "Invalid endpoint or your Appwrite server is not running as expected.";
499
+ }
500
+ }
501
+ }
478
502
];
479
503
504
+ const questionLoginWithEndpoint = [
505
+ questionsLogin[0],
506
+ { ...questionGetEndpoint[0], when: (answers) => answers.method !== 'select' },
507
+ questionsLogin[1],
508
+ questionsLogin[2],
509
+ questionsLogin[3]
510
+ ]
511
+
480
512
const questionsLogout = [
481
513
{
482
514
type: "checkbox",
@@ -722,30 +754,7 @@ const questionsMfaChallenge = [
722
754
}
723
755
];
724
756
725
- const questionGetEndpoint = [
726
- {
727
- type: "input",
728
- name: "endpoint",
729
- message: "Enter the endpoint of your {{ spec .title | caseUcfirst }} server",
730
- default: "http://localhost/v1",
731
- async validate(value) {
732
- if (!value) {
733
- return "Please enter a valid endpoint.";
734
- }
735
- let client = new Client().setEndpoint(value);
736
- try {
737
- let response = await client.call('get', '/health/version');
738
- if (response.version) {
739
- return true;
740
- } else {
741
- throw new Error();
742
- }
743
- } catch (error) {
744
- return "Invalid endpoint or your Appwrite server is not running as expected.";
745
- }
746
- }
747
- }
748
- ];
757
+
749
758
750
759
module.exports = {
751
760
questionsInitProject,
@@ -768,5 +777,6 @@ module.exports = {
768
777
questionsGetEntrypoint,
769
778
questionsListFactors,
770
779
questionsMfaChallenge,
771
- questionGetEndpoint
780
+ questionGetEndpoint,
781
+ questionLoginWithEndpoint
772
782
};
0 commit comments