Skip to content

Commit d907ef8

Browse files
Merge pull request #886 from appwrite/feat-cli-g2-fixes
Feat cli g2 fixes
2 parents a5d86a7 + 8405ebb commit d907ef8

File tree

10 files changed

+47
-24
lines changed

10 files changed

+47
-24
lines changed

example.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function getSSLPage($url) {
4242
$platform = 'console';
4343
// $platform = 'server';
4444

45-
$spec = getSSLPage("https://raw.githubusercontent.com/appwrite/appwrite/1.5.x/app/config/specs/swagger2-latest-{$platform}.json");
45+
$spec = getSSLPage("https://raw.githubusercontent.com/appwrite/appwrite/1.6.x/app/config/specs/swagger2-latest-{$platform}.json");
4646

4747
if(empty($spec)) {
4848
throw new Exception('Failed to fetch spec from Appwrite server');

templates/cli/index.js.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const { commandDescriptions, cliConfig } = require("./lib/parser");
1212
const { client } = require("./lib/commands/generic");
1313
const inquirer = require("inquirer");
1414
{% if sdk.test != "true" %}
15-
const { login, logout, whoami, migrate } = require("./lib/commands/generic");
15+
const { login, logout, whoami, migrate, register } = require("./lib/commands/generic");
1616
const { init } = require("./lib/commands/init");
1717
const { pull } = require("./lib/commands/pull");
1818
const { run } = require("./lib/commands/run");
@@ -62,6 +62,7 @@ program
6262
.showSuggestionAfterError()
6363
{% if sdk.test != "true" %}
6464
.addCommand(whoami)
65+
.addCommand(register)
6566
.addCommand(login)
6667
.addCommand(init)
6768
.addCommand(pull)

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ const loginCommand = async ({ email, password, endpoint, mfa, code }) => {
8181
} else {
8282
globalConfig.removeSession(id);
8383
globalConfig.setCurrentSession(oldCurrent);
84+
if(endpoint !== DEFAULT_ENDPOINT && error.response === 'user_invalid_credentials'){
85+
log('Use the --endpoint option for self-hosted instances')
86+
}
8487
throw error;
8588
}
8689
}
@@ -128,6 +131,12 @@ const whoami = new Command("whoami")
128131
drawTable(data)
129132
}));
130133

134+
const register = new Command("register")
135+
.description(commandDescriptions['register'])
136+
.action(actionRunner(async () => {
137+
log('Visit https://cloud.appwrite.io/register to create an account')
138+
}));
139+
131140
const login = new Command("login")
132141
.description(commandDescriptions['login'])
133142
.option(`--email [email]`, `User email`)
@@ -299,6 +308,7 @@ module.exports = {
299308
{% if sdk.test != "true" %}
300309
loginCommand,
301310
whoami,
311+
register,
302312
login,
303313
logout,
304314
{% endif %}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ const initProject = async ({ organizationId, projectId, projectName } = {}) => {
5353
answers.project = {};
5454
answers.organization = {};
5555

56-
answers.organization.id = organizationId ?? (await inquirer.prompt(questionsInitProject[2])).organization;
56+
answers.organization = organizationId ?? (await inquirer.prompt(questionsInitProject[2])).organization;
5757
answers.project.name = projectName ?? (await inquirer.prompt(questionsInitProject[3])).project;
58-
answers.project.id = projectId ?? (await inquirer.prompt(questionsInitProject[4])).id;
58+
answers.project = projectId ?? (await inquirer.prompt(questionsInitProject[4])).id;
5959

6060
try {
6161
await projectsGet({ projectId, parseOutput: false });
6262
} catch (e) {
6363
if (e.code === 404) {
6464
answers.start = 'new';
65-
answers.id = answers.project.id;
65+
answers.id = answers.project;
6666
answers.project = answers.project.name;
6767
} else {
6868
throw e;
@@ -74,13 +74,13 @@ const initProject = async ({ organizationId, projectId, projectName } = {}) => {
7474
response = await projectsCreate({
7575
projectId: answers.id,
7676
name: answers.project,
77-
teamId: answers.organization.id,
77+
teamId: answers.organization,
7878
parseOutput: false
7979
})
8080

8181
localConfig.setProject(response['$id']);
8282
} else {
83-
localConfig.setProject(answers.project.id);
83+
localConfig.setProject(answers.project);
8484
}
8585

8686
success();
@@ -273,6 +273,7 @@ const initFunction = async () => {
273273

274274
localConfig.addFunction(data);
275275
success();
276+
log(`* Use 'appwrite dev function' for local development\n${' '.repeat(7)}* Use 'appwrite push functions' to push the function to your {{ spec.title|caseUcfirst }} instance`)
276277
}
277278

278279
const init = new Command("init")

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } =
5555
}
5656

5757
if(!port) {
58-
let portFound = fale;
58+
let portFound = false;
5959
port = 3000;
6060
while(port < 3100) {
6161
const taken = await isPortTaken(port);
@@ -194,7 +194,7 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } =
194194
await dockerStart(func, variables, port);
195195
} else {
196196
log('Hot-swapping function files ...');
197-
197+
198198
const functionPath = path.join(process.cwd(), func.path);
199199
const hotSwapPath = path.join(functionPath, '.appwrite/hot-swap');
200200
const buildPath = path.join(functionPath, '.appwrite/build.tar.gz');
@@ -226,7 +226,7 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } =
226226
const filePath = path.join(hotSwapPath, f);
227227
if (fs.existsSync(filePath)) {
228228
fs.rmSync(filePath, { force: true });
229-
}
229+
}
230230

231231
const fileDir = path.dirname(filePath);
232232
if (!fs.existsSync(fileDir)) {
@@ -244,7 +244,7 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } =
244244
cwd: hotSwapPath,
245245
file: buildPath
246246
}, ['.']);
247-
247+
248248
fs.rmSync(hotSwapPath, { recursive: true, force: true });
249249

