Skip to content

Commit 70e8064

Browse files
Merge pull request appwrite#938 from appwrite/feat-run-from-sub-folders
Feat run from sub folders
2 parents d787825 + ed2acd9 commit 70e8064

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

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

Lines changed: 2 additions & 0 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');

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,8 @@ const pushSettings = async () => {
10031003
}
10041004

10051005
const pushFunction = async ({ functionId, async, code, withVariables } = { returnOnZero: false }) => {
1006+
process.chdir(localConfig.configDirectoryPath)
1007+
10061008
const functionIds = [];
10071009

10081010
if (functionId) {

templates/cli/lib/config.js.twig

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,26 @@ class Config {
123123

124124
class Local extends Config {
125125
static CONFIG_FILE_PATH = "{{ spec.title|caseLower }}.json";
126+
configDirectoryPath = ""
126127

127128
constructor(path = Local.CONFIG_FILE_PATH) {
128-
let absolutePath = `${process.cwd()}/${path}`;
129+
let currentPath = process.cwd();
130+
let absolutePath = `${currentPath}/${path}`;
131+
132+
while (true) {
133+
if (fs.existsSync(`${currentPath}/${path}`)) {
134+
absolutePath = `${currentPath}/${path}`;
135+
break
136+
} else {
137+
const parentDirectory = _path.dirname(currentPath);
138+
if (parentDirectory === currentPath) { // we hit the top directory
139+
break;
140+
}
141+
currentPath = parentDirectory
142+
}
143+
}
129144
super(absolutePath);
145+
this.configDirectoryPath =_path.dirname(absolutePath);
130146
}
131147

132148
getFunctions() {

0 commit comments

Comments
 (0)