appwrite-utils-cli 0.10.2 → 0.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -147,6 +147,7 @@ This updated CLI ensures that developers have robust tools at their fingertips t
147
147
 
148
148
  ## Changelog
149
149
 
150
+ - 0.10.03: Fixed `syncDb` to push the configurations properly, accidentally hurt it during `synchronizeConfigurations`
150
151
  - 0.10.02: Updated `wipeCollection` to handle errors gracefully
151
152
  - 0.10.01: Fixed `predeployCommands` to work
152
153
  - 0.10.001: Updated `deployFunction` to not updateConfig if it's already present
@@ -718,28 +718,46 @@ export class InteractiveCLI {
718
718
  }, bucketId.length > 0 ? bucketId : ulid());
719
719
  }
720
720
  async syncDb() {
721
- console.log(chalk.yellow("Syncing database..."));
722
- const functionsClient = new Functions(this.controller.appwriteServer);
723
- const databases = await this.selectDatabases(await fetchAllDatabases(this.controller.database), chalk.blue("Select databases to synchronize:"), true);
724
- const collections = await this.selectCollections(databases[0], this.controller.database, chalk.blue("Select collections to synchronize:"), true, true // prefer local
721
+ console.log(chalk.blue("Pushing local configuration to Appwrite..."));
722
+ const databases = await this.selectDatabases(this.getLocalDatabases(), chalk.blue("Select local databases to push:"), true);
723
+ if (!databases.length) {
724
+ console.log(chalk.yellow("No databases selected. Skipping database sync."));
725
+ return;
726
+ }
727
+ const collections = await this.selectCollections(databases[0], this.controller.database, chalk.blue("Select local collections to push:"), true, true // prefer local
725
728
  );
726
- const answer = await inquirer.prompt([
729
+ const { syncFunctions } = await inquirer.prompt([
727
730
  {
728
731
  type: "confirm",
729
732
  name: "syncFunctions",
730
- message: "Do you want to synchronize functions?",
733
+ message: "Do you want to push local functions to remote?",
731
734
  default: false,
732
735
  },
733
736
  ]);
734
- if (answer.syncFunctions) {
735
- const functions = await this.selectFunctions(chalk.blue("Select functions to synchronize:"), true, true // prefer local
736
- );
737
+ try {
738
+ // First sync databases and collections
737
739
  await this.controller.syncDb(databases, collections);
738
- for (const func of functions) {
739
- await deployLocalFunction(this.controller.appwriteServer, func.dirPath || `functions/${func.name}`, func);
740
+ console.log(chalk.green("Database and collections pushed successfully"));
741
+ // Then handle functions if requested
742
+ if (syncFunctions && this.controller.config?.functions?.length) {
743
+ const functions = await this.selectFunctions(chalk.blue("Select local functions to push:"), true, true // prefer local
744
+ );
745
+ for (const func of functions) {
746
+ try {
747
+ await this.controller.deployFunction(func.name);
748
+ console.log(chalk.green(`Function ${func.name} deployed successfully`));
749
+ }
750
+ catch (error) {
751
+ console.error(chalk.red(`Failed to deploy function ${func.name}:`), error);
752
+ }
753
+ }
740
754
  }
755
+ console.log(chalk.green("Local configuration push completed successfully!"));
756
+ }
757
+ catch (error) {
758
+ console.error(chalk.red("Failed to push local configuration:"), error);
759
+ throw error;
741
760
  }
742
- console.log(chalk.green("Database sync completed."));
743
761
  }
744
762
  async synchronizeConfigurations() {
745
763
  console.log(chalk.blue("Synchronizing configurations..."));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "appwrite-utils-cli",
3
3
  "description": "Appwrite Utility Functions to help with database management, data conversion, data import, migrations, and much more. Meant to be used as a CLI tool, I do not recommend installing this in frontend environments.",
4
- "version": "0.10.02",
4
+ "version": "0.10.03",
5
5
  "main": "src/main.ts",
6
6
  "type": "module",
7
7
  "repository": {
@@ -977,44 +977,73 @@ export class InteractiveCLI {
977
977
  }
978
978
 
979
979
  private async syncDb(): Promise<void> {
980
- console.log(chalk.yellow("Syncing database..."));
981
- const functionsClient = new Functions(this.controller!.appwriteServer!);
980
+ console.log(chalk.blue("Pushing local configuration to Appwrite..."));
981
+
982
982
  const databases = await this.selectDatabases(
983
- await fetchAllDatabases(this.controller!.database!),
984
- chalk.blue("Select databases to synchronize:"),
983
+ this.getLocalDatabases(),
984
+ chalk.blue("Select local databases to push:"),
985
985
  true
986
986
  );
987
+
988
+ if (!databases.length) {
989
+ console.log(
990
+ chalk.yellow("No databases selected. Skipping database sync.")
991
+ );
992
+ return;
993
+ }
994
+
987
995
  const collections = await this.selectCollections(
988
996
  databases[0],
989
997
  this.controller!.database!,
990
- chalk.blue("Select collections to synchronize:"),
998
+ chalk.blue("Select local collections to push:"),
991
999
  true,
992
1000
  true // prefer local
993
1001
  );
994
- const answer = await inquirer.prompt([
1002
+
1003
+ const { syncFunctions } = await inquirer.prompt([
995
1004
  {
996
1005
  type: "confirm",
997
1006
  name: "syncFunctions",
998
- message: "Do you want to synchronize functions?",
1007
+ message: "Do you want to push local functions to remote?",
999
1008
  default: false,
1000
1009
  },
1001
1010
  ]);
1002
- if (answer.syncFunctions) {
1003
- const functions = await this.selectFunctions(
1004
- chalk.blue("Select functions to synchronize:"),
1005
- true,
1006
- true // prefer local
1007
- );
1011
+
1012
+ try {
1013
+ // First sync databases and collections
1008
1014
  await this.controller!.syncDb(databases, collections);
1009
- for (const func of functions) {
1010
- await deployLocalFunction(
1011
- this.controller!.appwriteServer!,
1012
- func.dirPath || `functions/${func.name}`,
1013
- func
1015
+ console.log(chalk.green("Database and collections pushed successfully"));
1016
+
1017
+ // Then handle functions if requested
1018
+ if (syncFunctions && this.controller!.config?.functions?.length) {
1019
+ const functions = await this.selectFunctions(
1020
+ chalk.blue("Select local functions to push:"),
1021
+ true,
1022
+ true // prefer local
1014
1023
  );
1024
+
1025
+ for (const func of functions) {
1026
+ try {
1027
+ await this.controller!.deployFunction(func.name);
1028
+ console.log(
1029
+ chalk.green(`Function ${func.name} deployed successfully`)
1030
+ );
1031
+ } catch (error) {
1032
+ console.error(
1033
+ chalk.red(`Failed to deploy function ${func.name}:`),
1034
+ error
1035
+ );
1036
+ }
1037
+ }
1015
1038
  }
1039
+
1040
+ console.log(
1041
+ chalk.green("Local configuration push completed successfully!")
1042
+ );
1043
+ } catch (error) {
1044
+ console.error(chalk.red("Failed to push local configuration:"), error);
1045
+ throw error;
1016
1046
  }
1017
- console.log(chalk.green("Database sync completed."));
1018
1047
  }
1019
1048
 
1020
1049
  private async synchronizeConfigurations(): Promise<void> {