Skip to content

Commit 0428821

Browse files
committed
Merge remote-tracking branch 'origin/master' into fix-qa-releases
2 parents 475c653 + 81524aa commit 0428821

File tree

16 files changed

+182
-144
lines changed

16 files changed

+182
-144
lines changed

templates/cli/base/requests/api.twig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@
2424
);
2525
} else {
2626
parse(response)
27-
success()
2827
}
2928
{%~ else %}
3029
parse(response)
31-
success()
3230
{%~ endif %}
3331
}
3432

templates/cli/base/requests/file.twig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@
107107

108108
if (parseOutput) {
109109
parse(response)
110-
success()
111110
}
112111

113112
return response;

templates/cli/index.js.twig

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ program
3030
.description(commandDescriptions['main'])
3131
.configureHelp({
3232
helpWidth: process.stdout.columns || 80,
33-
sortSubcommands: true
33+
sortSubcommands: true,
3434
})
35-
.version(version, "-v, --version")
35+
.helpOption('-h, --help', "Display help for command")
36+
.version(version, "-v, --version", "Output the version number")
3637
.option("-V, --verbose", "Show complete error log")
3738
.option("-j, --json", "Output in JSON format")
3839
.hook('preAction', migrate)
3940
.option("-f,--force", "Flag to confirm all warnings")
4041
.option("-a,--all", "Flag to push all resources")
41-
.option("--id [id...]", "Flag to pass list of ids for a giving action")
42+
.option("--id [id...]", "Flag to pass a list of ids for a given action")
4243
.option("--report", "Enable reporting in case of CLI errors")
4344
.on("option:json", () => {
4445
cliConfig.json = true;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function convertReadStreamToReadableStream(readStream) {
3535
});
3636
}
3737

38-
const {{ service.name | caseLower }} = new Command("{{ service.name | caseLower }}").description(commandDescriptions['{{ service.name | caseLower }}']).configureHelp({
38+
const {{ service.name | caseLower }} = new Command("{{ service.name | caseLower }}").description(commandDescriptions['{{ service.name | caseLower }}'] ?? '').configureHelp({
3939
helpWidth: process.stdout.columns || 80
4040
})
4141

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@ const { actionRunner, success, parseBool, commandDescriptions, error, parse, hin
77
const ID = require("../id");
88
{% if sdk.test != "true" %}
99
const { questionsLogin, questionsLogout, questionsListFactors, questionsMfaChallenge } = require("../questions");
10-
const { accountUpdateMfaChallenge, accountCreateMfaChallenge, accountGet, accountCreateEmailPasswordSession, accountDeleteSession } = require("./account");
10+
const { accountUpdateMfaChallenge, accountCreateMfaChallenge, accountGet, accountCreateEmailPasswordSession, accountDeleteSession } = require("./account");
1111

1212
const DEFAULT_ENDPOINT = 'https://cloud.appwrite.io/v1';
1313

1414
const loginCommand = async ({ email, password, endpoint, mfa, code }) => {
1515
const oldCurrent = globalConfig.getCurrentSession();
1616
let configEndpoint = endpoint ?? DEFAULT_ENDPOINT;
1717

18-
if(globalConfig.getCurrentSession() !== '') {
18+
if (globalConfig.getCurrentSession() !== '') {
1919
log('You are currently signed in as ' + globalConfig.getEmail());
2020

21-
if(globalConfig.getSessions().length === 1) {
21+
if (globalConfig.getSessions().length === 1) {
2222
hint('You can sign in and manage multiple accounts with Appwrite CLI');
2323
}
2424
}
2525

2626
const answers = email && password ? { email, password } : await inquirer.prompt(questionsLogin);
2727

28-
if(!answers.method) {
28+
if (!answers.method) {
2929
answers.method = 'login';
3030
}
3131

@@ -93,7 +93,7 @@ const loginCommand = async ({ email, password, endpoint, mfa, code }) => {
9393
} else {
9494
globalConfig.removeSession(id);
9595
globalConfig.setCurrentSession(oldCurrent);
96-
if(endpoint !== DEFAULT_ENDPOINT && error.response === 'user_invalid_credentials'){
96+
if (endpoint !== DEFAULT_ENDPOINT && error.response === 'user_invalid_credentials') {
9797
log('Use the --endpoint option for self-hosted instances')
9898
}
9999
throw error;
@@ -136,7 +136,7 @@ const whoami = new Command("whoami")
136136
}
137137
];
138138

139-
if(cliConfig.json) {
139+
if (cliConfig.json) {
140140
console.log(data);
141141
return;
142142
}
@@ -194,7 +194,7 @@ const logout = new Command("logout")
194194
}
195195
if (sessions.length === 1) {
196196
await deleteSession(current);
197-
success();
197+
success("Logging out");
198198

199199
return;
200200
}
@@ -208,16 +208,16 @@ const logout = new Command("logout")
208208
}
209209
}
210210

211-
const remainingSessions = globalConfig.getSessions();
211+
const remainingSessions = globalConfig.getSessions();
212212

213-
if (remainingSessions .length > 0 && remainingSessions .filter(session => session.id === current).length !== 1) {
213+
if (remainingSessions.length > 0 && remainingSessions.filter(session => session.id === current).length !== 1) {
214214
const accountId = remainingSessions [0].id;
215215
globalConfig.setCurrentSession(accountId);
216216

217217
success(`Current account is ${accountId}`);
218218
}
219219

220-
success();
220+
success("Logging out");
221221
}));
222222
{% endif %}
223223

@@ -294,7 +294,7 @@ const client = new Command("client")
294294
}
295295
}
296296

297-
success()
297+
success("Setting client")
298298
}));
299299

