@tech4good/platform-tooling 0.1.0-alpha.1 → 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/README.md +107 -13
- package/dist/entities-cli.d.ts +2 -0
- package/dist/entities-cli.js +141 -0
- package/dist/entity-registry.d.ts +57 -0
- package/dist/entity-registry.js +313 -0
- package/dist/firestore-indexes.d.ts +16 -0
- package/dist/firestore-indexes.js +16 -0
- package/dist/firestore-rules.d.ts +35 -0
- package/dist/firestore-rules.js +164 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +14 -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 +7 -3
- package/skills/configure-firebase/SKILL.md +96 -0
|
@@ -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",
|
|
@@ -14,10 +14,14 @@
|
|
|
14
14
|
"./package.json": "./package.json"
|
|
15
15
|
},
|
|
16
16
|
"bin": {
|
|
17
|
-
"t4g-check-firestore-indexes": "./dist/cli.js"
|
|
17
|
+
"t4g-check-firestore-indexes": "./dist/cli.js",
|
|
18
|
+
"t4g-entities": "./dist/entities-cli.js",
|
|
19
|
+
"t4g-rules": "./dist/rules-cli.js",
|
|
20
|
+
"t4g-skills": "./dist/skills-cli.js"
|
|
18
21
|
},
|
|
19
22
|
"files": [
|
|
20
|
-
"dist"
|
|
23
|
+
"dist",
|
|
24
|
+
"skills"
|
|
21
25
|
],
|
|
22
26
|
"engines": {
|
|
23
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
|
+
```
|