appwrite-utils-cli 0.10.6 → 0.10.62

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,8 @@ This updated CLI ensures that developers have robust tools at their fingertips t
147
147
 
148
148
  ## Changelog
149
149
 
150
+ - 0.10.62: Made `Deploy Function(s)` also update the functions, as not all things (timeout, specification, etc.) are updated via deploy
151
+ - 0.10.61: Fixed ignore haha, also added `ignore` to the `Functions` config, to specify what to ignore when creating the `.tar.gz` file
150
152
  - 0.10.051: Added `node_modules` and a few others to the ignore
151
153
  - 0.10.05: Made deploy function into deploy function(s) -- so you can do more than one at a time
152
154
  - 0.10.04: Fixed stupid progress bar not updating -- also fixed double text
@@ -1,4 +1,4 @@
1
- import { Client } from "node-appwrite";
1
+ import { Client, type Models } from "node-appwrite";
2
2
  import { type AppwriteFunction } from "appwrite-utils";
3
- export declare const deployFunction: (client: Client, functionId: string, codePath: string, activate?: boolean, entrypoint?: string, commands?: string) => Promise<import("node-appwrite").Models.Deployment>;
4
- export declare const deployLocalFunction: (client: Client, functionName: string, functionConfig: AppwriteFunction, functionPath?: string) => Promise<import("node-appwrite").Models.Deployment>;
3
+ export declare const deployFunction: (client: Client, functionId: string, codePath: string, activate?: boolean, entrypoint?: string, commands?: string, ignored?: string[]) => Promise<Models.Deployment>;
4
+ export declare const deployLocalFunction: (client: Client, functionName: string, functionConfig: AppwriteFunction, functionPath?: string) => Promise<Models.Deployment>;
@@ -1,14 +1,14 @@
1
1
  import { Client, Functions, Runtime } from "node-appwrite";
2
2
  import { InputFile } from "node-appwrite/file";
3
3
  import { create as createTarball } from "tar";
4
- import { join } from "node:path";
4
+ import { join, relative } from "node:path";
5
5
  import fs from "node:fs";
6
6
  import { platform } from "node:os";
7
7
  import {} from "appwrite-utils";
8
8
  import chalk from "chalk";
9
9
  import cliProgress from "cli-progress";
10
10
  import { execSync } from "child_process";
11
- import { createFunction, getFunction, updateFunctionSpecifications, } from "./methods.js";
11
+ import { createFunction, getFunction, updateFunction, updateFunctionSpecifications, } from "./methods.js";
12
12
  import ignore from "ignore";
13
13
  const findFunctionDirectory = (basePath, functionName) => {
14
14
  const normalizedName = functionName.toLowerCase().replace(/\s+/g, "-");
@@ -27,18 +27,12 @@ const findFunctionDirectory = (basePath, functionName) => {
27
27
  }
28
28
  return undefined;
29
29
  };
