appwrite-utils-cli 0.9.57 → 0.9.59
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 +2 -0
- package/dist/migrations/schemaStrings.js +2 -2
- package/dist/setupController.d.ts +3 -0
- package/dist/setupController.js +16 -0
- package/dist/utils/loadConfigs.js +8 -5
- package/dist/utils/schemaStrings.js +2 -2
- package/package.json +1 -1
- package/src/setupController.ts +18 -1
- package/src/utils/loadConfigs.ts +8 -5
- package/src/utils/schemaStrings.ts +2 -2
package/README.md
CHANGED
@@ -124,6 +124,8 @@ This updated CLI ensures that developers have robust tools at their fingertips t
|
|
124
124
|
|
125
125
|
## Changelog
|
126
126
|
|
127
|
+
- 0.9.59: Fix to Windows path names for loading config
|
128
|
+
- 0.9.58: The same as before, I just missed it hah
|
127
129
|
- 0.9.57: Changed generated schema type of `$createdAt` and `$updatedAt` to string from `string | Date` cause honestly if you want a date just parse it
|
128
130
|
- 0.9.56: Changed the updateAttribute so it doesn't always update attributes and hopefully fixed the required error
|
129
131
|
- 0.9.55: Updated to use `node-appwrite@14` for appwrite 1.6.0
|
@@ -233,8 +233,8 @@ export class SchemaGenerator {
|
|
233
233
|
let schemaString = `${imports}\n\n`;
|
234
234
|
schemaString += `export const ${pascalName}SchemaBase = z.object({\n`;
|
235
235
|
schemaString += ` $id: z.string().optional(),\n`;
|
236
|
-
schemaString += ` $createdAt: z.
|
237
|
-
schemaString += ` $updatedAt: z.
|
236
|
+
schemaString += ` $createdAt: z.string().optional(),\n`;
|
237
|
+
schemaString += ` $updatedAt: z.string().optional(),\n`;
|
238
238
|
for (const attribute of attributes) {
|
239
239
|
if (attribute.type === "relationship") {
|
240
240
|
continue;
|
@@ -1,6 +1,9 @@
|
|
1
|
+
import type { AppwriteConfig } from "appwrite-utils";
|
1
2
|
export declare class SetupController {
|
2
3
|
private currentDir;
|
4
|
+
private config;
|
3
5
|
constructor(currentDir: string);
|
4
6
|
runSetup(withExampleData?: boolean): Promise<void>;
|
7
|
+
loadConfig(): Promise<AppwriteConfig | null>;
|
5
8
|
hasExistingConfig(): boolean;
|
6
9
|
}
|
package/dist/setupController.js
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
import { setupDirsFiles } from "./utils/setupFiles.js";
|
2
|
+
import { loadConfig } from "./utils/loadConfigs.js";
|
2
3
|
import path from "path";
|
3
4
|
import fs from "fs";
|
4
5
|
export class SetupController {
|
5
6
|
currentDir;
|
7
|
+
config = null;
|
6
8
|
constructor(currentDir) {
|
7
9
|
this.currentDir = currentDir;
|
8
10
|
}
|
@@ -10,6 +12,20 @@ export class SetupController {
|
|
10
12
|
await setupDirsFiles(withExampleData, this.currentDir);
|
11
13
|
console.log("Setup completed successfully.");
|
12
14
|
}
|
15
|
+
async loadConfig() {
|
16
|
+
if (this.hasExistingConfig()) {
|
17
|
+
try {
|
18
|
+
const appwriteDir = path.join(this.currentDir, "appwrite");
|
19
|
+
this.config = await loadConfig(appwriteDir);
|
20
|
+
return this.config;
|
21
|
+
}
|
22
|
+
catch (error) {
|
23
|
+
console.error("Error loading config:", error);
|
24
|
+
return null;
|
25
|
+
}
|
26
|
+
}
|
27
|
+
return null;
|
28
|
+
}
|
13
29
|
hasExistingConfig() {
|
14
30
|
const configPath = path.join(this.currentDir, "appwrite", "appwriteConfig.ts");
|
15
31
|
return fs.existsSync(configPath);
|
@@ -2,6 +2,7 @@ import path from "path";
|
|
2
2
|
import fs from "fs";
|
3
3
|
import {} from "appwrite-utils";
|
4
4
|
import { register } from "tsx/esm/api"; // Import the register function
|
5
|
+
import { fileURLToPath } from "node:url";
|
5
6
|
/**
|
6
7
|
* Recursively searches for a file named 'appwriteConfig.ts' starting from the given directory.
|
7
8
|
* @param dir The directory to start the search from.
|
@@ -32,15 +33,17 @@ export const findAppwriteConfig = (dir) => {
|
|
32
33
|
export const loadConfig = async (configDir) => {
|
33
34
|
const unregister = register(); // Register tsx enhancement
|
34
35
|
try {
|
35
|
-
const configPath = path.
|
36
|
+
const configPath = path.join(configDir, "appwriteConfig.ts");
|
36
37
|
console.log(`Loading config from: ${configPath}`);
|
37
|
-
const
|
38
|
-
const
|
38
|
+
const configUrl = fileURLToPath(new URL(configPath, import.meta.url));
|
39
|
+
const config = (await import(configUrl)).default;
|
40
|
+
const collectionsDir = path.join(configDir, "collections");
|
39
41
|
const collectionFiles = fs.readdirSync(collectionsDir);
|
40
42
|
config.collections = [];
|
41
43
|
for (const file of collectionFiles) {
|
42
|
-
const filePath = path.
|
43
|
-
const
|
44
|
+
const filePath = path.join(collectionsDir, file);
|
45
|
+
const fileUrl = fileURLToPath(new URL(filePath, import.meta.url));
|
46
|
+
const collectionModule = (await import(fileUrl)).default;
|
44
47
|
config.collections.push(collectionModule);
|
45
48
|
}
|
46
49
|
return config;
|
@@ -233,8 +233,8 @@ export class SchemaGenerator {
|
|
233
233
|
let schemaString = `${imports}\n\n`;
|
234
234
|
schemaString += `export const ${pascalName}SchemaBase = z.object({\n`;
|
235
235
|
schemaString += ` $id: z.string().optional(),\n`;
|
236
|
-
schemaString += ` $createdAt: z.
|
237
|
-
schemaString += ` $updatedAt: z.
|
236
|
+
schemaString += ` $createdAt: z.string().optional(),\n`;
|
237
|
+
schemaString += ` $updatedAt: z.string().optional(),\n`;
|
238
238
|
for (const attribute of attributes) {
|
239
239
|
if (attribute.type === "relationship") {
|
240
240
|
continue;
|
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.9.
|
4
|
+
"version": "0.9.59",
|
5
5
|
"main": "src/main.ts",
|
6
6
|
"type": "module",
|
7
7
|
"repository": {
|
package/src/setupController.ts
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
import { setupDirsFiles } from "./utils/setupFiles.js";
|
2
|
+
import { loadConfig } from "./utils/loadConfigs.js";
|
2
3
|
import path from "path";
|
3
4
|
import fs from "fs";
|
5
|
+
import type { AppwriteConfig } from "appwrite-utils";
|
4
6
|
|
5
7
|
export class SetupController {
|
6
8
|
private currentDir: string;
|
9
|
+
private config: AppwriteConfig | null = null;
|
7
10
|
|
8
11
|
constructor(currentDir: string) {
|
9
12
|
this.currentDir = currentDir;
|
@@ -14,6 +17,20 @@ export class SetupController {
|
|
14
17
|
console.log("Setup completed successfully.");
|
15
18
|
}
|
16
19
|
|
20
|
+
async loadConfig(): Promise<AppwriteConfig | null> {
|
21
|
+
if (this.hasExistingConfig()) {
|
22
|
+
try {
|
23
|
+
const appwriteDir = path.join(this.currentDir, "appwrite");
|
24
|
+
this.config = await loadConfig(appwriteDir);
|
25
|
+
return this.config;
|
26
|
+
} catch (error) {
|
27
|
+
console.error("Error loading config:", error);
|
28
|
+
return null;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
return null;
|
32
|
+
}
|
33
|
+
|
17
34
|
hasExistingConfig(): boolean {
|
18
35
|
const configPath = path.join(
|
19
36
|
this.currentDir,
|
@@ -22,4 +39,4 @@ export class SetupController {
|
|
22
39
|
);
|
23
40
|
return fs.existsSync(configPath);
|
24
41
|
}
|
25
|
-
}
|
42
|
+
}
|
package/src/utils/loadConfigs.ts
CHANGED
@@ -2,6 +2,7 @@ import path from "path";
|
|
2
2
|
import fs from "fs";
|
3
3
|
import { type AppwriteConfig, type Collection } from "appwrite-utils";
|
4
4
|
import { register } from "tsx/esm/api"; // Import the register function
|
5
|
+
import { fileURLToPath } from "node:url";
|
5
6
|
|
6
7
|
/**
|
7
8
|
* Recursively searches for a file named 'appwriteConfig.ts' starting from the given directory.
|
@@ -37,18 +38,20 @@ export const loadConfig = async (
|
|
37
38
|
const unregister = register(); // Register tsx enhancement
|
38
39
|
|
39
40
|
try {
|
40
|
-
const configPath = path.
|
41
|
+
const configPath = path.join(configDir, "appwriteConfig.ts");
|
41
42
|
console.log(`Loading config from: ${configPath}`);
|
42
|
-
const
|
43
|
+
const configUrl = fileURLToPath(new URL(configPath, import.meta.url));
|
44
|
+
const config = (await import(configUrl)).default as AppwriteConfig;
|
43
45
|
|
44
|
-
const collectionsDir = path.
|
46
|
+
const collectionsDir = path.join(configDir, "collections");
|
45
47
|
const collectionFiles = fs.readdirSync(collectionsDir);
|
46
48
|
|
47
49
|
config.collections = [];
|
48
50
|
|
49
51
|
for (const file of collectionFiles) {
|
50
|
-
const filePath = path.
|
51
|
-
const
|
52
|
+
const filePath = path.join(collectionsDir, file);
|
53
|
+
const fileUrl = fileURLToPath(new URL(filePath, import.meta.url));
|
54
|
+
const collectionModule = (await import(fileUrl)).default as Collection;
|
52
55
|
config.collections.push(collectionModule);
|
53
56
|
}
|
54
57
|
|
@@ -302,8 +302,8 @@ export class SchemaGenerator {
|
|
302
302
|
let schemaString = `${imports}\n\n`;
|
303
303
|
schemaString += `export const ${pascalName}SchemaBase = z.object({\n`;
|
304
304
|
schemaString += ` $id: z.string().optional(),\n`;
|
305
|
-
schemaString += ` $createdAt: z.
|
306
|
-
schemaString += ` $updatedAt: z.
|
305
|
+
schemaString += ` $createdAt: z.string().optional(),\n`;
|
306
|
+
schemaString += ` $updatedAt: z.string().optional(),\n`;
|
307
307
|
for (const attribute of attributes) {
|
308
308
|
if (attribute.type === "relationship") {
|
309
309
|
continue;
|