firestore-dart-generator 1.0.3 → 1.0.5
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 +1 -1
- package/dist/firestore-client.d.ts +1 -1
- package/dist/firestore-client.d.ts.map +1 -1
- package/dist/firestore-client.js +14 -7
- package/dist/firestore-client.js.map +1 -1
- package/dist/generators/base-generator.d.ts +44 -0
- package/dist/generators/base-generator.d.ts.map +1 -0
- package/dist/generators/base-generator.js +103 -0
- package/dist/generators/base-generator.js.map +1 -0
- package/dist/templates/dart/model.hbs +39 -0
- package/package.json +4 -4
- package/CONFIG_FILE_GUIDE.md +0 -445
- package/IMPLEMENTATION_SUMMARY.md +0 -305
- package/QUICK_START.md +0 -241
package/README.md
CHANGED
|
@@ -586,5 +586,5 @@ MIT
|
|
|
586
586
|
|
|
587
587
|
## Support
|
|
588
588
|
|
|
589
|
-
If you encounter any issues or have questions, please [open an issue](https://github.com/
|
|
589
|
+
If you encounter any issues or have questions, please [open an issue](https://github.com/MarcosTort/firestore-code-generator/issues) on GitHub.
|
|
590
590
|
|
|
@@ -34,7 +34,7 @@ export declare class FirestoreClient {
|
|
|
34
34
|
*/
|
|
35
35
|
listCollections(): Promise<string[]>;
|
|
36
36
|
/**
|
|
37
|
-
* List subcollections for a given collection (by checking
|
|
37
|
+
* List subcollections for a given collection (by checking a sample of documents)
|
|
38
38
|
*/
|
|
39
39
|
listSubcollections(collectionPath: string): Promise<string[]>;
|
|
40
40
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firestore-client.d.ts","sourceRoot":"","sources":["../src/firestore-client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"firestore-client.d.ts","sourceRoot":"","sources":["../src/firestore-client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AAIxC,qBAAa,eAAe;IAKxB,OAAO,CAAC,SAAS,CAAC;IAClB,OAAO,CAAC,kBAAkB,CAAC;IAL7B,OAAO,CAAC,EAAE,CAA0C;IACpD,OAAO,CAAC,WAAW,CAAS;gBAGlB,SAAS,CAAC,EAAE,MAAM,YAAA,EAClB,kBAAkB,CAAC,EAAE,MAAM,YAAA;IAGrC;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAoDjC;;OAEG;IACH,YAAY,IAAI,KAAK,CAAC,SAAS,CAAC,SAAS;IAOzC;;OAEG;IACG,oBAAoB,CACxB,cAAc,EAAE,MAAM,EACtB,KAAK,GAAE,MAAW,GACjB,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,gBAAgB,EAAE,CAAC;IAqB9C;;OAEG;IACG,qCAAqC,CACzC,oBAAoB,EAAE,MAAM,EAC5B,iBAAiB,EAAE,MAAM,EACzB,KAAK,GAAE,MAAW,GACjB,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,gBAAgB,EAAE,CAAC;IAoC9C;;OAEG;IACG,gBAAgB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAShE;;OAEG;IACG,mBAAmB,CACvB,oBAAoB,EAAE,MAAM,EAC5B,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC,OAAO,CAAC;IAwBnB;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAS1C;;OAEG;IACG,kBAAkB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IA0BnE;;OAEG;IACH,YAAY,IAAI,MAAM,GAAG,SAAS;IAIlC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAO7B"}
|
package/dist/firestore-client.js
CHANGED
|
@@ -37,10 +37,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.FirestoreClient = void 0;
|
|
40
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
40
41
|
const admin = __importStar(require("firebase-admin"));
|
|
41
42
|
const fs = __importStar(require("fs"));
|
|
42
43
|
const path = __importStar(require("path"));
|
|
43
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
44
44
|
class FirestoreClient {
|
|
45
45
|
constructor(projectId, serviceAccountPath) {
|
|
46
46
|
this.projectId = projectId;
|
|
@@ -194,20 +194,27 @@ class FirestoreClient {
|
|
|
194
194
|
return collections.map(col => col.id);
|
|
195
195
|
}
|
|
196
196
|
/**
|
|
197
|
-
* List subcollections for a given collection (by checking
|
|
197
|
+
* List subcollections for a given collection (by checking a sample of documents)
|
|
198
198
|
*/
|
|
199
199
|
async listSubcollections(collectionPath) {
|
|
200
200
|
if (!this.db) {
|
|
201
201
|
throw new Error('Firestore not initialized');
|
|
202
202
|
}
|
|
203
|
-
// Get
|
|
204
|
-
|
|
203
|
+
// Get a sample of documents to check for subcollections
|
|
204
|
+
// We check more than one because some documents might not have subcollections
|
|
205
|
+
// while others do
|
|
206
|
+
const snapshot = await this.db.collection(collectionPath).limit(10).get();
|
|
205
207
|
if (snapshot.empty) {
|
|
206
208
|
return [];
|
|
207
209
|
}
|
|
208
|
-
const
|
|
209
|
-
const
|
|
210
|
-
|
|
210
|
+
const subcollectionsSet = new Set();
|
|
211
|
+
for (const doc of snapshot.docs) {
|
|
212
|
+
const subcollections = await doc.ref.listCollections();
|
|
213
|
+
for (const col of subcollections) {
|
|
214
|
+
subcollectionsSet.add(col.id);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return Array.from(subcollectionsSet);
|
|
211
218
|
}
|
|
212
219
|
/**
|
|
213
220
|
* Get project ID from initialized Firebase app
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firestore-client.js","sourceRoot":"","sources":["../src/firestore-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAwC;AACxC,uCAAyB;AACzB,2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AAC;YAChC,MAAM,cAAc,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC;YACvD,KAAK,MAAM,GAAG,IAAI,cAAc,EAAE,CAAC;gBACjC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAChC,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACT,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,MAAM,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC;YAC3B,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;YACzB,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC;QACjB,CAAC;IACH,CAAC;CACF;AApPD,0CAoPC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { SchemaInfo, UniversalType } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Abstract base class for language-specific code generators.
|
|
4
|
+
* Each language generator extends this class and implements language-specific logic.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class BaseGenerator {
|
|
7
|
+
protected template: HandlebarsTemplateDelegate | null;
|
|
8
|
+
constructor();
|
|
9
|
+
/**
|
|
10
|
+
* Register Handlebars helpers common to all generators
|
|
11
|
+
*/
|
|
12
|
+
protected registerHelpers(): void;
|
|
13
|
+
/**
|
|
14
|
+
* Get the target programming language name
|
|
15
|
+
*/
|
|
16
|
+
protected abstract getLanguage(): string;
|
|
17
|
+
/**
|
|
18
|
+
* Get the file extension for generated files (e.g., '.dart', '.ts', '.kt')
|
|
19
|
+
*/
|
|
20
|
+
abstract getFileExtension(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Map a universal type to the target language's type
|
|
23
|
+
* @param universalType The language-agnostic type
|
|
24
|
+
* @returns The language-specific type string
|
|
25
|
+
*/
|
|
26
|
+
abstract mapType(universalType: UniversalType): string;
|
|
27
|
+
/**
|
|
28
|
+
* Generate code from schema
|
|
29
|
+
*/
|
|
30
|
+
abstract generateModel(schema: SchemaInfo): string;
|
|
31
|
+
/**
|
|
32
|
+
* Load the Handlebars template for this generator
|
|
33
|
+
*/
|
|
34
|
+
protected loadTemplate(templateName?: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Convert PascalCase to snake_case
|
|
37
|
+
*/
|
|
38
|
+
protected toSnakeCase(str: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Write generated code to file
|
|
41
|
+
*/
|
|
42
|
+
writeModelToFile(schema: SchemaInfo, outputDir: string): Promise<string>;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=base-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-generator.d.ts","sourceRoot":"","sources":["../../src/generators/base-generator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAErD;;;GAGG;AACH,8BAAsB,aAAa;IAC/B,SAAS,CAAC,QAAQ,EAAE,0BAA0B,GAAG,IAAI,CAAQ;;IAM7D;;OAEG;IACH,SAAS,CAAC,eAAe,IAAI,IAAI;IAOjC;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,WAAW,IAAI,MAAM;IAExC;;OAEG;IACH,QAAQ,CAAC,gBAAgB,IAAI,MAAM;IAEnC;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM;IAEtD;;OAEG;IACH,QAAQ,CAAC,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM;IAElD;;OAEG;IACH,SAAS,CAAC,YAAY,CAAC,YAAY,GAAE,MAAoB,GAAG,IAAI;IAoBhE;;OAEG;IACH,SAAS,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAQ1C;;OAEG;IACG,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAiBjF"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.BaseGenerator = void 0;
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
42
|
+
const path = __importStar(require("path"));
|
|
43
|
+
/**
|
|
44
|
+
* Abstract base class for language-specific code generators.
|
|
45
|
+
* Each language generator extends this class and implements language-specific logic.
|
|
46
|
+
*/
|
|
47
|
+
class BaseGenerator {
|
|
48
|
+
constructor() {
|
|
49
|
+
this.template = null;
|
|
50
|
+
this.registerHelpers();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Register Handlebars helpers common to all generators
|
|
54
|
+
*/
|
|
55
|
+
registerHelpers() {
|
|
56
|
+
// Helper to check equality
|
|
57
|
+
handlebars_1.default.registerHelper('eq', (a, b) => {
|
|
58
|
+
return a === b;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Load the Handlebars template for this generator
|
|
63
|
+
*/
|
|
64
|
+
loadTemplate(templateName = 'model.hbs') {
|
|
65
|
+
if (this.template) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const templatePath = path.join(__dirname, '../templates', this.getLanguage(), templateName);
|
|
69
|
+
if (!fs.existsSync(templatePath)) {
|
|
70
|
+
throw new Error(`Template file not found: ${templatePath}`);
|
|
71
|
+
}
|
|
72
|
+
const templateSource = fs.readFileSync(templatePath, 'utf8');
|
|
73
|
+
this.template = handlebars_1.default.compile(templateSource);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Convert PascalCase to snake_case
|
|
77
|
+
*/
|
|
78
|
+
toSnakeCase(str) {
|
|
79
|
+
return str
|
|
80
|
+
.replace(/([a-z])([A-Z])/g, '$1_$2')
|
|
81
|
+
.replace(/([0-9])([A-Z])/g, '$1_$2')
|
|
82
|
+
.replace(/([A-Z])([A-Z][a-z])/g, '$1_$2')
|
|
83
|
+
.toLowerCase();
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Write generated code to file
|
|
87
|
+
*/
|
|
88
|
+
async writeModelToFile(schema, outputDir) {
|
|
89
|
+
const code = this.generateModel(schema);
|
|
90
|
+
// Ensure output directory exists
|
|
91
|
+
if (!fs.existsSync(outputDir)) {
|
|
92
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
93
|
+
}
|
|
94
|
+
// Convert class name to appropriate filename
|
|
95
|
+
const fileName = this.toSnakeCase(schema.className) + this.getFileExtension();
|
|
96
|
+
const filePath = path.join(outputDir, fileName);
|
|
97
|
+
// Write file
|
|
98
|
+
fs.writeFileSync(filePath, code, 'utf8');
|
|
99
|
+
return filePath;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.BaseGenerator = BaseGenerator;
|
|
103
|
+
//# sourceMappingURL=base-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-generator.js","sourceRoot":"","sources":["../../src/generators/base-generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,4DAAoC;AACpC,2CAA6B;AAG7B;;;GAGG;AACH,MAAsB,aAAa;IAG/B;QAFU,aAAQ,GAAsC,IAAI,CAAC;QAGzD,IAAI,CAAC,eAAe,EAAE,CAAC;IAC3B,CAAC;IAED;;OAEG;IACO,eAAe;QACrB,2BAA2B;QAC3B,oBAAU,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAM,EAAE,CAAM,EAAE,EAAE;YAC/C,OAAO,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;IACP,CAAC;IAwBD;;OAEG;IACO,YAAY,CAAC,eAAuB,WAA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AEhD,aAAa;QACb,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAEzC,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ;AA7FD,sCA6FC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/// A model representing a {{collectionName}} document from Firestore.
|
|
2
|
+
class {{className}} extends Equatable {
|
|
3
|
+
/// Creates a new [{{className}}] instance.
|
|
4
|
+
const {{className}}({{#if fields.length}}{
|
|
5
|
+
{{#each fields}}
|
|
6
|
+
{{#unless isOptional}}required {{/unless}}this.{{name}},
|
|
7
|
+
{{/each}}
|
|
8
|
+
}{{/if}});
|
|
9
|
+
|
|
10
|
+
/// Creates a [{{className}}] from a JSON map.
|
|
11
|
+
factory {{className}}.fromJson(Map<String, dynamic> json) {
|
|
12
|
+
return {{className}}({{#if fields.length}}
|
|
13
|
+
{{#each fields}}
|
|
14
|
+
{{name}}: {{#if (eq type "DateTime")}}{{#if isNullable}}json['{{name}}'] != null ? DateTime.parse(json['{{name}}'] as String) : null{{else}}DateTime.parse(json['{{name}}'] as String){{/if}}{{else}}{{#if nestedSchema}}{{#if isNullable}}json['{{name}}'] != null ? {{type}}.fromJson(json['{{name}}'] as Map<String, dynamic>) : null{{else}}{{type}}.fromJson(json['{{name}}'] as Map<String, dynamic>){{/if}}{{else if listItemSchema}}{{#if isNullable}}json['{{name}}'] != null ? (json['{{name}}'] as List<dynamic>).map((e) => {{listItemSchema.className}}.fromJson(e as Map<String, dynamic>)).toList() : null{{else}}(json['{{name}}'] as List<dynamic>).map((e) => {{listItemSchema.className}}.fromJson(e as Map<String, dynamic>)).toList(){{/if}}{{else}}{{#if isNullable}}json['{{name}}'] as {{{type}}}?{{else}}json['{{name}}'] as {{{type}}}{{/if}}{{/if}}{{/if}},
|
|
15
|
+
{{/each}}{{/if}}
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
{{#each fields}}
|
|
20
|
+
/// The {{name}} field.
|
|
21
|
+
final {{{type}}}{{#if isNullable}}?{{/if}} {{name}};
|
|
22
|
+
|
|
23
|
+
{{/each}}
|
|
24
|
+
@override
|
|
25
|
+
List<Object?> get props => [
|
|
26
|
+
{{#each fields}}
|
|
27
|
+
{{name}},
|
|
28
|
+
{{/each}}
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
/// Converts this [{{className}}] to a JSON map.
|
|
32
|
+
Map<String, dynamic> toJson() {
|
|
33
|
+
return {
|
|
34
|
+
{{#each fields}}
|
|
35
|
+
{{#if isOptional}}if ({{name}} != null) {{/if}}'{{name}}': {{#if (eq type "DateTime")}}{{name}}{{#if isNullable}}?{{/if}}.toIso8601String(){{else if nestedSchema}}{{name}}{{#if isNullable}}?{{/if}}.toJson(){{else if listItemSchema}}{{name}}{{#if isNullable}}?{{/if}}.map((e) => e.toJson()).toList(){{else}}{{name}}{{/if}},
|
|
36
|
+
{{/each}}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "firestore-dart-generator",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Generate Dart models from Firestore collections by analyzing real document schemas",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"repository": {
|
|
35
35
|
"type": "git",
|
|
36
|
-
"url": "git+https://github.com/
|
|
36
|
+
"url": "git+https://github.com/MarcosTort/firestore-code-generator.git"
|
|
37
37
|
},
|
|
38
|
-
"homepage": "https://github.com/
|
|
38
|
+
"homepage": "https://github.com/MarcosTort/firestore-code-generator#readme",
|
|
39
39
|
"bugs": {
|
|
40
|
-
"url": "https://github.com/
|
|
40
|
+
"url": "https://github.com/MarcosTort/firestore-code-generator/issues"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"chalk": "^4.1.2",
|
package/CONFIG_FILE_GUIDE.md
DELETED
|
@@ -1,445 +0,0 @@
|
|
|
1
|
-
# 📄 Guía de Archivo de Configuración
|
|
2
|
-
|
|
3
|
-
## ✅ IMPLEMENTACIÓN COMPLETA
|
|
4
|
-
|
|
5
|
-
El CLI ahora soporta un archivo de configuración YAML que hace el uso mucho más conveniente.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## 🚀 Uso Rápido
|
|
10
|
-
|
|
11
|
-
### 1. Crear archivo de configuración
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
# Copiar el ejemplo
|
|
15
|
-
cp firestore-dart-gen.example.yaml firestore-dart-gen.yaml
|
|
16
|
-
|
|
17
|
-
# Editar con tus valores
|
|
18
|
-
nano firestore-dart-gen.yaml
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
### 2. Configurar
|
|
22
|
-
|
|
23
|
-
```yaml
|
|
24
|
-
# firestore-dart-gen.yaml
|
|
25
|
-
firebase:
|
|
26
|
-
serviceAccount: ./firebase_service_account.json
|
|
27
|
-
|
|
28
|
-
collections:
|
|
29
|
-
- users
|
|
30
|
-
- products
|
|
31
|
-
|
|
32
|
-
output:
|
|
33
|
-
directory: ./lib/src/models
|
|
34
|
-
sampleSize: 20
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### 3. Ejecutar
|
|
38
|
-
|
|
39
|
-
```bash
|
|
40
|
-
# Simplemente ejecuta sin argumentos
|
|
41
|
-
firestore-dart-gen
|
|
42
|
-
|
|
43
|
-
# El CLI:
|
|
44
|
-
# ✓ Carga credenciales del YAML
|
|
45
|
-
# ✓ Pre-selecciona users y products
|
|
46
|
-
# ✓ Usa ./lib/src/models como directorio por defecto
|
|
47
|
-
# ✓ Usa 20 como sample size por defecto
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
---
|
|
51
|
-
|
|
52
|
-
## 📋 Estructura del Archivo
|
|
53
|
-
|
|
54
|
-
### Completo (todos los campos opcionales)
|
|
55
|
-
|
|
56
|
-
```yaml
|
|
57
|
-
# Firebase Configuration
|
|
58
|
-
firebase:
|
|
59
|
-
# Path al service account (requerido si no usas CLI args)
|
|
60
|
-
serviceAccount: ./firebase_service_account.json
|
|
61
|
-
|
|
62
|
-
# Project ID (opcional, se puede obtener del service account)
|
|
63
|
-
projectId: my-project-id
|
|
64
|
-
|
|
65
|
-
# Collections que aparecerán pre-seleccionadas (opcional)
|
|
66
|
-
collections:
|
|
67
|
-
- users
|
|
68
|
-
- products
|
|
69
|
-
- orders
|
|
70
|
-
- reviews
|
|
71
|
-
- settings
|
|
72
|
-
|
|
73
|
-
# Configuración de output (opcional)
|
|
74
|
-
output:
|
|
75
|
-
# Directorio donde se generarán los modelos
|
|
76
|
-
directory: ./lib/src/models
|
|
77
|
-
|
|
78
|
-
# Cantidad de documentos a samplear por colección
|
|
79
|
-
sampleSize: 20
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### Mínimo (solo credenciales)
|
|
83
|
-
|
|
84
|
-
```yaml
|
|
85
|
-
firebase:
|
|
86
|
-
serviceAccount: ./firebase_service_account.json
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### Solo pre-selección (sin credenciales)
|
|
90
|
-
|
|
91
|
-
```yaml
|
|
92
|
-
collections:
|
|
93
|
-
- users
|
|
94
|
-
- products
|
|
95
|
-
|
|
96
|
-
output:
|
|
97
|
-
directory: ./lib/src/models
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
Luego ejecutar:
|
|
101
|
-
```bash
|
|
102
|
-
firestore-dart-gen --service-account credentials.json
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
---
|
|
106
|
-
|
|
107
|
-
## 🎯 Comportamiento
|
|
108
|
-
|
|
109
|
-
### Sin Archivo de Config
|
|
110
|
-
|
|
111
|
-
```bash
|
|
112
|
-
firestore-dart-gen --service-account credentials.json
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
**Resultado:**
|
|
116
|
-
- Todas las colecciones SIN pre-seleccionar
|
|
117
|
-
- Default output: `./lib/src/models`
|
|
118
|
-
- Default sample size: `20`
|
|
119
|
-
|
|
120
|
-
### Con Archivo de Config
|
|
121
|
-
|
|
122
|
-
```bash
|
|
123
|
-
# firestore-dart-gen.yaml existe
|
|
124
|
-
firestore-dart-gen
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
**Resultado:**
|
|
128
|
-
- Colecciones del YAML aparecen **✓ PRE-SELECCIONADAS**
|
|
129
|
-
- Output directory del YAML como default
|
|
130
|
-
- Sample size del YAML como default
|
|
131
|
-
- Usuario puede cambiar cualquier valor en los prompts
|
|
132
|
-
|
|
133
|
-
### Con Config + CLI Args
|
|
134
|
-
|
|
135
|
-
```bash
|
|
136
|
-
# firestore-dart-gen.yaml existe
|
|
137
|
-
firestore-dart-gen --service-account other.json
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
**Resultado:**
|
|
141
|
-
- Usa `other.json` (CLI arg gana sobre YAML)
|
|
142
|
-
- Pre-selecciona colecciones del YAML
|
|
143
|
-
- Usa outputs del YAML
|
|
144
|
-
|
|
145
|
-
---
|
|
146
|
-
|
|
147
|
-
## 🔐 Prioridad de Configuración
|
|
148
|
-
|
|
149
|
-
```
|
|
150
|
-
┌─────────────────────────────────────────────┐
|
|
151
|
-
│ 1. CLI Arguments (highest priority) │
|
|
152
|
-
│ --service-account │
|
|
153
|
-
│ --project-id │
|
|
154
|
-
│ --config │
|
|
155
|
-
├─────────────────────────────────────────────┤
|
|
156
|
-
│ 2. Config File │
|
|
157
|
-
│ firestore-dart-gen.yaml │
|
|
158
|
-
├─────────────────────────────────────────────┤
|
|
159
|
-
│ 3. Environment Variables (lowest priority) │
|
|
160
|
-
│ GOOGLE_APPLICATION_CREDENTIALS │
|
|
161
|
-
│ FIREBASE_PROJECT_ID │
|
|
162
|
-
└─────────────────────────────────────────────┘
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
**Ejemplo práctico:**
|
|
166
|
-
|
|
167
|
-
```yaml
|
|
168
|
-
# firestore-dart-gen.yaml
|
|
169
|
-
firebase:
|
|
170
|
-
serviceAccount: ./dev-credentials.json # Priority 2
|
|
171
|
-
|
|
172
|
-
# .env
|
|
173
|
-
GOOGLE_APPLICATION_CREDENTIALS=./prod-credentials.json # Priority 3
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
```bash
|
|
177
|
-
# Usa dev-credentials.json (del YAML, priority 2)
|
|
178
|
-
firestore-dart-gen
|
|
179
|
-
|
|
180
|
-
# Usa prod-credentials.json (CLI arg, priority 1)
|
|
181
|
-
firestore-dart-gen --service-account ./prod-credentials.json
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
---
|
|
185
|
-
|
|
186
|
-
## 📁 Ubicación del Archivo
|
|
187
|
-
|
|
188
|
-
El CLI busca el archivo de config en este orden:
|
|
189
|
-
|
|
190
|
-
1. Path especificado con `--config`
|
|
191
|
-
2. `firestore-dart-gen.yaml` (en directorio actual)
|
|
192
|
-
3. `firestore-dart-gen.yml`
|
|
193
|
-
4. `.firestore-dart-gen.yaml` (hidden)
|
|
194
|
-
5. `.firestore-dart-gen.yml` (hidden)
|
|
195
|
-
|
|
196
|
-
**Recomendación:** Usa `firestore-dart-gen.yaml` en la raíz de tu proyecto Flutter.
|
|
197
|
-
|
|
198
|
-
---
|
|
199
|
-
|
|
200
|
-
## 🎨 Ejemplo de Sesión Interactiva
|
|
201
|
-
|
|
202
|
-
### Con archivo de config:
|
|
203
|
-
|
|
204
|
-
```bash
|
|
205
|
-
$ firestore-dart-gen
|
|
206
|
-
|
|
207
|
-
🔥 Firestore Dart Generator - Interactive Mode
|
|
208
|
-
|
|
209
|
-
📄 Found config file: firestore-dart-gen.yaml
|
|
210
|
-
|
|
211
|
-
✓ Connected to Firebase Project: my-awesome-app
|
|
212
|
-
|
|
213
|
-
🔍 Discovering collections...
|
|
214
|
-
|
|
215
|
-
Found 7 collection(s)
|
|
216
|
-
|
|
217
|
-
Pre-selected from config: users, products
|
|
218
|
-
|
|
219
|
-
? Select collections to generate models for: (Use ↑↓, Space, Enter)
|
|
220
|
-
❯◉ users ← Pre-seleccionado ✓
|
|
221
|
-
◉ products ← Pre-seleccionado ✓
|
|
222
|
-
◯ orders
|
|
223
|
-
◯ reviews
|
|
224
|
-
◯ settings
|
|
225
|
-
◯ notifications
|
|
226
|
-
◯ analytics
|
|
227
|
-
|
|
228
|
-
🌳 Checking for subcollections...
|
|
229
|
-
|
|
230
|
-
Analyzing users...
|
|
231
|
-
Found 2 subcollection(s): profiles, settings
|
|
232
|
-
Include subcollections for users? (Y/n) y
|
|
233
|
-
|
|
234
|
-
? Output directory: ./lib/src/models ← Default del config
|
|
235
|
-
? Sample size: 20 ← Default del config
|
|
236
|
-
|
|
237
|
-
📋 Generation Summary:
|
|
238
|
-
────────────────────────────────────────────────
|
|
239
|
-
Firebase Project: my-awesome-app
|
|
240
|
-
Collections: users, products
|
|
241
|
-
Subcollections:
|
|
242
|
-
└─ users: profiles, settings
|
|
243
|
-
Output: ./lib/src/models
|
|
244
|
-
Sample Size: 20 documents per collection
|
|
245
|
-
────────────────────────────────────────────────
|
|
246
|
-
|
|
247
|
-
? Generate? (Y/n) y
|
|
248
|
-
|
|
249
|
-
✨ Success! Generated 4 model(s)
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
---
|
|
253
|
-
|
|
254
|
-
## 💡 Casos de Uso
|
|
255
|
-
|
|
256
|
-
### Desarrollo Local
|
|
257
|
-
|
|
258
|
-
```yaml
|
|
259
|
-
# firestore-dart-gen.yaml
|
|
260
|
-
firebase:
|
|
261
|
-
serviceAccount: ./dev-credentials.json
|
|
262
|
-
projectId: my-app-dev
|
|
263
|
-
|
|
264
|
-
collections:
|
|
265
|
-
- users
|
|
266
|
-
- products
|
|
267
|
-
|
|
268
|
-
output:
|
|
269
|
-
directory: ./lib/src/models
|
|
270
|
-
sampleSize: 10 # Menos documentos para desarrollo
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
### Producción / CI/CD
|
|
274
|
-
|
|
275
|
-
```yaml
|
|
276
|
-
# firestore-dart-gen.yaml (commitear en repo)
|
|
277
|
-
collections:
|
|
278
|
-
- users
|
|
279
|
-
- products
|
|
280
|
-
- orders
|
|
281
|
-
|
|
282
|
-
output:
|
|
283
|
-
directory: ./lib/src/models
|
|
284
|
-
sampleSize: 50 # Más documentos para mejor análisis
|
|
285
|
-
|
|
286
|
-
# NO incluir firebase.serviceAccount aquí!
|
|
287
|
-
# Usar variable de entorno o CLI arg en CI
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
En CI:
|
|
291
|
-
```bash
|
|
292
|
-
firestore-dart-gen --service-account $SERVICE_ACCOUNT_PATH
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
### Equipos
|
|
296
|
-
|
|
297
|
-
```yaml
|
|
298
|
-
# firestore-dart-gen.yaml (compartir en repo)
|
|
299
|
-
# NO incluir credenciales
|
|
300
|
-
|
|
301
|
-
collections:
|
|
302
|
-
- users
|
|
303
|
-
- products
|
|
304
|
-
- orders
|
|
305
|
-
- reviews
|
|
306
|
-
- notifications
|
|
307
|
-
|
|
308
|
-
output:
|
|
309
|
-
directory: ./packages/core/lib/models
|
|
310
|
-
sampleSize: 20
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
Cada desarrollador crea su propio `.env`:
|
|
314
|
-
```bash
|
|
315
|
-
GOOGLE_APPLICATION_CREDENTIALS=./mi-credentials.json
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
---
|
|
319
|
-
|
|
320
|
-
## ⚠️ Seguridad
|
|
321
|
-
|
|
322
|
-
### ✅ Buenas Prácticas
|
|
323
|
-
|
|
324
|
-
```yaml
|
|
325
|
-
# firestore-dart-gen.yaml (SAFE para commitear)
|
|
326
|
-
collections:
|
|
327
|
-
- users
|
|
328
|
-
- products
|
|
329
|
-
|
|
330
|
-
output:
|
|
331
|
-
directory: ./lib/src/models
|
|
332
|
-
```
|
|
333
|
-
|
|
334
|
-
```bash
|
|
335
|
-
# .gitignore
|
|
336
|
-
firestore-dart-gen.yaml # Si incluye credenciales
|
|
337
|
-
*service-account.json
|
|
338
|
-
```
|
|
339
|
-
|
|
340
|
-
### ❌ NO Hacer
|
|
341
|
-
|
|
342
|
-
```yaml
|
|
343
|
-
# ❌ NO commitear credenciales en el YAML
|
|
344
|
-
firebase:
|
|
345
|
-
serviceAccount: ./super-secret-credentials.json # PELIGRO!
|
|
346
|
-
```
|
|
347
|
-
|
|
348
|
-
**Solución:** Usa variables de entorno o CLI args para credenciales sensibles.
|
|
349
|
-
|
|
350
|
-
---
|
|
351
|
-
|
|
352
|
-
## 🔧 Troubleshooting
|
|
353
|
-
|
|
354
|
-
### "Could not load config file"
|
|
355
|
-
|
|
356
|
-
```bash
|
|
357
|
-
# Verifica que el YAML es válido
|
|
358
|
-
cat firestore-dart-gen.yaml
|
|
359
|
-
|
|
360
|
-
# Verifica la sintaxis YAML
|
|
361
|
-
npm install -g js-yaml
|
|
362
|
-
js-yaml firestore-dart-gen.yaml
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
### "Service account file not found"
|
|
366
|
-
|
|
367
|
-
```bash
|
|
368
|
-
# Verifica el path en el config
|
|
369
|
-
cat firestore-dart-gen.yaml
|
|
370
|
-
|
|
371
|
-
# Verifica que el archivo existe
|
|
372
|
-
ls -la firebase_service_account.json
|
|
373
|
-
|
|
374
|
-
# Usa path absoluto si es necesario
|
|
375
|
-
firebase:
|
|
376
|
-
serviceAccount: /Users/you/projects/credentials.json
|
|
377
|
-
```
|
|
378
|
-
|
|
379
|
-
### Config no se carga
|
|
380
|
-
|
|
381
|
-
```bash
|
|
382
|
-
# Verifica que estás en el directorio correcto
|
|
383
|
-
pwd
|
|
384
|
-
ls firestore-dart-gen.yaml
|
|
385
|
-
|
|
386
|
-
# O especifica el path explícitamente
|
|
387
|
-
firestore-dart-gen --config ./path/to/config.yaml
|
|
388
|
-
```
|
|
389
|
-
|
|
390
|
-
---
|
|
391
|
-
|
|
392
|
-
## 📊 Archivos Creados
|
|
393
|
-
|
|
394
|
-
### Nuevos Archivos
|
|
395
|
-
- ✅ `src/config-file-loader.ts` (108 líneas) - Loader de configuración
|
|
396
|
-
- ✅ `firestore-dart-gen.example.yaml` (27 líneas) - Ejemplo de configuración
|
|
397
|
-
- ✅ `CONFIG_FILE_GUIDE.md` (este archivo) - Guía completa
|
|
398
|
-
|
|
399
|
-
### Archivos Modificados
|
|
400
|
-
- ✅ `src/interactive-cli.ts` - Integra configuración YAML
|
|
401
|
-
- ✅ `src/index.ts` - Agrega opción --config
|
|
402
|
-
- ✅ `src/types.ts` - Define CLIConfig interface
|
|
403
|
-
- ✅ `.gitignore` - Ignora archivos de config
|
|
404
|
-
- ✅ `README.md` - Documenta configuración
|
|
405
|
-
|
|
406
|
-
---
|
|
407
|
-
|
|
408
|
-
## ✨ Beneficios
|
|
409
|
-
|
|
410
|
-
### Para Desarrolladores
|
|
411
|
-
✅ No escribir credenciales cada vez
|
|
412
|
-
✅ Pre-selección automática de colecciones frecuentes
|
|
413
|
-
✅ Configuración compartible entre equipo
|
|
414
|
-
✅ Valores por defecto personalizables
|
|
415
|
-
|
|
416
|
-
### Para Equipos
|
|
417
|
-
✅ Configuración estándar compartida en repo
|
|
418
|
-
✅ Credenciales manejadas externamente
|
|
419
|
-
✅ Consistencia en outputs
|
|
420
|
-
✅ Fácil onboarding de nuevos miembros
|
|
421
|
-
|
|
422
|
-
### Para CI/CD
|
|
423
|
-
✅ Config en repo, credenciales en secrets
|
|
424
|
-
✅ Override con CLI args
|
|
425
|
-
✅ Configuración versionada
|
|
426
|
-
✅ Reproducible
|
|
427
|
-
|
|
428
|
-
---
|
|
429
|
-
|
|
430
|
-
## 🎉 Estado
|
|
431
|
-
|
|
432
|
-
**✅ COMPLETAMENTE IMPLEMENTADO Y FUNCIONAL**
|
|
433
|
-
|
|
434
|
-
- Build exitoso ✓
|
|
435
|
-
- Tests pasando (23/23) ✓
|
|
436
|
-
- CLI funcionando ✓
|
|
437
|
-
- Documentación completa ✓
|
|
438
|
-
|
|
439
|
-
**Listo para usar!** 🚀
|
|
440
|
-
|
|
441
|
-
---
|
|
442
|
-
|
|
443
|
-
*Creado: Diciembre 17, 2024*
|
|
444
|
-
*Versión: 1.1.0*
|
|
445
|
-
|
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
# 🎉 Resumen de Implementación - Config File Support
|
|
2
|
-
|
|
3
|
-
## ✅ COMPLETADO EXITOSAMENTE
|
|
4
|
-
|
|
5
|
-
El soporte para archivo de configuración YAML ha sido completamente implementado y está listo para usar.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## 📊 Resultados
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
╔═══════════════════════════════════════════════════════════╗
|
|
13
|
-
║ ✅ Build: EXITOSO ║
|
|
14
|
-
║ ✅ Tests: 23/23 pasando ║
|
|
15
|
-
║ ✅ Compilación: Sin errores ║
|
|
16
|
-
║ ✅ TODOs: 8/8 completados ║
|
|
17
|
-
╚═══════════════════════════════════════════════════════════╝
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
## 📁 Archivos Nuevos (3)
|
|
23
|
-
|
|
24
|
-
1. **`src/config-file-loader.ts`** (108 líneas)
|
|
25
|
-
- Clase ConfigFileLoader
|
|
26
|
-
- Métodos de carga y validación
|
|
27
|
-
- Resolución de prioridades
|
|
28
|
-
- Soporte para múltiples nombres de archivo
|
|
29
|
-
|
|
30
|
-
2. **`firestore-dart-gen.example.yaml`** (27 líneas)
|
|
31
|
-
- Archivo de ejemplo comentado
|
|
32
|
-
- Documenta todas las opciones
|
|
33
|
-
- Listo para copiar y personalizar
|
|
34
|
-
|
|
35
|
-
3. **`CONFIG_FILE_GUIDE.md`** (350+ líneas)
|
|
36
|
-
- Guía completa de uso
|
|
37
|
-
- Ejemplos de configuración
|
|
38
|
-
- Troubleshooting
|
|
39
|
-
- Casos de uso
|
|
40
|
-
|
|
41
|
-
---
|
|
42
|
-
|
|
43
|
-
## 📝 Archivos Modificados (6)
|
|
44
|
-
|
|
45
|
-
1. **`src/interactive-cli.ts`**
|
|
46
|
-
- Importa ConfigFileLoader
|
|
47
|
-
- Carga config al inicio
|
|
48
|
-
- Pre-selecciona colecciones del config
|
|
49
|
-
- Usa defaults del config
|
|
50
|
-
|
|
51
|
-
2. **`src/index.ts`**
|
|
52
|
-
- Agrega opción `--config <path>`
|
|
53
|
-
- Pasa configPath a runInteractiveCLI
|
|
54
|
-
|
|
55
|
-
3. **`src/types.ts`**
|
|
56
|
-
- Define CLIConfig interface
|
|
57
|
-
- Tipos para firebase, collections, output
|
|
58
|
-
|
|
59
|
-
4. **`.gitignore`**
|
|
60
|
-
- Ignora archivos de configuración
|
|
61
|
-
- Previene commit de credenciales
|
|
62
|
-
|
|
63
|
-
5. **`README.md`**
|
|
64
|
-
- Nueva sección "Configuration File"
|
|
65
|
-
- Ejemplos de uso
|
|
66
|
-
- Prioridad de configuración
|
|
67
|
-
- Beneficios documentados
|
|
68
|
-
|
|
69
|
-
6. **`package.json`**
|
|
70
|
-
- Ya contenía las dependencias necesarias
|
|
71
|
-
|
|
72
|
-
---
|
|
73
|
-
|
|
74
|
-
## 🎯 Funcionalidades Implementadas
|
|
75
|
-
|
|
76
|
-
### ✅ Carga Automática de Config
|
|
77
|
-
- [x] Busca `firestore-dart-gen.yaml` automáticamente
|
|
78
|
-
- [x] Soporta variantes (.yml, hidden files)
|
|
79
|
-
- [x] Opción --config para especificar path custom
|
|
80
|
-
- [x] Funciona sin config file (opcional)
|
|
81
|
-
|
|
82
|
-
### ✅ Resolución de Credenciales
|
|
83
|
-
- [x] Prioridad: CLI args > Config > Env
|
|
84
|
-
- [x] Service account desde YAML
|
|
85
|
-
- [x] Project ID desde YAML
|
|
86
|
-
- [x] Fallback a variables de entorno
|
|
87
|
-
|
|
88
|
-
### ✅ Pre-selección de Colecciones
|
|
89
|
-
- [x] Colecciones del YAML aparecen checked ✓
|
|
90
|
-
- [x] Usuario puede agregar/quitar más
|
|
91
|
-
- [x] Validación de al menos 1 seleccionada
|
|
92
|
-
- [x] Indicador visual de pre-selección
|
|
93
|
-
|
|
94
|
-
### ✅ Defaults Configurables
|
|
95
|
-
- [x] Output directory desde config
|
|
96
|
-
- [x] Sample size desde config
|
|
97
|
-
- [x] Usuario puede cambiarlos en prompts
|
|
98
|
-
- [x] Fallback a valores sensatos
|
|
99
|
-
|
|
100
|
-
### ✅ Validación y Errores
|
|
101
|
-
- [x] Valida estructura del YAML
|
|
102
|
-
- [x] Verifica que service account existe
|
|
103
|
-
- [x] Valida que collections sea array
|
|
104
|
-
- [x] Valida sample size > 0
|
|
105
|
-
- [x] Mensajes de error claros
|
|
106
|
-
|
|
107
|
-
---
|
|
108
|
-
|
|
109
|
-
## 🎨 Ejemplo de Uso Completo
|
|
110
|
-
|
|
111
|
-
### 1. Crear Config
|
|
112
|
-
|
|
113
|
-
```bash
|
|
114
|
-
cp firestore-dart-gen.example.yaml firestore-dart-gen.yaml
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
Editar:
|
|
118
|
-
```yaml
|
|
119
|
-
firebase:
|
|
120
|
-
serviceAccount: ./firebase_service_account.json
|
|
121
|
-
|
|
122
|
-
collections:
|
|
123
|
-
- users
|
|
124
|
-
- products
|
|
125
|
-
|
|
126
|
-
output:
|
|
127
|
-
directory: ./lib/src/models
|
|
128
|
-
sampleSize: 20
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
### 2. Ejecutar
|
|
132
|
-
|
|
133
|
-
```bash
|
|
134
|
-
firestore-dart-gen
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
### 3. Experiencia
|
|
138
|
-
|
|
139
|
-
```
|
|
140
|
-
🔥 Firestore Dart Generator - Interactive Mode
|
|
141
|
-
|
|
142
|
-
📄 Found config file: firestore-dart-gen.yaml
|
|
143
|
-
|
|
144
|
-
✓ Connected to Firebase Project: my-app
|
|
145
|
-
|
|
146
|
-
Found 7 collection(s)
|
|
147
|
-
|
|
148
|
-
Pre-selected from config: users, products
|
|
149
|
-
|
|
150
|
-
? Select collections: (↑↓ Space Enter)
|
|
151
|
-
❯◉ users ← ✓
|
|
152
|
-
◉ products ← ✓
|
|
153
|
-
◯ orders
|
|
154
|
-
◯ reviews
|
|
155
|
-
|
|
156
|
-
? Output directory: ./lib/src/models
|
|
157
|
-
? Sample size: 20
|
|
158
|
-
|
|
159
|
-
? Generate? Yes
|
|
160
|
-
|
|
161
|
-
✨ Success! Generated 2 model(s)
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
---
|
|
165
|
-
|
|
166
|
-
## 🔐 Prioridad de Configuración
|
|
167
|
-
|
|
168
|
-
```
|
|
169
|
-
┌──────────────────────────────┐
|
|
170
|
-
│ 1. CLI Arguments │ ← Highest Priority
|
|
171
|
-
│ --service-account │
|
|
172
|
-
│ --project-id │
|
|
173
|
-
│ --config │
|
|
174
|
-
├──────────────────────────────┤
|
|
175
|
-
│ 2. Config File │
|
|
176
|
-
│ firestore-dart-gen.yaml │
|
|
177
|
-
├──────────────────────────────┤
|
|
178
|
-
│ 3. Environment Variables │ ← Lowest Priority
|
|
179
|
-
│ .env │
|
|
180
|
-
└──────────────────────────────┘
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
**Ejemplo:**
|
|
184
|
-
|
|
185
|
-
```yaml
|
|
186
|
-
# firestore-dart-gen.yaml
|
|
187
|
-
firebase:
|
|
188
|
-
serviceAccount: ./dev.json
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
```bash
|
|
192
|
-
# Usa dev.json del YAML
|
|
193
|
-
firestore-dart-gen
|
|
194
|
-
|
|
195
|
-
# Usa prod.json del CLI arg (gana)
|
|
196
|
-
firestore-dart-gen --service-account prod.json
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
---
|
|
200
|
-
|
|
201
|
-
## 📚 Documentación Creada
|
|
202
|
-
|
|
203
|
-
- ✅ **README.md**: Sección "Configuration File (Optional)"
|
|
204
|
-
- ✅ **CONFIG_FILE_GUIDE.md**: Guía completa (este archivo)
|
|
205
|
-
- ✅ **firestore-dart-gen.example.yaml**: Archivo ejemplo
|
|
206
|
-
- ✅ **cli.plan.md**: Plan de implementación
|
|
207
|
-
|
|
208
|
-
---
|
|
209
|
-
|
|
210
|
-
## 🧪 Testing
|
|
211
|
-
|
|
212
|
-
```bash
|
|
213
|
-
npm test
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
**Resultado:**
|
|
217
|
-
```
|
|
218
|
-
✅ Test Suites: 2 passed, 2 total
|
|
219
|
-
✅ Tests: 23 passed, 23 total
|
|
220
|
-
✅ Time: ~2s
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
La lógica core no cambió, por lo que todos los tests siguen pasando.
|
|
224
|
-
|
|
225
|
-
---
|
|
226
|
-
|
|
227
|
-
## 🚀 Próximos Pasos
|
|
228
|
-
|
|
229
|
-
### Para Usar
|
|
230
|
-
|
|
231
|
-
```bash
|
|
232
|
-
# 1. Crear config
|
|
233
|
-
cp firestore-dart-gen.example.yaml firestore-dart-gen.yaml
|
|
234
|
-
|
|
235
|
-
# 2. Editar con tus valores
|
|
236
|
-
nano firestore-dart-gen.yaml
|
|
237
|
-
|
|
238
|
-
# 3. Ejecutar
|
|
239
|
-
firestore-dart-gen
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
### Para Publicar
|
|
243
|
-
|
|
244
|
-
El paquete está listo para publicar en npm con esta nueva funcionalidad.
|
|
245
|
-
|
|
246
|
-
Ver: [`PUBLICACION_NPM.md`](PUBLICACION_NPM.md)
|
|
247
|
-
|
|
248
|
-
---
|
|
249
|
-
|
|
250
|
-
## ✨ Mejoras Logradas
|
|
251
|
-
|
|
252
|
-
### Antes
|
|
253
|
-
```bash
|
|
254
|
-
# Escribir todo cada vez
|
|
255
|
-
firestore-dart-gen batch \
|
|
256
|
-
--service-account firebase_service_account.json \
|
|
257
|
-
--config collections.yaml
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
### Ahora
|
|
261
|
-
```bash
|
|
262
|
-
# Una sola vez: configurar YAML
|
|
263
|
-
# Luego simplemente:
|
|
264
|
-
firestore-dart-gen
|
|
265
|
-
|
|
266
|
-
# Pre-selecciona tus colecciones favoritas ✓
|
|
267
|
-
# Usa tus defaults ✓
|
|
268
|
-
# Menos typing ✓
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
---
|
|
272
|
-
|
|
273
|
-
## 📊 Estadísticas
|
|
274
|
-
|
|
275
|
-
- **Archivos nuevos:** 3
|
|
276
|
-
- **Archivos modificados:** 6
|
|
277
|
-
- **Líneas de código:** ~450 nuevas
|
|
278
|
-
- **Tests pasando:** 23/23
|
|
279
|
-
- **Build time:** ~2s
|
|
280
|
-
- **Tiempo de implementación:** Completo
|
|
281
|
-
|
|
282
|
-
---
|
|
283
|
-
|
|
284
|
-
## 🎉 Conclusión
|
|
285
|
-
|
|
286
|
-
**✅ IMPLEMENTACIÓN 100% COMPLETA**
|
|
287
|
-
|
|
288
|
-
El archivo de configuración YAML está completamente integrado en el CLI interactivo:
|
|
289
|
-
|
|
290
|
-
✅ Carga automática
|
|
291
|
-
✅ Pre-selección de colecciones
|
|
292
|
-
✅ Defaults configurables
|
|
293
|
-
✅ Prioridad flexible
|
|
294
|
-
✅ Documentación completa
|
|
295
|
-
✅ Tests pasando
|
|
296
|
-
✅ Build exitoso
|
|
297
|
-
|
|
298
|
-
**Estado: LISTO PARA PRODUCCIÓN** 🚀
|
|
299
|
-
|
|
300
|
-
---
|
|
301
|
-
|
|
302
|
-
*Implementado: Diciembre 17, 2024*
|
|
303
|
-
*Tests: 23/23 passing ✓*
|
|
304
|
-
*Build: Successful ✓*
|
|
305
|
-
|
package/QUICK_START.md
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
# 🚀 Inicio Rápido - Firestore Dart Generator
|
|
2
|
-
|
|
3
|
-
## Opción 1: Con Archivo de Configuración (Recomendado)
|
|
4
|
-
|
|
5
|
-
### Paso 1: Crear configuración
|
|
6
|
-
```bash
|
|
7
|
-
cp firestore-dart-gen.example.yaml firestore-dart-gen.yaml
|
|
8
|
-
```
|
|
9
|
-
|
|
10
|
-
### Paso 2: Editar configuración
|
|
11
|
-
```yaml
|
|
12
|
-
# firestore-dart-gen.yaml
|
|
13
|
-
firebase:
|
|
14
|
-
serviceAccount: ./firebase_service_account.json
|
|
15
|
-
|
|
16
|
-
collections:
|
|
17
|
-
- users # Pre-seleccionados
|
|
18
|
-
- products # Pre-seleccionados
|
|
19
|
-
|
|
20
|
-
output:
|
|
21
|
-
directory: ./lib/src/models
|
|
22
|
-
sampleSize: 20
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
### Paso 3: Ejecutar
|
|
26
|
-
```bash
|
|
27
|
-
npm run dev
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
**Resultado:**
|
|
31
|
-
- ✅ Carga credenciales automáticamente
|
|
32
|
-
- ✅ users y products aparecen pre-seleccionados
|
|
33
|
-
- ✅ Puedes agregar/quitar más colecciones
|
|
34
|
-
- ✅ Defaults ya configurados
|
|
35
|
-
|
|
36
|
-
---
|
|
37
|
-
|
|
38
|
-
## Opción 2: Sin Archivo de Configuración
|
|
39
|
-
|
|
40
|
-
### Ejecutar directamente
|
|
41
|
-
```bash
|
|
42
|
-
npm run dev -- --service-account firebase_service_account.json
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
**Resultado:**
|
|
46
|
-
- Te pedirá seleccionar colecciones
|
|
47
|
-
- Te pedirá configurar output
|
|
48
|
-
- Todo manual, más flexible
|
|
49
|
-
|
|
50
|
-
---
|
|
51
|
-
|
|
52
|
-
## 📋 Flujo Interactivo
|
|
53
|
-
|
|
54
|
-
```
|
|
55
|
-
🔥 Firestore Dart Generator - Interactive Mode
|
|
56
|
-
|
|
57
|
-
📄 Found config file: firestore-dart-gen.yaml
|
|
58
|
-
|
|
59
|
-
✓ Connected to Firebase Project: mi-proyecto
|
|
60
|
-
|
|
61
|
-
Found 5 collection(s)
|
|
62
|
-
|
|
63
|
-
Pre-selected from config: users, products
|
|
64
|
-
|
|
65
|
-
? Select collections: (↑↓ Space Enter)
|
|
66
|
-
❯◉ users ← Pre-seleccionado
|
|
67
|
-
◉ products ← Pre-seleccionado
|
|
68
|
-
◯ orders
|
|
69
|
-
◯ reviews
|
|
70
|
-
◯ settings
|
|
71
|
-
|
|
72
|
-
🌳 Checking for subcollections...
|
|
73
|
-
|
|
74
|
-
Analyzing users...
|
|
75
|
-
Found 2 subcollection(s): profiles, settings
|
|
76
|
-
Include subcollections for users? (Y/n) y
|
|
77
|
-
|
|
78
|
-
? Output directory: ./lib/src/models
|
|
79
|
-
? Sample size: 20
|
|
80
|
-
|
|
81
|
-
📋 Generation Summary:
|
|
82
|
-
────────────────────────────────────────────
|
|
83
|
-
Firebase Project: mi-proyecto
|
|
84
|
-
Collections: users, products
|
|
85
|
-
Subcollections:
|
|
86
|
-
└─ users: profiles, settings
|
|
87
|
-
Output: ./lib/src/models
|
|
88
|
-
Sample Size: 20 documents per collection
|
|
89
|
-
────────────────────────────────────────────
|
|
90
|
-
|
|
91
|
-
? Generate Dart models with these settings? (Y/n) y
|
|
92
|
-
|
|
93
|
-
🚀 Starting generation...
|
|
94
|
-
|
|
95
|
-
📦 Processing collection: users
|
|
96
|
-
Analyzing schema for users...
|
|
97
|
-
✓ Detected 10 fields
|
|
98
|
-
✓ Generated UserDTO model
|
|
99
|
-
with 2 nested class(es)
|
|
100
|
-
✓ Written to: lib/src/models/user_dto.dart
|
|
101
|
-
|
|
102
|
-
📦 Processing subcollection: users/profiles
|
|
103
|
-
...
|
|
104
|
-
|
|
105
|
-
✨ Success! Generated 4 model(s)
|
|
106
|
-
|
|
107
|
-
Generated files:
|
|
108
|
-
✓ lib/src/models/user_dto.dart
|
|
109
|
-
✓ lib/src/models/profile_dto.dart
|
|
110
|
-
✓ lib/src/models/setting_dto.dart
|
|
111
|
-
✓ lib/src/models/product_dto.dart
|
|
112
|
-
|
|
113
|
-
📚 Next steps:
|
|
114
|
-
1. Review the generated files
|
|
115
|
-
2. Import the models in your Dart code
|
|
116
|
-
3. Add 'equatable' to your pubspec.yaml
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
---
|
|
120
|
-
|
|
121
|
-
## ⚙️ Configuración Avanzada
|
|
122
|
-
|
|
123
|
-
### Pre-seleccionar colecciones específicas
|
|
124
|
-
|
|
125
|
-
```yaml
|
|
126
|
-
collections:
|
|
127
|
-
- users
|
|
128
|
-
- products
|
|
129
|
-
- orders
|
|
130
|
-
- reviews
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
Al ejecutar el CLI, estas 4 aparecerán **pre-seleccionadas con ✓**.
|
|
134
|
-
|
|
135
|
-
### Cambiar directorio de salida
|
|
136
|
-
|
|
137
|
-
```yaml
|
|
138
|
-
output:
|
|
139
|
-
directory: ./packages/core/lib/models
|
|
140
|
-
sampleSize: 50
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
### Override con CLI args
|
|
144
|
-
|
|
145
|
-
```bash
|
|
146
|
-
# Usa prod.json en lugar del del config
|
|
147
|
-
firestore-dart-gen --service-account prod.json
|
|
148
|
-
|
|
149
|
-
# Usa config custom
|
|
150
|
-
firestore-dart-gen --config my-config.yaml
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
---
|
|
154
|
-
|
|
155
|
-
## 🎯 Casos de Uso
|
|
156
|
-
|
|
157
|
-
### Desarrollo diario
|
|
158
|
-
```yaml
|
|
159
|
-
# firestore-dart-gen.yaml
|
|
160
|
-
firebase:
|
|
161
|
-
serviceAccount: ./dev-credentials.json
|
|
162
|
-
|
|
163
|
-
collections:
|
|
164
|
-
- users
|
|
165
|
-
- products
|
|
166
|
-
|
|
167
|
-
output:
|
|
168
|
-
directory: ./lib/src/models
|
|
169
|
-
sampleSize: 10 # Rápido para desarrollo
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
```bash
|
|
173
|
-
firestore-dart-gen # ¡Eso es todo!
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
### Diferentes ambientes
|
|
177
|
-
|
|
178
|
-
```bash
|
|
179
|
-
# Desarrollo
|
|
180
|
-
firestore-dart-gen --service-account dev.json
|
|
181
|
-
|
|
182
|
-
# Staging
|
|
183
|
-
firestore-dart-gen --service-account staging.json
|
|
184
|
-
|
|
185
|
-
# Producción
|
|
186
|
-
firestore-dart-gen --service-account prod.json
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
Las colecciones pre-seleccionadas permanecen, solo cambias credenciales.
|
|
190
|
-
|
|
191
|
-
---
|
|
192
|
-
|
|
193
|
-
## 🔧 Comandos Útiles
|
|
194
|
-
|
|
195
|
-
```bash
|
|
196
|
-
# Desarrollo con config
|
|
197
|
-
npm run dev
|
|
198
|
-
|
|
199
|
-
# Desarrollo con service account específico
|
|
200
|
-
npm run dev -- --service-account credentials.json
|
|
201
|
-
|
|
202
|
-
# Con config custom
|
|
203
|
-
npm run dev -- --config other-config.yaml
|
|
204
|
-
|
|
205
|
-
# Ver help
|
|
206
|
-
npm run dev -- --help
|
|
207
|
-
|
|
208
|
-
# Build y ejecutar producción
|
|
209
|
-
npm run build
|
|
210
|
-
npm start
|
|
211
|
-
|
|
212
|
-
# Ejecutar tests
|
|
213
|
-
npm test
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
---
|
|
217
|
-
|
|
218
|
-
## 📚 Más Información
|
|
219
|
-
|
|
220
|
-
- **Guía Completa**: [`CONFIG_FILE_GUIDE.md`](CONFIG_FILE_GUIDE.md)
|
|
221
|
-
- **Archivo Ejemplo**: [`firestore-dart-gen.example.yaml`](firestore-dart-gen.example.yaml)
|
|
222
|
-
- **README Principal**: [`README.md`](README.md)
|
|
223
|
-
- **Testing**: [`TESTING.md`](TESTING.md)
|
|
224
|
-
- **Publicación**: [`PUBLICACION_NPM.md`](PUBLICACION_NPM.md)
|
|
225
|
-
|
|
226
|
-
---
|
|
227
|
-
|
|
228
|
-
## ✅ Checklist para Empezar
|
|
229
|
-
|
|
230
|
-
- [ ] Crear `firestore-dart-gen.yaml` desde el ejemplo
|
|
231
|
-
- [ ] Configurar path de service account
|
|
232
|
-
- [ ] Listar colecciones que usas frecuentemente
|
|
233
|
-
- [ ] Ejecutar `npm run dev`
|
|
234
|
-
- [ ] Seleccionar colecciones (pre-seleccionadas por ti)
|
|
235
|
-
- [ ] Revisar modelos generados
|
|
236
|
-
- [ ] ¡Listo para usar en tu app Flutter!
|
|
237
|
-
|
|
238
|
-
---
|
|
239
|
-
|
|
240
|
-
🎉 **¡Disfruta del nuevo sistema de configuración!**
|
|
241
|
-
|