300300
const migrate = async () => {

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

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const initBucket = async () => {
129129
fileSecurity: answers.fileSecurity.toLowerCase() === 'yes',
130130
enabled: true,
131131
});
132-
success();
132+
success("Initialing bucket");
133133
log("Next you can use 'appwrite push bucket' to deploy the changes.");
134134
};
135135

@@ -141,7 +141,7 @@ const initTeam = async () => {
141141
name: answers.bucket,
142142
});
143143

144-
success();
144+
success("Initialing team");
145145
log("Next you can use 'appwrite push team' to deploy the changes.");
146146
};
147147

@@ -174,7 +174,7 @@ const initCollection = async () => {
174174
enabled: true,
175175
});
176176

177-
success();
177+
success("Initialing collection");
178178
log("Next you can use 'appwrite push collection' to deploy the changes.");
179179
};
180180

@@ -187,7 +187,7 @@ const initTopic = async () => {
187187

188188
});
189189

190-
success();
190+
success("Initialing topic");
191191
log("Next you can use 'appwrite push topic' to deploy the changes.");
192192
};
193193

@@ -223,21 +223,7 @@ const initFunction = async () => {
223223
fs.mkdirSync(templatesDir, "777");
224224
const repo = "https://github.com/{{ sdk.gitUserName }}/templates";
225225
const api = `https://api.github.com/repos/{{ sdk.gitUserName }}/templates/contents/${answers.runtime.name}`
226-
let selected = undefined;
227-
228-
if(answers.template === 'starter') {
229-
selected = { template: 'starter' };
230-
} else {
231-
try {
232-
const res = await fetch(api);
233-
const templates = [];
234-
templates.push(...(await res.json()).map((template) => template.name));
235-
selected = await inquirer.prompt(questionsCreateFunctionSelectTemplate(templates));
236-
} catch {
237-
// Not a problem will go with directory pulling
238-
log('Loading templates...');
239-
}
240-
}
226+
let selected = { template: 'starter' };
241227

242228
const sparse = (selected ? `${answers.runtime.name}/${selected.template}` : answers.runtime.name).toLowerCase();
243229

@@ -312,6 +298,7 @@ const initFunction = async () => {
312298
runtime: answers.runtime.id,
313299
execute: [],
314300
events: [],
301+
scopes: [],
315302
schedule: "",
316303
timeout: 15,
317304
enabled: true,
@@ -323,7 +310,7 @@ const initFunction = async () => {
323310
};
324311

325312
localConfig.addFunction(data);
326-
success();
313+
success("Initialing function");
327314
log("Next you can use 'appwrite run function' to develop a function locally. To deploy the function, use 'appwrite push function'");
328315
}
329316

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

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const pullSettings = async () => {
5656
}
5757
}
5858

