Skip to content

Commit 5f2a178

Browse files
committed
Merge branch 'master' of https://github.com/appwrite/sdk-generator into fix-php
2 parents 22d4bac + 947e439 commit 5f2a178

File tree

9 files changed

+218
-139
lines changed

9 files changed

+218
-139
lines changed

templates/apple/Package.swift.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ let package = Package(
2222
),
2323
],
2424
dependencies: [
25-
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.17.0"),
26-
.package(url: "https://github.com/apple/swift-nio.git", from: "2.32.0"),
25+
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.19.0"),
26+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.58.0"),
2727
],
2828
targets: [
2929
.target(

templates/cli/base/params.twig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@
2626

2727
const files = getAllFiles({{ parameter.name | caseCamel | escapeKeyword }}).map((file) => pathLib.relative({{ parameter.name | caseCamel | escapeKeyword }}, file)).filter((file) => !ignorer.ignores(file));
2828

29+
const archiveFileName = `${functionId}-code.tar.gz`;
30+
2931
await tar
3032
.create({
3133
gzip: true,
3234
sync: true,
3335
cwd: folderPath,
34-
file: 'code.tar.gz'
36+
file: archiveFileName
3537
}, files);
3638

37-
let archivePath = fs.realpathSync('code.tar.gz')
39+
let archivePath = fs.realpathSync(archiveFileName)
3840
if (typeof archivePath !== 'undefined') {
3941
payload['{{ parameter.name }}'] = archivePath;
4042
{{ parameter.name | caseCamel | escapeKeyword }} = archivePath;

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ const initTopic = async () => {
192192
};
193193

194194
const initFunction = async () => {
195+
process.chdir(localConfig.configDirectoryPath)
196+
195197
// TODO: Add CI/CD support (ID, name, runtime)
196198
const answers = await inquirer.prompt(questionsCreateFunction)
197199
const functionFolder = path.join(process.cwd(), 'functions');
@@ -203,12 +205,13 @@ const initFunction = async () => {
203205
}
204206

205207
const functionId = answers.id === 'unique()' ? ID.unique() : answers.id;
206-
const functionDir = path.join(functionFolder, functionId);
208+
const functionName = answers.name;
209+
const functionDir = path.join(functionFolder, functionName);
207210
const templatesDir = path.join(functionFolder, `${functionId}-templates`);
208211
const runtimeDir = path.join(templatesDir, answers.runtime.name);
209212

210213
if (fs.existsSync(functionDir)) {
211-
throw new Error(`( ${functionId} ) already exists in the current directory. Please choose another name.`);
214+
throw new Error(`( ${functionName} ) already exists in the current directory. Please choose another name.`);
212215
}
213216

214217
if (!answers.runtime.entrypoint) {
@@ -285,7 +288,7 @@ const initFunction = async () => {
285288

286289
fs.rmSync(templatesDir, { recursive: true, force: true });
287290

288-
const readmePath = path.join(process.cwd(), 'functions', functionId, 'README.md');
291+
const readmePath = path.join(process.cwd(), 'functions', functionName, 'README.md');
289292
const readmeFile = fs.readFileSync(readmePath).toString();
290293
const newReadmeFile = readmeFile.split('\n');
291294
newReadmeFile[0] = `# ${answers.name}`;
@@ -306,7 +309,7 @@ const initFunction = async () => {
306309
entrypoint: answers.runtime.entrypoint || '',
307310
commands: answers.runtime.commands || '',
308311
ignore: answers.runtime.ignore || null,
309-
path: `functions/${functionId}`,
312+
path: `functions/${functionName}`,
310313
};
311314

312315
localConfig.addFunction(data);

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

Lines changed: 70 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const inquirer = require("inquirer");
66
const { messagingListTopics } = require("./messaging");
77
const { teamsList } = require("./teams");
88
const { projectsGet } = require("./projects");
9-
const { functionsList, functionsDownloadDeployment } = require("./functions");
9+
const { functionsList, functionsGetDeploymentDownload, functionsListDeployments } = require("./functions");
1010
const { databasesGet, databasesListCollections, databasesList } = require("./databases");
1111
const { storageListBuckets } = require("./storage");
1212
const { localConfig } = require("../config");
@@ -57,6 +57,8 @@ const pullSettings = async () => {
5757
}
5858

5959
const pullFunctions = async ({ code, withVariables }) => {
60+
process.chdir(localConfig.configDirectoryPath)
61+
6062
log("Fetching functions ...");
6163
let total = 0;
6264

@@ -84,7 +86,7 @@ const pullFunctions = async ({ code, withVariables }) => {
8486

8587
func['path'] = localFunction['path'];
8688
if (!localFunction['path']) {
87-
func['path'] = `functions/${func.$id}`;
89+
func['path'] = `functions/${func.name}`;
8890
}
8991
if (!withVariables) {
9092
delete func['vars'];
@@ -97,45 +99,70 @@ const pullFunctions = async ({ code, withVariables }) => {
9799

98100
if (code === false) {
99101
warn("Source code download skipped.");
100-
} else if (!func['deployment']) {
101-
warn("Source code download skipped because function doesn't have active deployment.");
102-
} else {
103-
if (allowCodePull === null) {
104-
const codeAnswer = await inquirer.prompt(questionsPullFunctionsCode);
105-
allowCodePull = codeAnswer.override;
102+
continue;
103+
}
104+
105+
if (allowCodePull === null) {
106+
const codeAnswer = await inquirer.prompt(questionsPullFunctionsCode);
107+
allowCodePull = codeAnswer.override;
108+
}
109+
110+
if (!allowCodePull) {
111+
continue;
112+
}
113+
114+
let deploymentId = null;
115+
116+
try {
117+
const fetchResponse = await functionsListDeployments({
118+
functionId: func['$id'],
119+
queries: [
120+
JSON.stringify({ method: 'limit', values: [1] }),
121+
JSON.stringify({ method: 'orderDesc', values: ['$id'] })
122+
],
123+
parseOutput: false
124+
});
125+
126+
if (fetchResponse['total'] > 0) {
127+
deploymentId = fetchResponse['deployments'][0]['$id'];
106128
}
107129

108-
if (allowCodePull) {
109-
log("Pulling active deployment's code ...");
110-
111-
const compressedFileName = `${func['$id']}-${+new Date()}.tar.gz`
112-
await functionsDownloadDeployment({
113-
functionId: func['$id'],
114-
deploymentId: func['deployment'],
115-
destination: compressedFileName,
116-
overrideForCli: true,
117-
parseOutput: false
118-
});
119-
120-
tar.extract({
121-
sync: true,
122-
cwd: func['path'],
123-
file: compressedFileName,
124-
strict: false,
125-
});
126-
127-
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-
}
130+
} catch {
131+
}
132+
133+
if (deploymentId === null) {
134+
log("Source code download skipped because function doesn't have any available deployment");
135+
continue;
136+
}
137+
138+
log("Pulling latest deployment code ...");
139+
140+
const compressedFileName = `${func['$id']}-${+new Date()}.tar.gz`
141+
await functionsGetDeploymentDownload({
142+
functionId: func['$id'],
143+
deploymentId,
144+
destination: compressedFileName,
145+
overrideForCli: true,
146+
parseOutput: false
147+
});
148+
149+
tar.extract({
150+
sync: true,
151+
cwd: func['path'],
152+
file: compressedFileName,
153+
strict: false,
154+
});
155+
156+
fs.rmSync(compressedFileName);
157+
158+
if (withVariables) {
159+
const envFileLocation = `${func['path']}/.env`
160+
try {
161+
fs.rmSync(envFileLocation);
162+
} catch {
138163
}
164+
165+
fs.writeFileSync(envFileLocation, func['vars'].map(r => `${r.key}=${r.value}\n`).join(''))
139166
}
140167
}
141168

@@ -289,33 +316,33 @@ pull
289316
pull
290317
.command("function")
291318
.alias("functions")
292-
.description("Pulling your {{ spec.title|caseUcfirst }} cloud function")
319+
.description("Pull your {{ spec.title|caseUcfirst }} cloud function")
293320
.option("--no-code", "Don't pull the function's code")
294321
.option("--with-variables", `Pull function variables. ${chalk.red('recommend for testing purposes only')}`)
295322
.action(actionRunner(pullFunctions))
296323

297324
pull
298325
.command("collection")
299326
.alias("collections")
300-
.description("Pulling your {{ spec.title|caseUcfirst }} collections")
327+
.description("Pull your {{ spec.title|caseUcfirst }} collections")
301328
.action(actionRunner(pullCollection))
302329

303330
pull
304331
.command("bucket")
305332
.alias("buckets")
306-
.description("Pulling your Appwrite buckets")
333+
.description("Pull your Appwrite buckets")
307334
.action(actionRunner(pullBucket))
308335

309336
pull
310337
.command("team")
311338
.alias("teams")
312-
.description("Pulling your Appwrite teams")
339+
.description("Pull your Appwrite teams")
313340
.action(actionRunner(pullTeam))
314341

315342
pull
316343
.command("topic")
317344
.alias("topics")
318-
.description("Initialise your Appwrite messaging topics")
345+
.description("Pull your Appwrite messaging topics")
319346
.action(actionRunner(pullMessagingTopic))
320347

321348
module.exports = {

0 commit comments

Comments
 (0)