appwrite-utils-cli 1.2.9 → 1.2.11
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/dist/config/yamlConfig.js +6 -4
- package/dist/interactiveCLI.js +7 -6
- package/dist/shared/schemaGenerator.d.ts +1 -1
- package/dist/shared/schemaGenerator.js +12 -7
- package/dist/utilsController.js +2 -0
- package/package.json +1 -1
- package/src/config/yamlConfig.ts +6 -4
- package/src/interactiveCLI.ts +10 -10
- package/src/shared/schemaGenerator.ts +12 -8
- package/src/utilsController.ts +3 -0
@@ -236,10 +236,10 @@ export const loadYamlConfig = async (configPath) => {
|
|
236
236
|
export const findYamlConfig = (startDir) => {
|
237
237
|
// First check current directory for YAML configs
|
238
238
|
const possiblePaths = [
|
239
|
-
path.join(startDir, ".appwrite", "appwriteConfig.yaml"),
|
240
|
-
path.join(startDir, ".appwrite", "appwriteConfig.yml"),
|
241
239
|
path.join(startDir, ".appwrite", "config.yaml"),
|
242
240
|
path.join(startDir, ".appwrite", "config.yml"),
|
241
|
+
path.join(startDir, ".appwrite", "appwriteConfig.yaml"),
|
242
|
+
path.join(startDir, ".appwrite", "appwriteConfig.yml"),
|
243
243
|
path.join(startDir, "appwrite.yaml"),
|
244
244
|
path.join(startDir, "appwrite.yml"),
|
245
245
|
];
|
@@ -257,6 +257,8 @@ export const findYamlConfig = (startDir) => {
|
|
257
257
|
const parentDir = path.dirname(startDir);
|
258
258
|
if (parentDir !== startDir && path.basename(parentDir) !== 'node_modules') {
|
259
259
|
const parentPossiblePaths = [
|
260
|
+
path.join(parentDir, ".appwrite", "config.yaml"),
|
261
|
+
path.join(parentDir, ".appwrite", "config.yml"),
|
260
262
|
path.join(parentDir, ".appwrite", "appwriteConfig.yaml"),
|
261
263
|
path.join(parentDir, ".appwrite", "appwriteConfig.yml"),
|
262
264
|
path.join(parentDir, "appwrite.yaml"),
|
@@ -325,10 +327,10 @@ const findYamlConfigRecursive = (dir, depth = 0) => {
|
|
325
327
|
// Check if this is an .appwrite directory
|
326
328
|
if (entry.name === ".appwrite") {
|
327
329
|
const configPaths = [
|
328
|
-
path.join(fullPath, "appwriteConfig.yaml"),
|
329
|
-
path.join(fullPath, "appwriteConfig.yml"),
|
330
330
|
path.join(fullPath, "config.yaml"),
|
331
331
|
path.join(fullPath, "config.yml"),
|
332
|
+
path.join(fullPath, "appwriteConfig.yaml"),
|
333
|
+
path.join(fullPath, "appwriteConfig.yml"),
|
332
334
|
];
|
333
335
|
for (const configPath of configPaths) {
|
334
336
|
if (fs.existsSync(configPath)) {
|
package/dist/interactiveCLI.js
CHANGED
@@ -879,19 +879,22 @@ export class InteractiveCLI {
|
|
879
879
|
async synchronizeConfigurations() {
|
880
880
|
console.log(chalk.blue("Synchronizing configurations..."));
|
881
881
|
await this.controller.init();
|
882
|
-
// Sync databases and buckets
|
882
|
+
// Sync databases, collections, and buckets
|
883
883
|
const { syncDatabases } = await inquirer.prompt([
|
884
884
|
{
|
885
885
|
type: "confirm",
|
886
886
|
name: "syncDatabases",
|
887
|
-
message: "Do you want to synchronize databases and their buckets?",
|
887
|
+
message: "Do you want to synchronize databases, collections, and their buckets?",
|
888
888
|
default: true,
|
889
889
|
},
|
890
890
|
]);
|
891
891
|
if (syncDatabases) {
|
892
892
|
const remoteDatabases = await fetchAllDatabases(this.controller.database);
|
893
|
+
// Use the controller's synchronizeConfigurations method which handles collections properly
|
894
|
+
console.log(chalk.blue("Pulling collections and generating collection files..."));
|
895
|
+
await this.controller.synchronizeConfigurations(remoteDatabases);
|
896
|
+
// Also configure buckets for any new databases
|
893
897
|
const localDatabases = this.controller.config?.databases || [];
|
894
|
-
// Update config with remote databases that don't exist locally
|
895
898
|
const updatedConfig = await this.configureBuckets({
|
896
899
|
...this.controller.config,
|
897
900
|
databases: [
|
@@ -1065,9 +1068,7 @@ export class InteractiveCLI {
|
|
1065
1068
|
}
|
1066
1069
|
}
|
1067
1070
|
}
|
1068
|
-
//
|
1069
|
-
const schemaGenerator = new SchemaGenerator(this.controller.config, this.controller.getAppwriteFolderPath());
|
1070
|
-
await schemaGenerator.updateConfig(this.controller.config);
|
1071
|
+
// Schema generation and collection file writing is handled by controller.synchronizeConfigurations()
|
1071
1072
|
}
|
1072
1073
|
console.log(chalk.green("✨ Configurations synchronized successfully!"));
|
1073
1074
|
}
|
@@ -6,7 +6,7 @@ export declare class SchemaGenerator {
|
|
6
6
|
constructor(config: AppwriteConfig, appwriteFolderPath: string);
|
7
7
|
updateYamlCollections(): void;
|
8
8
|
updateTsSchemas(): void;
|
9
|
-
updateConfig(config: AppwriteConfig): Promise<void>;
|
9
|
+
updateConfig(config: AppwriteConfig, isYamlConfig?: boolean): Promise<void>;
|
10
10
|
private updateYamlConfig;
|
11
11
|
private updateTypeScriptConfig;
|
12
12
|
private extractRelationships;
|
@@ -154,13 +154,18 @@ export class SchemaGenerator {
|
|
154
154
|
console.log(`Collection schema written to ${collectionFilePath}`);
|
155
155
|
});
|
156
156
|
}
|
157
|
-
async updateConfig(config) {
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
157
|
+
async updateConfig(config, isYamlConfig = false) {
|
158
|
+
if (isYamlConfig) {
|
159
|
+
// User has YAML config - find the config file and update it + generate individual collection files
|
160
|
+
const { findYamlConfig } = await import("../config/yamlConfig.js");
|
161
|
+
const yamlConfigPath = findYamlConfig(this.appwriteFolderPath);
|
162
|
+
if (yamlConfigPath) {
|
163
|
+
await this.updateYamlConfig(config, yamlConfigPath);
|
164
|
+
}
|
165
|
+
else {
|
166
|
+
console.warn("⚠️ YAML config expected but not found, falling back to TypeScript");
|
167
|
+
this.updateTypeScriptConfig(config);
|
168
|
+
}
|
164
169
|
}
|
165
170
|
else {
|
166
171
|
// User has TypeScript config - update the TS file
|
package/dist/utilsController.js
CHANGED
@@ -396,6 +396,8 @@ export class UtilsController {
|
|
396
396
|
}
|
397
397
|
const appwriteToX = new AppwriteToX(configToUse, this.appwriteFolderPath, this.storage);
|
398
398
|
await appwriteToX.toSchemas(databases);
|
399
|
+
// Update the controller's config with the synchronized collections
|
400
|
+
this.config = appwriteToX.updatedConfig;
|
399
401
|
}
|
400
402
|
async syncDb(databases = [], collections = []) {
|
401
403
|
await this.init();
|
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": "1.2.
|
4
|
+
"version": "1.2.11",
|
5
5
|
"main": "src/main.ts",
|
6
6
|
"type": "module",
|
7
7
|
"repository": {
|
package/src/config/yamlConfig.ts
CHANGED
@@ -248,10 +248,10 @@ export const loadYamlConfig = async (configPath: string): Promise<AppwriteConfig
|
|
248
248
|
export const findYamlConfig = (startDir: string): string | null => {
|
249
249
|
// First check current directory for YAML configs
|
250
250
|
const possiblePaths = [
|
251
|
-
path.join(startDir, ".appwrite", "appwriteConfig.yaml"),
|
252
|
-
path.join(startDir, ".appwrite", "appwriteConfig.yml"),
|
253
251
|
path.join(startDir, ".appwrite", "config.yaml"),
|
254
252
|
path.join(startDir, ".appwrite", "config.yml"),
|
253
|
+
path.join(startDir, ".appwrite", "appwriteConfig.yaml"),
|
254
|
+
path.join(startDir, ".appwrite", "appwriteConfig.yml"),
|
255
255
|
path.join(startDir, "appwrite.yaml"),
|
256
256
|
path.join(startDir, "appwrite.yml"),
|
257
257
|
];
|
@@ -272,6 +272,8 @@ export const findYamlConfig = (startDir: string): string | null => {
|
|
272
272
|
const parentDir = path.dirname(startDir);
|
273
273
|
if (parentDir !== startDir && path.basename(parentDir) !== 'node_modules') {
|
274
274
|
const parentPossiblePaths = [
|
275
|
+
path.join(parentDir, ".appwrite", "config.yaml"),
|
276
|
+
path.join(parentDir, ".appwrite", "config.yml"),
|
275
277
|
path.join(parentDir, ".appwrite", "appwriteConfig.yaml"),
|
276
278
|
path.join(parentDir, ".appwrite", "appwriteConfig.yml"),
|
277
279
|
path.join(parentDir, "appwrite.yaml"),
|
@@ -349,10 +351,10 @@ const findYamlConfigRecursive = (dir: string, depth: number = 0): string | null
|
|
349
351
|
// Check if this is an .appwrite directory
|
350
352
|
if (entry.name === ".appwrite") {
|
351
353
|
const configPaths = [
|
352
|
-
path.join(fullPath, "appwriteConfig.yaml"),
|
353
|
-
path.join(fullPath, "appwriteConfig.yml"),
|
354
354
|
path.join(fullPath, "config.yaml"),
|
355
355
|
path.join(fullPath, "config.yml"),
|
356
|
+
path.join(fullPath, "appwriteConfig.yaml"),
|
357
|
+
path.join(fullPath, "appwriteConfig.yml"),
|
356
358
|
];
|
357
359
|
|
358
360
|
for (const configPath of configPaths) {
|
package/src/interactiveCLI.ts
CHANGED
@@ -1186,12 +1186,13 @@ export class InteractiveCLI {
|
|
1186
1186
|
private async synchronizeConfigurations(): Promise<void> {
|
1187
1187
|
console.log(chalk.blue("Synchronizing configurations..."));
|
1188
1188
|
await this.controller!.init();
|
1189
|
-
|
1189
|
+
|
1190
|
+
// Sync databases, collections, and buckets
|
1190
1191
|
const { syncDatabases } = await inquirer.prompt([
|
1191
1192
|
{
|
1192
1193
|
type: "confirm",
|
1193
1194
|
name: "syncDatabases",
|
1194
|
-
message: "Do you want to synchronize databases and their buckets?",
|
1195
|
+
message: "Do you want to synchronize databases, collections, and their buckets?",
|
1195
1196
|
default: true,
|
1196
1197
|
},
|
1197
1198
|
]);
|
@@ -1200,9 +1201,13 @@ export class InteractiveCLI {
|
|
1200
1201
|
const remoteDatabases = await fetchAllDatabases(
|
1201
1202
|
this.controller!.database!
|
1202
1203
|
);
|
1204
|
+
|
1205
|
+
// Use the controller's synchronizeConfigurations method which handles collections properly
|
1206
|
+
console.log(chalk.blue("Pulling collections and generating collection files..."));
|
1207
|
+
await this.controller!.synchronizeConfigurations(remoteDatabases);
|
1208
|
+
|
1209
|
+
// Also configure buckets for any new databases
|
1203
1210
|
const localDatabases = this.controller!.config?.databases || [];
|
1204
|
-
|
1205
|
-
// Update config with remote databases that don't exist locally
|
1206
1211
|
const updatedConfig = await this.configureBuckets({
|
1207
1212
|
...this.controller!.config!,
|
1208
1213
|
databases: [
|
@@ -1437,12 +1442,7 @@ export class InteractiveCLI {
|
|
1437
1442
|
}
|
1438
1443
|
}
|
1439
1444
|
|
1440
|
-
//
|
1441
|
-
const schemaGenerator = new SchemaGenerator(
|
1442
|
-
this.controller!.config!,
|
1443
|
-
this.controller!.getAppwriteFolderPath()!
|
1444
|
-
);
|
1445
|
-
await schemaGenerator.updateConfig(this.controller!.config!);
|
1445
|
+
// Schema generation and collection file writing is handled by controller.synchronizeConfigurations()
|
1446
1446
|
}
|
1447
1447
|
|
1448
1448
|
console.log(chalk.green("✨ Configurations synchronized successfully!"));
|
@@ -197,14 +197,18 @@ export class SchemaGenerator {
|
|
197
197
|
});
|
198
198
|
}
|
199
199
|
|
200
|
-
public async updateConfig(config: AppwriteConfig): Promise<void> {
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
200
|
+
public async updateConfig(config: AppwriteConfig, isYamlConfig: boolean = false): Promise<void> {
|
201
|
+
if (isYamlConfig) {
|
202
|
+
// User has YAML config - find the config file and update it + generate individual collection files
|
203
|
+
const { findYamlConfig } = await import("../config/yamlConfig.js");
|
204
|
+
const yamlConfigPath = findYamlConfig(this.appwriteFolderPath);
|
205
|
+
|
206
|
+
if (yamlConfigPath) {
|
207
|
+
await this.updateYamlConfig(config, yamlConfigPath);
|
208
|
+
} else {
|
209
|
+
console.warn("⚠️ YAML config expected but not found, falling back to TypeScript");
|
210
|
+
this.updateTypeScriptConfig(config);
|
211
|
+
}
|
208
212
|
} else {
|
209
213
|
// User has TypeScript config - update the TS file
|
210
214
|
this.updateTypeScriptConfig(config);
|
package/src/utilsController.ts
CHANGED