appwrite-cli 1.2.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/docs/examples/account/create.md +1 -1
- package/docs/examples/account/update-password.md +1 -1
- package/docs/examples/console/variables.md +1 -0
- package/docs/examples/databases/create-relationship-attribute.md +9 -0
- package/docs/examples/databases/get-document.md +2 -1
- package/docs/examples/databases/update-boolean-attribute.md +6 -0
- package/docs/examples/databases/update-datetime-attribute.md +6 -0
- package/docs/examples/databases/update-email-attribute.md +6 -0
- package/docs/examples/databases/update-enum-attribute.md +7 -0
- package/docs/examples/databases/update-float-attribute.md +8 -0
- package/docs/examples/databases/update-integer-attribute.md +8 -0
- package/docs/examples/databases/update-ip-attribute.md +6 -0
- package/docs/examples/databases/update-relationship-attribute.md +5 -0
- package/docs/examples/databases/update-string-attribute.md +6 -0
- package/docs/examples/databases/update-url-attribute.md +6 -0
- package/docs/examples/functions/create.md +1 -1
- package/docs/examples/functions/update.md +1 -1
- package/docs/examples/projects/update-auth-password-dictionary.md +3 -0
- package/docs/examples/projects/update-auth-password-history.md +3 -0
- package/docs/examples/teams/create-membership.md +3 -1
- package/docs/examples/teams/get-prefs.md +2 -0
- package/docs/examples/teams/{update.md → update-name.md} +1 -1
- package/docs/examples/teams/update-prefs.md +3 -0
- package/docs/examples/users/update-password.md +1 -1
- package/index.js +2 -0
- package/install.ps1 +2 -2
- package/install.sh +1 -1
- package/lib/client.js +7 -7
- package/lib/commands/account.js +40 -7
- package/lib/commands/console.js +44 -0
- package/lib/commands/databases.js +727 -103
- package/lib/commands/deploy.js +270 -146
- package/lib/commands/functions.js +35 -9
- package/lib/commands/generic.js +6 -3
- package/lib/commands/init.js +215 -179
- package/lib/commands/projects.js +139 -5
- package/lib/commands/storage.js +37 -9
- package/lib/commands/teams.js +102 -16
- package/lib/commands/users.js +51 -2
- package/lib/config.js +84 -6
- package/lib/parser.js +6 -2
- package/lib/questions.js +307 -280
- package/package.json +1 -1
- package/docs/examples/account/get-logs.md +0 -2
- package/docs/examples/account/get-sessions.md +0 -1
- package/docs/examples/functions/retry-build.md +0 -4
- package/docs/examples/locale/get-continents.md +0 -1
- package/docs/examples/locale/get-countries-e-u.md +0 -1
- package/docs/examples/locale/get-countries-phones.md +0 -1
- package/docs/examples/locale/get-countries.md +0 -1
- package/docs/examples/locale/get-currencies.md +0 -1
- package/docs/examples/locale/get-languages.md +0 -1
- package/docs/examples/teams/get-memberships.md +0 -4
- package/docs/examples/users/get-logs.md +0 -3
- package/docs/examples/users/get-memberships.md +0 -2
- package/docs/examples/users/get-sessions.md +0 -2
|
@@ -41,11 +41,11 @@ const functionsList = async ({ queries, search, parseOutput = true, sdk = undefi
|
|
|
41
41
|
return response;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
const functionsCreate = async ({ functionId, name,
|
|
44
|
+
const functionsCreate = async ({ functionId, name, runtime, execute, events, schedule, timeout, enabled, parseOutput = true, sdk = undefined}) => {
|
|
45
45
|
/* @param {string} functionId */
|
|
46
46
|
/* @param {string} name */
|
|
47
|
-
/* @param {string[]} execute */
|
|
48
47
|
/* @param {string} runtime */
|
|
48
|
+
/* @param {string[]} execute */
|
|
49
49
|
/* @param {string[]} events */
|
|
50
50
|
/* @param {string} schedule */
|
|
51
51
|
/* @param {number} timeout */
|
|
@@ -56,34 +56,44 @@ const functionsCreate = async ({ functionId, name, execute, runtime, events, sch
|
|
|
56
56
|
let payload = {};
|
|
57
57
|
|
|
58
58
|
/** Body Params */
|
|
59
|
+
|
|
59
60
|
if (typeof functionId !== 'undefined') {
|
|
60
61
|
payload['functionId'] = functionId;
|
|
61
62
|
}
|
|
62
63
|
|
|
64
|
+
|
|
63
65
|
if (typeof name !== 'undefined') {
|
|
64
66
|
payload['name'] = name;
|
|
65
67
|
}
|
|
66
68
|
|
|
69
|
+
execute = execute === true ? [] : execute;
|
|
70
|
+
|
|
67
71
|
if (typeof execute !== 'undefined') {
|
|
68
72
|
payload['execute'] = execute;
|
|
69
73
|
}
|
|
70
74
|
|
|
75
|
+
|
|
71
76
|
if (typeof runtime !== 'undefined') {
|
|
72
77
|
payload['runtime'] = runtime;
|
|
73
78
|
}
|
|
74
79
|
|
|
80
|
+
events = events === true ? [] : events;
|
|
81
|
+
|
|
75
82
|
if (typeof events !== 'undefined') {
|
|
76
83
|
payload['events'] = events;
|
|
77
84
|
}
|
|
78
85
|
|
|
86
|
+
|
|
79
87
|
if (typeof schedule !== 'undefined') {
|
|
80
88
|
payload['schedule'] = schedule;
|
|
81
89
|
}
|
|
82
90
|
|
|
91
|
+
|
|
83
92
|
if (typeof timeout !== 'undefined') {
|
|
84
93
|
payload['timeout'] = timeout;
|
|
85
94
|
}
|
|
86
95
|
|
|
96
|
+
|
|
87
97
|
if (typeof enabled !== 'undefined') {
|
|
88
98
|
payload['enabled'] = enabled;
|
|
89
99
|
}
|
|
@@ -172,26 +182,34 @@ const functionsUpdate = async ({ functionId, name, execute, events, schedule, ti
|
|
|
172
182
|
let payload = {};
|
|
173
183
|
|
|
174
184
|
/** Body Params */
|
|
185
|
+
|
|
175
186
|
if (typeof name !== 'undefined') {
|
|
176
187
|
payload['name'] = name;
|
|
177
188
|
}
|
|
178
189
|
|
|
190
|
+
execute = execute === true ? [] : execute;
|
|
191
|
+
|
|
179
192
|
if (typeof execute !== 'undefined') {
|
|
180
193
|
payload['execute'] = execute;
|
|
181
194
|
}
|
|
182
195
|
|
|
196
|
+
events = events === true ? [] : events;
|
|
197
|
+
|
|
183
198
|
if (typeof events !== 'undefined') {
|
|
184
199
|
payload['events'] = events;
|
|
185
200
|
}
|
|
186
201
|
|
|
202
|
+
|
|
187
203
|
if (typeof schedule !== 'undefined') {
|
|
188
204
|
payload['schedule'] = schedule;
|
|
189
205
|
}
|
|
190
206
|
|
|
207
|
+
|
|
191
208
|
if (typeof timeout !== 'undefined') {
|
|
192
209
|
payload['timeout'] = timeout;
|
|
193
210
|
}
|
|
194
211
|
|
|
212
|
+
|
|
195
213
|
if (typeof enabled !== 'undefined') {
|
|
196
214
|
payload['enabled'] = enabled;
|
|
197
215
|
}
|
|
@@ -265,6 +283,7 @@ const functionsCreateDeployment = async ({ functionId, entrypoint, code, activat
|
|
|
265
283
|
let payload = {};
|
|
266
284
|
|
|
267
285
|
/** Body Params */
|
|
286
|
+
|
|
268
287
|
if (typeof entrypoint !== 'undefined') {
|
|
269
288
|
payload['entrypoint'] = entrypoint;
|
|
270
289
|
}
|
|
@@ -300,6 +319,7 @@ const functionsCreateDeployment = async ({ functionId, entrypoint, code, activat
|
|
|
300
319
|
code = archivePath;
|
|
301
320
|
}
|
|
302
321
|
|
|
322
|
+
|
|
303
323
|
if (typeof activate !== 'undefined') {
|
|
304
324
|
payload['activate'] = activate.toString();
|
|
305
325
|
}
|
|
@@ -486,10 +506,12 @@ const functionsCreateExecution = async ({ functionId, data, async, parseOutput =
|
|
|
486
506
|
let payload = {};
|
|
487
507
|
|
|
488
508
|
/** Body Params */
|
|
509
|
+
|
|
489
510
|
if (typeof data !== 'undefined') {
|
|
490
511
|
payload['data'] = data;
|
|
491
512
|
}
|
|
492
513
|
|
|
514
|
+
|
|
493
515
|
if (typeof async !== 'undefined') {
|
|
494
516
|
payload['async'] = async;
|
|
495
517
|
}
|
|
@@ -577,10 +599,12 @@ const functionsCreateVariable = async ({ functionId, key, value, parseOutput = t
|
|
|
577
599
|
let payload = {};
|
|
578
600
|
|
|
579
601
|
/** Body Params */
|
|
602
|
+
|
|
580
603
|
if (typeof key !== 'undefined') {
|
|
581
604
|
payload['key'] = key;
|
|
582
605
|
}
|
|
583
606
|
|
|
607
|
+
|
|
584
608
|
if (typeof value !== 'undefined') {
|
|
585
609
|
payload['value'] = value;
|
|
586
610
|
}
|
|
@@ -627,10 +651,12 @@ const functionsUpdateVariable = async ({ functionId, variableId, key, value, par
|
|
|
627
651
|
let payload = {};
|
|
628
652
|
|
|
629
653
|
/** Body Params */
|
|
654
|
+
|
|
630
655
|
if (typeof key !== 'undefined') {
|
|
631
656
|
payload['key'] = key;
|
|
632
657
|
}
|
|
633
658
|
|
|
659
|
+
|
|
634
660
|
if (typeof value !== 'undefined') {
|
|
635
661
|
payload['value'] = value;
|
|
636
662
|
}
|
|
@@ -670,7 +696,7 @@ const functionsDeleteVariable = async ({ functionId, variableId, parseOutput = t
|
|
|
670
696
|
functions
|
|
671
697
|
.command(`list`)
|
|
672
698
|
.description(`Get a list of all the project's functions. You can use the query params to filter your results.`)
|
|
673
|
-
.option(`--queries
|
|
699
|
+
.option(`--queries [queries...]`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, enabled, runtime, deployment, schedule, scheduleNext, schedulePrevious, timeout`)
|
|
674
700
|
.option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`)
|
|
675
701
|
.action(actionRunner(functionsList))
|
|
676
702
|
|
|
@@ -679,9 +705,9 @@ functions
|
|
|
679
705
|
.description(`Create a new function. You can pass a list of [permissions](/docs/permissions) to allow different project users or team with access to execute the function using the client API.`)
|
|
680
706
|
.requiredOption(`--functionId <functionId>`, `Function ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`)
|
|
681
707
|
.requiredOption(`--name <name>`, `Function name. Max length: 128 chars.`)
|
|
682
|
-
.requiredOption(`--execute <execute...>`, `An array of strings with execution roles. By default no user is granted with any execute permissions. [learn more about permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 64 characters long.`)
|
|
683
708
|
.requiredOption(`--runtime <runtime>`, `Execution runtime.`)
|
|
684
|
-
.option(`--
|
|
709
|
+
.option(`--execute [execute...]`, `An array of strings with execution roles. By default no user is granted with any execute permissions. [learn more about permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 64 characters long.`)
|
|
710
|
+
.option(`--events [events...]`, `Events list. Maximum of 100 events are allowed.`)
|
|
685
711
|
.option(`--schedule <schedule>`, `Schedule CRON syntax.`)
|
|
686
712
|
.option(`--timeout <timeout>`, `Function maximum execution time in seconds.`, parseInteger)
|
|
687
713
|
.option(`--enabled <enabled>`, `Is function enabled?`, parseBool)
|
|
@@ -709,8 +735,8 @@ functions
|
|
|
709
735
|
.description(`Update function by its unique ID.`)
|
|
710
736
|
.requiredOption(`--functionId <functionId>`, `Function ID.`)
|
|
711
737
|
.requiredOption(`--name <name>`, `Function name. Max length: 128 chars.`)
|
|
712
|
-
.
|
|
713
|
-
.option(`--events
|
|
738
|
+
.option(`--execute [execute...]`, `An array of strings with execution roles. By default no user is granted with any execute permissions. [learn more about permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 64 characters long.`)
|
|
739
|
+
.option(`--events [events...]`, `Events list. Maximum of 100 events are allowed.`)
|
|
714
740
|
.option(`--schedule <schedule>`, `Schedule CRON syntax.`)
|
|
715
741
|
.option(`--timeout <timeout>`, `Maximum execution time in seconds.`, parseInteger)
|
|
716
742
|
.option(`--enabled <enabled>`, `Is function enabled?`, parseBool)
|
|
@@ -726,7 +752,7 @@ functions
|
|
|
726
752
|
.command(`listDeployments`)
|
|
727
753
|
.description(`Get a list of all the project's code deployments. You can use the query params to filter your results.`)
|
|
728
754
|
.requiredOption(`--functionId <functionId>`, `Function ID.`)
|
|
729
|
-
.option(`--queries
|
|
755
|
+
.option(`--queries [queries...]`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: entrypoint, size, buildId, activate`)
|
|
730
756
|
.option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`)
|
|
731
757
|
.action(actionRunner(functionsListDeployments))
|
|
732
758
|
|
|
@@ -772,7 +798,7 @@ functions
|
|
|
772
798
|
.command(`listExecutions`)
|
|
773
799
|
.description(`Get a list of all the current user function execution logs. You can use the query params to filter your results.`)
|
|
774
800
|
.requiredOption(`--functionId <functionId>`, `Function ID.`)
|
|
775
|
-
.option(`--queries
|
|
801
|
+
.option(`--queries [queries...]`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: trigger, status, statusCode, duration`)
|
|
776
802
|
.option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`)
|
|
777
803
|
.action(actionRunner(functionsListExecutions))
|
|
778
804
|
|
package/lib/commands/generic.js
CHANGED
|
@@ -78,13 +78,16 @@ const client = new Command("client")
|
|
|
78
78
|
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
79
79
|
throw new Error();
|
|
80
80
|
}
|
|
81
|
-
|
|
81
|
+
|
|
82
82
|
let client = new Client().setEndpoint(endpoint);
|
|
83
|
+
if (selfSigned || globalConfig.getSelfSigned()) {
|
|
84
|
+
client.setSelfSigned(true);
|
|
85
|
+
}
|
|
83
86
|
let response = await client.call('GET', '/health/version');
|
|
84
|
-
if(!response.version) {
|
|
87
|
+
if (!response.version) {
|
|
85
88
|
throw new Error();
|
|
86
89
|
}
|
|
87
|
-
|
|
90
|
+
|
|
88
91
|
globalConfig.setEndpoint(endpoint);
|
|
89
92
|
} catch (_) {
|
|
90
93
|
throw new Error("Invalid endpoint or your Appwrite server is not running as expected.");
|
package/lib/commands/init.js
CHANGED
|
@@ -6,229 +6,265 @@ const inquirer = require("inquirer");
|
|
|
6
6
|
const { teamsCreate, teamsList } = require("./teams");
|
|
7
7
|
const { projectsCreate } = require("./projects");
|
|
8
8
|
const { functionsCreate } = require("./functions");
|
|
9
|
-
const { databasesListCollections, databasesList } = require("./databases");
|
|
9
|
+
const { databasesGet, databasesListCollections, databasesList } = require("./databases");
|
|
10
|
+
const { storageListBuckets } = require("./storage");
|
|
10
11
|
const { sdkForConsole } = require("../sdks");
|
|
11
12
|
const { localConfig } = require("../config");
|
|
12
13
|
const { questionsInitProject, questionsInitFunction, questionsInitCollection } = require("../questions");
|
|
13
14
|
const { success, log, actionRunner, commandDescriptions } = require("../parser");
|
|
14
15
|
|
|
15
16
|
const init = new Command("init")
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
.description(commandDescriptions['init'])
|
|
18
|
+
.configureHelp({
|
|
18
19
|
helpWidth: process.stdout.columns || 80
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
})
|
|
21
|
+
.action(actionRunner(async (_options, command) => {
|
|
22
|
+
command.help();
|
|
23
|
+
}));
|
|
23
24
|
|
|
24
25
|
const initProject = async () => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
let response = {}
|
|
27
|
+
let answers = await inquirer.prompt(questionsInitProject)
|
|
28
|
+
if (!answers.project) process.exit(1)
|
|
29
|
+
|
|
30
|
+
let sdk = await sdkForConsole();
|
|
31
|
+
if (answers.start == "new") {
|
|
32
|
+
response = await teamsCreate({
|
|
33
|
+
teamId: 'unique()',
|
|
34
|
+
name: answers.project,
|
|
35
|
+
sdk,
|
|
36
|
+
parseOutput: false
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
let teamId = response['$id'];
|
|
40
|
+
response = await projectsCreate({
|
|
41
|
+
projectId: answers.id,
|
|
42
|
+
name: answers.project,
|
|
43
|
+
teamId,
|
|
44
|
+
parseOutput: false
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
localConfig.setProject(response['$id'], response.name);
|
|
48
|
+
} else {
|
|
49
|
+
localConfig.setProject(answers.project.id, answers.project.name);
|
|
50
|
+
}
|
|
51
|
+
success();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const initFunction = async () => {
|
|
55
|
+
// TODO: Add CI/CD support (ID, name, runtime)
|
|
56
|
+
let answers = await inquirer.prompt(questionsInitFunction)
|
|
57
|
+
let functionFolder = path.join(process.cwd(), 'functions');
|
|
58
|
+
|
|
59
|
+
if (!fs.existsSync(functionFolder)) {
|
|
60
|
+
fs.mkdirSync(functionFolder, {
|
|
61
|
+
recursive: true
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const functionDir = path.join(functionFolder, answers.name);
|
|
37
66
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
67
|
+
if (fs.existsSync(functionDir)) {
|
|
68
|
+
throw new Error(`( ${answers.name} ) already exists in the current directory. Please choose another name.`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!answers.runtime.entrypoint) {
|
|
72
|
+
log(`Entrypoint for this runtime not found. You will be asked to configure entrypoint when you first deploy the function.`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let response = await functionsCreate({
|
|
76
|
+
functionId: answers.id,
|
|
77
|
+
name: answers.name,
|
|
78
|
+
runtime: answers.runtime.id,
|
|
79
|
+
parseOutput: false
|
|
44
80
|
})
|
|
45
81
|
|
|
46
|
-
|
|
47
|
-
} else {
|
|
48
|
-
localConfig.setProject(answers.project.id, answers.project.name);
|
|
49
|
-
}
|
|
50
|
-
success();
|
|
51
|
-
}
|
|
82
|
+
fs.mkdirSync(functionDir, "777");
|
|
52
83
|
|
|
53
|
-
|
|
54
|
-
// TODO: Add CI/CD support (ID, name, runtime)
|
|
55
|
-
let answers = await inquirer.prompt(questionsInitFunction)
|
|
56
|
-
let functionFolder = path.join(process.cwd(), 'functions');
|
|
84
|
+
let gitInitCommands = "git clone --depth 1 --sparse https://github.com/appwrite/functions-starter ."; // depth prevents fetching older commits reducing the amount fetched
|
|
57
85
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const functionDir = path.join(functionFolder, answers.name);
|
|
65
|
-
|
|
66
|
-
if (fs.existsSync(functionDir)) {
|
|
67
|
-
throw new Error(`( ${answers.name} ) already exists in the current directory. Please choose another name.`);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if(!answers.runtime.entrypoint) {
|
|
71
|
-
log(`Entrypoint for this runtime not found. You will be asked to configure entrypoint when you first deploy the function.`);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
let response = await functionsCreate({
|
|
75
|
-
functionId: answers.id,
|
|
76
|
-
name: answers.name,
|
|
77
|
-
runtime: answers.runtime.id,
|
|
78
|
-
parseOutput: false
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
fs.mkdirSync(functionDir, "777");
|
|
82
|
-
|
|
83
|
-
let gitInitCommands = "git clone --depth 1 --sparse https://github.com/appwrite/functions-starter ."; // depth prevents fetching older commits reducing the amount fetched
|
|
84
|
-
|
|
85
|
-
let gitPullCommands = `git sparse-checkout add ${answers.runtime.id}`;
|
|
86
|
-
|
|
87
|
-
/* Force use CMD as powershell does not support && */
|
|
88
|
-
if (process.platform == 'win32') {
|
|
89
|
-
gitInitCommands = 'cmd /c "' + gitInitCommands + '"';
|
|
90
|
-
gitPullCommands = 'cmd /c "' + gitPullCommands + '"';
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/* Execute the child process but do not print any std output */
|
|
94
|
-
try {
|
|
95
|
-
childProcess.execSync(gitInitCommands, { stdio: 'pipe', cwd: functionDir });
|
|
96
|
-
childProcess.execSync(gitPullCommands, { stdio: 'pipe', cwd: functionDir });
|
|
97
|
-
} catch (error) {
|
|
98
|
-
/* Specialised errors with recommended actions to take */
|
|
99
|
-
if (error.message.includes('error: unknown option')) {
|
|
100
|
-
throw new Error(`${error.message} \n\nSuggestion: Try updating your git to the latest version, then trying to run this command again.`)
|
|
101
|
-
} else if (error.message.includes('is not recognized as an internal or external command,') || error.message.includes('command not found')) {
|
|
102
|
-
throw new Error(`${error.message} \n\nSuggestion: It appears that git is not installed, try installing git then trying to run this command again.`)
|
|
103
|
-
} else {
|
|
104
|
-
throw error;
|
|
86
|
+
let gitPullCommands = `git sparse-checkout add ${answers.runtime.id}`;
|
|
87
|
+
|
|
88
|
+
/* Force use CMD as powershell does not support && */
|
|
89
|
+
if (process.platform == 'win32') {
|
|
90
|
+
gitInitCommands = 'cmd /c "' + gitInitCommands + '"';
|
|
91
|
+
gitPullCommands = 'cmd /c "' + gitPullCommands + '"';
|
|
105
92
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
});
|
|
121
|
-
} else {
|
|
122
|
-
fs.copyFileSync(src, dest);
|
|
93
|
+
|
|
94
|
+
/* Execute the child process but do not print any std output */
|
|
95
|
+
try {
|
|
96
|
+
childProcess.execSync(gitInitCommands, { stdio: 'pipe', cwd: functionDir });
|
|
97
|
+
childProcess.execSync(gitPullCommands, { stdio: 'pipe', cwd: functionDir });
|
|
98
|
+
} catch (error) {
|
|
99
|
+
/* Specialised errors with recommended actions to take */
|
|
100
|
+
if (error.message.includes('error: unknown option')) {
|
|
101
|
+
throw new Error(`${error.message} \n\nSuggestion: Try updating your git to the latest version, then trying to run this command again.`)
|
|
102
|
+
} else if (error.message.includes('is not recognized as an internal or external command,') || error.message.includes('command not found')) {
|
|
103
|
+
throw new Error(`${error.message} \n\nSuggestion: It appears that git is not installed, try installing git then trying to run this command again.`)
|
|
104
|
+
} else {
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
123
107
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
108
|
+
|
|
109
|
+
fs.rmSync(path.join(functionDir, ".git"), { recursive: true });
|
|
110
|
+
const copyRecursiveSync = (src, dest) => {
|
|
111
|
+
let exists = fs.existsSync(src);
|
|
112
|
+
let stats = exists && fs.statSync(src);
|
|
113
|
+
let isDirectory = exists && stats.isDirectory();
|
|
114
|
+
if (isDirectory) {
|
|
115
|
+
if (!fs.existsSync(dest)) {
|
|
116
|
+
fs.mkdirSync(dest);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
fs.readdirSync(src).forEach(function (childItemName) {
|
|
120
|
+
copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName));
|
|
121
|
+
});
|
|
122
|
+
} else {
|
|
123
|
+
fs.copyFileSync(src, dest);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
copyRecursiveSync(path.join(functionDir, answers.runtime.id), functionDir);
|
|
127
|
+
|
|
128
|
+
fs.rmSync(`${functionDir}/${answers.runtime.id}`, { recursive: true, force: true });
|
|
129
|
+
|
|
130
|
+
const readmePath = path.join(process.cwd(), 'functions', answers.name, 'README.md');
|
|
131
|
+
const readmeFile = fs.readFileSync(readmePath).toString();
|
|
132
|
+
const newReadmeFile = readmeFile.split('\n');
|
|
133
|
+
newReadmeFile[0] = `# ${answers.name}`;
|
|
134
|
+
newReadmeFile.splice(1, 2);
|
|
135
|
+
fs.writeFileSync(readmePath, newReadmeFile.join('\n'));
|
|
136
|
+
|
|
137
|
+
let data = {
|
|
138
|
+
$id: response['$id'],
|
|
139
|
+
name: response.name,
|
|
140
|
+
runtime: response.runtime,
|
|
141
|
+
path: `functions/${answers.name}`,
|
|
142
|
+
entrypoint: answers.runtime.entrypoint || '',
|
|
143
|
+
ignore: answers.runtime.ignore || null,
|
|
144
|
+
execute: response.execute,
|
|
145
|
+
events: response.events,
|
|
146
|
+
schedule: response.schedule,
|
|
147
|
+
timeout: response.timeout,
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
localConfig.addFunction(data);
|
|
151
|
+
success();
|
|
151
152
|
}
|
|
152
153
|
|
|
153
154
|
const initCollection = async ({ all, databaseId } = {}) => {
|
|
154
|
-
|
|
155
|
+
const databaseIds = [];
|
|
155
156
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
157
|
+
if (databaseId) {
|
|
158
|
+
databaseIds.push(databaseId);
|
|
159
|
+
} else if (all) {
|
|
160
|
+
let allDatabases = await databasesList({
|
|
161
|
+
parseOutput: false
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
databaseIds.push(...allDatabases.databases.map((d) => d.$id));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (databaseIds.length <= 0) {
|
|
168
|
+
let answers = await inquirer.prompt(questionsInitCollection)
|
|
169
|
+
if (!answers.databases) process.exit(1)
|
|
170
|
+
databaseIds.push(...answers.databases);
|
|
171
|
+
}
|
|
162
172
|
|
|
163
|
-
|
|
164
|
-
|
|
173
|
+
for (const databaseId of databaseIds) {
|
|
174
|
+
const database = await databasesGet({
|
|
175
|
+
databaseId,
|
|
176
|
+
parseOutput: false
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
localConfig.addDatabase(database);
|
|
180
|
+
|
|
181
|
+
// TODO: Pagination?
|
|
182
|
+
let response = await databasesListCollections({
|
|
183
|
+
databaseId,
|
|
184
|
+
queries: ['limit(100)'],
|
|
185
|
+
parseOutput: false
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
let collections = response.collections;
|
|
189
|
+
log(`Found ${collections.length} collections`);
|
|
190
|
+
|
|
191
|
+
collections.forEach(async collection => {
|
|
192
|
+
log(`Fetching ${collection.name} ...`);
|
|
193
|
+
localConfig.addCollection({
|
|
194
|
+
...collection,
|
|
195
|
+
'$createdAt': undefined,
|
|
196
|
+
'$updatedAt': undefined,
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
}
|
|
165
200
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if (!answers.databases) process.exit(1)
|
|
169
|
-
databaseIds.push(...answers.databases);
|
|
170
|
-
}
|
|
201
|
+
success();
|
|
202
|
+
}
|
|
171
203
|
|
|
172
|
-
|
|
204
|
+
const initBucket = async () => {
|
|
173
205
|
// TODO: Pagination?
|
|
174
|
-
let response = await
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
parseOutput: false
|
|
206
|
+
let response = await storageListBuckets({
|
|
207
|
+
queries: ['limit(100)'],
|
|
208
|
+
parseOutput: false
|
|
178
209
|
})
|
|
179
210
|
|
|
180
|
-
let
|
|
181
|
-
log(`Found ${
|
|
211
|
+
let buckets = response.buckets;
|
|
212
|
+
log(`Found ${buckets.length} buckets`);
|
|
182
213
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
214
|
+
buckets.forEach(async bucket => {
|
|
215
|
+
log(`Fetching ${bucket.name} ...`);
|
|
216
|
+
localConfig.addBucket(bucket);
|
|
186
217
|
});
|
|
187
|
-
}
|
|
188
218
|
|
|
189
|
-
|
|
219
|
+
success();
|
|
190
220
|
}
|
|
191
221
|
|
|
192
222
|
const initTeam = async () => {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
223
|
+
// TODO: Pagination?
|
|
224
|
+
let response = await teamsList({
|
|
225
|
+
queries: ['limit(100)'],
|
|
226
|
+
parseOutput: false
|
|
227
|
+
})
|
|
198
228
|
|
|
199
|
-
|
|
200
|
-
|
|
229
|
+
let teams = response.teams;
|
|
230
|
+
log(`Found ${teams.length} teams`);
|
|
201
231
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
232
|
+
teams.forEach(async team => {
|
|
233
|
+
log(`Fetching ${team.name} ...`);
|
|
234
|
+
const { total, $updatedAt, $createdAt, prefs, ...rest } = team;
|
|
235
|
+
localConfig.addTeam(rest);
|
|
236
|
+
});
|
|
206
237
|
|
|
207
|
-
|
|
238
|
+
success();
|
|
208
239
|
}
|
|
209
240
|
|
|
210
241
|
init
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
242
|
+
.command("project")
|
|
243
|
+
.description("Initialise your Appwrite project")
|
|
244
|
+
.action(actionRunner(initProject));
|
|
245
|
+
|
|
246
|
+
init
|
|
247
|
+
.command("function")
|
|
248
|
+
.description("Initialise your Appwrite cloud function")
|
|
249
|
+
.action(actionRunner(initFunction))
|
|
214
250
|
|
|
215
251
|
init
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
252
|
+
.command("collection")
|
|
253
|
+
.description("Initialise your Appwrite collections")
|
|
254
|
+
.option(`--databaseId <databaseId>`, `Database ID`)
|
|
255
|
+
.option(`--all`, `Flag to initialize all databases`)
|
|
256
|
+
.action(actionRunner(initCollection))
|
|
219
257
|
|
|
220
258
|
init
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
.option(`--all`, `Flag to initialize all databases`)
|
|
225
|
-
.action(actionRunner(initCollection))
|
|
259
|
+
.command("bucket")
|
|
260
|
+
.description("Initialise your Appwrite buckets")
|
|
261
|
+
.action(actionRunner(initBucket))
|
|
226
262
|
|
|
227
263
|
init
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
264
|
+
.command("team")
|
|
265
|
+
.description("Initialise your Appwrite teams")
|
|
266
|
+
.action(actionRunner(initTeam))
|
|
231
267
|
|
|
232
268
|
module.exports = {
|
|
233
|
-
|
|
269
|
+
init,
|
|
234
270
|
};
|