Skip to content

Commit 1ee0069

Browse files
Merge pull request #973 from appwrite/fix-cli-error
Fix path for directory
2 parents d5653a2 + 0ca97f7 commit 1ee0069

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ const runFunction = async ({ port, functionId, withVariables, reload, userId } =
9797
process.exit();
9898
});
9999

100-
const logsPath = path.join(process.cwd(), func.path, '.appwrite/logs.txt');
101-
const errorsPath = path.join(process.cwd(), func.path, '.appwrite/errors.txt');
100+
const logsPath = path.join(localConfig.getDirname(), func.path, '.appwrite/logs.txt');
101+
const errorsPath = path.join(localConfig.getDirname(), func.path, '.appwrite/errors.txt');
102102

103103
if(!fs.existsSync(path.dirname(logsPath))) {
104104
fs.mkdirSync(path.dirname(logsPath), { recursive: true });
@@ -131,7 +131,7 @@ const runFunction = async ({ port, functionId, withVariables, reload, userId } =
131131
}
132132
}
133133

134-
const functionPath = path.join(process.cwd(), func.path);
134+
const functionPath = path.join(localConfig.getDirname(), func.path);
135135
const envPath = path.join(functionPath, '.env');
136136
if(fs.existsSync(envPath)) {
137137
const env = parseDotenv(fs.readFileSync(envPath).toString() ?? '');
@@ -192,7 +192,7 @@ const runFunction = async ({ port, functionId, withVariables, reload, userId } =
192192
}
193193

194194
chokidar.watch('.', {
195-
cwd: path.join(process.cwd(), func.path),
195+
cwd: path.join(localConfig.getDirname(), func.path),
196196
ignoreInitial: true,
197197
ignored: (xpath) => {
198198
const relativePath = path.relative(functionPath, xpath);

templates/cli/lib/config.js.twig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ class Local extends Config {
145145
this.configDirectoryPath =_path.dirname(absolutePath);
146146
}
147147

148+
getDirname() {
149+
return _path.dirname(this.path)
150+
}
151+
148152
getFunctions() {
149153
if (!this.has("functions")) {
150154
return [];

templates/cli/lib/emulation/docker.js.twig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async function dockerBuild(func, variables) {
4747
const runtimeName = runtimeChunks.join("-");
4848
const imageName = `openruntimes/${runtimeName}:${openRuntimesVersion}-${runtimeVersion}`;
4949

50-
const functionDir = path.join(process.cwd(), func.path);
50+
const functionDir = path.join(localConfig.getDirname(), func.path);
5151

5252
const id = func.$id;
5353

@@ -124,7 +124,7 @@ async function dockerBuild(func, variables) {
124124
return;
125125
}
126126

127-
const copyPath = path.join(process.cwd(), func.path, '.appwrite', 'build.tar.gz');
127+
const copyPath = path.join(localConfig.getDirname(), func.path, '.appwrite', 'build.tar.gz');
128128
const copyDir = path.dirname(copyPath);
129129
if (!fs.existsSync(copyDir)) {
130130
fs.mkdirSync(copyDir, { recursive: true });
@@ -143,7 +143,7 @@ async function dockerBuild(func, variables) {
143143

144144
await dockerStop(id);
145145

146-
const tempPath = path.join(process.cwd(), func.path, 'code.tar.gz');
146+
const tempPath = path.join(localConfig.getDirname(), func.path, 'code.tar.gz');
147147
if (fs.existsSync(tempPath)) {
148148
fs.rmSync(tempPath, { force: true });
149149
}
@@ -153,7 +153,7 @@ async function dockerBuild(func, variables) {
153153

154154
async function dockerStart(func, variables, port) {
155155
// Pack function files
156-
const functionDir = path.join(process.cwd(), func.path);
156+
const functionDir = path.join(localConfig.getDirname(), func.path);
157157

158158
const runtimeChunks = func.runtime.split("-");
159159
const runtimeVersion = runtimeChunks.pop();
@@ -211,12 +211,12 @@ async function dockerCleanup(functionId) {
211211
await dockerStop(functionId);
212212

213213
const func = localConfig.getFunction(functionId);
214-
const appwritePath = path.join(process.cwd(), func.path, '.appwrite');
214+
const appwritePath = path.join(localConfig.getDirname(), func.path, '.appwrite');
215215
if (fs.existsSync(appwritePath)) {
216216
fs.rmSync(appwritePath, { recursive: true, force: true });
217217
}
218218

219-
const tempPath = path.join(process.cwd(), func.path, 'code.tar.gz');
219+
const tempPath = path.join(localConfig.getDirname(), func.path, 'code.tar.gz');
220220
if (fs.existsSync(tempPath)) {
221221
fs.rmSync(tempPath, { force: true });
222222
}

0 commit comments

Comments
 (0)