@snorreks/firestack 0.0.12 → 0.0.13
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 +34 -29
- package/lib/commands/build.d.ts +3 -0
- package/lib/commands/build.d.ts.map +1 -0
- package/lib/commands/delete/utils/delete_functions.d.ts +3 -0
- package/lib/commands/delete/utils/delete_functions.d.ts.map +1 -0
- package/lib/commands/delete/utils/read_functions.d.ts +5 -0
- package/lib/commands/delete/utils/read_functions.d.ts.map +1 -0
- package/lib/commands/delete.d.ts +3 -0
- package/lib/commands/delete.d.ts.map +1 -0
- package/lib/commands/deploy/index.d.ts +3 -0
- package/lib/commands/deploy/index.d.ts.map +1 -0
- package/lib/commands/deploy/utils/create_deploy_index.d.ts +9 -0
- package/lib/commands/deploy/utils/create_deploy_index.d.ts.map +1 -0
- package/lib/commands/deploy/utils/environment.d.ts +2 -0
- package/lib/commands/deploy/utils/environment.d.ts.map +1 -0
- package/lib/commands/deploy/utils/find_functions.d.ts +2 -0
- package/lib/commands/deploy/utils/find_functions.d.ts.map +1 -0
- package/lib/commands/deploy/utils/options.d.ts +30 -0
- package/lib/commands/deploy/utils/options.d.ts.map +1 -0
- package/lib/commands/deploy/utils/process_function.d.ts +6 -0
- package/lib/commands/deploy/utils/process_function.d.ts.map +1 -0
- package/lib/commands/deploy/utils/retry_failed_functions.d.ts +16 -0
- package/lib/commands/deploy/utils/retry_failed_functions.d.ts.map +1 -0
- package/lib/commands/emulate.d.ts +3 -0
- package/lib/commands/emulate.d.ts.map +1 -0
- package/lib/commands/logs.d.ts +3 -0
- package/lib/commands/logs.d.ts.map +1 -0
- package/lib/commands/rules/utils/rule_files.d.ts +9 -0
- package/lib/commands/rules/utils/rule_files.d.ts.map +1 -0
- package/lib/commands/rules.d.ts +3 -0
- package/lib/commands/rules.d.ts.map +1 -0
- package/lib/commands/scripts.d.ts +3 -0
- package/lib/commands/scripts.d.ts.map +1 -0
- package/lib/constants/index.d.ts +1 -0
- package/lib/constants/index.d.ts.map +1 -1
- package/lib/constants/options.d.ts +2 -0
- package/lib/constants/options.d.ts.map +1 -0
- package/lib/helpers/auth.d.ts +1 -1
- package/lib/helpers/auth.d.ts.map +1 -1
- package/lib/helpers/database.d.ts +1 -1
- package/lib/helpers/database.d.ts.map +1 -1
- package/lib/helpers/firestore.d.ts +1 -1
- package/lib/helpers/firestore.d.ts.map +1 -1
- package/lib/helpers/https.d.ts +8 -14
- package/lib/helpers/https.d.ts.map +1 -1
- package/lib/helpers/scheduler.d.ts +1 -1
- package/lib/helpers/scheduler.d.ts.map +1 -1
- package/lib/helpers/storage.d.ts +1 -1
- package/lib/helpers/storage.d.ts.map +1 -1
- package/lib/types/core.d.ts +1 -1
- package/lib/types/function-types.d.ts +1 -1
- package/lib/types/function-types.d.ts.map +1 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/utils/build_utils.d.ts +20 -0
- package/lib/utils/build_utils.d.ts.map +1 -0
- package/lib/utils/checksum.d.ts +8 -0
- package/lib/utils/checksum.d.ts.map +1 -0
- package/lib/utils/common.d.ts +2 -0
- package/lib/utils/common.d.ts.map +1 -0
- package/lib/utils/create-deploy-index.d.ts +9 -0
- package/lib/utils/create-deploy-index.d.ts.map +1 -0
- package/lib/utils/env.d.ts +2 -0
- package/lib/utils/env.d.ts.map +1 -0
- package/lib/utils/firebase_utils.d.ts +5 -0
- package/lib/utils/firebase_utils.d.ts.map +1 -0
- package/lib/utils/function_naming.d.ts +38 -0
- package/lib/utils/function_naming.d.ts.map +1 -0
- package/lib/utils/logger.d.ts +30 -0
- package/lib/utils/logger.d.ts.map +1 -0
- package/lib/utils/node-shim.d.ts +71 -0
- package/lib/utils/node-shim.d.ts.map +1 -0
- package/lib/utils/read-compiled-file.d.ts +2 -0
- package/lib/utils/read-compiled-file.d.ts.map +1 -0
- package/lib/utils/run-functions.d.ts +12 -0
- package/lib/utils/run-functions.d.ts.map +1 -0
- package/main.d.ts +2 -0
- package/main.d.ts.map +1 -0
- package/main.js +122 -86
- package/package.json +4 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Utilities for deriving function names and document paths from file paths.
|
|
3
|
+
* @license MIT
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Derives a function name from a file path relative to the controllers directory.
|
|
7
|
+
*
|
|
8
|
+
* Examples:
|
|
9
|
+
* - `api/test_api.ts` → `test_api`
|
|
10
|
+
* - `firestore/users/[uid]/created.ts` → `users_created`
|
|
11
|
+
* - `scheduler/daily.ts` → `daily`
|
|
12
|
+
*
|
|
13
|
+
* @param funcPath The absolute path to the function file.
|
|
14
|
+
* @param controllersPath The absolute path to the controllers directory.
|
|
15
|
+
* @returns The derived function name.
|
|
16
|
+
*/
|
|
17
|
+
export declare function deriveFunctionName(funcPath: string, controllersPath: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Extracts a Firestore document path from a file path.
|
|
20
|
+
*
|
|
21
|
+
* Examples:
|
|
22
|
+
* - `firestore/users/[uid]/created.ts` → `users/{uid}`
|
|
23
|
+
* - `firestore/users/[uid]/notifications/[notificationId]/created.ts` → `users/{uid}/notifications/{notificationId}`
|
|
24
|
+
*
|
|
25
|
+
* @param funcPath The absolute path to the function file.
|
|
26
|
+
* @param controllersPath The absolute path to the controllers directory.
|
|
27
|
+
* @returns The Firestore document path, or undefined if not a Firestore trigger.
|
|
28
|
+
*/
|
|
29
|
+
export declare function extractDocumentPath(funcPath: string, controllersPath: string): string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Extracts a database reference path from a file path.
|
|
32
|
+
*
|
|
33
|
+
* @param funcPath The absolute path to the function file.
|
|
34
|
+
* @param controllersPath The absolute path to the controllers directory.
|
|
35
|
+
* @returns The database reference path, or undefined if not a database trigger.
|
|
36
|
+
*/
|
|
37
|
+
export declare function extractDatabaseRef(funcPath: string, controllersPath: string): string | undefined;
|
|
38
|
+
//# sourceMappingURL=function_naming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function_naming.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/function_naming.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM,CAcpF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAuBjG;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAuBhG"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type LogType = 'debug' | 'info' | 'warn' | 'error' | 'log';
|
|
2
|
+
declare enum LogSeverityPriority {
|
|
3
|
+
silent = 0,
|
|
4
|
+
debug = 1,
|
|
5
|
+
info = 2,
|
|
6
|
+
warn = 4,
|
|
7
|
+
error = 5
|
|
8
|
+
}
|
|
9
|
+
export type LogSeverity = keyof typeof LogSeverityPriority;
|
|
10
|
+
export interface LogEntry {
|
|
11
|
+
severity?: LogSeverity;
|
|
12
|
+
logType?: LogType;
|
|
13
|
+
message?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface LoggerInterface {
|
|
16
|
+
readonly currentLogSeverity: LogSeverity;
|
|
17
|
+
setLogSeverity(options: {
|
|
18
|
+
silent?: boolean;
|
|
19
|
+
verbose?: boolean;
|
|
20
|
+
}): void;
|
|
21
|
+
write(entry: LogEntry, ...data: unknown[]): void;
|
|
22
|
+
debug(...args: unknown[]): void;
|
|
23
|
+
log(...args: unknown[]): void;
|
|
24
|
+
info(...args: unknown[]): void;
|
|
25
|
+
warn(...args: unknown[]): void;
|
|
26
|
+
error(...args: unknown[]): void;
|
|
27
|
+
}
|
|
28
|
+
export declare const logger: LoggerInterface;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/logger.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;AAElE,aAAK,mBAAmB;IACtB,MAAM,IAAI;IACV,KAAK,IAAI;IACT,IAAI,IAAI;IACR,IAAI,IAAI;IACR,KAAK,IAAI;CACV;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,mBAAmB,CAAC;AAE3D,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,EAAE,WAAW,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,kBAAkB,EAAE,WAAW,CAAC;IAEzC,cAAc,CAAC,OAAO,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IAEvE,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACjD,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChC,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC9B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC/B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC/B,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CACjC;AAkGD,eAAO,MAAM,MAAM,iBAA4B,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export { spawn } from 'node:child_process';
|
|
2
|
+
export { existsSync, mkdirSync, watch } from 'node:fs';
|
|
3
|
+
export { mkdir as mkdirProm, readdir, readFile, rm, stat, writeFile } from 'node:fs/promises';
|
|
4
|
+
export { dirname } from 'node:path';
|
|
5
|
+
export { cwd, exit } from 'node:process';
|
|
6
|
+
export { TextDecoder, TextEncoder } from 'node:util';
|
|
7
|
+
export declare const errors: {
|
|
8
|
+
NotFound: {
|
|
9
|
+
new (message?: string): {
|
|
10
|
+
code: string;
|
|
11
|
+
name: string;
|
|
12
|
+
message: string;
|
|
13
|
+
stack?: string;
|
|
14
|
+
cause?: unknown;
|
|
15
|
+
};
|
|
16
|
+
new (message?: string, options?: ErrorOptions): {
|
|
17
|
+
code: string;
|
|
18
|
+
name: string;
|
|
19
|
+
message: string;
|
|
20
|
+
stack?: string;
|
|
21
|
+
cause?: unknown;
|
|
22
|
+
};
|
|
23
|
+
isError(error: unknown): error is Error;
|
|
24
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
25
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
26
|
+
stackTraceLimit: number;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export declare function readTextFile(path: string): Promise<string>;
|
|
30
|
+
export declare function writeTextFile(path: string, contents: string): Promise<void>;
|
|
31
|
+
export declare function mkdir(path: string, options?: {
|
|
32
|
+
recursive?: boolean;
|
|
33
|
+
}): Promise<void>;
|
|
34
|
+
export declare function cwdDir(): string;
|
|
35
|
+
export declare function exitCode(code: number): never;
|
|
36
|
+
export declare function readDir(path: string): Promise<{
|
|
37
|
+
name: string;
|
|
38
|
+
isDirectory: () => boolean;
|
|
39
|
+
isFile: () => boolean;
|
|
40
|
+
}[]>;
|
|
41
|
+
export declare function remove(path: string, options?: {
|
|
42
|
+
recursive?: boolean;
|
|
43
|
+
}): Promise<void>;
|
|
44
|
+
export declare function watchFs(path: string): AsyncIterable<{
|
|
45
|
+
kind: string;
|
|
46
|
+
paths: string[];
|
|
47
|
+
}>;
|
|
48
|
+
export declare class Command {
|
|
49
|
+
private cmd;
|
|
50
|
+
private args;
|
|
51
|
+
private opts;
|
|
52
|
+
constructor(cmd: string, options?: {
|
|
53
|
+
args?: string[];
|
|
54
|
+
cwd?: string;
|
|
55
|
+
env?: Record<string, string>;
|
|
56
|
+
stdout?: 'inherit' | 'pipe';
|
|
57
|
+
stderr?: 'inherit' | 'pipe';
|
|
58
|
+
});
|
|
59
|
+
output(): Promise<{
|
|
60
|
+
code: number;
|
|
61
|
+
stdout: Uint8Array;
|
|
62
|
+
stderr: Uint8Array;
|
|
63
|
+
}>;
|
|
64
|
+
spawn(): {
|
|
65
|
+
status: Promise<{
|
|
66
|
+
code: number;
|
|
67
|
+
success: boolean;
|
|
68
|
+
}>;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=node-shim.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-shim.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/node-shim.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9F,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAErD,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;CAIlB,CAAC;AAEF,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAEhE;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAMjF;AAED,wBAAsB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1F;AAED,wBAAgB,MAAM,IAAI,MAAM,CAE/B;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAE5C;AAED,wBAAsB,OAAO,CAC3B,IAAI,EAAE,MAAM,GACX,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,OAAO,CAAA;CAAE,EAAE,CAAC,CAOhF;AAED,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAE3F;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAiCtF;AAED,qBAAa,OAAO;IAClB,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,IAAI,CAAgB;IAC5B,OAAO,CAAC,IAAI,CAKL;gBAGL,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE;QACR,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAChB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC7B,MAAM,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;QAC5B,MAAM,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;KAC7B;IAUG,MAAM,IAAI,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,UAAU,CAAC;QAAC,MAAM,EAAE,UAAU,CAAA;KAAE,CAAC;IAwBjF,KAAK,IAAI;QAAE,MAAM,EAAE,OAAO,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,OAAO,CAAA;SAAE,CAAC,CAAA;KAAE;CAcjE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-compiled-file.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/read-compiled-file.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,oBAAoB,GAC/B,YAAY,MAAM,EAClB,aAAa,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAClC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAa5C,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file This file contains a function for running multiple functions in parallel.
|
|
3
|
+
* @license MIT
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Runs multiple functions in parallel.
|
|
7
|
+
* @param functions The functions to run.
|
|
8
|
+
* @param concurrency The number of functions to run in parallel.
|
|
9
|
+
* @returns The results of the functions.
|
|
10
|
+
*/
|
|
11
|
+
export declare const runFunctions: <T>(functions: (() => Promise<T>)[], concurrency?: number) => Promise<T[]>;
|
|
12
|
+
//# sourceMappingURL=run-functions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-functions.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/run-functions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAU,CAAC,EAClC,WAAW,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,EAC/B,oBAAe,KACd,OAAO,CAAC,CAAC,EAAE,CAWb,CAAC"}
|
package/main.d.ts
ADDED
package/main.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":""}
|
package/main.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { Command as Command9 } from "commander";
|
|
5
5
|
|
|
6
6
|
// src/lib/commands/build.ts
|
|
7
|
-
import { readdir, readFile, writeFile
|
|
7
|
+
import { readdir, readFile, writeFile } from "node:fs/promises";
|
|
8
8
|
import { basename, join } from "node:path";
|
|
9
9
|
import { cwd, exit } from "node:process";
|
|
10
10
|
import chalk2 from "chalk";
|
|
@@ -12,9 +12,52 @@ import { Command } from "commander";
|
|
|
12
12
|
|
|
13
13
|
// src/lib/utils/build_utils.ts
|
|
14
14
|
import { mkdir } from "node:fs/promises";
|
|
15
|
-
import { dirname } from "node:path";
|
|
15
|
+
import { dirname as _dirname, dirname } from "node:path";
|
|
16
16
|
import { build } from "esbuild";
|
|
17
17
|
|
|
18
|
+
// src/lib/constants/function-types.ts
|
|
19
|
+
var firestoreFunctions = [
|
|
20
|
+
"onCreated",
|
|
21
|
+
"onUpdated",
|
|
22
|
+
"onDeleted",
|
|
23
|
+
"onWritten",
|
|
24
|
+
"onDocumentCreated",
|
|
25
|
+
"onDocumentUpdated",
|
|
26
|
+
"onDocumentDeleted",
|
|
27
|
+
"onDocumentWritten"
|
|
28
|
+
];
|
|
29
|
+
var databaseFunctions = [
|
|
30
|
+
"onValueCreated",
|
|
31
|
+
"onValueDeleted",
|
|
32
|
+
"onValueUpdated",
|
|
33
|
+
"onValueWritten"
|
|
34
|
+
];
|
|
35
|
+
var storageFunctions = [
|
|
36
|
+
"onObjectArchived",
|
|
37
|
+
"onObjectDeleted",
|
|
38
|
+
"onObjectFinalized",
|
|
39
|
+
"onObjectMetadataUpdated"
|
|
40
|
+
];
|
|
41
|
+
var authFunctions = [
|
|
42
|
+
"onAuthCreate",
|
|
43
|
+
"onAuthDelete",
|
|
44
|
+
"beforeAuthCreate",
|
|
45
|
+
"beforeAuthSignIn"
|
|
46
|
+
];
|
|
47
|
+
var schedulerFunctions = ["onSchedule"];
|
|
48
|
+
var httpsFunctions = ["onCall", "onRequest"];
|
|
49
|
+
var functions = [
|
|
50
|
+
...authFunctions,
|
|
51
|
+
...databaseFunctions,
|
|
52
|
+
...firestoreFunctions,
|
|
53
|
+
...storageFunctions,
|
|
54
|
+
...schedulerFunctions,
|
|
55
|
+
...httpsFunctions
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
// src/lib/constants/options.ts
|
|
59
|
+
var DEFAULT_NODE_VERSION = "22";
|
|
60
|
+
|
|
18
61
|
// src/lib/utils/logger.ts
|
|
19
62
|
import chalk from "chalk";
|
|
20
63
|
var LogSeverityPriority = /* @__PURE__ */ ((LogSeverityPriority2) => {
|
|
@@ -113,28 +156,63 @@ var logger = LoggerFactory.getLogger();
|
|
|
113
156
|
|
|
114
157
|
// src/lib/utils/build_utils.ts
|
|
115
158
|
async function buildFunction(options) {
|
|
116
|
-
const {
|
|
159
|
+
const {
|
|
160
|
+
inputFile,
|
|
161
|
+
outputFile,
|
|
162
|
+
external,
|
|
163
|
+
sourceRoot,
|
|
164
|
+
keepNames,
|
|
165
|
+
footer,
|
|
166
|
+
sourcemap,
|
|
167
|
+
tsconfig,
|
|
168
|
+
requireFix = true,
|
|
169
|
+
minify = true,
|
|
170
|
+
__dirnameFix = true,
|
|
171
|
+
__filenameFix = true
|
|
172
|
+
} = options;
|
|
117
173
|
const outDir = dirname(outputFile);
|
|
118
174
|
await mkdir(outDir, { recursive: true });
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
175
|
+
let banner;
|
|
176
|
+
if (__dirnameFix || __filenameFix || requireFix) {
|
|
177
|
+
const dirname4 = _dirname(inputFile).replace(/\\/g, "\\\\");
|
|
178
|
+
const filename = inputFile.replace(/\\/g, "\\\\");
|
|
179
|
+
let js = "";
|
|
180
|
+
if (__dirnameFix) {
|
|
181
|
+
js += `const __dirname='${dirname4}';`;
|
|
182
|
+
}
|
|
183
|
+
if (__filenameFix) {
|
|
184
|
+
js += `const __filename='${filename}';`;
|
|
185
|
+
}
|
|
186
|
+
if (requireFix) {
|
|
187
|
+
js += "import {createRequire} from 'module';const require=createRequire(import.meta.url);";
|
|
188
|
+
}
|
|
189
|
+
banner = {
|
|
190
|
+
js
|
|
191
|
+
};
|
|
192
|
+
}
|
|
122
193
|
try {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
194
|
+
const esbuildOptions = {
|
|
195
|
+
banner,
|
|
196
|
+
footer: footer ? { js: footer } : void 0,
|
|
126
197
|
bundle: true,
|
|
198
|
+
entryPoints: [inputFile],
|
|
127
199
|
format: "esm",
|
|
128
|
-
|
|
129
|
-
// external: ['firebase-functions', 'firebase-admin'],
|
|
200
|
+
external,
|
|
130
201
|
minify,
|
|
131
202
|
sourcemap,
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
|
|
203
|
+
treeShaking: true,
|
|
204
|
+
tsconfig,
|
|
205
|
+
outfile: outputFile,
|
|
206
|
+
platform: "node",
|
|
207
|
+
target: `node${options.nodeVersion || DEFAULT_NODE_VERSION}`,
|
|
208
|
+
keepNames,
|
|
209
|
+
sourceRoot
|
|
210
|
+
};
|
|
211
|
+
logger.debug("executeEsbuild:build", esbuildOptions);
|
|
212
|
+
const result = await build(esbuildOptions);
|
|
213
|
+
if (result.errors?.length) {
|
|
214
|
+
throw new Error(result.errors[0].text);
|
|
215
|
+
}
|
|
138
216
|
} catch (error) {
|
|
139
217
|
logger.error("buildFunction", {
|
|
140
218
|
error,
|
|
@@ -222,10 +300,10 @@ async function findFunctions(dir) {
|
|
|
222
300
|
// src/lib/commands/delete.ts
|
|
223
301
|
import { Command as Command3 } from "commander";
|
|
224
302
|
|
|
225
|
-
// src/lib/node-shim.ts
|
|
303
|
+
// src/lib/utils/node-shim.ts
|
|
226
304
|
import { spawn } from "node:child_process";
|
|
227
305
|
import { existsSync, mkdirSync, watch } from "node:fs";
|
|
228
|
-
import { mkdir as mkdirProm, readdir as readdir2, readFile as readFile2, rm, writeFile as
|
|
306
|
+
import { mkdir as mkdirProm, readdir as readdir2, readFile as readFile2, rm, writeFile as writeFile2 } from "node:fs/promises";
|
|
229
307
|
import { dirname as dirname2 } from "node:path";
|
|
230
308
|
import { cwd as cwd2, exit as exit2 } from "node:process";
|
|
231
309
|
async function readTextFile(path) {
|
|
@@ -236,9 +314,9 @@ async function writeTextFile(path, contents) {
|
|
|
236
314
|
if (!existsSync(dir)) {
|
|
237
315
|
mkdirSync(dir, { recursive: true });
|
|
238
316
|
}
|
|
239
|
-
await
|
|
317
|
+
await writeFile2(path, contents, "utf-8");
|
|
240
318
|
}
|
|
241
|
-
async function
|
|
319
|
+
async function mkdir2(path, options) {
|
|
242
320
|
await mkdirProm(path, { recursive: options?.recursive ?? false });
|
|
243
321
|
}
|
|
244
322
|
function cwdDir2() {
|
|
@@ -434,7 +512,7 @@ async function getOptions(cliOptions) {
|
|
|
434
512
|
scriptsDirectory: cliOptions.scriptsDirectory || config.scriptsDirectory || "scripts",
|
|
435
513
|
initScript: cliOptions.initScript || config.initScript || "init.ts",
|
|
436
514
|
region: cliOptions.region || config.region,
|
|
437
|
-
nodeVersion: cliOptions.nodeVersion || config.nodeVersion ||
|
|
515
|
+
nodeVersion: cliOptions.nodeVersion || config.nodeVersion || DEFAULT_NODE_VERSION,
|
|
438
516
|
projectId: cliOptions.projectId || config.flavors?.[cliOptions.flavor]
|
|
439
517
|
};
|
|
440
518
|
logger.setLogSeverity(options);
|
|
@@ -467,7 +545,7 @@ var deleteCommand = new Command3("delete").description("Deletes all unused Fireb
|
|
|
467
545
|
});
|
|
468
546
|
|
|
469
547
|
// src/lib/commands/deploy/index.ts
|
|
470
|
-
import { basename as
|
|
548
|
+
import { basename as basename3, join as join10 } from "node:path";
|
|
471
549
|
import { cwd as cwd3, exit as exit3 } from "node:process";
|
|
472
550
|
import { Command as Command4 } from "commander";
|
|
473
551
|
|
|
@@ -702,48 +780,6 @@ import {
|
|
|
702
780
|
ScriptTarget,
|
|
703
781
|
SyntaxKind
|
|
704
782
|
} from "typescript";
|
|
705
|
-
|
|
706
|
-
// src/lib/constants/function-types.ts
|
|
707
|
-
var firestoreFunctions = [
|
|
708
|
-
"onCreated",
|
|
709
|
-
"onUpdated",
|
|
710
|
-
"onDeleted",
|
|
711
|
-
"onWritten",
|
|
712
|
-
"onDocumentCreated",
|
|
713
|
-
"onDocumentUpdated",
|
|
714
|
-
"onDocumentDeleted",
|
|
715
|
-
"onDocumentWritten"
|
|
716
|
-
];
|
|
717
|
-
var databaseFunctions = [
|
|
718
|
-
"onValueCreated",
|
|
719
|
-
"onValueDeleted",
|
|
720
|
-
"onValueUpdated",
|
|
721
|
-
"onValueWritten"
|
|
722
|
-
];
|
|
723
|
-
var storageFunctions = [
|
|
724
|
-
"onObjectArchived",
|
|
725
|
-
"onObjectDeleted",
|
|
726
|
-
"onObjectFinalized",
|
|
727
|
-
"onObjectMetadataUpdated"
|
|
728
|
-
];
|
|
729
|
-
var authFunctions = [
|
|
730
|
-
"onAuthCreate",
|
|
731
|
-
"onAuthDelete",
|
|
732
|
-
"beforeAuthCreate",
|
|
733
|
-
"beforeAuthSignIn"
|
|
734
|
-
];
|
|
735
|
-
var schedulerFunctions = ["onSchedule"];
|
|
736
|
-
var httpsFunctions = ["onCall", "onRequest"];
|
|
737
|
-
var functions = [
|
|
738
|
-
...authFunctions,
|
|
739
|
-
...databaseFunctions,
|
|
740
|
-
...firestoreFunctions,
|
|
741
|
-
...storageFunctions,
|
|
742
|
-
...schedulerFunctions,
|
|
743
|
-
...httpsFunctions
|
|
744
|
-
];
|
|
745
|
-
|
|
746
|
-
// src/lib/commands/deploy/utils/create_deploy_index.ts
|
|
747
783
|
async function createTemporaryIndexFunctionFile(buildFunctionData) {
|
|
748
784
|
logger.debug("Creating temporary index file", buildFunctionData);
|
|
749
785
|
const code = await toDeployIndexCode(buildFunctionData);
|
|
@@ -949,8 +985,8 @@ async function processFunction(funcPath, options, environment, controllersPath)
|
|
|
949
985
|
Processing function: ${functionName}`);
|
|
950
986
|
const outputDir = join9(cwdDir2(), "dist", functionName);
|
|
951
987
|
const temporaryDir = join9(cwdDir2(), "tmp", functionName);
|
|
952
|
-
await
|
|
953
|
-
await
|
|
988
|
+
await mkdir2(join9(outputDir, "src"), { recursive: true });
|
|
989
|
+
await mkdir2(temporaryDir, { recursive: true });
|
|
954
990
|
await writeTextFile(join9(outputDir, "firebase.json"), createFirebaseConfig(options.nodeVersion));
|
|
955
991
|
await writeTextFile(
|
|
956
992
|
join9(outputDir, "src", "package.json"),
|
|
@@ -1127,7 +1163,7 @@ var deployCommand = new Command4("deploy").description("Builds and deploys all F
|
|
|
1127
1163
|
if (options.only) {
|
|
1128
1164
|
const onlyFunctions = options.only.split(",").map((f) => f.trim());
|
|
1129
1165
|
functionFiles = functionFiles.filter((file) => {
|
|
1130
|
-
const functionName =
|
|
1166
|
+
const functionName = basename3(file).replace(/\.(ts|tsx|js)$/, "");
|
|
1131
1167
|
return onlyFunctions.includes(functionName);
|
|
1132
1168
|
});
|
|
1133
1169
|
}
|
|
@@ -1161,8 +1197,8 @@ Deployment failed for ${failedFunctions.length} functions.`);
|
|
|
1161
1197
|
|
|
1162
1198
|
// src/lib/commands/emulate.ts
|
|
1163
1199
|
import { existsSync as existsSync4, watch as watch2 } from "node:fs";
|
|
1164
|
-
import { mkdir as
|
|
1165
|
-
import { basename as
|
|
1200
|
+
import { mkdir as mkdir3, rm as rm2, writeFile as writeFile3 } from "node:fs/promises";
|
|
1201
|
+
import { basename as basename4, join as join11, relative as relative3 } from "node:path";
|
|
1166
1202
|
import { Command as Command5 } from "commander";
|
|
1167
1203
|
import { execa as execa2 } from "execa";
|
|
1168
1204
|
async function runInitScript(scriptsDirectory, initScript, projectId) {
|
|
@@ -1191,8 +1227,8 @@ async function runInitScript(scriptsDirectory, initScript, projectId) {
|
|
|
1191
1227
|
async function buildEmulatorFunctions(functionFiles, outputDir, options, controllersPath) {
|
|
1192
1228
|
const projectRoot = await findProjectRoot();
|
|
1193
1229
|
const tempDir = join11(process.cwd(), "tmp", "emulator");
|
|
1194
|
-
await
|
|
1195
|
-
await
|
|
1230
|
+
await mkdir3(tempDir, { recursive: true });
|
|
1231
|
+
await mkdir3(join11(outputDir, "src"), { recursive: true });
|
|
1196
1232
|
const exports = [];
|
|
1197
1233
|
for (const funcFile of functionFiles) {
|
|
1198
1234
|
const funcName = deriveFunctionName(funcFile, controllersPath);
|
|
@@ -1211,7 +1247,7 @@ async function buildEmulatorFunctions(functionFiles, outputDir, options, control
|
|
|
1211
1247
|
const combinedIndexContent = `${exports.join("\n")}
|
|
1212
1248
|
`;
|
|
1213
1249
|
const tempIndexPath = join11(tempDir, "index.ts");
|
|
1214
|
-
await
|
|
1250
|
+
await writeFile3(tempIndexPath, combinedIndexContent);
|
|
1215
1251
|
logger.debug("Generated combined index file:", combinedIndexContent);
|
|
1216
1252
|
await buildFunction({
|
|
1217
1253
|
inputFile: tempIndexPath,
|
|
@@ -1224,16 +1260,16 @@ async function buildEmulatorFunctions(functionFiles, outputDir, options, control
|
|
|
1224
1260
|
name: "functions",
|
|
1225
1261
|
type: "module",
|
|
1226
1262
|
main: "index.js",
|
|
1227
|
-
engines: { node: `${options.nodeVersion ||
|
|
1263
|
+
engines: { node: `${options.nodeVersion || DEFAULT_NODE_VERSION}` }
|
|
1228
1264
|
};
|
|
1229
|
-
await
|
|
1265
|
+
await writeFile3(join11(outputDir, "src", "package.json"), JSON.stringify(packageJson, null, 2));
|
|
1230
1266
|
logger.info("Installing dependencies...");
|
|
1231
1267
|
try {
|
|
1232
1268
|
await execa2("npm", ["install"], {
|
|
1233
1269
|
cwd: join11(outputDir, "src"),
|
|
1234
1270
|
stdio: "inherit"
|
|
1235
1271
|
});
|
|
1236
|
-
} catch (
|
|
1272
|
+
} catch (_error) {
|
|
1237
1273
|
throw new Error("Failed to install dependencies");
|
|
1238
1274
|
}
|
|
1239
1275
|
logger.info("Dependencies installed.");
|
|
@@ -1248,7 +1284,7 @@ async function generateFirebaseJson(outputDir, options) {
|
|
|
1248
1284
|
{
|
|
1249
1285
|
source: "src",
|
|
1250
1286
|
codebase: "default",
|
|
1251
|
-
runtime: `nodejs${options.nodeVersion ||
|
|
1287
|
+
runtime: `nodejs${options.nodeVersion || DEFAULT_NODE_VERSION}`
|
|
1252
1288
|
}
|
|
1253
1289
|
],
|
|
1254
1290
|
emulators: {
|
|
@@ -1268,14 +1304,14 @@ async function generateFirebaseJson(outputDir, options) {
|
|
|
1268
1304
|
rules: options.storageRules
|
|
1269
1305
|
};
|
|
1270
1306
|
}
|
|
1271
|
-
await
|
|
1307
|
+
await writeFile3(join11(outputDir, "firebase.json"), JSON.stringify(firebaseConfig, null, 2));
|
|
1272
1308
|
}
|
|
1273
1309
|
async function watchAndRebuild(functionsPath, functionFiles, outputDir, options, controllersPath) {
|
|
1274
1310
|
logger.info("Watching for file changes...");
|
|
1275
1311
|
const watcher = watch2(functionsPath, { recursive: true });
|
|
1276
1312
|
watcher.on("change", async (_eventType, filename) => {
|
|
1277
1313
|
if (filename && typeof filename === "string" && (filename.endsWith(".ts") || filename.endsWith(".tsx"))) {
|
|
1278
|
-
logger.info(`File changed: ${
|
|
1314
|
+
logger.info(`File changed: ${basename4(filename)}, rebuilding...`);
|
|
1279
1315
|
try {
|
|
1280
1316
|
await buildEmulatorFunctions(functionFiles, outputDir, options, controllersPath);
|
|
1281
1317
|
logger.info("Rebuild complete.");
|
|
@@ -1311,7 +1347,7 @@ var emulateCommand = new Command5("emulate").description("Starts the Firebase em
|
|
|
1311
1347
|
options.initScript || "init.ts",
|
|
1312
1348
|
options.projectId
|
|
1313
1349
|
);
|
|
1314
|
-
} catch (
|
|
1350
|
+
} catch (_error) {
|
|
1315
1351
|
logger.error("Failed to run init script, continuing without initialization...");
|
|
1316
1352
|
}
|
|
1317
1353
|
}
|
|
@@ -1323,7 +1359,7 @@ var emulateCommand = new Command5("emulate").description("Starts the Firebase em
|
|
|
1323
1359
|
}
|
|
1324
1360
|
logger.info(`Found ${functionFiles.length} functions to build.`);
|
|
1325
1361
|
const outputDir = join11(process.cwd(), "dist", "emulator");
|
|
1326
|
-
await
|
|
1362
|
+
await mkdir3(outputDir, { recursive: true });
|
|
1327
1363
|
logger.info("Building functions for emulator...");
|
|
1328
1364
|
await buildEmulatorFunctions(functionFiles, outputDir, options, functionsPath);
|
|
1329
1365
|
logger.info("Build complete.");
|
|
@@ -1428,7 +1464,7 @@ var rulesCommand = new Command7("rules").description("Deploys Firestore, Storage
|
|
|
1428
1464
|
);
|
|
1429
1465
|
exitCode2(1);
|
|
1430
1466
|
}
|
|
1431
|
-
const
|
|
1467
|
+
const _rulesDir = join13(cwdDir2(), options.rulesDirectory || "src/rules");
|
|
1432
1468
|
const ruleFiles = await findRuleFiles(options.rulesDirectory || "src/rules");
|
|
1433
1469
|
if (ruleFiles.length === 0) {
|
|
1434
1470
|
logger.warn("No rule or index files found to deploy.");
|
|
@@ -1436,7 +1472,7 @@ var rulesCommand = new Command7("rules").description("Deploys Firestore, Storage
|
|
|
1436
1472
|
}
|
|
1437
1473
|
logger.info(`Found ${ruleFiles.length} rule/index file(s) to deploy.`);
|
|
1438
1474
|
const tempDir = join13(cwdDir2(), "dist", "rules-deploy");
|
|
1439
|
-
await
|
|
1475
|
+
await mkdir2(join13(tempDir), { recursive: true });
|
|
1440
1476
|
const firebaseConfig = {};
|
|
1441
1477
|
for (const rule of ruleFiles) {
|
|
1442
1478
|
if (rule.type === "firestore") {
|
|
@@ -1498,7 +1534,7 @@ import { execa as execa5 } from "execa";
|
|
|
1498
1534
|
import prompts from "prompts";
|
|
1499
1535
|
|
|
1500
1536
|
// src/lib/utils/env.ts
|
|
1501
|
-
import { existsSync as existsSync6, readFileSync as
|
|
1537
|
+
import { existsSync as existsSync6, readFileSync as readFileSync3 } from "node:fs";
|
|
1502
1538
|
import { join as join14 } from "node:path";
|
|
1503
1539
|
async function getScriptEnvironment(flavor) {
|
|
1504
1540
|
const envPath = join14(process.cwd(), `.env.${flavor}`);
|
|
@@ -1507,7 +1543,7 @@ async function getScriptEnvironment(flavor) {
|
|
|
1507
1543
|
logger.debug(`.env.${flavor} file not found, continuing without it.`);
|
|
1508
1544
|
return {};
|
|
1509
1545
|
}
|
|
1510
|
-
const envContent =
|
|
1546
|
+
const envContent = readFileSync3(envPath, "utf-8");
|
|
1511
1547
|
const env = {};
|
|
1512
1548
|
let currentKey = "";
|
|
1513
1549
|
let currentValue = "";
|
|
@@ -1642,7 +1678,7 @@ var scriptsCommand = new Command8("scripts").description("Run a script from the
|
|
|
1642
1678
|
|
|
1643
1679
|
// src/main.ts
|
|
1644
1680
|
var program = new Command9();
|
|
1645
|
-
program.name("firestack").version("
|
|
1681
|
+
program.name("firestack").version("0.0.12").description("CLI for building and deploying Firebase Cloud Functions.");
|
|
1646
1682
|
program.addCommand(buildCommand);
|
|
1647
1683
|
program.addCommand(deployCommand);
|
|
1648
1684
|
program.addCommand(scriptsCommand);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snorreks/firestack",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"description": "CLI tool for deploying Firebase Cloud Functions with ease",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
"engines": {
|
|
17
17
|
"node": ">=20.0.0"
|
|
18
18
|
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
19
22
|
"repository": {
|
|
20
23
|
"type": "git",
|
|
21
24
|
"url": "git+https://github.com/snorreks/firestack.git"
|