Skip to content

Commit d08399a

Browse files
committed
Improve CLI after 0.15
1 parent e5949c5 commit d08399a

File tree

7 files changed

+164
-68
lines changed

7 files changed

+164
-68
lines changed

composer.lock

Lines changed: 29 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ function getSSLPage($url) {
183183
->setTwitter('appwrite_io')
184184
->setDiscord('564160730845151244', 'https://appwrite.io/discord')
185185
->setDefaultHeaders([
186-
'X-Appwrite-Response-Format' => '0.13.0',
186+
'X-Appwrite-Response-Format' => '0.15.0',
187187
])
188188
;
189189

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

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,24 @@ const { questionsDeployFunctions, questionsGetEntrypoint, questionsDeployCollect
66
const { actionRunner, success, log, error, commandDescriptions } = require("../parser");
77
const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsUpdateDeployment } = require('./functions');
88
const {
9-
databaseCreateBooleanAttribute,
10-
databaseGetCollection,
11-
databaseCreateCollection,
12-
databaseCreateStringAttribute,
13-
databaseCreateIntegerAttribute,
14-
databaseCreateFloatAttribute,
15-
databaseCreateEmailAttribute,
16-
databaseCreateIndex,
17-
databaseCreateUrlAttribute,
18-
databaseCreateIpAttribute,
19-
databaseCreateEnumAttribute,
20-
databaseDeleteAttribute,
21-
databaseListAttributes,
22-
databaseListIndexes,
23-
databaseDeleteIndex
24-
} = require("./database");
9+
databasesCreateBooleanAttribute,
10+
databasesGetCollection,
11+
databasesCreateCollection,
12+
databasesCreateStringAttribute,
13+
databasesCreateIntegerAttribute,
14+
databasesCreateFloatAttribute,
15+
databasesCreateEmailAttribute,
16+
databasesCreateIndex,
17+
databasesCreateUrlAttribute,
18+
databasesCreateIpAttribute,
19+
databasesCreateEnumAttribute,
20+
databasesDeleteAttribute,
21+
databasesListAttributes,
22+
databasesListIndexes,
23+
databasesDeleteIndex
24+
} = require("./databases");
25+
26+
// TODO: Add databaseId everywhere
2527

2628
const POOL_DEBOUNCE = 2000; // in milliseconds
2729
const POOL_MAX_DEBOUNCES = 30;
@@ -145,12 +147,34 @@ const deploy = new Command("deploy")
145147
await deployCollection()
146148
}));
147149