59-
const pullFunctions = async ({ code }) => {
59+
const pullFunctions = async ({ code, withVariables }) => {
6060
log("Fetching functions ...");
6161
let total = 0;
6262

@@ -83,27 +83,29 @@ const pullFunctions = async ({ code }) => {
8383
const localFunction = localConfig.getFunction(func.$id);
8484

8585
func['path'] = localFunction['path'];
86-
if(!localFunction['path']) {
86+
if (!localFunction['path']) {
8787
func['path'] = `functions/${func.$id}`;
8888
}
89-
89+
if (!withVariables) {
90+
delete func['vars'];
91+
}
9092
localConfig.addFunction(func);
9193

9294
if (!fs.existsSync(func['path'])) {
9395
fs.mkdirSync(func['path'], { recursive: true });
9496
}
9597

96-
if(code === false) {
98+
if (code === false) {
9799
warn("Source code download skipped.");
98-
} else if(!func['deployment']) {
100+
} else if (!func['deployment']) {
99101
warn("Source code download skipped because function doesn't have active deployment.");
100102
} else {
101-
if(allowCodePull === null) {
103+
if (allowCodePull === null) {
102104
const codeAnswer = await inquirer.prompt(questionsPullFunctionsCode);
103105
allowCodePull = codeAnswer.override;
104106
}
105107

106-
if(allowCodePull) {
108+
if (allowCodePull) {
107109
log("Pulling active deployment's code ...");
108110

109111
const compressedFileName = `${func['$id']}-${+new Date()}.tar.gz`
@@ -123,6 +125,16 @@ const pullFunctions = async ({ code }) => {
123125
});
124126

125127
fs.rmSync(compressedFileName);
128+
129+
if (withVariables) {
130+
const envFileLocation = `${func['path']}/.env`
131+
try {
132+
fs.rmSync(envFileLocation);
133+
} catch {
134+
}
135+
136+
fs.writeFileSync(envFileLocation, func['vars'].map(r => `${r.key}=${r.value}\n`).join(''))
137+
}
126138
}
127139
}
128140
}
@@ -170,7 +182,7 @@ const pullCollection = async () => {
170182
parseOutput: false
171183
}, 100, 'collections');
172184

173-
for(const collection of collections) {
185+
for (const collection of collections) {
174186
localConfig.addCollection({
175187
...collection,
176188
'$createdAt': undefined,
@@ -198,7 +210,7 @@ const pullBucket = async () => {
198210

199211
const { buckets } = await paginate(storageListBuckets, { parseOutput: false }, 100, 'buckets');
200212

201-
for(const bucket of buckets) {
213+
for (const bucket of buckets) {
202214
total++;
203215
log(`Pulling bucket ${chalk.bold(bucket['name'])} ...`);
204216
localConfig.addBucket(bucket);
@@ -223,7 +235,7 @@ const pullTeam = async () => {
223235

224236
const { teams } = await paginate(teamsList, { parseOutput: false }, 100, 'teams');
225237

226-
for(const team of teams) {
238+
for (const team of teams) {
227239
total++;
228240
log(`Pulling team ${chalk.bold(team['name'])} ...`);
229241
localConfig.addTeam(team);
@@ -248,7 +260,7 @@ const pullMessagingTopic = async () => {
248260

249261
const { topics } = await paginate(messagingListTopics, { parseOutput: false }, 100, 'topics');
250262

251-
for(const topic of topics) {
263+
for (const topic of topics) {
252264
total++;
253265
log(`Pulling topic ${chalk.bold(topic['name'])} ...`);
254266
localConfig.addMessagingTopic(topic);
@@ -279,6 +291,7 @@ pull
279291
.alias("functions")
280292
.description("Pulling your {{ spec.title|caseUcfirst }} cloud function")
281293
.option("--no-code", "Don't pull the function's code")
294+
.option("--with-variables", `Pull function variables. ${chalk.red('recommend for testing purposes only')}`)
282295
.action(actionRunner(pullFunctions))
283296

284297
pull

0 commit comments

Comments
 (0)