30
- export const deployFunction = async (client, functionId, codePath, activate = true, entrypoint = "index.js", commands) => {
30
+ export const deployFunction = async (client, functionId, codePath, activate = true, entrypoint = "index.js", commands = "npm install", ignored = ["node_modules", ".git", ".vscode", ".DS_Store"]) => {
31
31
  const functions = new Functions(client);
32
32
  console.log(chalk.blue("Preparing function deployment..."));
33
- // Setup ignore rules
34
- const ig = ignore.default();
35
- ig.add(["node_modules", ".git", ".vscode", ".DS_Store"]); // Common directories to ignore
36
- // Read .gitignore if it exists
37
- const gitignorePath = join(codePath, ".gitignore");
38
- if (fs.existsSync(gitignorePath)) {
39
- const gitignoreContent = fs.readFileSync(gitignorePath, "utf8");
40
- ig.add(gitignoreContent);
41
- }
33
+ // Convert ignored patterns to lowercase for case-insensitive comparison
34
+ const ignoredLower = ignored.map((pattern) => pattern.toLowerCase());
35
+ const tarPath = join(process.cwd(), `function-${functionId}.tar.gz`);
42
36
  const progressBar = new cliProgress.SingleBar({
43
37
  format: "Uploading |" +
44
38
  chalk.cyan("{bar}") +
@@ -47,12 +41,15 @@ export const deployFunction = async (client, functionId, codePath, activate = tr
47
41
  barIncompleteChar: "░",
48
42
  hideCursor: true,
49
43
  });
50
- const tarPath = join(process.cwd(), `function-${functionId}.tar.gz`);
51
44
  await createTarball({
52
45
  gzip: true,
53
46
  file: tarPath,
54
47
  cwd: codePath,
55
- filter: (path) => !ig.ignores(path), // Use ignore to filter files
48
+ filter: (path, stat) => {
49
+ const relativePath = relative(codePath, join(codePath, path)).toLowerCase();
50
+ return !ignoredLower.some((pattern) => relativePath.startsWith(pattern) ||
51
+ relativePath.includes(`/${pattern}`));
52
+ },
56
53
  }, ["."]);
57
54
  const fileBuffer = await fs.promises.readFile(tarPath);
58
55
  const fileObject = InputFile.fromBuffer(new Uint8Array(fileBuffer), `function-${functionId}.tar.gz`);
@@ -95,8 +92,9 @@ export const deployFunction = async (client, functionId, codePath, activate = tr
95
92
  };
96
93
  export const deployLocalFunction = async (client, functionName, functionConfig, functionPath) => {
97
94
  let functionExists = true;
95
+ let functionThatExists;
98
96
  try {
99
- await getFunction(client, functionConfig.$id);
97
+ functionThatExists = await getFunction(client, functionConfig.$id);
100
98
  }
101
99
  catch (error) {
102
100
  functionExists = false;
@@ -129,13 +127,14 @@ export const deployLocalFunction = async (client, functionName, functionConfig,
129
127
  }
130
128
  // Only create function if it doesn't exist
131
129
  if (!functionExists) {
132
- await createFunction(client, functionConfig.$id, functionConfig.name, functionConfig.runtime, functionConfig.execute, functionConfig.events, functionConfig.schedule, functionConfig.timeout, functionConfig.enabled, functionConfig.logging, functionConfig.entrypoint, functionConfig.commands);
130
+ await createFunction(client, functionConfig.$id, functionConfig.name, functionConfig.runtime, functionConfig.execute, functionConfig.events, functionConfig.schedule, functionConfig.timeout, functionConfig.enabled, functionConfig.logging, functionConfig.entrypoint, functionConfig.commands, functionConfig.scopes, functionConfig.installationId, functionConfig.providerRepositoryId, functionConfig.providerBranch, functionConfig.providerSilentMode, functionConfig.providerRootDirectory, functionConfig.templateRepository, functionConfig.templateOwner, functionConfig.templateRootDirectory, functionConfig.templateVersion, functionConfig.specification);
133
131
  }
134
- if (functionConfig.specification) {
135
- await updateFunctionSpecifications(client, functionConfig.$id, functionConfig.specification);
132
+ else {
133
+ console.log(chalk.blue("Updating function..."));
134
+ await updateFunction(client, functionConfig.$id, functionConfig.name, functionConfig.runtime, functionConfig.execute, functionConfig.events, functionConfig.schedule, functionConfig.timeout, functionConfig.enabled, functionConfig.logging, functionConfig.entrypoint, functionConfig.commands, functionConfig.scopes, functionConfig.installationId, functionConfig.providerRepositoryId, functionConfig.providerBranch, functionConfig.providerSilentMode, functionConfig.providerRootDirectory, functionConfig.specification);
136
135
  }
137
136
  const deployPath = functionConfig.deployDir
138
137
  ? join(resolvedPath, functionConfig.deployDir)
139
138
  : resolvedPath;
140
- return deployFunction(client, functionConfig.$id, deployPath, true, functionConfig.entrypoint, functionConfig.commands);
139
+ return deployFunction(client, functionConfig.$id, deployPath, true, functionConfig.entrypoint, functionConfig.commands, functionConfig.ignore);
141
140
  };
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.06",
4
+ "version": "0.10.62",
5
5
  "main": "src/main.ts",
6
6
  "type": "module",
7
7
  "repository": {
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@types/inquirer": "^9.0.7",
34
- "appwrite-utils": "^0.3.97",
34
+ "appwrite-utils": "^0.3.98",
35
35
  "chalk": "^5.3.0",
36
36
  "cli-progress": "^3.12.0",
37
37
  "commander": "^12.1.0",
@@ -1,7 +1,7 @@
1
- import { Client, Functions, Runtime } from "node-appwrite";
1
+ import { Client, Functions, Runtime, type Models } from "node-appwrite";
2
2
  import { InputFile } from "node-appwrite/file";
3
3
  import { create as createTarball } from "tar";
4
- import { join } from "node:path";
4
+ import { join, relative } from "node:path";
5
5
  import fs from "node:fs";
6
6
  import { platform } from "node:os";
7
7
  import { type AppwriteFunction, type Specification } from "appwrite-utils";
@@ -11,6 +11,7 @@ import { execSync } from "child_process";
11
11
  import {
12
12
  createFunction,
13
13
  getFunction,
14
+ updateFunction,
14
15
  updateFunctionSpecifications,
15
16
  } from "./methods.js";
16
17
  import ignore from "ignore";
@@ -45,21 +46,16 @@ export const deployFunction = async (
45
46
  codePath: string,
46
47
  activate: boolean = true,
47
48
  entrypoint: string = "index.js",
48
- commands?: string
49
+ commands: string = "npm install",
50
+ ignored: string[] = ["node_modules", ".git", ".vscode", ".DS_Store"]
49
51
  ) => {
50
52
  const functions = new Functions(client);
51
53
  console.log(chalk.blue("Preparing function deployment..."));
52
54
 
53
- // Setup ignore rules
54
- const ig = ignore.default();
55
- ig.add(["node_modules", ".git", ".vscode", ".DS_Store"]); // Common directories to ignore
55
+ // Convert ignored patterns to lowercase for case-insensitive comparison
56
+ const ignoredLower = ignored.map((pattern) => pattern.toLowerCase());
56
57
 
57
- // Read .gitignore if it exists
58
- const gitignorePath = join(codePath, ".gitignore");
59
- if (fs.existsSync(gitignorePath)) {
60
- const gitignoreContent = fs.readFileSync(gitignorePath, "utf8");
61
- ig.add(gitignoreContent);
62
- }
58
+ const tarPath = join(process.cwd(), `function-${functionId}.tar.gz`);
63
59
 
64
60
  const progressBar = new cliProgress.SingleBar({
65
61
  format:
@@ -71,14 +67,22 @@ export const deployFunction = async (
71
67
  hideCursor: true,
72
68
  });
73
69
 
74
- const tarPath = join(process.cwd(), `function-${functionId}.tar.gz`);
75
-
76
70
  await createTarball(
77
71
  {
78
72
  gzip: true,
79
73
  file: tarPath,
80
74
  cwd: codePath,
81
- filter: (path) => !ig.ignores(path), // Use ignore to filter files
75
+ filter: (path, stat) => {
76
+ const relativePath = relative(
77
+ codePath,
78
+ join(codePath, path)
79
+ ).toLowerCase();
80
+ return !ignoredLower.some(
81
+ (pattern) =>
82
+ relativePath.startsWith(pattern) ||
83
+ relativePath.includes(`/${pattern}`)
84
+ );
85
+ },
82
86
  },
83
87
  ["."]
84
88
  );
@@ -144,8 +148,9 @@ export const deployLocalFunction = async (
144
148
  functionPath?: string
145
149
  ) => {
146
150
  let functionExists = true;
151
+ let functionThatExists: Models.Function;
147
152
  try {
148
- await getFunction(client, functionConfig.$id);
153
+ functionThatExists = await getFunction(client, functionConfig.$id);
149
154
  } catch (error) {
150
155
  functionExists = false;
151
156
  }
@@ -201,14 +206,40 @@ export const deployLocalFunction = async (
201
206
  functionConfig.enabled,
202
207
  functionConfig.logging,
203
208
  functionConfig.entrypoint,
204
- functionConfig.commands
209
+ functionConfig.commands,
210
+ functionConfig.scopes,
211
+ functionConfig.installationId,
212
+ functionConfig.providerRepositoryId,
213
+ functionConfig.providerBranch,
214
+ functionConfig.providerSilentMode,
215
+ functionConfig.providerRootDirectory,
216
+ functionConfig.templateRepository,
217
+ functionConfig.templateOwner,
218
+ functionConfig.templateRootDirectory,
219
+ functionConfig.templateVersion,
220
+ functionConfig.specification
205
221
  );
206
- }
207
-
208
- if (functionConfig.specification) {
209
- await updateFunctionSpecifications(
222
+ } else {
223
+ console.log(chalk.blue("Updating function..."));
224
+ await updateFunction(
210
225
  client,
211
226
  functionConfig.$id,
227
+ functionConfig.name,
228
+ functionConfig.runtime as Runtime,
229
+ functionConfig.execute,
230
+ functionConfig.events,
231
+ functionConfig.schedule,
232
+ functionConfig.timeout,
233
+ functionConfig.enabled,
234
+ functionConfig.logging,
235
+ functionConfig.entrypoint,
236
+ functionConfig.commands,
237
+ functionConfig.scopes,
238
+ functionConfig.installationId,
239
+ functionConfig.providerRepositoryId,
240
+ functionConfig.providerBranch,
241
+ functionConfig.providerSilentMode,
242
+ functionConfig.providerRootDirectory,
212
243
  functionConfig.specification
213
244
  );
214
245
  }
@@ -223,6 +254,7 @@ export const deployLocalFunction = async (
223
254
  deployPath,
224
255
  true,
225
256
  functionConfig.entrypoint,
226
- functionConfig.commands
257
+ functionConfig.commands,
258
+ functionConfig.ignore
227
259
  );
228
260
  };