@tech4good/platform-tooling 0.1.0-alpha.2 → 0.1.0-alpha.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/dist/entity-registry.js +15 -4
- package/dist/firestore-rules.d.ts +35 -0
- package/dist/firestore-rules.js +164 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +10 -1
- package/dist/rules-cli.d.ts +2 -0
- package/dist/rules-cli.js +60 -0
- package/dist/skills-cli.d.ts +2 -0
- package/dist/skills-cli.js +61 -0
- package/dist/skills-sync.d.ts +40 -0
- package/dist/skills-sync.js +236 -0
- package/package.json +6 -3
- package/skills/configure-firebase/SKILL.md +96 -0
package/dist/entity-registry.js
CHANGED
|
@@ -152,12 +152,23 @@ function generateEntityRegistrySources(sources, options = {}) {
|
|
|
152
152
|
continue;
|
|
153
153
|
for (const { name, call } of declarations(file, 'defineEntity', '@tech4good/platform-data').declarations) {
|
|
154
154
|
const value = call.arguments[0] && unwrap(call.arguments[0]);
|
|
155
|
-
if (call.arguments.length !== 1 || !value || !typescript_1.default.isObjectLiteralExpression(value)
|
|
155
|
+
if (call.arguments.length !== 1 || !value || !typescript_1.default.isObjectLiteralExpression(value)) {
|
|
156
156
|
throw new Error(`${file.fileName}: defineEntity requires { collection: 'literal-name' }.`);
|
|
157
157
|
}
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
const allowedProps = new Set(['collection', 'accessPolicy']);
|
|
159
|
+
let collection;
|
|
160
|
+
for (const property of value.properties) {
|
|
161
|
+
if (!typescript_1.default.isPropertyAssignment(property)) {
|
|
162
|
+
throw new Error(`${file.fileName}: defineEntity requires { collection: 'literal-name' }.`);
|
|
163
|
+
}
|
|
164
|
+
const propName = property.name.getText(file).replace(/^['"]|['"]$/g, '');
|
|
165
|
+
if (!allowedProps.has(propName)) {
|
|
166
|
+
throw new Error(`${file.fileName}: defineEntity requires { collection: 'literal-name' }.`);
|
|
167
|
+
}
|
|
168
|
+
if (propName === 'collection') {
|
|
169
|
+
collection = unwrap(property.initializer);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
161
172
|
if (!collection || !typescript_1.default.isStringLiteralLike(collection) || !collection.text || collection.text.trim() !== collection.text ||
|
|
162
173
|
collection.text.includes('/') || ['.', '..'].includes(collection.text) || /^__.*__$/.test(collection.text)) {
|
|
163
174
|
throw new Error(`${file.fileName}: collection must be a nonempty literal collection name, without slashes.`);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare const ENTITY_RULES_MARKER = "// @t4g-entity-rules";
|
|
2
|
+
export interface FirestoreRulesOptions {
|
|
3
|
+
/** Application root directory containing firestore.base.rules (default: process.cwd()). */
|
|
4
|
+
projectRoot?: string;
|
|
5
|
+
/** Project-relative directory scanned for *.firestore.rules fragments (default: src/app). */
|
|
6
|
+
sourceRoot?: string;
|
|
7
|
+
/** Project-relative base rules file containing shared helpers and the marker (default: firestore.base.rules). */
|
|
8
|
+
baseFile?: string;
|
|
9
|
+
/** Project-relative compiled output file (default: firestore.rules). */
|
|
10
|
+
outputFile?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface FirestoreRulesResult {
|
|
13
|
+
success: boolean;
|
|
14
|
+
/** Project-relative output file path (e.g. firestore.rules). */
|
|
15
|
+
outputFile: string;
|
|
16
|
+
/** Generated compiled rules text. */
|
|
17
|
+
content: string;
|
|
18
|
+
/** Project-relative fragment paths included in deterministic order. */
|
|
19
|
+
fragments: string[];
|
|
20
|
+
/** Whether the output file differed from disk (or was missing). */
|
|
21
|
+
changed: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Pure in-memory assembler shared by both `t4g-rules` CLI and Angular schematics.
|
|
25
|
+
* Combines `firestore.base.rules` with all `*.firestore.rules` fragments under `sourceRoot`
|
|
26
|
+
* (sorted deterministically) at the `// @t4g-entity-rules` marker.
|
|
27
|
+
*/
|
|
28
|
+
export declare function assembleFirestoreRulesSources(sources: Record<string, string>, options?: Pick<FirestoreRulesOptions, 'sourceRoot' | 'baseFile' | 'outputFile'>): Omit<FirestoreRulesResult, 'success' | 'changed'>;
|
|
29
|
+
/**
|
|
30
|
+
* Read `firestore.base.rules` and `*.firestore.rules` from disk, assemble `firestore.rules`,
|
|
31
|
+
* and write it (or verify it is up to date when `check: true`).
|
|
32
|
+
*/
|
|
33
|
+
export declare function generateFirestoreRules(options?: FirestoreRulesOptions & {
|
|
34
|
+
check?: boolean;
|
|
35
|
+
}): FirestoreRulesResult;
|
|
@@ -0,0 +1,164 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ENTITY_RULES_MARKER = void 0;
|
|
37
|
+
exports.assembleFirestoreRulesSources = assembleFirestoreRulesSources;
|
|
38
|
+
exports.generateFirestoreRules = generateFirestoreRules;
|
|
39
|
+
const fs = __importStar(require("node:fs"));
|
|
40
|
+
const path = __importStar(require("node:path"));
|
|
41
|
+
exports.ENTITY_RULES_MARKER = '// @t4g-entity-rules';
|
|
42
|
+
const slash = (p) => p.replace(/\\/g, '/');
|
|
43
|
+
function normalizeRelPath(p) {
|
|
44
|
+
const clean = path.posix.normalize(slash(p)).replace(/^\/+|\/+$/g, '');
|
|
45
|
+
if (!clean || clean === '..' || clean.startsWith('../')) {
|
|
46
|
+
throw new Error(`Invalid project-relative path: ${JSON.stringify(p)}`);
|
|
47
|
+
}
|
|
48
|
+
return clean;
|
|
49
|
+
}
|
|
50
|
+
/** Indent every non-empty line of a fragment so it nests cleanly under `match /databases/{database}/documents`. */
|
|
51
|
+
function indentBlock(text, spaces) {
|
|
52
|
+
const prefix = ' '.repeat(spaces);
|
|
53
|
+
return text
|
|
54
|
+
.replace(/\r\n/g, '\n')
|
|
55
|
+
.trim()
|
|
56
|
+
.split('\n')
|
|
57
|
+
.map((line) => (line.trim().length > 0 ? `${prefix}${line}` : ''))
|
|
58
|
+
.join('\n');
|
|
59
|
+
}
|
|
60
|
+
/** Extract top-level `match /<collection>/...` paths in a fragment to catch duplicate collection rules. */
|
|
61
|
+
function extractMatchPaths(fragment) {
|
|
62
|
+
const matches = [];
|
|
63
|
+
const regex = /\bmatch\s+\/([A-Za-z0-9_-]+)\/\{[^}]+\}/g;
|
|
64
|
+
let m;
|
|
65
|
+
while ((m = regex.exec(fragment)) !== null) {
|
|
66
|
+
matches.push(m[1]);
|
|
67
|
+
}
|
|
68
|
+
return matches;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Pure in-memory assembler shared by both `t4g-rules` CLI and Angular schematics.
|
|
72
|
+
* Combines `firestore.base.rules` with all `*.firestore.rules` fragments under `sourceRoot`
|
|
73
|
+
* (sorted deterministically) at the `// @t4g-entity-rules` marker.
|
|
74
|
+
*/
|
|
75
|
+
function assembleFirestoreRulesSources(sources, options = {}) {
|
|
76
|
+
const sourceRoot = normalizeRelPath(options.sourceRoot ?? 'src/app');
|
|
77
|
+
const baseFile = normalizeRelPath(options.baseFile ?? 'firestore.base.rules');
|
|
78
|
+
const outputFile = normalizeRelPath(options.outputFile ?? 'firestore.rules');
|
|
79
|
+
const normalized = new Map();
|
|
80
|
+
for (const [filePath, text] of Object.entries(sources)) {
|
|
81
|
+
normalized.set(slash(filePath).replace(/^\/+/, ''), text);
|
|
82
|
+
}
|
|
83
|
+
const baseContent = normalized.get(baseFile);
|
|
84
|
+
if (baseContent === undefined) {
|
|
85
|
+
throw new Error(`Base rules file "${baseFile}" was not found.`);
|
|
86
|
+
}
|
|
87
|
+
if (!baseContent.includes(exports.ENTITY_RULES_MARKER)) {
|
|
88
|
+
throw new Error(`Base rules file "${baseFile}" must contain the marker "${exports.ENTITY_RULES_MARKER}".`);
|
|
89
|
+
}
|
|
90
|
+
const fragmentPaths = [...normalized.keys()]
|
|
91
|
+
.filter((file) => (sourceRoot === '.' || file.startsWith(`${sourceRoot}/`)) && file.endsWith('.firestore.rules'))
|
|
92
|
+
.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
93
|
+
const seenCollections = new Map();
|
|
94
|
+
const renderedBlocks = [];
|
|
95
|
+
for (const fragmentPath of fragmentPaths) {
|
|
96
|
+
const raw = (normalized.get(fragmentPath) ?? '').trim();
|
|
97
|
+
if (!raw) {
|
|
98
|
+
throw new Error(`${fragmentPath}: entity rules fragment cannot be empty.`);
|
|
99
|
+
}
|
|
100
|
+
if (/\brules_version\b/.test(raw) || /\bservice\s+cloud\.firestore\b/.test(raw)) {
|
|
101
|
+
throw new Error(`${fragmentPath}: entity rules fragments must contain only match blocks, not rules_version or service wrappers.`);
|
|
102
|
+
}
|
|
103
|
+
for (const collection of extractMatchPaths(raw)) {
|
|
104
|
+
const existing = seenCollections.get(collection);
|
|
105
|
+
if (existing) {
|
|
106
|
+
throw new Error(`${fragmentPath}: duplicate Firestore rules for collection "${collection}" (already defined in ${existing}).`);
|
|
107
|
+
}
|
|
108
|
+
seenCollections.set(collection, fragmentPath);
|
|
109
|
+
}
|
|
110
|
+
renderedBlocks.push(` // Source: ${fragmentPath}\n${indentBlock(raw, 4)}`);
|
|
111
|
+
}
|
|
112
|
+
// Replace the marker line (including its leading indentation) cleanly.
|
|
113
|
+
const markerLineRegex = new RegExp(`^[ \\t]*${exports.ENTITY_RULES_MARKER.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[ \\t]*$`, 'm');
|
|
114
|
+
const assembledBody = baseContent
|
|
115
|
+
.replace(/\r\n/g, '\n')
|
|
116
|
+
.replace(markerLineRegex, renderedBlocks.join('\n\n'));
|
|
117
|
+
const header = `// Generated by t4g-rules from ${baseFile} and ${sourceRoot}/**/*.firestore.rules.\n` +
|
|
118
|
+
`// Do not edit this file directly; edit ${baseFile} or per-entity *.firestore.rules files and run \`npm run generate:rules\`.\n`;
|
|
119
|
+
const content = `${header}${assembledBody.trimEnd()}\n`;
|
|
120
|
+
return { outputFile, content, fragments: fragmentPaths };
|
|
121
|
+
}
|
|
122
|
+
function walkRuleFiles(dir, projectRoot, out) {
|
|
123
|
+
if (!fs.existsSync(dir))
|
|
124
|
+
return;
|
|
125
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
126
|
+
if (entry.name === 'node_modules' || entry.name === 'dist' || entry.name.startsWith('.'))
|
|
127
|
+
continue;
|
|
128
|
+
const full = path.join(dir, entry.name);
|
|
129
|
+
if (entry.isDirectory()) {
|
|
130
|
+
walkRuleFiles(full, projectRoot, out);
|
|
131
|
+
}
|
|
132
|
+
else if (entry.isFile() && entry.name.endsWith('.firestore.rules')) {
|
|
133
|
+
const rel = slash(path.relative(projectRoot, full));
|
|
134
|
+
out[rel] = fs.readFileSync(full, 'utf8');
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Read `firestore.base.rules` and `*.firestore.rules` from disk, assemble `firestore.rules`,
|
|
140
|
+
* and write it (or verify it is up to date when `check: true`).
|
|
141
|
+
*/
|
|
142
|
+
function generateFirestoreRules(options = {}) {
|
|
143
|
+
const projectRoot = path.resolve(options.projectRoot ?? process.cwd());
|
|
144
|
+
const sourceRoot = normalizeRelPath(options.sourceRoot ?? 'src/app');
|
|
145
|
+
const baseFile = normalizeRelPath(options.baseFile ?? 'firestore.base.rules');
|
|
146
|
+
const outputFile = normalizeRelPath(options.outputFile ?? 'firestore.rules');
|
|
147
|
+
const sources = {};
|
|
148
|
+
const absBase = path.join(projectRoot, baseFile);
|
|
149
|
+
if (fs.existsSync(absBase)) {
|
|
150
|
+
sources[baseFile] = fs.readFileSync(absBase, 'utf8');
|
|
151
|
+
}
|
|
152
|
+
walkRuleFiles(path.join(projectRoot, sourceRoot), projectRoot, sources);
|
|
153
|
+
const assembled = assembleFirestoreRulesSources(sources, { sourceRoot, baseFile, outputFile });
|
|
154
|
+
const absOutput = path.join(projectRoot, outputFile);
|
|
155
|
+
const existing = fs.existsSync(absOutput) ? fs.readFileSync(absOutput, 'utf8') : undefined;
|
|
156
|
+
const changed = existing !== assembled.content;
|
|
157
|
+
if (options.check) {
|
|
158
|
+
return { ...assembled, changed, success: !changed };
|
|
159
|
+
}
|
|
160
|
+
if (changed) {
|
|
161
|
+
fs.writeFileSync(absOutput, assembled.content, 'utf8');
|
|
162
|
+
}
|
|
163
|
+
return { ...assembled, changed, success: true };
|
|
164
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { checkFirestoreIndexes, CheckOptions, CheckResult } from './firestore-indexes';
|
|
2
2
|
export { generateEntityRegistries, generateEntityRegistrySources, watchEntityRegistries, EntityRegistryOptions, EntityRegistryResult } from './entity-registry';
|
|
3
|
+
export { ENTITY_RULES_MARKER, assembleFirestoreRulesSources, generateFirestoreRules, FirestoreRulesOptions, FirestoreRulesResult, } from './firestore-rules';
|
|
4
|
+
export { SKILLS_MANIFEST_FILE, SKILLS_GITIGNORE_FILE, discoverPackageSkills, syncPlatformSkills, DiscoveredSkill, SkillsSyncOptions, SkillsSyncResult, } from './skills-sync';
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.watchEntityRegistries = exports.generateEntityRegistrySources = exports.generateEntityRegistries = exports.checkFirestoreIndexes = void 0;
|
|
3
|
+
exports.syncPlatformSkills = exports.discoverPackageSkills = exports.SKILLS_GITIGNORE_FILE = exports.SKILLS_MANIFEST_FILE = exports.generateFirestoreRules = exports.assembleFirestoreRulesSources = exports.ENTITY_RULES_MARKER = exports.watchEntityRegistries = exports.generateEntityRegistrySources = exports.generateEntityRegistries = exports.checkFirestoreIndexes = void 0;
|
|
4
4
|
var firestore_indexes_1 = require("./firestore-indexes");
|
|
5
5
|
Object.defineProperty(exports, "checkFirestoreIndexes", { enumerable: true, get: function () { return firestore_indexes_1.checkFirestoreIndexes; } });
|
|
6
6
|
var entity_registry_1 = require("./entity-registry");
|
|
7
7
|
Object.defineProperty(exports, "generateEntityRegistries", { enumerable: true, get: function () { return entity_registry_1.generateEntityRegistries; } });
|
|
8
8
|
Object.defineProperty(exports, "generateEntityRegistrySources", { enumerable: true, get: function () { return entity_registry_1.generateEntityRegistrySources; } });
|
|
9
9
|
Object.defineProperty(exports, "watchEntityRegistries", { enumerable: true, get: function () { return entity_registry_1.watchEntityRegistries; } });
|
|
10
|
+
var firestore_rules_1 = require("./firestore-rules");
|
|
11
|
+
Object.defineProperty(exports, "ENTITY_RULES_MARKER", { enumerable: true, get: function () { return firestore_rules_1.ENTITY_RULES_MARKER; } });
|
|
12
|
+
Object.defineProperty(exports, "assembleFirestoreRulesSources", { enumerable: true, get: function () { return firestore_rules_1.assembleFirestoreRulesSources; } });
|
|
13
|
+
Object.defineProperty(exports, "generateFirestoreRules", { enumerable: true, get: function () { return firestore_rules_1.generateFirestoreRules; } });
|
|
14
|
+
var skills_sync_1 = require("./skills-sync");
|
|
15
|
+
Object.defineProperty(exports, "SKILLS_MANIFEST_FILE", { enumerable: true, get: function () { return skills_sync_1.SKILLS_MANIFEST_FILE; } });
|
|
16
|
+
Object.defineProperty(exports, "SKILLS_GITIGNORE_FILE", { enumerable: true, get: function () { return skills_sync_1.SKILLS_GITIGNORE_FILE; } });
|
|
17
|
+
Object.defineProperty(exports, "discoverPackageSkills", { enumerable: true, get: function () { return skills_sync_1.discoverPackageSkills; } });
|
|
18
|
+
Object.defineProperty(exports, "syncPlatformSkills", { enumerable: true, get: function () { return skills_sync_1.syncPlatformSkills; } });
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const firestore_rules_1 = require("./firestore-rules");
|
|
5
|
+
const help = `Usage: t4g-rules [--check] [--project-root <path>] [--source-root <path>] [--base-file <path>] [--output-file <path>]
|
|
6
|
+
|
|
7
|
+
Assemble firestore.rules from firestore.base.rules and per-entity *.firestore.rules files under src/app.
|
|
8
|
+
|
|
9
|
+
--check Fail if firestore.rules is missing or stale; do not write
|
|
10
|
+
--project-root <path> Default: current directory
|
|
11
|
+
--source-root <path> Project-relative scan directory (default: src/app)
|
|
12
|
+
--base-file <path> Project-relative base rules file (default: firestore.base.rules)
|
|
13
|
+
--output-file <path> Project-relative output file (default: firestore.rules)
|
|
14
|
+
--help, -h Show this help
|
|
15
|
+
|
|
16
|
+
Examples: t4g-rules
|
|
17
|
+
t4g-rules --check`;
|
|
18
|
+
function main(args) {
|
|
19
|
+
const options = {};
|
|
20
|
+
let check = false;
|
|
21
|
+
for (let i = 0; i < args.length; i++) {
|
|
22
|
+
const arg = args[i];
|
|
23
|
+
if (arg === '--help' || arg === '-h') {
|
|
24
|
+
console.log(help);
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
if (arg === '--check') {
|
|
28
|
+
check = true;
|
|
29
|
+
}
|
|
30
|
+
else if (['--project-root', '--source-root', '--base-file', '--output-file'].includes(arg)) {
|
|
31
|
+
const value = args[++i];
|
|
32
|
+
if (!value || value.startsWith('-'))
|
|
33
|
+
throw new Error(`${arg} requires a path.`);
|
|
34
|
+
if (arg === '--project-root')
|
|
35
|
+
options.projectRoot = value;
|
|
36
|
+
if (arg === '--source-root')
|
|
37
|
+
options.sourceRoot = value;
|
|
38
|
+
if (arg === '--base-file')
|
|
39
|
+
options.baseFile = value;
|
|
40
|
+
if (arg === '--output-file')
|
|
41
|
+
options.outputFile = value;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
throw new Error(`Unknown argument: ${arg}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const result = (0, firestore_rules_1.generateFirestoreRules)({ ...options, check });
|
|
48
|
+
if (result.changed) {
|
|
49
|
+
console.log(`[rules] ${result.fragments.length} entity rule fragment(s); ` +
|
|
50
|
+
`${result.success ? 'generated' : 'stale'}: ${result.outputFile}`);
|
|
51
|
+
}
|
|
52
|
+
return result.success ? 0 : 1;
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
process.exitCode = main(process.argv.slice(2));
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.error(`[rules] ${error instanceof Error ? error.message : String(error)}`);
|
|
59
|
+
process.exitCode = 1;
|
|
60
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const skills_sync_1 = require("./skills-sync");
|
|
5
|
+
const help = `Usage: t4g-skills [sync] [--check] [--project-root <path>] [--output-dir <path>]
|
|
6
|
+
|
|
7
|
+
Sync agent skills co-located inside installed @tech4good/* npm packages into .agents/skills/.
|
|
8
|
+
Runs automatically via "postinstall" so skill versions always match installed package versions.
|
|
9
|
+
|
|
10
|
+
--check Fail if .agents/skills/ is out of date; do not write
|
|
11
|
+
--project-root <path> Default: current directory
|
|
12
|
+
--output-dir <path> Project-relative skills directory (default: .agents/skills)
|
|
13
|
+
--help, -h Show this help
|
|
14
|
+
|
|
15
|
+
Examples: t4g-skills sync
|
|
16
|
+
t4g-skills --check`;
|
|
17
|
+
function main(args) {
|
|
18
|
+
const options = {};
|
|
19
|
+
let check = false;
|
|
20
|
+
for (let i = 0; i < args.length; i++) {
|
|
21
|
+
const arg = args[i];
|
|
22
|
+
if (arg === 'sync')
|
|
23
|
+
continue;
|
|
24
|
+
if (arg === '--help' || arg === '-h') {
|
|
25
|
+
console.log(help);
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
if (arg === '--check') {
|
|
29
|
+
check = true;
|
|
30
|
+
}
|
|
31
|
+
else if (['--project-root', '--output-dir'].includes(arg)) {
|
|
32
|
+
const value = args[++i];
|
|
33
|
+
if (!value || value.startsWith('-'))
|
|
34
|
+
throw new Error(`${arg} requires a path.`);
|
|
35
|
+
if (arg === '--project-root')
|
|
36
|
+
options.projectRoot = value;
|
|
37
|
+
if (arg === '--output-dir')
|
|
38
|
+
options.outputDir = value;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
throw new Error(`Unknown argument: ${arg}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const result = (0, skills_sync_1.syncPlatformSkills)({ ...options, check });
|
|
45
|
+
if (result.changed) {
|
|
46
|
+
const parts = [];
|
|
47
|
+
if (result.synced.length)
|
|
48
|
+
parts.push(`${check ? 'stale' : 'synced'}: ${result.synced.join(', ')}`);
|
|
49
|
+
if (result.removed.length)
|
|
50
|
+
parts.push(`${check ? 'extra' : 'removed'}: ${result.removed.join(', ')}`);
|
|
51
|
+
console.log(`[skills] ${result.outputDir} (${parts.join('; ') || 'metadata updated'})`);
|
|
52
|
+
}
|
|
53
|
+
return result.success ? 0 : 1;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
process.exitCode = main(process.argv.slice(2));
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.error(`[skills] ${error instanceof Error ? error.message : String(error)}`);
|
|
60
|
+
process.exitCode = 1;
|
|
61
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare const SKILLS_MANIFEST_FILE = ".t4g-managed.json";
|
|
2
|
+
export declare const SKILLS_GITIGNORE_FILE = ".gitignore";
|
|
3
|
+
export interface SkillsSyncOptions {
|
|
4
|
+
/** Application root directory containing node_modules (default: process.cwd()). */
|
|
5
|
+
projectRoot?: string;
|
|
6
|
+
/** Project-relative target directory for synced skills (default: .agents/skills). */
|
|
7
|
+
outputDir?: string;
|
|
8
|
+
/** npm scope under node_modules to scan for co-located skills (default: @tech4good). */
|
|
9
|
+
scope?: string;
|
|
10
|
+
/** If true, report drift without writing or deleting files. */
|
|
11
|
+
check?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface DiscoveredSkill {
|
|
14
|
+
name: string;
|
|
15
|
+
packageName: string;
|
|
16
|
+
sourceDir: string;
|
|
17
|
+
}
|
|
18
|
+
export interface SkillsSyncResult {
|
|
19
|
+
success: boolean;
|
|
20
|
+
outputDir: string;
|
|
21
|
+
synced: string[];
|
|
22
|
+
removed: string[];
|
|
23
|
+
unchanged: string[];
|
|
24
|
+
changed: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Discover skills shipped inside installed `node_modules/<scope>/<pkg>/skills/<skill-name>/SKILL.md`.
|
|
28
|
+
* Rejects duplicate skill names across different packages so ownership is unambiguous.
|
|
29
|
+
*/
|
|
30
|
+
export declare function discoverPackageSkills(projectRoot: string, scope?: string): DiscoveredSkill[];
|
|
31
|
+
/**
|
|
32
|
+
* Sync co-located skills from installed `@tech4good/*` npm packages into `.agents/skills/`.
|
|
33
|
+
*
|
|
34
|
+
* - Writes `.agents/skills/.t4g-managed.json` to track synced skills so upgrades
|
|
35
|
+
* cleanly prune removed skills without touching app-authored custom skills.
|
|
36
|
+
* - Writes `.agents/skills/.gitignore` so synced platform skills stay untracked
|
|
37
|
+
* while app-authored custom skills in `.agents/skills/` remain tracked in git.
|
|
38
|
+
* - Throws if a platform skill collides with an existing unmanaged app skill.
|
|
39
|
+
*/
|
|
40
|
+
export declare function syncPlatformSkills(options?: SkillsSyncOptions): SkillsSyncResult;
|
|
@@ -0,0 +1,236 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.SKILLS_GITIGNORE_FILE = exports.SKILLS_MANIFEST_FILE = void 0;
|
|
37
|
+
exports.discoverPackageSkills = discoverPackageSkills;
|
|
38
|
+
exports.syncPlatformSkills = syncPlatformSkills;
|
|
39
|
+
const fs = __importStar(require("node:fs"));
|
|
40
|
+
const path = __importStar(require("node:path"));
|
|
41
|
+
exports.SKILLS_MANIFEST_FILE = '.t4g-managed.json';
|
|
42
|
+
exports.SKILLS_GITIGNORE_FILE = '.gitignore';
|
|
43
|
+
const slash = (p) => p.replace(/\\/g, '/');
|
|
44
|
+
function readDirFilesRecursive(rootDir, currentDir = rootDir, out = new Map()) {
|
|
45
|
+
if (!fs.existsSync(currentDir))
|
|
46
|
+
return out;
|
|
47
|
+
for (const entry of fs.readdirSync(currentDir, { withFileTypes: true })) {
|
|
48
|
+
if (entry.name === '.DS_Store')
|
|
49
|
+
continue;
|
|
50
|
+
const full = path.join(currentDir, entry.name);
|
|
51
|
+
if (entry.isDirectory()) {
|
|
52
|
+
readDirFilesRecursive(rootDir, full, out);
|
|
53
|
+
}
|
|
54
|
+
else if (entry.isFile()) {
|
|
55
|
+
const rel = slash(path.relative(rootDir, full));
|
|
56
|
+
out.set(rel, fs.readFileSync(full));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
function directoriesEqual(dirA, dirB) {
|
|
62
|
+
if (!fs.existsSync(dirA) || !fs.existsSync(dirB))
|
|
63
|
+
return false;
|
|
64
|
+
const filesA = readDirFilesRecursive(dirA);
|
|
65
|
+
const filesB = readDirFilesRecursive(dirB);
|
|
66
|
+
if (filesA.size !== filesB.size)
|
|
67
|
+
return false;
|
|
68
|
+
for (const [rel, bufA] of filesA.entries()) {
|
|
69
|
+
const bufB = filesB.get(rel);
|
|
70
|
+
if (!bufB || !bufA.equals(bufB))
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
function copyDirClean(sourceDir, targetDir) {
|
|
76
|
+
fs.rmSync(targetDir, { recursive: true, force: true });
|
|
77
|
+
fs.cpSync(sourceDir, targetDir, { recursive: true });
|
|
78
|
+
}
|
|
79
|
+
function readManagedManifest(outputAbs) {
|
|
80
|
+
const manifestPath = path.join(outputAbs, exports.SKILLS_MANIFEST_FILE);
|
|
81
|
+
if (!fs.existsSync(manifestPath)) {
|
|
82
|
+
return { managed: [], sources: {} };
|
|
83
|
+
}
|
|
84
|
+
const parsed = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
85
|
+
return {
|
|
86
|
+
managed: Array.isArray(parsed.managed) ? parsed.managed.filter((v) => typeof v === 'string') : [],
|
|
87
|
+
sources: parsed.sources && typeof parsed.sources === 'object' ? parsed.sources : {},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function renderSkillsGitignore(managedNames) {
|
|
91
|
+
const lines = [
|
|
92
|
+
'# Managed by t4g-skills sync — do not edit directly.',
|
|
93
|
+
`/${exports.SKILLS_GITIGNORE_FILE}`,
|
|
94
|
+
`/${exports.SKILLS_MANIFEST_FILE}`,
|
|
95
|
+
...managedNames.map((name) => `/${name}/`),
|
|
96
|
+
];
|
|
97
|
+
return `${lines.join('\n')}\n`;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Discover skills shipped inside installed `node_modules/<scope>/<pkg>/skills/<skill-name>/SKILL.md`.
|
|
101
|
+
* Rejects duplicate skill names across different packages so ownership is unambiguous.
|
|
102
|
+
*/
|
|
103
|
+
function discoverPackageSkills(projectRoot, scope = '@tech4good') {
|
|
104
|
+
const scopeDir = path.join(projectRoot, 'node_modules', scope);
|
|
105
|
+
if (!fs.existsSync(scopeDir))
|
|
106
|
+
return [];
|
|
107
|
+
const discovered = [];
|
|
108
|
+
const seenNames = new Map();
|
|
109
|
+
const packageEntries = fs.readdirSync(scopeDir, { withFileTypes: true })
|
|
110
|
+
.filter((entry) => entry.isDirectory() || entry.isSymbolicLink())
|
|
111
|
+
.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
112
|
+
for (const pkgEntry of packageEntries) {
|
|
113
|
+
const pkgName = `${scope}/${pkgEntry.name}`;
|
|
114
|
+
const skillsDir = path.join(scopeDir, pkgEntry.name, 'skills');
|
|
115
|
+
if (!fs.existsSync(skillsDir) || !fs.statSync(skillsDir).isDirectory())
|
|
116
|
+
continue;
|
|
117
|
+
const skillEntries = fs.readdirSync(skillsDir, { withFileTypes: true })
|
|
118
|
+
.filter((entry) => entry.isDirectory() || entry.isSymbolicLink())
|
|
119
|
+
.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
120
|
+
for (const skillEntry of skillEntries) {
|
|
121
|
+
const skillDir = path.join(skillsDir, skillEntry.name);
|
|
122
|
+
const skillFile = path.join(skillDir, 'SKILL.md');
|
|
123
|
+
if (!fs.existsSync(skillFile))
|
|
124
|
+
continue;
|
|
125
|
+
const existingPkg = seenNames.get(skillEntry.name);
|
|
126
|
+
if (existingPkg) {
|
|
127
|
+
throw new Error(`Duplicate platform skill "${skillEntry.name}" provided by both "${existingPkg}" and "${pkgName}".`);
|
|
128
|
+
}
|
|
129
|
+
seenNames.set(skillEntry.name, pkgName);
|
|
130
|
+
discovered.push({
|
|
131
|
+
name: skillEntry.name,
|
|
132
|
+
packageName: pkgName,
|
|
133
|
+
sourceDir: skillDir,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return discovered.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Sync co-located skills from installed `@tech4good/*` npm packages into `.agents/skills/`.
|
|
141
|
+
*
|
|
142
|
+
* - Writes `.agents/skills/.t4g-managed.json` to track synced skills so upgrades
|
|
143
|
+
* cleanly prune removed skills without touching app-authored custom skills.
|
|
144
|
+
* - Writes `.agents/skills/.gitignore` so synced platform skills stay untracked
|
|
145
|
+
* while app-authored custom skills in `.agents/skills/` remain tracked in git.
|
|
146
|
+
* - Throws if a platform skill collides with an existing unmanaged app skill.
|
|
147
|
+
*/
|
|
148
|
+
function syncPlatformSkills(options = {}) {
|
|
149
|
+
const projectRoot = path.resolve(options.projectRoot ?? process.cwd());
|
|
150
|
+
const outputRel = slash(options.outputDir ?? '.agents/skills').replace(/^\/+|\/+$/g, '');
|
|
151
|
+
const outputAbs = path.join(projectRoot, outputRel);
|
|
152
|
+
const scope = options.scope ?? '@tech4good';
|
|
153
|
+
const discovered = discoverPackageSkills(projectRoot, scope);
|
|
154
|
+
const previous = readManagedManifest(outputAbs);
|
|
155
|
+
const previouslyManaged = new Set(previous.managed);
|
|
156
|
+
const synced = [];
|
|
157
|
+
const unchanged = [];
|
|
158
|
+
const removed = [];
|
|
159
|
+
const discoveredNames = new Set(discovered.map((skill) => skill.name));
|
|
160
|
+
// Verify no platform skill collides with an unmanaged app-authored skill.
|
|
161
|
+
for (const skill of discovered) {
|
|
162
|
+
const targetDir = path.join(outputAbs, skill.name);
|
|
163
|
+
if (fs.existsSync(targetDir) && !previouslyManaged.has(skill.name)) {
|
|
164
|
+
throw new Error(`Cannot sync platform skill "${skill.name}" from "${skill.packageName}": ` +
|
|
165
|
+
`"${outputRel}/${skill.name}" already exists and is not managed by t4g-skills.`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// Determine additions/updates.
|
|
169
|
+
for (const skill of discovered) {
|
|
170
|
+
const targetDir = path.join(outputAbs, skill.name);
|
|
171
|
+
if (directoriesEqual(skill.sourceDir, targetDir)) {
|
|
172
|
+
unchanged.push(skill.name);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
synced.push(skill.name);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
// Determine removals of previously managed skills that are no longer installed.
|
|
179
|
+
for (const oldName of [...previouslyManaged].sort()) {
|
|
180
|
+
if (!discoveredNames.has(oldName)) {
|
|
181
|
+
removed.push(oldName);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const nextManifest = {
|
|
185
|
+
managed: discovered.map((s) => s.name),
|
|
186
|
+
sources: Object.fromEntries(discovered.map((s) => [s.name, s.packageName])),
|
|
187
|
+
};
|
|
188
|
+
const nextManifestText = `${JSON.stringify(nextManifest, null, 2)}\n`;
|
|
189
|
+
const nextGitignoreText = renderSkillsGitignore(nextManifest.managed);
|
|
190
|
+
const manifestPath = path.join(outputAbs, exports.SKILLS_MANIFEST_FILE);
|
|
191
|
+
const gitignorePath = path.join(outputAbs, exports.SKILLS_GITIGNORE_FILE);
|
|
192
|
+
const existingManifestText = fs.existsSync(manifestPath) ? fs.readFileSync(manifestPath, 'utf8') : undefined;
|
|
193
|
+
const existingGitignoreText = fs.existsSync(gitignorePath) ? fs.readFileSync(gitignorePath, 'utf8') : undefined;
|
|
194
|
+
const metadataChanged = (discovered.length > 0 || previouslyManaged.size > 0) &&
|
|
195
|
+
(existingManifestText !== nextManifestText || existingGitignoreText !== nextGitignoreText);
|
|
196
|
+
const changed = synced.length > 0 || removed.length > 0 || metadataChanged;
|
|
197
|
+
if (options.check) {
|
|
198
|
+
return {
|
|
199
|
+
success: !changed,
|
|
200
|
+
outputDir: outputRel,
|
|
201
|
+
synced,
|
|
202
|
+
removed,
|
|
203
|
+
unchanged,
|
|
204
|
+
changed,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
if (discovered.length === 0 && previouslyManaged.size === 0) {
|
|
208
|
+
return {
|
|
209
|
+
success: true,
|
|
210
|
+
outputDir: outputRel,
|
|
211
|
+
synced,
|
|
212
|
+
removed,
|
|
213
|
+
unchanged,
|
|
214
|
+
changed: false,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
fs.mkdirSync(outputAbs, { recursive: true });
|
|
218
|
+
for (const skill of discovered) {
|
|
219
|
+
if (synced.includes(skill.name)) {
|
|
220
|
+
copyDirClean(skill.sourceDir, path.join(outputAbs, skill.name));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
for (const oldName of removed) {
|
|
224
|
+
fs.rmSync(path.join(outputAbs, oldName), { recursive: true, force: true });
|
|
225
|
+
}
|
|
226
|
+
fs.writeFileSync(manifestPath, nextManifestText, 'utf8');
|
|
227
|
+
fs.writeFileSync(gitignorePath, nextGitignoreText, 'utf8');
|
|
228
|
+
return {
|
|
229
|
+
success: true,
|
|
230
|
+
outputDir: outputRel,
|
|
231
|
+
synced,
|
|
232
|
+
removed,
|
|
233
|
+
unchanged,
|
|
234
|
+
changed,
|
|
235
|
+
};
|
|
236
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tech4good/platform-tooling",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.3",
|
|
4
4
|
"description": "Development tools for Tech4Good Angular and Firebase applications.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -15,10 +15,13 @@
|
|
|
15
15
|
},
|
|
16
16
|
"bin": {
|
|
17
17
|
"t4g-check-firestore-indexes": "./dist/cli.js",
|
|
18
|
-
"t4g-entities": "./dist/entities-cli.js"
|
|
18
|
+
"t4g-entities": "./dist/entities-cli.js",
|
|
19
|
+
"t4g-rules": "./dist/rules-cli.js",
|
|
20
|
+
"t4g-skills": "./dist/skills-cli.js"
|
|
19
21
|
},
|
|
20
22
|
"files": [
|
|
21
|
-
"dist"
|
|
23
|
+
"dist",
|
|
24
|
+
"skills"
|
|
22
25
|
],
|
|
23
26
|
"engines": {
|
|
24
27
|
"node": ">=22"
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: configure-firebase
|
|
3
|
+
description: "Should trigger when the user asks to configure Firebase projects, set up .firebaserc, initialize Firestore databases or Firebase Authentication, deploy initial security rules and Cloud Functions, or configure .env and Angular environment files for this Tech4Good project."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Configure Firebase & Environment Files
|
|
7
|
+
|
|
8
|
+
This skill guides you through connecting an already-scaffolded Tech4Good Angular repository to its Firebase projects (**dev**, **prod**, and **log**), deploying initial security rules and Cloud Functions, and configuring Angular environment files and `.env`.
|
|
9
|
+
|
|
10
|
+
Follow these steps sequentially.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Step 1: Set Firebase MCP Project Directory (if available)
|
|
15
|
+
|
|
16
|
+
If a Firebase MCP server is connected, its active project directory persists globally across sessions and may point at a prior workspace. Before making any Firebase MCP calls:
|
|
17
|
+
|
|
18
|
+
1. Call `firebase_update_environment` to set `project_dir` to the root directory of this repository.
|
|
19
|
+
2. Call `firebase_get_environment` to confirm `Project Directory` matches this repository.
|
|
20
|
+
3. If it does not match, stop and ask the user for guidance.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Step 2: Gather Firebase Project Information
|
|
25
|
+
|
|
26
|
+
1. Ask the user for:
|
|
27
|
+
- Their Firebase Project IDs for **production**, **dev**, and **log** databases.
|
|
28
|
+
- Whether they need assistance creating these projects or databases.
|
|
29
|
+
2. Remind the user to run `firebase login` in their terminal if they have not already done so.
|
|
30
|
+
3. Stop and wait for the user's response.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Step 3: Create Firebase Infrastructure (if requested)
|
|
35
|
+
|
|
36
|
+
If the user asks for help creating projects or databases:
|
|
37
|
+
|
|
38
|
+
1. Use `firebase_create_project` (via Firebase MCP) to create the requested projects. Avoid using the Firebase CLI for project creation in sandboxed environments where config-store or network restrictions may fail.
|
|
39
|
+
2. Note that provisioning projects and databases via Google Cloud APIs requires billing to be enabled.
|
|
40
|
+
3. Share direct links for each project so the user can enable the Cloud Firestore API and link a Billing Account:
|
|
41
|
+
- API: `https://console.developers.google.com/apis/api/firestore.googleapis.com/overview?project=<project-id>`
|
|
42
|
+
- Billing: `https://console.developers.google.com/billing/enable?project=<project-id>`
|
|
43
|
+
4. Stop and wait for the user to confirm they have enabled both the API and billing.
|
|
44
|
+
5. Use `firebase_init` (with the `firestore` feature) to provision the `(default)` database for each environment, then verify all three with `firestore_list_databases`.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Step 4: Configure `.firebaserc`, Authentication & Authorized Domains
|
|
49
|
+
|
|
50
|
+
1. Update `.firebaserc` at the repository root to map the project IDs to `default` (dev), `dev`, `prod`, and `log`.
|
|
51
|
+
2. If using Firebase MCP, initialize Authentication with `firebase_init` (passing the `auth` feature).
|
|
52
|
+
3. Direct the user to configure sign-in providers and domains in the Firebase Console for **both dev and prod** projects:
|
|
53
|
+
- `https://console.firebase.google.com/project/<dev-project-id>/authentication/providers`
|
|
54
|
+
- `https://console.firebase.google.com/project/<prod-project-id>/authentication/providers`
|
|
55
|
+
4. Ask them to enable:
|
|
56
|
+
- **Sign-in Providers**:
|
|
57
|
+
- **Google**: Enable and save.
|
|
58
|
+
- **Email/Password**: Enable **Email link (passwordless sign-in)** and save.
|
|
59
|
+
- **Anonymous**: Enable and save.
|
|
60
|
+
- **Authorized Domains** (**Settings → Authorized domains**):
|
|
61
|
+
- Add `localhost` (without a port; `localhost:4200` is rejected by Firebase).
|
|
62
|
+
- Add any custom application domain(s).
|
|
63
|
+
- **Email Templates & Custom Hosting Domains** (optional): Configure custom From/Reply-To details or custom hosting domains if needed.
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Step 5: Deploy Initial Security Rules & Cloud Functions
|
|
68
|
+
|
|
69
|
+
Provide the exact terminal commands and wait for the user to run them in their terminal:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npm run deploy:dev
|
|
73
|
+
npm run deploy:prod
|
|
74
|
+
npm run deploy:logs
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
*(To deploy Cloud Functions independently: `npm run deploy:functions:dev` and `npm run deploy:functions:prod`.)*
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## Step 6: Update Angular Environments & `.env`
|
|
82
|
+
|
|
83
|
+
Follow Tech4Good's strict separation between **non-secret metadata** and **API keys**:
|
|
84
|
+
|
|
85
|
+
1. **Only dev & logs API keys belong in `.env`**:
|
|
86
|
+
- Put ONLY `NG_APP_FIREBASE_DEV_API_KEY` and `NG_APP_FIREBASE_LOGS_API_KEY` in the root `.env` file.
|
|
87
|
+
- **CRITICAL**: Do NOT put non-secret properties (`authDomain`, `projectId`, `storageBucket`, `messagingSenderId`, `appId`) into `.env`.
|
|
88
|
+
- **CRITICAL**: Do NOT put the production API key (`NG_APP_FIREBASE_API_KEY`) into `.env`.
|
|
89
|
+
2. **Hardcode non-secret project metadata in `src/environments/environment.ts` and `src/environments/environment.prod.ts`**, referencing `import.meta.env` strictly for the API keys:
|
|
90
|
+
- `environment.ts`: `NG_APP_FIREBASE_DEV_API_KEY` (for `firebase`) and `NG_APP_FIREBASE_LOGS_API_KEY` (for `firebaseLogs`).
|
|
91
|
+
- `environment.prod.ts`: `NG_APP_FIREBASE_API_KEY` (for `firebase`) and `NG_APP_FIREBASE_LOGS_API_KEY` (for `firebaseLogs`).
|
|
92
|
+
3. Create or update the root `.env` file with:
|
|
93
|
+
```env
|
|
94
|
+
NG_APP_FIREBASE_DEV_API_KEY=<dev-api-key>
|
|
95
|
+
NG_APP_FIREBASE_LOGS_API_KEY=<logs-api-key>
|
|
96
|
+
```
|