From a3516c8e8460de6a779197f5dcbfa66b0af38132 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 9 Sep 2024 17:07:48 +0200 Subject: [PATCH 1/3] Fix path --- templates/cli/lib/commands/run.js.twig | 8 ++++---- templates/cli/lib/config.js.twig | 4 ++++ templates/cli/lib/emulation/docker.js.twig | 12 ++++++------ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/templates/cli/lib/commands/run.js.twig b/templates/cli/lib/commands/run.js.twig index fea72c332..9633f8466 100644 --- a/templates/cli/lib/commands/run.js.twig +++ b/templates/cli/lib/commands/run.js.twig @@ -97,8 +97,8 @@ const runFunction = async ({ port, functionId, withVariables, reload, userId } = process.exit(); }); - const logsPath = path.join(process.cwd(), func.path, '.appwrite/logs.txt'); - const errorsPath = path.join(process.cwd(), func.path, '.appwrite/errors.txt'); + const logsPath = path.join(localConfig.dirname(), func.path, '.appwrite/logs.txt'); + const errorsPath = path.join(localConfig.dirname(), func.path, '.appwrite/errors.txt'); if(!fs.existsSync(path.dirname(logsPath))) { fs.mkdirSync(path.dirname(logsPath), { recursive: true }); @@ -131,7 +131,7 @@ const runFunction = async ({ port, functionId, withVariables, reload, userId } = } } - const functionPath = path.join(process.cwd(), func.path); + const functionPath = path.join(localConfig.dirname(), func.path); const envPath = path.join(functionPath, '.env'); if(fs.existsSync(envPath)) { const env = parseDotenv(fs.readFileSync(envPath).toString() ?? ''); @@ -192,7 +192,7 @@ const runFunction = async ({ port, functionId, withVariables, reload, userId } = } chokidar.watch('.', { - cwd: path.join(process.cwd(), func.path), + cwd: path.join(localConfig.dirname(), func.path), ignoreInitial: true, ignored: (xpath) => { const relativePath = path.relative(functionPath, xpath); diff --git a/templates/cli/lib/config.js.twig b/templates/cli/lib/config.js.twig index a0ab89dc9..d1b6be69b 100644 --- a/templates/cli/lib/config.js.twig +++ b/templates/cli/lib/config.js.twig @@ -145,6 +145,10 @@ class Local extends Config { this.configDirectoryPath =_path.dirname(absolutePath); } + getDirname() { + return path.dirname(this.path) + } + getFunctions() { if (!this.has("functions")) { return []; diff --git a/templates/cli/lib/emulation/docker.js.twig b/templates/cli/lib/emulation/docker.js.twig index 41e39f510..6e4dc56de 100644 --- a/templates/cli/lib/emulation/docker.js.twig +++ b/templates/cli/lib/emulation/docker.js.twig @@ -47,7 +47,7 @@ async function dockerBuild(func, variables) { const runtimeName = runtimeChunks.join("-"); const imageName = `openruntimes/${runtimeName}:${openRuntimesVersion}-${runtimeVersion}`; - const functionDir = path.join(process.cwd(), func.path); + const functionDir = path.join(localConfig.dirname(), func.path); const id = func.$id; @@ -124,7 +124,7 @@ async function dockerBuild(func, variables) { return; } - const copyPath = path.join(process.cwd(), func.path, '.appwrite', 'build.tar.gz'); + const copyPath = path.join(localConfig.dirname(), func.path, '.appwrite', 'build.tar.gz'); const copyDir = path.dirname(copyPath); if (!fs.existsSync(copyDir)) { fs.mkdirSync(copyDir, { recursive: true }); @@ -143,7 +143,7 @@ async function dockerBuild(func, variables) { await dockerStop(id); - const tempPath = path.join(process.cwd(), func.path, 'code.tar.gz'); + const tempPath = path.join(localConfig.dirname(), func.path, 'code.tar.gz'); if (fs.existsSync(tempPath)) { fs.rmSync(tempPath, { force: true }); } @@ -153,7 +153,7 @@ async function dockerBuild(func, variables) { async function dockerStart(func, variables, port) { // Pack function files - const functionDir = path.join(process.cwd(), func.path); + const functionDir = path.join(localConfig.dirname(), func.path); const runtimeChunks = func.runtime.split("-"); const runtimeVersion = runtimeChunks.pop(); @@ -211,12 +211,12 @@ async function dockerCleanup(functionId) { await dockerStop(functionId); const func = localConfig.getFunction(functionId); - const appwritePath = path.join(process.cwd(), func.path, '.appwrite'); + const appwritePath = path.join(localConfig.dirname(), func.path, '.appwrite'); if (fs.existsSync(appwritePath)) { fs.rmSync(appwritePath, { recursive: true, force: true }); } - const tempPath = path.join(process.cwd(), func.path, 'code.tar.gz'); + const tempPath = path.join(localConfig.dirname(), func.path, 'code.tar.gz'); if (fs.existsSync(tempPath)) { fs.rmSync(tempPath, { force: true }); } From a9d57fa1753de6179db36dd7fbc94a93793dfd16 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 9 Sep 2024 17:16:28 +0200 Subject: [PATCH 2/3] Fix method name --- templates/cli/lib/commands/run.js.twig | 8 ++++---- templates/cli/lib/emulation/docker.js.twig | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/templates/cli/lib/commands/run.js.twig b/templates/cli/lib/commands/run.js.twig index 9633f8466..1fae14f22 100644 --- a/templates/cli/lib/commands/run.js.twig +++ b/templates/cli/lib/commands/run.js.twig @@ -97,8 +97,8 @@ const runFunction = async ({ port, functionId, withVariables, reload, userId } = process.exit(); }); - const logsPath = path.join(localConfig.dirname(), func.path, '.appwrite/logs.txt'); - const errorsPath = path.join(localConfig.dirname(), func.path, '.appwrite/errors.txt'); + const logsPath = path.join(localConfig.getDirname(), func.path, '.appwrite/logs.txt'); + const errorsPath = path.join(localConfig.getDirname(), func.path, '.appwrite/errors.txt'); if(!fs.existsSync(path.dirname(logsPath))) { fs.mkdirSync(path.dirname(logsPath), { recursive: true }); @@ -131,7 +131,7 @@ const runFunction = async ({ port, functionId, withVariables, reload, userId } = } } - const functionPath = path.join(localConfig.dirname(), func.path); + const functionPath = path.join(localConfig.getDirname(), func.path); const envPath = path.join(functionPath, '.env'); if(fs.existsSync(envPath)) { const env = parseDotenv(fs.readFileSync(envPath).toString() ?? ''); @@ -192,7 +192,7 @@ const runFunction = async ({ port, functionId, withVariables, reload, userId } = } chokidar.watch('.', { - cwd: path.join(localConfig.dirname(), func.path), + cwd: path.join(localConfig.getDirname(), func.path), ignoreInitial: true, ignored: (xpath) => { const relativePath = path.relative(functionPath, xpath); diff --git a/templates/cli/lib/emulation/docker.js.twig b/templates/cli/lib/emulation/docker.js.twig index 6e4dc56de..0b774d86d 100644 --- a/templates/cli/lib/emulation/docker.js.twig +++ b/templates/cli/lib/emulation/docker.js.twig @@ -47,7 +47,7 @@ async function dockerBuild(func, variables) { const runtimeName = runtimeChunks.join("-"); const imageName = `openruntimes/${runtimeName}:${openRuntimesVersion}-${runtimeVersion}`; - const functionDir = path.join(localConfig.dirname(), func.path); + const functionDir = path.join(localConfig.getDirname(), func.path); const id = func.$id; @@ -124,7 +124,7 @@ async function dockerBuild(func, variables) { return; } - const copyPath = path.join(localConfig.dirname(), func.path, '.appwrite', 'build.tar.gz'); + const copyPath = path.join(localConfig.getDirname(), func.path, '.appwrite', 'build.tar.gz'); const copyDir = path.dirname(copyPath); if (!fs.existsSync(copyDir)) { fs.mkdirSync(copyDir, { recursive: true }); @@ -143,7 +143,7 @@ async function dockerBuild(func, variables) { await dockerStop(id); - const tempPath = path.join(localConfig.dirname(), func.path, 'code.tar.gz'); + const tempPath = path.join(localConfig.getDirname(), func.path, 'code.tar.gz'); if (fs.existsSync(tempPath)) { fs.rmSync(tempPath, { force: true }); } @@ -153,7 +153,7 @@ async function dockerBuild(func, variables) { async function dockerStart(func, variables, port) { // Pack function files - const functionDir = path.join(localConfig.dirname(), func.path); + const functionDir = path.join(localConfig.getDirname(), func.path); const runtimeChunks = func.runtime.split("-"); const runtimeVersion = runtimeChunks.pop(); @@ -211,12 +211,12 @@ async function dockerCleanup(functionId) { await dockerStop(functionId); const func = localConfig.getFunction(functionId); - const appwritePath = path.join(localConfig.dirname(), func.path, '.appwrite'); + const appwritePath = path.join(localConfig.getDirname(), func.path, '.appwrite'); if (fs.existsSync(appwritePath)) { fs.rmSync(appwritePath, { recursive: true, force: true }); } - const tempPath = path.join(localConfig.dirname(), func.path, 'code.tar.gz'); + const tempPath = path.join(localConfig.getDirname(), func.path, 'code.tar.gz'); if (fs.existsSync(tempPath)) { fs.rmSync(tempPath, { force: true }); } From 0ca97f74ac6b685ab43782df2747a5c7014ba97a Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 9 Sep 2024 17:30:21 +0200 Subject: [PATCH 3/3] Fix path --- templates/cli/lib/config.js.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/cli/lib/config.js.twig b/templates/cli/lib/config.js.twig index d1b6be69b..408c56ee6 100644 --- a/templates/cli/lib/config.js.twig +++ b/templates/cli/lib/config.js.twig @@ -146,7 +146,7 @@ class Local extends Config { } getDirname() { - return path.dirname(this.path) + return _path.dirname(this.path) } getFunctions() {