Skip to content

Commit 8662a88

Browse files
authored
Merge pull request #103 from christyjacob4/feat-na-appwrite-cli
fix: fixed issues with function packaging
2 parents 2eb9774 + c723528 commit 8662a88

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

templates/cli/app/services/help.php.twig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
33
namespace {{ spec.title | caseUcfirst }}\Services;
44
5-
printf("
5+
echo "\e[0;31;m
66
_ _ _
77
/_\ _ __ _ ____ ___ __(_) |_ ___
88
//_\\| '_ \| '_ \ \ /\ / / '__| | __/ _ \
99
/ _ \ |_) | |_) \ V V /| | | | || __/
1010
\_/ \_/ .__/| .__/ \_/\_/ |_| |_|\__\___|
1111
|_| |_|
1212
13-
");
13+
\e[0m" ;
14+
1415
printf("\nUsage : appwrite [SERVICE] [COMMAND] --[OPTION]\n\n");
1516
printf("Services :\n");
1617
$mask = "\t%-20.20s %-125.125s\n";

templates/cli/app/services/service.php.twig

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,31 @@ $cli
6969
7070
{% for parameter in method.parameters.body %}
7171
72-
{% if parameter.type == 'file' %}
72+
{% if parameter.type == 'file' and method.packaging %}
73+
$cloudFunctionPath = realpath(__DIR__.'/../../../files/'.${{ parameter.name | caseCamel }});
74+
$cloudFunctionParentDir = dirname($cloudFunctionPath, 1);
75+
$cloudFunctionDirName = basename(${{ parameter.name | caseCamel }});
76+
if (file_exists($cloudFunctionPath) === false ) {
77+
throw new Exception("Path doesn't exist. Please ensure that the path is within the current directory. ");
78+
}
79+
$archiveName = 'code.tar.gz';
80+
$volumeMountPoint = realpath(__DIR__.'/../../../files/');
81+
exec("tar -zcvf $archiveName -C ${cloudFunctionParentDir} $cloudFunctionDirName && mv ${archiveName} ${volumeMountPoint}");
82+
$archivePath = realpath($volumeMountPoint."/$archiveName");$archivePath = realpath($volumeMountPoint."/$archiveName");
83+
$cFile = new \CURLFile($archivePath, 'application/x-gzip' , basename($archivePath));
84+
85+
$params['{{ parameter.name }}'] = $cFile;
86+
87+
{% elseif parameter.type == 'file' %}
88+
7389
${{ parameter.name | caseCamel }} = realpath(__DIR__.'/../../../files/'.${{ parameter.name | caseCamel }});
7490
if (file_exists(${{ parameter.name | caseCamel }}) === false ) {
7591
throw new Exception("Path doesn't exist. Please ensure that the path is within the current directory. ");
7692
}
77-
{% if method.packaging %}
78-
$archive_file_name = '{{ parameter.name | caseCamel }}.tar';
79-
$archive_file_path = dirname(${{ parameter.name | caseCamel }}, 1)."/${archive_file_name}";
80-
$archive = new PharData($archive_file_path);
81-
$archive->buildFromDirectory(${{ parameter.name | caseCamel }});
82-
$archive->compress(Phar::GZ);
83-
${{ parameter.name | caseCamel }} = $archive_file_path.'.gz';
84-
{% endif %}
93+
8594
$cFile = new \CURLFile(${{ parameter.name | caseCamel }}, {% if method.packaging %} 'application/x-gzip' {% else %} 'image/png' {% endif %}, basename(${{ parameter.name | caseCamel }}));
8695
$params['{{ parameter.name }}'] = $cFile;
96+
8797
{% else %}
8898
$params['{{ parameter.name }}'] = ${{ parameter.name | caseCamel }};
8999
{% endif %}
@@ -117,8 +127,7 @@ $cli
117127
{% endif %}
118128
119129
{% if method.packaging %}
120-
unlink($archive_file_path); // as we already obtained a tar.gz
121-
unlink($archive_file_path.'.gz');
130+
unlink($archivePath);
122131
{% endif %}
123132
});
124133

0 commit comments

Comments
 (0)