250250
await dockerStart(func, variables, port);

templates/cli/lib/config.js.twig

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,16 @@ class Local extends Config {
333333
};
334334
}
335335

336-
setProject(projectId, projectName = '', projectSettings = {}) {
336+
setProject(projectId, projectName = '', projectSettings = undefined) {
337337
this.set("projectId", projectId);
338338

339339
if (projectName !== '') {
340340
this.set("projectName", projectName);
341341
}
342342

343+
if (projectSettings === undefined) {
344+
return;
345+
}
343346

344347
const settings = {
345348
services: {
@@ -414,8 +417,10 @@ class Global extends Config {
414417
return this.get(Global.PREFERENCE_CURRENT);
415418
}
416419

417-
setCurrentSession(endpoint) {
418-
this.set(Global.PREFERENCE_CURRENT, endpoint);
420+
setCurrentSession(session) {
421+
if (session !== undefined) {
422+
this.set(Global.PREFERENCE_CURRENT, session);
423+
}
419424
}
420425

421426
getSessionIds() {

templates/cli/lib/emulation/docker.js.twig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
const childProcess = require('child_process');
2+
const { localConfig } = require("../config");
3+
const path = require('path');
4+
const fs = require('fs');
5+
const { log,success } = require("../parser");
6+
const { openRuntimesVersion, systemTools } = require("./utils");
7+
const ID = require("../id");
8+
19
const activeDockerIds = {};
210

311
async function dockerStop(id) {

templates/cli/lib/emulation/utils.js.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
const EventEmitter = require('node:events');
2+
const { projectsCreateJWT } = require('../commands/projects');
3+
const { localConfig } = require("../config");
4+
25

36
const openRuntimesVersion = 'v3';
47

templates/cli/lib/parser.js.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ const commandDescriptions = {
222222
"login": `The login command allows you to authenticate and manage a user account.`,
223223
"logout": `The logout command allows you to logout of your {{ spec.title|caseUcfirst }} account.`,
224224
"whoami": `The whoami command gives information about the currently logged in user.`,
225+
"register": `Outputs the link to create an {{ spec.title|caseUcfirst }} account..`,
225226
"console" : `The console command allows gives you access to the APIs used by the Appwrite console.`,
226227
"assistant": `The assistant command allows you to interact with the Appwrite Assistant AI`,
227228
"messaging": `The messaging command allows you to send messages.`,

templates/cli/lib/questions.js.twig

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,12 @@ const questionsInitProject = [
155155
let choices = teams.map((team, idx) => {
156156
return {
157157
name: `${team.name} (${team['$id']})`,
158-
value: {
159-
name: team.name,
160-
id: team['$id']
161-
}
158+
value: team['$id']
162159
}
163160
})
164161

165162
if (choices.length == 0) {
166-
throw new Error("No organizations found. Please create a new organization.")
163+
throw new Error(`No organizations found. Please create a new organization at ${globalConfig.getEndpoint().replace('/v1', '/console/onboarding')}`)
167164
}
168165

169166
return choices;
@@ -199,10 +196,7 @@ const questionsInitProject = [
199196
let choices = projects.map((project) => {
200197
return {
201198
name: `${project.name} (${project['$id']})`,
202-
value: {
203-
name: project.name,
204-
id: project['$id']
205-
}
199+
value: project['$id']
206200
}
207201
})
208202

@@ -781,7 +775,7 @@ const questionsRunFunctions = [
781775
choices: () => {
782776
let functions = localConfig.getFunctions();
783777
if (functions.length === 0) {
784-
throw new Error("No functions found in the current directory.");
778+
throw new Error("No functions found in the current directory. Use 'appwrite init function' to create one");
785779
}
786780
let choices = functions.map((func, idx) => {
787781
return {

0 commit comments

Comments
 (0)