Skip to content

Commit 9e23c22

Browse files
Merge pull request #715 from appwrite/fix-cli-for-1.4
feat: update CLI to support functions g4
2 parents edd5da6 + 916cacf commit 9e23c22

File tree

3 files changed

+68
-15
lines changed

3 files changed

+68
-15
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,14 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
206206
functionId: func['$id'],
207207
name: func.name,
208208
execute: func.execute,
209-
vars: JSON.stringify(response.vars),
210209
events: func.events,
211210
schedule: func.schedule,
212211
timeout: func.timeout,
212+
enabled: func.enabled,
213+
logging: func.logging,
214+
entrypoint: func.entrypoint,
215+
commands: func.commands,
216+
vars: JSON.stringify(response.vars),
213217
parseOutput: false
214218
});
215219
} catch (e) {
@@ -220,10 +224,14 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
220224
name: func.name,
221225
runtime: func.runtime,
222226
execute: func.execute,
223-
vars: JSON.stringify(func.vars),
224227
events: func.events,
225228
schedule: func.schedule,
226229
timeout: func.timeout,
230+
enabled: func.enabled,
231+
logging: func.logging,
232+
entrypoint: func.entrypoint,
233+
commands: func.commands,
234+
vars: JSON.stringify(func.vars),
227235
parseOutput: false
228236
});
229237

@@ -292,6 +300,7 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
292300
response = await functionsCreateDeployment({
293301
functionId: func['$id'],
294302
entrypoint: func.entrypoint,
303+
commands: func.commands,
295304
code: func.path,
296305
activate: true,
297306
parseOutput: false

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,16 @@ const initFunction = async () => {
7272
log(`Entrypoint for this runtime not found. You will be asked to configure entrypoint when you first deploy the function.`);
7373
}
7474

75+
if (!answers.runtime.commands) {
76+
log(`Installation command for this runtime not found. You will be asked to configure the install command when you first deploy the function.`);
77+
}
78+
7579
let response = await functionsCreate({
7680
functionId: answers.id,
7781
name: answers.name,
7882
runtime: answers.runtime.id,
83+
entrypoint: answers.runtime.entrypoint || '',
84+
commands: answers.runtime.commands || '',
7985
parseOutput: false
8086
})
8187

@@ -138,13 +144,16 @@ const initFunction = async () => {
138144
$id: response['$id'],
139145
name: response.name,
140146
runtime: response.runtime,
141-
path: `functions/${answers.name}`,
142-
entrypoint: answers.runtime.entrypoint || '',
143-
ignore: answers.runtime.ignore || null,
144147
execute: response.execute,
145148
events: response.events,
146149
schedule: response.schedule,
147150
timeout: response.timeout,
151+
enabled: response.enabled,
152+
logging: response.logging,
153+
entrypoint: response.entrypoint,
154+
commands: response.commands,
155+
ignore: answers.runtime.ignore || null,
156+
path: `functions/${answers.name}`,
148157
};
149158

150159
localConfig.addFunction(data);

templates/cli/lib/questions.js.twig

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,57 @@ const getEntrypoint = (runtime) => {
4343
case 'dart':
4444
return 'lib/main.dart';
4545
case 'deno':
46-
return 'src/mod.ts';
46+
return 'src/main.ts';
4747
case 'node':
48-
return 'src/index.js';
48+
return 'src/main.js';
4949
case 'php':
5050
return 'src/index.php';
5151
case 'python':
52-
return 'src/index.py';
52+
return 'src/main.py';
5353
case 'ruby':
54-
return 'src/index.rb';
54+
return 'lib/main.rb';
5555
case 'rust':
5656
return 'main.rs';
5757
case 'swift':
58-
return 'Sources/swift-5.5/main.swift';
58+
return 'Sources/index.swift';
5959
case 'cpp':
60-
return 'src/index.cc';
60+
return 'src/main.cc';
6161
case 'dotnet':
6262
return 'src/Index.cs';
6363
case 'java':
64-
return 'src/Index.java';
64+
return 'src/Main.java';
6565
case 'kotlin':
66-
return 'src/Index.kt';
66+
return 'src/Main.kt';
67+
}
68+
69+
return undefined;
70+
};
71+
72+
const getInstallCommand = (runtime) => {
73+
const languge = runtime.split('-')[0];
74+
75+
switch (languge) {
76+
case 'dart':
77+
return 'dart pub get';
78+
case 'deno':
79+
return "deno install";
80+
case 'node':
81+
return 'npm install';
82+
case 'php':
83+
return 'composer install';
84+
case 'python':
85+
return 'pip install -r requirements.txt';
86+
case 'ruby':
87+
return 'bundle install';
88+
case 'rust':
89+
return 'cargo install';
90+
case 'dotnet':
91+
return 'dotnet restore';
92+
case 'swift':
93+
case 'java':
94+
case 'kotlin':
95+
case 'cpp':
96+
return '';
6797
}
6898

6999
return undefined;
@@ -171,10 +201,15 @@ const questionsInitFunction = [
171201
parseOutput: false
172202
})
173203
let runtimes = response["runtimes"]
174-
let choices = runtimes.map((runtime, idx) => {
204+
let choices = runtimes.map((runtime, idx) => {
175205
return {
176206
name: `${runtime.name} (${runtime['$id']})`,
177-
value: { id: runtime['$id'], entrypoint: getEntrypoint(runtime['$id']), ignore: getIgnores(runtime['$id']) },
207+
value: {
208+
id: runtime['$id'],
209+
entrypoint: getEntrypoint(runtime['$id']),
210+
ignore: getIgnores(runtime['$id']),
211+
commands : getInstallCommand(runtime['$id'])
212+
},
178213
}
179214
})
180215
return choices;

0 commit comments

Comments
 (0)