From d3fcdf80b5ec052fe3e011e88e4efa00335e4ae5 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Tue, 18 Jun 2024 15:39:41 -0400 Subject: [PATCH 1/4] fix: typo --- templates/cli/lib/commands/pull.js.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/cli/lib/commands/pull.js.twig b/templates/cli/lib/commands/pull.js.twig index c4f4fefe3..b4d4c4954 100644 --- a/templates/cli/lib/commands/pull.js.twig +++ b/templates/cli/lib/commands/pull.js.twig @@ -202,7 +202,7 @@ pull .command("function") .alias("functions") .description("Pulling your {{ spec.title|caseUcfirst }} cloud function") - .action(actionRunner(pullFunction)) + .action(actionRunner(pullFunctions)) pull .command("collection") From fe3bcaa20ca3ae1ea19b1e394954f454bbd470ce Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Tue, 18 Jun 2024 15:39:51 -0400 Subject: [PATCH 2/4] fix: missing import --- templates/cli/index.js.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/cli/index.js.twig b/templates/cli/index.js.twig index bc99de8b8..39882577f 100644 --- a/templates/cli/index.js.twig +++ b/templates/cli/index.js.twig @@ -12,7 +12,7 @@ const { commandDescriptions, cliConfig } = require("./lib/parser"); const { client } = require("./lib/commands/generic"); const inquirer = require("inquirer"); {% if sdk.test != "true" %} -const { login, logout, whoami } = require("./lib/commands/generic"); +const { login, logout, whoami, migrate } = require("./lib/commands/generic"); const { init } = require("./lib/commands/init"); const { pull } = require("./lib/commands/pull"); const { run } = require("./lib/commands/run"); From 6711fbd98396b5923f99d282a425ad6af962dbd9 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Tue, 18 Jun 2024 15:40:06 -0400 Subject: [PATCH 3/4] feat: expanding functions update paramateters --- templates/cli/lib/commands/push.js.twig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/templates/cli/lib/commands/push.js.twig b/templates/cli/lib/commands/push.js.twig index a2672743f..dc299ec16 100644 --- a/templates/cli/lib/commands/push.js.twig +++ b/templates/cli/lib/commands/push.js.twig @@ -765,6 +765,11 @@ const pushFunction = async ({ functionId, async, returnOnZero } = { returnOnZero logging: func.logging, entrypoint: func.entrypoint, commands: func.commands, + providerRepositoryId: func.providerRepositoryId ?? "", + installationId: func.installationId ?? '', + providerBranch: func.providerBranch ?? '', + providerRootDirectory: func.providerRootDirectory ?? '', + providerSilentMode: func.providerSilentMode ?? false, vars: JSON.stringify(response.vars), parseOutput: false }); From 88b97a9a1fa463cca964b1da320daabb8717a38c Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Wed, 19 Jun 2024 08:41:22 -0400 Subject: [PATCH 4/4] chore: Module to commonjs --- templates/cli/lib/emulation/docker.js.twig | 35 ++++++++++++++-------- templates/cli/lib/emulation/utils.js.twig | 24 ++++++++++----- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/templates/cli/lib/emulation/docker.js.twig b/templates/cli/lib/emulation/docker.js.twig index fa0b942c5..08544ad97 100644 --- a/templates/cli/lib/emulation/docker.js.twig +++ b/templates/cli/lib/emulation/docker.js.twig @@ -1,6 +1,6 @@ const activeDockerIds = {}; -export async function dockerStop(id) { +async function dockerStop(id) { delete activeDockerIds[id]; const stopProcess = childProcess.spawn('docker', ['rm', '--force', id], { stdio: 'pipe', @@ -9,7 +9,7 @@ export async function dockerStop(id) { await new Promise((res) => { stopProcess.on('close', res) }); } -export async function dockerPull(func) { +async function dockerPull(func) { log('Pulling Docker image of function runtime ...'); const runtimeChunks = func.runtime.split("-"); @@ -29,7 +29,7 @@ export async function dockerPull(func) { await new Promise((res) => { pullProcess.on('close', res) }); } -export async function dockerBuild(func, variables) { +async function dockerBuild(func, variables) { log('Building function using Docker ...'); const runtimeChunks = func.runtime.split("-"); @@ -63,7 +63,7 @@ export async function dockerBuild(func, variables) { buildProcess.stdout.on('data', (data) => { process.stdout.write(`\n${data}`); }); - + buildProcess.stderr.on('data', (data) => { process.stderr.write(`\n${data}`); }); @@ -95,10 +95,10 @@ export async function dockerBuild(func, variables) { const tempPath = path.join(process.cwd(), func.path, 'code.tar.gz'); if (fs.existsSync(tempPath)) { fs.rmSync(tempPath, { force: true }); - } + } } -export async function dockerStart(func, variables, port) { +async function dockerStart(func, variables, port) { log('Starting function using Docker ...'); log("Permissions, events, CRON and timeouts dont apply when running locally."); @@ -106,8 +106,8 @@ export async function dockerStart(func, variables, port) { log('💡 Hint: Function automatically restarts when you edit your code.'); success(`Visit http://localhost:${port}/ to execute your function.`); - - + + const runtimeChunks = func.runtime.split("-"); const runtimeVersion = runtimeChunks.pop(); const runtimeName = runtimeChunks.join("-"); @@ -136,7 +136,7 @@ export async function dockerStart(func, variables, port) { params.push('-v', `${functionDir}/.appwrite/errors.txt:/mnt/logs/dev_errors.log:rw`); params.push('-v', `${functionDir}/.appwrite/build.tar.gz:/mnt/code/code.tar.gz:ro`); params.push(imageName, 'sh', '-c', `helpers/start.sh "${tool.startCommand}"`); - + childProcess.spawn('docker', params, { stdio: 'pipe', pwd: functionDir @@ -145,7 +145,7 @@ export async function dockerStart(func, variables, port) { activeDockerIds[id] = true; } -export async function dockerCleanup() { +async function dockerCleanup() { await dockerStop(); const functions = localConfig.getFunctions(); @@ -162,9 +162,18 @@ export async function dockerCleanup() { } } -export async function dockerStopActive() { +async function dockerStopActive() { const ids = Object.keys(activeDockerIds); for await (const id of ids) { await dockerStop(id); - } -} \ No newline at end of file + } +} + +module.exports = { + dockerStop, + dockerPull, + dockerBuild, + dockerStart, + dockerCleanup, + dockerStopActive, +} diff --git a/templates/cli/lib/emulation/utils.js.twig b/templates/cli/lib/emulation/utils.js.twig index a7011f3eb..eefa096b6 100644 --- a/templates/cli/lib/emulation/utils.js.twig +++ b/templates/cli/lib/emulation/utils.js.twig @@ -1,6 +1,8 @@ -export const openRuntimesVersion = 'v3'; +const EventEmitter = require('node:events'); -export const runtimeNames = { +const openRuntimesVersion = 'v3'; + +const runtimeNames = { 'node': 'Node.js', 'php': 'PHP', 'ruby': 'Ruby', @@ -15,7 +17,7 @@ export const runtimeNames = { 'bun': 'Bun' }; -export const systemTools = { +const systemTools = { 'node': { isCompiled: false, startCommand: "node src/server.js", @@ -78,7 +80,7 @@ export const systemTools = { }, }; -export const JwtManager = { +const JwtManager = { userJwt: null, functionJwt: null, @@ -115,7 +117,7 @@ export const JwtManager = { }); this.userJwt = userResponse.jwt; } - + const functionResponse = await projectsCreateJWT({ projectId: localConfig.getProject().projectId, // TODO: Once we have endpoint for this, use it @@ -127,7 +129,7 @@ export const JwtManager = { } }; -export const Queue = { +const Queue = { files: [], locked: false, events: new EventEmitter(), @@ -161,4 +163,12 @@ export const Queue = { this.debounce = null; }, 300); } -}; \ No newline at end of file +}; + +module.exports = { + openRuntimesVersion, + runtimeNames, + systemTools, + JwtManager, + Queue +}