Skip to content

Commit

Permalink
Merge pull request #973 from appwrite/fix-cli-error
Browse files Browse the repository at this point in the history
Fix path for directory
  • Loading branch information
christyjacob4 authored Sep 9, 2024
2 parents d5653a2 + 0ca97f7 commit 1ee0069
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
8 changes: 4 additions & 4 deletions templates/cli/lib/commands/run.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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.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 });
Expand Down Expand Up @@ -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.getDirname(), func.path);
const envPath = path.join(functionPath, '.env');
if(fs.existsSync(envPath)) {
const env = parseDotenv(fs.readFileSync(envPath).toString() ?? '');
Expand Down Expand Up @@ -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.getDirname(), func.path),
ignoreInitial: true,
ignored: (xpath) => {
const relativePath = path.relative(functionPath, xpath);
Expand Down
4 changes: 4 additions & 0 deletions templates/cli/lib/config.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
Expand Down
12 changes: 6 additions & 6 deletions templates/cli/lib/emulation/docker.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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.getDirname(), func.path);

const id = func.$id;

Expand Down Expand Up @@ -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.getDirname(), func.path, '.appwrite', 'build.tar.gz');
const copyDir = path.dirname(copyPath);
if (!fs.existsSync(copyDir)) {
fs.mkdirSync(copyDir, { recursive: true });
Expand All @@ -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.getDirname(), func.path, 'code.tar.gz');
if (fs.existsSync(tempPath)) {
fs.rmSync(tempPath, { force: true });
}
Expand All @@ -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.getDirname(), func.path);

const runtimeChunks = func.runtime.split("-");
const runtimeVersion = runtimeChunks.pop();
Expand Down Expand Up @@ -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.getDirname(), 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.getDirname(), func.path, 'code.tar.gz');
if (fs.existsSync(tempPath)) {
fs.rmSync(tempPath, { force: true });
}
Expand Down

0 comments on commit 1ee0069

Please sign in to comment.