148-
const deployFunction = async () => {
150+
const deployFunction = async ({ functionId, all } = {}) => {
149151
let response = {};
150152

151-
let answers = await inquirer.prompt(questionsDeployFunctions)
152-
let functions = answers.functions.map((func) => JSONbig.parse(func))
153+
const functionIds = [];
153154

155+
if(functionId) {
156+
functionIds.push(functionId);
157+
} else if(all) {
158+
const functions = localConfig.getFunctions();
159+
if (functions.length === 0) {
160+
throw new Error("No functions found in the current directory.");
161+
}
162+
functionIds.push(...functions.map((func, idx) => {
163+
return func.$id;
164+
}));
165+
}
166+
167+
if(functionIds.length <= 0) {
168+
const answers = await inquirer.prompt(questionsDeployFunctions);
169+
functionIds.push(...answers.functions);
170+
}
171+
172+
let functions = functionIds.map((id) => {
173+
const functions = localConfig.getFunctions();
174+
const func = functions.find((f) => f.$id === id);
175+
return JSONbig.stringify(func);
176+
});
177+
154178
for (let func of functions) {
155179
log(`Deploying function ${func.name} ( ${func['$id']} )`)
156180

@@ -466,6 +490,8 @@ const deployCollection = async () => {
466490
deploy
467491
.command("function")
468492
.description("Deploy functions in the current directory.")
493+
.option(`--functionId <functionId>`, `Function ID`)
494+
.option(`--all`, `Flag to deploy all functions`)
469495
.action(actionRunner(deployFunction));
470496

471497
deploy

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { globalConfig, localConfig } = require("../config");
66
const { actionRunner, success, parseBool, commandDescriptions, log, parse } = require("../parser");
77
{% if sdk.test != "true" %}
88
const { questionsLogin } = require("../questions");
9-
const { accountCreateSession, accountDeleteSession } = require("./account");
9+
const { accountCreateEmailSession, accountDeleteSession } = require("./account");
1010

1111
const login = new Command("login")
1212
.description(commandDescriptions['login'])
@@ -15,7 +15,7 @@ const login = new Command("login")
1515

1616
let client = await sdkForConsole(false);
1717

18-
await accountCreateSession({
18+
await accountCreateEmailSession({
1919
email: answers.email,
2020
password: answers.password,
2121
parseOutput: false,

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

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ const inquirer = require("inquirer");
66
const { teamsCreate } = require("./teams");
77
const { projectsCreate } = require("./projects");
88
const { functionsCreate } = require("./functions");
9-
const { databaseListCollections } = require("./database");
9+
const { databasesListCollections, databasesList } = require("./databases");
1010
const { sdkForConsole } = require("../sdks");
1111
const { localConfig } = require("../config");
12-
const { questionsInitProject, questionsInitFunction } = require("../questions");
12+
const { questionsInitProject, questionsInitFunction, questionsInitCollection } = require("../questions");
1313
const { success, log, actionRunner, commandDescriptions } = require("../parser");
1414

1515
const init = new Command("init")
@@ -40,7 +40,7 @@ const initProject = async () => {
4040

4141
let teamId = response['$id'];
4242
response = await projectsCreate({
43-
projectId: 'unique()',
43+
projectId: answers.id,
4444
name: answers.project,
4545
teamId,
4646
parseOutput: false
@@ -54,6 +54,7 @@ const initProject = async () => {
5454
}
5555

5656
const initFunction = async () => {
57+
// TODO: Add CI/CD support (ID, name, runtime)
5758
let answers = await inquirer.prompt(questionsInitFunction)
5859

5960
if (fs.existsSync(path.join(process.cwd(), 'functions', answers.name))) {
@@ -65,7 +66,7 @@ const initFunction = async () => {
6566
}
6667

6768
let response = await functionsCreate({
68-
functionId: 'unique()',
69+
functionId: answers.id,
6970
name: answers.name,
7071
runtime: answers.runtime.id,
7172
parseOutput: false
@@ -110,20 +111,43 @@ const initFunction = async () => {
110111
success();
111112
}
112113

113-
const initCollection = async () => {
114-
// TODO: Pagination?
115-
let response = await databaseListCollections({
116-
limit: 100,
117-
parseOutput: false
118-
})
114+
const initCollection = async ({ all, databaseId } = {}) => {
115+
const databaseIds = [];
116+
117+
console.log(all);
119118

120-
let collections = response.collections;
121-
log(`Found ${collections.length} collections`);
119+
if(databaseId) {
120+
databaseIds.push(databaseId);
121+
} else if(all) {
122+
let allDatabases = await databasesList({
123+
parseOutput: false
124+
})
125+
console.log(allDatabases);
126+
databaseIds.push(...allDatabases.databases);
127+
}
128+
129+
if(databaseIds.length <= 0) {
130+
let answers = await inquirer.prompt(questionsInitCollection)
131+
if (!answers.databases) process.exit(1)
132+
databaseIds.push(...answers.databases);
133+
}
122134

123-
collections.forEach(async collection => {
124-
log(`Fetching ${collection.name} ...`);
125-
localConfig.addCollection(collection);
126-
});
135+
for(const databaseId of databaseIds) {
136+
// TODO: Pagination?
137+
let response = await databasesListCollections({
138+
databaseId,
139+
limit: 100,
140+
parseOutput: false
141+
})
142+
143+
let collections = response.collections;
144+
log(`Found ${collections.length} collections`);
145+
146+
collections.forEach(async collection => {
147+
log(`Fetching ${collection.name} ...`);
148+
localConfig.addCollection(collection);
149+
});
150+
}
127151

128152
success();
129153
}
@@ -141,6 +165,8 @@ init
141165
init
142166
.command("collection")
143167
.description("Initialise your {{ spec.title|caseUcfirst }} collections")
168+
.option(`--databaseId <databaseId>`, `Database ID`)
169+
.option(`--all`, `Flag to initialize all databases`)
144170
.action(actionRunner(initCollection))
145171

146172
module.exports = {

0 commit comments

Comments
 (0)